Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(browser): support browsers as well as node #8

Merged
merged 4 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules
/dist
*.js
*.d.ts
*.map
*.tsbuildinfo
*.tsbuildinfo
!src/jsx/*.d.ts
6 changes: 3 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**/**
!readme.md
!src/**/*.js
!src/**/*.d.ts
!dist/*.?(js|d.ts)
!README.md
!src/**/*.?(js|d.ts)
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"**/*?.js": {
"when": "$(basename).tsx"
},
"**/*.d.ts": true,
"*/*.d.ts": true,
"src/jsx/*.d.ts": false,
"**/*.map": true,
"**/*.tsbuildinfo": true
},
Expand Down
13 changes: 13 additions & 0 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ However, the following piece of code will **NOT** compile:
<a foo="bar"></a>; // => Error: Property 'foo' does not exist on type 'HtmlAnchorTag'
```

## Supported environments

Typed HTML supports both NodeJS and (since 2.0) the browser.

For use in the browser, either load typed-html as a module, or use a bundler like webpack or rollup to bundle the package for you.

```ts
// Direct ES import:
import * as elements from './node_modules/typed-html/dist/elements.js';
// OR, when using a bundler like rollup or webpack
import * as elements from 'typed-html';
```

## Supported scenarios

All template scenarios are supported with plain TypeScript.
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"description": "TypeSafe HTML templates using TypeScript. No need to learn a template library.",
"main": "src/elements.js",
"typings": "src/elements.d.ts",
"module": "dist/elements.js",
"repository": {
"type": "git",
"url": "https://github.com/nicojs/typed-html"
},
"scripts": {
"prebuild": "rimraf \"+(test|src)/**/*.+(js|map|tsbuildinfo|d.ts)\" dist",
"build": "tsc -b",
"prebuild": "rimraf \"+(test|src)/*.+(js|map|tsbuildinfo|d.ts)\" dist",
"build": "tsc -b && tsc -p src --outDir dist --module esnext --target esnext",
"pretest": "npm run build",
"test": "mocha",
"preversion": "npm test",
Expand Down
12 changes: 5 additions & 7 deletions src/elements.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/// <reference path="./jsx/element-types.ts" />
/// <reference path="./jsx/events.ts" />
/// <reference path="./jsx/intrinsic-elements.ts" />

import * as os from 'os';
/// <reference path="./jsx/element-types.d.ts" />
/// <reference path="./jsx/events.d.ts" />
/// <reference path="./jsx/intrinsic-elements.d.ts" />

type AttributeValue = number | string | Date | boolean;

Expand Down Expand Up @@ -79,8 +77,8 @@ const attributesToString = (attributes: Attributes | undefined): string => {
const contentsToString = (contents: any[] | undefined) => {
if (contents) {
return contents
.map(elements => Array.isArray(elements) ? elements.join(os.EOL) : elements)
.join(os.EOL);
.map(elements => Array.isArray(elements) ? elements.join('\n') : elements)
.join('\n');
} else {
return '';
}
Expand Down
Loading