Skip to content

Commit 9d7f999

Browse files
committed
Use ESM
1 parent 7b0e1ec commit 9d7f999

File tree

7 files changed

+26
-42
lines changed

7 files changed

+26
-42
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-
unist-util-modify-children.js
7-
unist-util-modify-children.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-
unist-util-modify-children.js
3-
unist-util-modify-children.min.js
4-
*.json
52
*.md

index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
'use strict'
2-
3-
var iterate = require('array-iterate')
4-
5-
module.exports = modifierFactory
1+
import {arrayIterate} from 'array-iterate'
62

73
// Turn `callback` into a child-modifier accepting a parent. See
84
// `array-iterate` for more info.
9-
function modifierFactory(callback) {
5+
export function modifyChildren(callback) {
106
return iterator
117

128
function iterator(parent) {
139
if (!parent || !parent.children) {
1410
throw new Error('Missing children in `parent` for `modifier`')
1511
}
1612

17-
iterate(parent.children, iteratee, parent)
13+
arrayIterate(parent.children, iteratee, parent)
1814
}
1915

2016
// Pass the context as the third argument to `callback`.

package.json

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,33 @@
2424
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
2525
"Merlijn Vos <merlijn@soverin.net>"
2626
],
27+
"sideEffects": false,
28+
"type": "module",
29+
"main": "index.js",
30+
"types": "types/index.d.ts",
2731
"files": [
2832
"index.js",
2933
"types/index.d.ts"
3034
],
31-
"types": "types/index.d.ts",
3235
"dependencies": {
33-
"array-iterate": "^1.0.0"
36+
"array-iterate": "^2.0.0"
3437
},
3538
"devDependencies": {
36-
"browserify": "^17.0.0",
39+
"c8": "^7.0.0",
3740
"dtslint": "^4.0.0",
38-
"nyc": "^15.0.0",
3941
"prettier": "^2.0.0",
4042
"remark-cli": "^9.0.0",
4143
"remark-preset-wooorm": "^8.0.0",
4244
"tape": "^5.0.0",
43-
"tinyify": "^3.0.0",
4445
"unified": "^9.0.0",
4546
"xo": "^0.38.0"
4647
},
4748
"scripts": {
4849
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
49-
"build-bundle": "browserify . -s unistUtilModifyChildren -o unist-util-modify-children.js",
50-
"build-mangle": "browserify . -s unistUtilModifyChildren -o unist-util-modify-children.min.js -p tinyify",
51-
"build": "npm run build-bundle && npm run build-mangle",
52-
"test-api": "node test",
53-
"test-coverage": "nyc --reporter lcov tape test.js",
50+
"test-api": "node test.js",
51+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
5452
"test-types": "dtslint types",
55-
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
53+
"test": "npm run format && npm run test-coverage && npm run test-types"
5654
},
5755
"prettier": {
5856
"tabWidth": 2,
@@ -64,17 +62,10 @@
6462
},
6563
"xo": {
6664
"prettier": true,
67-
"esnext": false,
68-
"ignore": [
69-
"types/",
70-
"unist-util-modify-children.js"
71-
]
72-
},
73-
"nyc": {
74-
"check-coverage": true,
75-
"lines": 100,
76-
"functions": 100,
77-
"branches": 100
65+
"rules": {
66+
"no-var": "off",
67+
"prefer-arrow-callback": "off"
68+
}
7869
},
7970
"remarkConfig": {
8071
"plugins": [

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Modify direct children of a parent.
1212

1313
## Install
1414

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.
17+
1518
[npm][]:
1619

1720
```sh
@@ -21,8 +24,8 @@ npm install unist-util-modify-children
2124
## Use
2225

2326
```js
24-
var u = require('unist-builder')
25-
var modifyChildren = require('unist-util-modify-children')
27+
import u from 'unist-builder'
28+
import {modifyChildren} from 'unist-util-modify-children'
2629

2730
var modify = modifyChildren(modifier)
2831

@@ -59,6 +62,9 @@ Yields:
5962

6063
## API
6164

65+
This package exports the following identifiers: `modifyChildren`.
66+
There is no default export.
67+
6268
### `modify = modifyChildren(modifier)`
6369

6470
Wrap [`modifier`][modifier] to be invoked for each child in the node given to

test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var modifyChildren = require('.')
1+
import test from 'tape'
2+
import {modifyChildren} from './index.js'
53

64
var noop = Function.prototype
75

types/tslint.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{
32
"extends": "dtslint/dtslint.json",
43
"rules": {

0 commit comments

Comments
 (0)