Skip to content

Commit ed90b0e

Browse files
committed
Use ESM
1 parent 810e58a commit ed90b0e

File tree

26 files changed

+205
-240
lines changed

26 files changed

+205
-240
lines changed

Diff for: .babelrc

-3
This file was deleted.

Diff for: index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {fromDom} from './lib/index.js'

Diff for: src/index.js renamed to lib/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import ns from 'web-namespaces'
2-
import h from 'hastscript/html.js'
3-
import s from 'hastscript/svg.js'
1+
import {webNamespaces} from 'web-namespaces'
2+
import {h, s} from 'hastscript'
43

54
const ELEMENT_NODE = 1
65
const TEXT_NODE = 3
@@ -57,10 +56,11 @@ function comment(node) {
5756
// Transform an element.
5857
function element(node) {
5958
const space = node.namespaceURI
60-
const fn = space === ns.svg ? s : h
61-
const tagName = space === ns.html ? node.tagName.toLowerCase() : node.tagName
59+
const fn = space === webNamespaces.svg ? s : h
60+
const tagName =
61+
space === webNamespaces.html ? node.tagName.toLowerCase() : node.tagName
6262
const content =
63-
space === ns.html && tagName === 'template' ? node.content : node
63+
space === webNamespaces.html && tagName === 'template' ? node.content : node
6464
const attributes = node.getAttributeNames()
6565
const {length} = attributes
6666
const props = {}
@@ -94,6 +94,6 @@ function all(node) {
9494
return children
9595
}
9696

97-
export default function fromDOM(node) {
97+
export function fromDom(node) {
9898
return transform(node) || {type: 'root', children: []}
9999
}

Diff for: package.json

+13-24
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,37 @@
2424
"Keith McKnight <[email protected]> (https://keith.mcknig.ht)",
2525
"Titus Wormer <[email protected]> (https://wooorm.com)"
2626
],
27-
"main": "dist/hast-util-from-dom.js",
27+
"main": "index.js",
2828
"module": "dist/hast-util-from-dom.mjs",
29+
"sideEffects": false,
30+
"type": "module",
2931
"files": [
30-
"dist/"
32+
"lib/",
33+
"index.js"
3134
],
3235
"dependencies": {
33-
"hastscript": "^6.0.0",
34-
"web-namespaces": "^1.0.0"
36+
"hastscript": "^7.0.0",
37+
"web-namespaces": "^2.0.0"
3538
},
3639
"devDependencies": {
3740
"@babel/core": "^7.0.0",
3841
"@babel/preset-env": "^7.0.0",
3942
"@rollup/plugin-babel": "^5.0.0",
40-
"babel-jest": "^26.0.0",
43+
"c8": "^7.0.0",
4144
"glob": "^7.0.0",
42-
"jest-cli": "^26.0.0",
45+
"jsdom": "^16.5.3",
4346
"prettier": "^2.0.0",
4447
"remark-cli": "^9.0.0",
4548
"remark-preset-wooorm": "^8.0.0",
4649
"rollup": "^2.0.0",
50+
"tape": "^5.2.2",
4751
"xo": "^0.39.0"
4852
},
4953
"scripts": {
50-
"build": "rollup -c",
5154
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
52-
"test:api": "jest",
53-
"test:dev": "jest --watchAll",
54-
"test": "npm run build && npm run format && npm run test:api"
55+
"test-api": "node test/index.js",
56+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
57+
"test": "npm run format && npm run test-coverage"
5558
},
5659
"prettier": {
5760
"tabWidth": 2,
@@ -64,20 +67,6 @@
6467
"xo": {
6568
"prettier": true
6669
},
67-
"jest": {
68-
"collectCoverage": true,
69-
"coveragePathIgnorePatterns": [
70-
"/src/utils.js"
71-
],
72-
"coverageThreshold": {
73-
"global": {
74-
"branches": 100,
75-
"functions": 100,
76-
"lines": 100,
77-
"statements": 100
78-
}
79-
}
80-
},
8170
"remarkConfig": {
8271
"plugins": [
8372
"preset-wooorm"

Diff for: readme.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212

1313
## Install
1414

15-
[yarn][]:
16-
17-
```sh
18-
yarn add hast-util-from-dom
19-
```
15+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
16+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
2017

2118
[npm][]:
2219

@@ -39,12 +36,12 @@ Say we have the following file, `example.html`:
3936
Suppose `example.js` is a bundled version of something like this:
4037

4138
```js
42-
import inspect from 'unist-util-inspect';
43-
import fromDom from 'hast-util-from-dom';
39+
import {inspect} from 'unist-util-inspect'
40+
import {fromDom} from 'hast-util-from-dom'
4441

45-
const hast = fromDom(document);
42+
const hast = fromDom(document)
4643

47-
console.log(inspect.noColor(hast));
44+
console.log(inspect.noColor(hast))
4845
```
4946

5047
Viewing `example.html` in a browser should yield the following in the console:
@@ -65,6 +62,9 @@ root[2]
6562

6663
## API
6764

65+
This package exports the following identifiers: `fromDom`.
66+
There is no default export.
67+
6868
### `fromDom(node)`
6969

7070
Transform a DOM tree to a [**hast**][hast] [*tree*][tree].
@@ -132,8 +132,6 @@ abide by its terms.
132132

133133
[chat]: https://github.com/syntax-tree/unist/discussions
134134

135-
[yarn]: https://yarnpkg.com/lang/en/docs/install
136-
137135
[npm]: https://docs.npmjs.com/cli/install
138136

139137
[license]: license

Diff for: rollup.config.js

-19
This file was deleted.

Diff for: src/index.test.js

-176
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)