Skip to content

Commit adc6d70

Browse files
committed
Use ESM
1 parent 8251eaa commit adc6d70

File tree

6 files changed

+28
-57
lines changed

6 files changed

+28
-57
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-find-all-before.js
7-
unist-util-find-all-before.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-find-all-before.js
3-
unist-util-find-all-before.min.js
4-
*.json
52
*.md

index.js

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

3-
var convert = require('unist-util-is/convert')
4-
5-
module.exports = findAllBefore
6-
7-
function findAllBefore(parent, index, test) {
3+
export function findAllBefore(parent, index, test) {
84
var is = convert(test)
95
var results = []
106
var offset = -1
@@ -14,7 +10,7 @@ function findAllBefore(parent, index, test) {
1410
}
1511

1612
if (typeof index === 'number') {
17-
if (index < 0 || index === Infinity) {
13+
if (index < 0 || index === Number.POSITIVE_INFINITY) {
1814
throw new Error('Expected positive finite number as index')
1915
}
2016
} else {

package.json

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,31 @@
2222
"contributors": [
2323
"Titus Wormer <[email protected]> (https://wooorm.com)"
2424
],
25+
"sideEffects": false,
26+
"type": "module",
27+
"main": "index.js",
28+
"types": "index.d.ts",
2529
"files": [
26-
"index.js",
27-
"index.d.ts"
30+
"index.d.ts",
31+
"index.js"
2832
],
29-
"types": "index.d.ts",
3033
"dependencies": {
31-
"unist-util-is": "^4.0.0"
34+
"unist-util-is": "^5.0.0"
3235
},
3336
"devDependencies": {
34-
"browserify": "^17.0.0",
35-
"dtslint": "^4.0.0",
36-
"nyc": "^15.0.0",
37+
"c8": "^7.0.0",
3738
"prettier": "^2.0.0",
3839
"remark": "^13.0.0",
3940
"remark-cli": "^9.0.0",
4041
"remark-preset-wooorm": "^8.0.0",
4142
"tape": "^5.0.0",
42-
"tinyify": "^3.0.0",
4343
"xo": "^0.38.0"
4444
},
4545
"scripts": {
4646
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
47-
"build-bundle": "browserify . -s unistUtilFindAllBefore -o unist-util-find-all-before.js",
48-
"build-mangle": "browserify . -s unistUtilFindAllBefore -o unist-util-find-all-before.min.js -p tinyify",
49-
"build": "npm run build-bundle && npm run build-mangle",
50-
"test-api": "node test",
51-
"test-coverage": "nyc --reporter lcov tape test.js",
52-
"test-types": "dtslint .",
53-
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
54-
},
55-
"nyc": {
56-
"check-coverage": true,
57-
"lines": 100,
58-
"functions": 100,
59-
"branches": 100
47+
"test-api": "node test.js",
48+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
49+
"test": "npm run format && npm run test-coverage"
6050
},
6151
"prettier": {
6252
"tabWidth": 2,
@@ -68,23 +58,10 @@
6858
},
6959
"xo": {
7060
"prettier": true,
71-
"esnext": false,
7261
"rules": {
73-
"eqeqeq": [
74-
"error",
75-
"always",
76-
{
77-
"null": "ignore"
78-
}
79-
],
80-
"guard-for-in": "off",
81-
"no-eq-null": "off",
82-
"unicorn/prefer-number-properties": "off"
83-
},
84-
"ignore": [
85-
"unist-util-find-all-before.js",
86-
"*.ts"
87-
]
62+
"no-var": "off",
63+
"prefer-arrow-callback": "off"
64+
}
8865
},
8966
"remarkConfig": {
9067
"plugins": [

readme.md

Lines changed: 8 additions & 2 deletions
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-all-before
2124
## Use
2225

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

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

5154
## API
5255

56+
This package exports the following identifiers: `findAllBefore`.
57+
There is no default export.
58+
5359
### `findAllBefore(parent, node|index[, test])`
5460

5561
Find the first child before `index` (or `node`) in `parent`, that passes `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 remark = require('remark')
5-
var findAllBefore = require('.')
1+
import test from 'tape'
2+
import remark from 'remark'
3+
import {findAllBefore} 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)