File tree Expand file tree Collapse file tree 6 files changed +24
-41
lines changed Expand file tree Collapse file tree 6 files changed +24
-41
lines changed Original file line number Diff line number Diff line change 1
1
.DS_Store
2
2
* .log
3
- .nyc_output /
4
3
coverage /
5
4
node_modules /
6
- unist-util-size.js
7
- unist-util-size.min.js
8
5
yarn.lock
Original file line number Diff line number Diff line change 1
1
coverage /
2
- unist-util-size.js
3
- unist-util-size.min.js
4
- * .json
5
2
* .md
Original file line number Diff line number Diff line change 1
- 'use strict '
1
+ import { convert } from 'unist-util-is '
2
2
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 ) {
8
4
var is = convert ( test )
9
5
return fastSize ( node )
10
6
@@ -13,7 +9,7 @@ function size(node, test) {
13
9
var count = 0
14
10
var index = - 1
15
11
16
- if ( children && children . length ) {
12
+ if ( children && children . length > 0 ) {
17
13
while ( ++ index < children . length ) {
18
14
if ( is ( children [ index ] , index , node ) ) count ++
19
15
count += fastSize ( children [ index ] )
Original file line number Diff line number Diff line change 22
22
"contributors" : [
23
23
" Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
24
24
],
25
+ "sideEffects" : false ,
26
+ "type" : " module" ,
27
+ "main" : " index.js" ,
25
28
"files" : [
26
29
" index.js"
27
30
],
28
31
"dependencies" : {
29
- "unist-util-is" : " ^4 .0.0"
32
+ "unist-util-is" : " ^5 .0.0"
30
33
},
31
34
"devDependencies" : {
32
- "browserify " : " ^17 .0.0" ,
35
+ "c8 " : " ^7 .0.0" ,
33
36
"hastscript" : " ^6.0.0" ,
34
- "nyc" : " ^15.0.0" ,
35
37
"prettier" : " ^2.0.0" ,
36
38
"remark-cli" : " ^9.0.0" ,
37
39
"remark-preset-wooorm" : " ^8.0.0" ,
38
40
"tape" : " ^5.0.0" ,
39
- "tinyify" : " ^3.0.0" ,
40
41
"xo" : " ^0.38.0"
41
42
},
42
43
"scripts" : {
43
44
"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"
56
48
},
57
49
"prettier" : {
58
50
"tabWidth" : 2 ,
64
56
},
65
57
"xo" : {
66
58
"prettier" : true ,
67
- "esnext" : false ,
68
- "ignores" : [
69
- " unist-util-size.js"
70
- ],
71
59
"rules" : {
72
- "unicorn/explicit-length-check" : " off"
60
+ "no-var" : " off" ,
61
+ "prefer-arrow-callback" : " off"
73
62
}
74
63
},
75
64
"remarkConfig" : {
Original file line number Diff line number Diff line change 12
12
13
13
## Install
14
14
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
+
15
18
[ npm] [ ] :
16
19
17
20
``` sh
@@ -21,8 +24,8 @@ npm install unist-util-size
21
24
## Use
22
25
23
26
``` 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'
26
29
27
30
var tree = h (' div' , [
28
31
h (' p' , [
@@ -41,6 +44,9 @@ console.log(size(tree, 'element')) // => 5
41
44
42
45
## API
43
46
47
+ This package exports the following identifiers: ` size ` .
48
+ There is no default export.
49
+
44
50
### ` size(tree[, test]) `
45
51
46
52
Calculate the number of nodes in [ ` tree ` ] [ node ] .
Original file line number Diff line number Diff line change 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'
6
4
7
5
test ( 'unist-util-size' , function ( t ) {
8
6
var tree = h ( 'div' , [
You can’t perform that action at this time.
0 commit comments