Skip to content

Commit 5c35f92

Browse files
committed
Use ESM
1 parent 42fbe0e commit 5c35f92

File tree

6 files changed

+24
-41
lines changed

6 files changed

+24
-41
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-size.js
7-
unist-util-size.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-size.js
3-
unist-util-size.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 = size
6-
7-
function size(node, test) {
3+
export function size(node, test) {
84
var is = convert(test)
95
return fastSize(node)
106

@@ -13,7 +9,7 @@ function size(node, test) {
139
var count = 0
1410
var index = -1
1511

16-
if (children && children.length) {
12+
if (children && children.length > 0) {
1713
while (++index < children.length) {
1814
if (is(children[index], index, node)) count++
1915
count += fastSize(children[index])

package.json

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,29 @@
2222
"contributors": [
2323
"Titus Wormer <tituswormer@gmail.com> (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",
35+
"c8": "^7.0.0",
3336
"hastscript": "^6.0.0",
34-
"nyc": "^15.0.0",
3537
"prettier": "^2.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 unistUtilSize -o unist-util-size.js",
45-
"build-mangle": "browserify . -s unistUtilSize -o unist-util-size.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,12 +56,9 @@
6456
},
6557
"xo": {
6658
"prettier": true,
67-
"esnext": false,
68-
"ignores": [
69-
"unist-util-size.js"
70-
],
7159
"rules": {
72-
"unicorn/explicit-length-check": "off"
60+
"no-var": "off",
61+
"prefer-arrow-callback": "off"
7362
}
7463
},
7564
"remarkConfig": {

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-size
2124
## Use
2225

2326
```js
24-
var h = require('hastscript')
25-
var size = require('unist-util-size')
27+
import {h} from 'hastscript'
28+
import {size} from 'unist-util-size'
2629

2730
var tree = h('div', [
2831
h('p', [
@@ -41,6 +44,9 @@ console.log(size(tree, 'element')) // => 5
4144

4245
## API
4346

47+
This package exports the following identifiers: `size`.
48+
There is no default export.
49+
4450
### `size(tree[, test])`
4551

4652
Calculate the number of nodes in [`tree`][node].

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 h = require('hastscript')
5-
var size = require('.')
1+
import test from 'tape'
2+
import h from 'hastscript'
3+
import {size} from './index.js'
64

75
test('unist-util-size', function (t) {
86
var tree = h('div', [

0 commit comments

Comments
 (0)