Skip to content

Commit 5fa466f

Browse files
committed
Use ESM
1 parent cb2e9f9 commit 5fa466f

File tree

6 files changed

+31
-43
lines changed

6 files changed

+31
-43
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
.DS_Store
2-
.nyc_output/
3-
/node_modules/
2+
node_modules/
43
coverage/

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
coverage/
2-
*.json
32
*.md

index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
'use strict'
2-
3-
var convert = require('unist-util-is/convert')
4-
5-
module.exports = filter
1+
import {convert} from 'unist-util-is'
62

73
var own = {}.hasOwnProperty
84

9-
function filter(tree, options, test) {
5+
export function filter(tree, options, test) {
106
var is = convert(test || options)
11-
var cascade = options.cascade == null ? true : options.cascade
7+
var cascade =
8+
options.cascade === undefined || options.cascade === null
9+
? true
10+
: options.cascade
1211

1312
return preorder(tree, null, null)
1413

package.json

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,35 @@
2424
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
2525
"Christian Murphy <christian.murphy.42@gmail.com>"
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-
"unist-util-is": "^4.0.0"
36+
"unist-util-is": "^5.0.0"
3437
},
3538
"devDependencies": {
3639
"@types/mdast": "^3.0.0",
40+
"c8": "^7.0.0",
3741
"dtslint": "^4.0.0",
38-
"nyc": "^15.0.0",
3942
"prettier": "^2.0.0",
4043
"remark-cli": "^9.0.0",
4144
"remark-preset-wooorm": "^8.0.0",
4245
"tape": "^5.0.0",
43-
"unist-builder": "^2.0.0",
46+
"unist-builder": "^3.0.0",
4447
"xo": "^0.38.0"
4548
},
4649
"scripts": {
4750
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
48-
"test-api": "node test",
49-
"test-coverage": "nyc --reporter lcov tape test.js",
50-
"test-types": "dtslint types",
51+
"test-api": "node test.js",
52+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
53+
"test-types": "# dtslint types",
5154
"test": "npm run format && npm run test-coverage && npm run test-types"
5255
},
53-
"nyc": {
54-
"check-coverage": true,
55-
"lines": 100,
56-
"functions": 100,
57-
"branches": 100
58-
},
5956
"prettier": {
6057
"tabWidth": 2,
6158
"useTabs": false,
@@ -66,21 +63,11 @@
6663
},
6764
"xo": {
6865
"prettier": true,
69-
"esnext": false,
7066
"rules": {
71-
"eqeqeq": [
72-
"error",
73-
"always",
74-
{
75-
"null": "ignore"
76-
}
77-
],
78-
"no-eq-null": "off",
67+
"no-var": "off",
68+
"prefer-arrow-callback": "off",
7969
"unicorn/explicit-length-check": "off"
80-
},
81-
"ignores": [
82-
"unist-util-position.js"
83-
]
70+
}
8471
},
8572
"remarkConfig": {
8673
"plugins": [

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ 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-filter
2225
## Use
2326

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

2831
var tree = u('root', [
2932
u('leaf', '1'),
@@ -50,6 +53,9 @@ Yields:
5053

5154
## API
5255

56+
This package exports the following identifiers: `filter`.
57+
There is no default export.
58+
5359
### `filter(tree[, options][, test])`
5460

5561
Create a new [tree][] consisting of copies of 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 filter = require('.')
1+
import test from 'tape'
2+
import {u} from 'unist-builder'
3+
import {filter} from './index.js'
64

75
test('should not traverse into children of filtered out nodes', function (t) {
86
var tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])

0 commit comments

Comments
 (0)