Skip to content

Commit fc6f506

Browse files
committed
Use ESM
1 parent 0fe3709 commit fc6f506

File tree

6 files changed

+29
-43
lines changed

6 files changed

+29
-43
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.DS_Store
22
*.log
3-
.nyc_output/
43
coverage/
54
node_modules/
65
yarn.lock

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
coverage/
2-
*.json
32
*.md

index.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
// LICENSE : MIT
2-
'use strict'
3-
4-
var assign = require('object-assign')
5-
6-
module.exports = map
7-
8-
function map(tree, iteratee) {
1+
export function map(tree, iteratee) {
92
return preorder(tree, null, null)
103

114
function preorder(node, index, parent) {
12-
var children = node.children
13-
var newNode = assign({}, iteratee(node, index, parent))
5+
var newNode = Object.assign({}, iteratee(node, index, parent))
146

15-
if (children) {
16-
newNode.children = children.map(function (child, index) {
7+
if (node.children) {
8+
newNode.children = node.children.map(function (child, index) {
179
return preorder(child, index, node)
1810
})
1911
}

package.json

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626
"Titus Wormer <[email protected]> (https://wooorm.com)",
2727
"Christian Murphy <[email protected]>"
2828
],
29+
"sideEffects": false,
30+
"type": "module",
31+
"main": "index.js",
32+
"types": "types/index.d.ts",
2933
"files": [
3034
"index.js",
3135
"types/index.d.ts"
3236
],
33-
"types": "types/index.d.ts",
34-
"dependencies": {
35-
"@types/mdast": "^3.0.0",
36-
"object-assign": "^4.0.0"
37-
},
37+
"dependencies": {},
3838
"devDependencies": {
39+
"c8": "^7.0.0",
3940
"dtslint": "^4.0.0",
40-
"nyc": "^15.0.0",
4141
"prettier": "^2.0.0",
4242
"remark-cli": "^9.0.0",
4343
"remark-preset-wooorm": "^8.0.0",
@@ -49,17 +49,11 @@
4949
},
5050
"scripts": {
5151
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
52-
"test-api": "node test",
53-
"test-coverage": "nyc --reporter lcov tape test.js",
52+
"test-api": "node test.js",
53+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
5454
"test-types": "dtslint types",
5555
"test": "npm run format && npm run test-coverage && npm run test-types"
5656
},
57-
"nyc": {
58-
"check-coverage": true,
59-
"lines": 100,
60-
"functions": 100,
61-
"branches": 100
62-
},
6357
"prettier": {
6458
"tabWidth": 2,
6559
"useTabs": false,
@@ -70,13 +64,10 @@
7064
},
7165
"xo": {
7266
"prettier": true,
73-
"esnext": false,
7467
"rules": {
75-
"unicorn/no-fn-reference-in-iterator": "off"
76-
},
77-
"ignore": [
78-
"types/"
79-
]
68+
"no-var": "off",
69+
"prefer-arrow-callback": "off"
70+
}
8071
},
8172
"remarkConfig": {
8273
"plugins": [

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ with the given function.
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
```sh
@@ -22,8 +25,8 @@ npm install unist-util-map
2225
## Use
2326

2427
```js
25-
var u = require('unist-builder')
26-
var map = require('unist-util-map')
28+
import u from 'unist-builder'
29+
import {map} from 'unist-util-map'
2730

2831
var tree = u('tree', [
2932
u('leaf', 'leaf 1'),
@@ -59,6 +62,9 @@ Yields:
5962

6063
## API
6164

65+
This package exports the following identifiers: `map`.
66+
There is no default export.
67+
6268
### `map(tree, mapFn)`
6369

6470
Create a new [tree][] by mapping all [node][]s with the given function.

test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var assign = require('object-assign')
5-
var u = require('unist-builder')
6-
var map = require('.')
1+
import test from 'tape'
2+
import u from 'unist-builder'
3+
import {map} from './index.js'
74

85
test('unist-util-map', function (t) {
96
t.deepEqual(
@@ -27,7 +24,9 @@ test('unist-util-map', function (t) {
2724
t.end()
2825

2926
function changeLeaf(node) {
30-
return node.type === 'leaf' ? assign({}, node, {value: 'CHANGED'}) : node
27+
return node.type === 'leaf'
28+
? Object.assign({}, node, {value: 'CHANGED'})
29+
: node
3130
}
3231

3332
function nullLeaf(node) {

0 commit comments

Comments
 (0)