Skip to content

Commit d4e9db7

Browse files
committed
Use ESM
1 parent 305a76b commit d4e9db7

File tree

6 files changed

+26
-50
lines changed

6 files changed

+26
-50
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
.DS_Store
22
*.log
3-
.nyc_output/
43
coverage/
54
node_modules/
6-
hast-util-from-text.js
7-
hast-util-from-text.min.js
85
yarn.lock

.prettierignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
coverage/
2-
hast-util-from-text.js
3-
hast-util-from-text.min.js
4-
*.json
52
*.md

index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
'use strict'
2-
3-
module.exports = fromText
4-
51
var search = /\r?\n|\r/g
62

73
// Implementation of the `innerText` setter:
84
// <https://html.spec.whatwg.org/#the-innertext-idl-attribute>
95
// Note that `innerText` only exists on element.
106
// In this utility, we accept all parent nodes and handle them as elements, and
117
// for all literals we set the `value` of the given node the the given value.
12-
function fromText(node, content) {
13-
var value = content == null ? '' : String(content)
8+
export function fromText(node, content) {
9+
var value = content === undefined || content === null ? '' : String(content)
1410
var nodes = []
1511
var start = 0
1612
var match

package.json

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,27 @@
2525
"contributors": [
2626
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
2727
],
28+
"sideEffects": false,
29+
"type": "module",
30+
"main": "index.js",
2831
"files": [
2932
"index.js"
3033
],
3134
"devDependencies": {
32-
"browserify": "^17.0.0",
33-
"hastscript": "^6.0.0",
34-
"nyc": "^15.0.0",
35+
"c8": "^7.0.0",
36+
"hastscript": "^7.0.0",
3537
"prettier": "^2.0.0",
3638
"remark-cli": "^9.0.0",
3739
"remark-preset-wooorm": "^8.0.0",
3840
"tape": "^5.0.0",
39-
"tinyify": "^3.0.0",
40-
"unist-builder": "^2.0.0",
41-
"xo": "^0.38.0"
41+
"unist-builder": "^3.0.0",
42+
"xo": "^0.39.0"
4243
},
4344
"scripts": {
4445
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
45-
"build-bundle": "browserify . -s hastUtilFromText -o hast-util-from-text.js",
46-
"build-mangle": "browserify . -s hastUtilFromText -o hast-util-from-text.min.js -p tinyify",
47-
"build": "npm run build-bundle && npm run build-mangle",
48-
"test-api": "node test",
49-
"test-coverage": "nyc --reporter lcov tape test.js",
50-
"test": "npm run format && npm run build && npm run test-coverage"
51-
},
52-
"nyc": {
53-
"check-coverage": true,
54-
"lines": 100,
55-
"functions": 100,
56-
"branches": 100
46+
"test-api": "node test.js",
47+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
48+
"test": "npm run format && npm run test-coverage"
5749
},
5850
"prettier": {
5951
"tabWidth": 2,
@@ -65,19 +57,9 @@
6557
},
6658
"xo": {
6759
"prettier": true,
68-
"esnext": false,
69-
"ignores": [
70-
"hast-util-from-text.js"
71-
],
7260
"rules": {
73-
"eqeqeq": [
74-
"error",
75-
"always",
76-
{
77-
"null": "ignore"
78-
}
79-
],
80-
"no-eq-null": "off"
61+
"no-var": "off",
62+
"prefer-arrow-callback": "off"
8163
}
8264
},
8365
"remarkConfig": {

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ instead of line breaks.
1818

1919
## Install
2020

21+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
22+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
23+
2124
[npm][]:
2225

2326
```sh
@@ -27,8 +30,8 @@ npm install hast-util-from-text
2730
## Use
2831

2932
```js
30-
var h = require('hastscript')
31-
var fromText = require('hast-util-from-text')
33+
import {h} from 'hastscript'
34+
import {fromText} from 'hast-util-from-text'
3235

3336
fromText(h('p'), 'Alpha')
3437
// { type: 'element',
@@ -54,6 +57,9 @@ fromText(h('p'), 'Delta\nEcho')
5457

5558
## API
5659

60+
This package exports the following identifiers: `fromText`.
61+
There is no default export.
62+
5763
### `fromText(node[, value])`
5864

5965
If the given `node` is a [*literal*][literal], set that to the given `value` or

test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var u = require('unist-builder')
5-
var h = require('hastscript')
6-
var fromText = require('.')
1+
import test from 'tape'
2+
import {u} from 'unist-builder'
3+
import {h} from 'hastscript'
4+
import {fromText} from './index.js'
75

86
test('hast-util-from-text', function (t) {
97
t.deepEqual(

0 commit comments

Comments
 (0)