Skip to content

Commit d596f2f

Browse files
committed
🚀
0 parents  commit d596f2f

33 files changed

+6758
-0
lines changed

‎.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["env"]
3+
}

‎.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist

‎.eslintrc.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
extends: [
3+
'airbnb-base'
4+
],
5+
parser: 'babel-eslint',
6+
env: {
7+
es6: true
8+
},
9+
overrides: [{
10+
files: ['*.test.*'],
11+
env: {
12+
jest: true
13+
}
14+
}, {
15+
files: ['karma.conf.js'],
16+
env: {
17+
node: true
18+
},
19+
rules: {
20+
'import/no-extraneous-dependencies': 'off',
21+
},
22+
}, {
23+
files: ['src/*'],
24+
env: {
25+
browser: true
26+
},
27+
}],
28+
rules: {
29+
'no-use-before-define': 'off',
30+
},
31+
};

‎.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/node_modules
2+
npm-debug.log
3+
yarn-error.log
4+
.DS_Store
5+
/dist

‎.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: node_js
2+
node_js:
3+
- lts/* # latest long term support release
4+
- stable # latest stable release
5+
script:
6+
- yarn test
7+
- yarn lint
8+
cache: yarn

‎LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(ISC License)
2+
3+
Copyright (c) 2018 Keith McKnight <[email protected]>
4+
5+
Permission to use, copy, modify, and/or distribute this software for any purpose
6+
with or without fee is hereby granted, provided that the above copyright notice
7+
and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
13+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
14+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
15+
THIS SOFTWARE.

‎README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# hast-util-to-dom [![Build Status][travis-badge]][travis]
2+
3+
Transform [HAST][] to a DOM tree
4+
5+
## Installation
6+
7+
[yarn][]:
8+
9+
```bash
10+
yarn add hast-util-to-dom
11+
```
12+
13+
[npm][]:
14+
15+
```bash
16+
npm install hast-util-to-dom
17+
```
18+
19+
## Usage
20+
21+
This utility is intended for browser use!
22+
23+
```js
24+
import toDOM from 'hast-util-to-dom';
25+
26+
const el = toDOM({
27+
type: 'element',
28+
tagName: 'h1',
29+
properties: {},
30+
children: [{type: 'text', value: 'World!'}]
31+
});
32+
33+
console.log(el);
34+
```
35+
36+
This will create a DOM node like this:
37+
38+
```html
39+
<h1>World!</h1>
40+
```
41+
42+
If you want a string of HTML, you have a few options:
43+
44+
```js
45+
// Outer HTML, eg. if you want an entire fragment
46+
console.log(el.outerHTML);
47+
// "<h1>World</h1>"
48+
49+
// Inner HTML, eg. if you have a wrapping element you don't need
50+
console.log(el.innerHTML);
51+
// "World"
52+
53+
// Full serialization, eg. when you want the whole document
54+
console.log(new XMLSerializer().serializeToString(el));
55+
// "<div xmlns="http://www.w3.org/1999/xhtml">World</div>"
56+
```
57+
58+
Due to the nature of various browser implementations, you may notice cross-browser differences in the serialized output, especially with respect to whitespace or self-closing tags. Buddy, that's the web!
59+
60+
## API
61+
62+
### `toDOM(node)`
63+
64+
Transform a [HAST Node][node] to DOM `Node`.
65+
66+
## License
67+
68+
[ISC][license] © [Keith McKnight][author]
69+
70+
<!-- Definitions -->
71+
72+
[travis-badge]: https://img.shields.io/travis/kmck/hast-util-to-dom.svg
73+
74+
[travis]: https://travis-ci.org/kmck/hast-util-to-dom
75+
76+
[yarn]: https://yarnpkg.com/lang/en/docs/install
77+
78+
[npm]: https://docs.npmjs.com/cli/install
79+
80+
[license]: LICENSE
81+
82+
[author]: https://keith.mcknig.ht
83+
84+
[hast]: https://github.com/syntax-tree/hast
85+
86+
[hast-util-to-parse5]: https://github.com/syntax-tree/hast-util-to-parse5
87+
88+
[node]: https://github.com/syntax-tree/hast#ast
89+
90+
[vfile]: https://github.com/vfile/vfile

‎karma.conf.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const babel = require('rollup-plugin-babel');
2+
const { default: babelrc } = require('babelrc-rollup');
3+
const commonjs = require('rollup-plugin-commonjs');
4+
const resolve = require('rollup-plugin-node-resolve');
5+
6+
module.exports = function karmaConfig(config) {
7+
config.set({
8+
frameworks: ['jasmine'],
9+
files: [
10+
'src/index.test.js',
11+
],
12+
preprocessors: {
13+
'**/*.test.js': ['rollup'],
14+
},
15+
rollupPreprocessor: {
16+
output: {
17+
name: 'Spangle',
18+
format: 'iife',
19+
sourcemap: 'inline',
20+
},
21+
plugins: [
22+
resolve({
23+
browser: true,
24+
extensions: ['.mjs', '.js', '.json', '.node'],
25+
}),
26+
commonjs(),
27+
babel(babelrc()),
28+
],
29+
},
30+
reporters: ['mocha'],
31+
port: 9876, // karma web server port
32+
colors: true,
33+
logLevel: config.LOG_INFO,
34+
browsers: [
35+
'Chrome',
36+
'ChromeHeadless',
37+
'Firefox',
38+
'FirefoxHeadless',
39+
],
40+
autoWatch: false,
41+
// singleRun: false, // Karma captures browsers, runs the tests and exits
42+
concurrency: Infinity,
43+
});
44+
};

‎package.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "hast-util-to-dom",
3+
"version": "1.0.2",
4+
"description": "Transform HAST to DOM",
5+
"main": "dist/hast-util-to-dom.js",
6+
"module": "dist/hast-util-to-dom.mjs",
7+
"repository": "https://github.com/syntax-tree/hast-util-to-dom",
8+
"author": "Keith McKnight <[email protected]> (https://keith.mcknig.ht)",
9+
"license": "ISC",
10+
"scripts": {
11+
"build": "rollup -c",
12+
"lint": "eslint .",
13+
"test": "jest",
14+
"test:karma": "karma start --single-run --browsers ChromeHeadless,FirefoxHeadless,Safari karma.conf.js",
15+
"test:karma:chrome": "karma start --single-run --browsers ChromeHeadless karma.conf.js",
16+
"test:karma:firefox": "karma start --single-run --browsers FirefoxHeadless karma.conf.js",
17+
"test:karma:safari": "karma start --single-run --browsers Safari karma.conf.js",
18+
"test:dev": "jest --watchAll"
19+
},
20+
"dependencies": {
21+
"property-information": "^3.2.0"
22+
},
23+
"devDependencies": {
24+
"babel-core": "^6.26.3",
25+
"babel-eslint": "^8.2.3",
26+
"babel-jest": "^23.0.1",
27+
"babel-plugin-external-helpers": "^6.22.0",
28+
"babel-preset-env": "^1.7.0",
29+
"babelrc-rollup": "^3.0.0",
30+
"bowser": "^1.9.3",
31+
"eslint": "^4.19.1",
32+
"eslint-config-airbnb-base": "^12.1.0",
33+
"eslint-plugin-import": "^2.12.0",
34+
"glob": "^7.1.2",
35+
"hastscript": "^3.1.0",
36+
"jasmine-core": "^3.1.0",
37+
"jest-cli": "^23.1.0",
38+
"karma": "^2.0.2",
39+
"karma-chrome-launcher": "^2.2.0",
40+
"karma-firefox-launcher": "^1.1.0",
41+
"karma-jasmine": "^1.1.2",
42+
"karma-mocha-reporter": "^2.2.5",
43+
"karma-rollup-preprocessor": "^6.0.0",
44+
"karma-safari-launcher": "^1.0.0",
45+
"rollup": "^0.59.4",
46+
"rollup-plugin-babel": "^3.0.4",
47+
"rollup-plugin-commonjs": "^9.1.3",
48+
"rollup-plugin-node-resolve": "^3.3.0"
49+
},
50+
"files": [
51+
"dist"
52+
]
53+
}

‎rollup.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import babel from 'rollup-plugin-babel';
2+
3+
import pkg from './package.json';
4+
5+
export default {
6+
input: 'src/index.js',
7+
output: [
8+
{ file: pkg.main, format: 'cjs' },
9+
{ file: pkg.module, format: 'es' },
10+
],
11+
plugins: [
12+
babel({
13+
presets: [
14+
['env', { modules: false }],
15+
],
16+
babelrc: false,
17+
}),
18+
],
19+
external: ['property-information'],
20+
};

0 commit comments

Comments
 (0)