File tree Expand file tree Collapse file tree 6 files changed +25
-37
lines changed Expand file tree Collapse file tree 6 files changed +25
-37
lines changed Original file line number Diff line number Diff line change 11.DS_Store
22* .log
3- .nyc_output /
43coverage /
54node_modules /
65yarn.lock
Original file line number Diff line number Diff line change 11coverage /
2- * .json
32* .md
Original file line number Diff line number Diff line change 1- 'use strict'
2-
3- module . exports = u
4-
5- function u ( type , props , value ) {
1+ export function u ( type , props , value ) {
62 var node = { type : String ( type ) }
73
8- if ( value == null && ( typeof props !== 'object' || Array . isArray ( props ) ) ) {
4+ if (
5+ ( value === undefined || value === null ) &&
6+ ( typeof props !== 'object' || Array . isArray ( props ) )
7+ ) {
98 value = props
109 } else {
1110 Object . assign ( node , props )
1211 }
1312
1413 if ( Array . isArray ( value ) ) {
1514 node . children = value
16- } else if ( value != null ) {
15+ } else if ( value !== undefined && value !== null ) {
1716 node . value = String ( value )
1817 }
1918
Original file line number Diff line number Diff line change 3030 " Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" ,
3131 " Christian Murphy <christian.murphy.42@gmail.com>"
3232 ],
33+ "sideEffects" : false ,
34+ "type" : " module" ,
35+ "main" : " index.js" ,
36+ "types" : " types/index.d.ts" ,
3337 "files" : [
3438 " index.js" ,
3539 " types/index.d.ts"
3640 ],
37- "types" : " types/index.d.ts" ,
3841 "devDependencies" : {
3942 "@types/mdast" : " ^3.0.0" ,
43+ "c8" : " ^7.0.0" ,
4044 "dtslint" : " ^4.0.0" ,
41- "nyc" : " ^15.0.0" ,
4245 "prettier" : " ^2.0.0" ,
4346 "remark-cli" : " ^9.0.0" ,
4447 "remark-preset-wooorm" : " ^8.0.0" ,
4750 },
4851 "scripts" : {
4952 "format" : " remark . -qfo && prettier . -w --loglevel warn && xo --fix" ,
50- "test-api" : " node test" ,
51- "test-coverage" : " nyc --reporter lcov tape test.js" ,
53+ "test-api" : " node test.js " ,
54+ "test-coverage" : " c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 -- reporter lcov node test.js" ,
5255 "test-types" : " dtslint types" ,
5356 "test" : " npm run format && npm run test-coverage && npm run test-types"
5457 },
55- "nyc" : {
56- "check-coverage" : true ,
57- "lines" : 100 ,
58- "functions" : 100 ,
59- "branches" : 100
60- },
6158 "prettier" : {
6259 "tabWidth" : 2 ,
6360 "useTabs" : false ,
6865 },
6966 "xo" : {
7067 "prettier" : true ,
71- "esnext" : false ,
72- "ignore" : [
73- " types/"
74- ],
7568 "rules" : {
76- "eqeqeq" : [
77- " error" ,
78- " always" ,
79- {
80- "null" : " ignore"
81- }
82- ],
83- "no-eq-null" : " off"
69+ "no-var" : " off" ,
70+ "prefer-arrow-callback" : " off"
8471 }
8572 },
8673 "remarkConfig" : {
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ syntax.
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``` bash
@@ -22,7 +25,7 @@ npm install unist-builder
2225## Use
2326
2427``` js
25- var u = require ( ' unist-builder' )
28+ import { u } from ' unist-builder'
2629
2730var tree = u (' root' , [
2831 u (' subtree' , {id: 1 }),
@@ -64,6 +67,9 @@ results in the following tree:
6467
6568## API
6669
70+ This package exports the following identifiers: ` u ` .
71+ There is no default export.
72+
6773### ` u(type[, props][, children|value]) `
6874
6975Creates a node from ` props ` , ` children ` , and optionally ` value ` .
Original file line number Diff line number Diff line change 1- 'use strict'
1+ import test from 'tape'
2+ import { u } from './index.js'
23
3- var test = require ( 'tape' )
4- var u = require ( '.' )
5-
6- test ( function ( t ) {
4+ test ( 'u' , function ( t ) {
75 t . deepEqual (
86 u ( 'root' , [
97 u ( 'subtree' , { id : 1 } ) ,
You can’t perform that action at this time.
0 commit comments