Skip to content

Commit a069621

Browse files
committed
Use ESM
1 parent f5e9530 commit a069621

File tree

6 files changed

+26
-43
lines changed

6 files changed

+26
-43
lines changed

.gitignore

-3
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-find-before.js
7-
unist-util-find-before.min.js
85
yarn.lock

.prettierignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
coverage/
2-
unist-util-find-before.js
3-
unist-util-find-before.min.js
4-
*.json
52
*.md

index.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
'use strict'
1+
import {convert} from 'unist-util-is'
22

3-
var convert = require('unist-util-is/convert')
4-
5-
module.exports = findBefore
6-
7-
function findBefore(parent, index, test) {
3+
export function findBefore(parent, index, test) {
84
var is = convert(test)
95

106
if (!parent || !parent.type || !parent.children) {
117
throw new Error('Expected parent node')
128
}
139

1410
if (typeof index === 'number') {
15-
if (index < 0 || index === Infinity) {
11+
if (index < 0 || index === Number.POSITIVE_INFINITY) {
1612
throw new Error('Expected positive finite number as index')
1713
}
1814
} else {

package.json

+11-22
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,29 @@
2222
"contributors": [
2323
"Titus Wormer <[email protected]> (https://wooorm.com)"
2424
],
25+
"sideEffects": false,
26+
"type": "module",
27+
"main": "index.js",
2528
"files": [
2629
"index.js"
2730
],
2831
"dependencies": {
29-
"unist-util-is": "^4.0.0"
32+
"unist-util-is": "^5.0.0"
3033
},
3134
"devDependencies": {
32-
"browserify": "^17.0.0",
33-
"nyc": "^15.0.0",
35+
"c8": "^7.0.0",
3436
"prettier": "^2.0.0",
3537
"remark": "^13.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",
4041
"xo": "^0.38.0"
4142
},
4243
"scripts": {
4344
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
44-
"build-bundle": "browserify . -s unistUtilFindBefore -o unist-util-find-before.js",
45-
"build-mangle": "browserify . -s unistUtilFindBefore -o unist-util-find-before.min.js -p tinyify",
46-
"build": "npm run build-bundle && npm run build-mangle",
47-
"test-api": "node test",
48-
"test-coverage": "nyc --reporter lcov tape test.js",
49-
"test": "npm run format && npm run build && npm run test-coverage"
50-
},
51-
"nyc": {
52-
"check-coverage": true,
53-
"lines": 100,
54-
"functions": 100,
55-
"branches": 100
45+
"test-api": "node test.js",
46+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
47+
"test": "npm run format && npm run test-coverage"
5648
},
5749
"prettier": {
5850
"tabWidth": 2,
@@ -64,13 +56,10 @@
6456
},
6557
"xo": {
6658
"prettier": true,
67-
"esnext": false,
6859
"rules": {
69-
"unicorn/prefer-number-properties": "off"
70-
},
71-
"ignore": [
72-
"unist-util-find-before.js"
73-
]
60+
"no-var": "off",
61+
"prefer-arrow-callback": "off"
62+
}
7463
},
7564
"remarkConfig": {
7665
"plugins": [

readme.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
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-find-before
2124
## Use
2225

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

2730
var tree = u('tree', [
2831
u('leaf', 'leaf 1'),
@@ -42,11 +45,14 @@ console.log(findBefore(tree, empty, 'node'))
4245
Yields:
4346

4447
```js
45-
{ type: 'node', children: [ { type: 'leaf', value: 'leaf 5' } ] }
48+
{type: 'node', children: [{type: 'leaf', value: 'leaf 5'}]}
4649
```
4750

4851
## API
4952

53+
This package exports the following identifiers: `findBefore`.
54+
There is no default export.
55+
5056
### `findBefore(parent, node|index[, test])`
5157

5258
Find the first [child][] before `index` (or `node`) in `parent`, that passes

test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var remark = require('remark')
5-
var findBefore = require('.')
1+
import test from 'tape'
2+
import remark from 'remark'
3+
import {findBefore} from './index.js'
64

75
var tree = remark().parse('Some *emphasis*, **importance**, and `code`.')
86
var paragraph = tree.children[0]

0 commit comments

Comments
 (0)