Skip to content

Commit 37efcc5

Browse files
committed
Use ESM
1 parent b87b381 commit 37efcc5

File tree

5 files changed

+30
-40
lines changed

5 files changed

+30
-40
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
.nyc_output/
21
coverage/
32
node_modules/

index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
'use strict'
1+
import {convert} from 'unist-util-is'
22

3-
var convert = require('unist-util-is/convert')
4-
5-
module.exports = remove
6-
7-
function remove(tree, options, test) {
3+
export function remove(tree, options, test) {
84
var is = convert(test || options)
9-
var cascade = options.cascade == null ? true : options.cascade
5+
var cascade =
6+
options.cascade === undefined || options.cascade === null
7+
? true
8+
: options.cascade
109

1110
return preorder(tree, null, null)
1211

@@ -21,7 +20,7 @@ function remove(tree, options, test) {
2120
return null
2221
}
2322

24-
if (children && children.length) {
23+
if (children && children.length > 0) {
2524
// Move all living children to the beginning of the children array.
2625
while (++childIndex < children.length) {
2726
if (preorder(children[childIndex], childIndex, node)) {

package.json

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,35 @@
2929
"Eugene Sharygin <[email protected]>",
3030
"Titus Wormer <[email protected]> (https://wooorm.com)"
3131
],
32+
"sideEffects": false,
33+
"type": "module",
34+
"main": "index.js",
35+
"types": "types/index.d.ts",
3236
"files": [
3337
"index.js",
3438
"types/index.d.ts"
3539
],
36-
"types": "types/index.d.ts",
3740
"dependencies": {
38-
"unist-util-is": "^4.0.0"
41+
"unist-util-is": "^5.0.0"
3942
},
4043
"devDependencies": {
44+
"c8": "^7.0.0",
4145
"dtslint": "^4.0.0",
4246
"nyc": "^15.0.0",
4347
"prettier": "^2.0.0",
4448
"remark-cli": "^9.0.0",
4549
"remark-preset-wooorm": "^8.0.0",
4650
"tape": "^5.0.0",
47-
"unist-builder": "^2.0.0",
51+
"unist-builder": "^3.0.0",
4852
"xo": "^0.38.0"
4953
},
5054
"scripts": {
5155
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
52-
"test-api": "node test",
53-
"test-coverage": "nyc --reporter lcov tape test.js",
56+
"test-api": "node test.js",
57+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
5458
"test-types": "dtslint types",
5559
"test": "npm run format && npm run test-coverage && npm run test-types"
5660
},
57-
"nyc": {
58-
"check-coverage": true,
59-
"lines": 100,
60-
"functions": 100,
61-
"branches": 100
62-
},
6361
"prettier": {
6462
"tabWidth": 2,
6563
"useTabs": false,
@@ -70,17 +68,9 @@
7068
},
7169
"xo": {
7270
"prettier": true,
73-
"esnext": false,
7471
"rules": {
75-
"eqeqeq": [
76-
"error",
77-
"always",
78-
{
79-
"null": "ignore"
80-
}
81-
],
82-
"no-eq-null": "off",
83-
"unicorn/explicit-length-check": "off"
72+
"no-var": "off",
73+
"prefer-arrow-callback": "off"
8474
}
8575
},
8676
"remarkConfig": {

readme.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ pass the given test.
1313

1414
## Install
1515

16+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
17+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
18+
1619
[npm][]:
1720

1821
```sh
@@ -22,8 +25,8 @@ npm install unist-util-remove
2225
## Use
2326

2427
```js
25-
var u = require('unist-builder')
26-
var remove = require('unist-util-remove')
28+
import {u} from 'unist-builder'
29+
import {remove} from 'unist-util-remove'
2730

2831
var tree = u('root', [
2932
u('leaf', '1'),
@@ -49,16 +52,17 @@ Yields: (note the parent of `5` is also removed, due to `options.cascade`)
4952
children: [
5053
{
5154
type: 'node',
52-
children: [
53-
{ type: 'node', children: [ { type: 'other', value: '4' } ] }
54-
]
55+
children: [{type: 'node', children: [{type: 'other', value: '4'}]}]
5556
}
5657
]
5758
}
5859
```
5960

6061
## API
6162

63+
This package exports the following identifiers: `remove`.
64+
There is no default export.
65+
6266
### `remove(tree[, options][, test])`
6367

6468
Mutate the given [tree][] by removing all nodes that pass `test`.

test.js

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

75
test('should compare nodes by partial properties', function (t) {
86
var tree = u('node', [u('leaf', '1'), u('leaf', '2')])

0 commit comments

Comments
 (0)