Skip to content

Commit 2d993f8

Browse files
committed
Use ESM
1 parent a7bbefd commit 2d993f8

File tree

6 files changed

+32
-44
lines changed

6 files changed

+32
-44
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-
mdast-util-compact.js
7-
mdast-util-compact.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-
mdast-util-compact.js
3-
mdast-util-compact.min.js
4-
*.json
52
*.md

index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
'use strict'
2-
3-
var visit = require('unist-util-visit')
4-
5-
module.exports = compact
1+
import {visit} from 'unist-util-visit'
62

73
// Make an mdast tree compact by merging adjacent text nodes.
8-
function compact(tree) {
4+
export function compact(tree) {
95
visit(tree, visitor)
106

117
return tree

package.json

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,29 @@
2323
"contributors": [
2424
"Titus Wormer <[email protected]> (https://wooorm.com)"
2525
],
26+
"sideEffects": false,
27+
"type": "module",
28+
"main": "index.js",
2629
"files": [
2730
"index.js"
2831
],
2932
"dependencies": {
30-
"unist-util-visit": "^2.0.0"
33+
"unist-util-visit": "^3.0.0"
3134
},
3235
"devDependencies": {
33-
"browserify": "^17.0.0",
34-
"nyc": "^15.0.0",
36+
"c8": "^7.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",
40-
"unist-builder": "^2.0.0",
41-
"xo": "^0.38.0"
41+
"unist-builder": "^3.0.0",
42+
"xo": "^0.39.0"
4243
},
4344
"scripts": {
44-
"format": "remark . -qfo && prettier . --write && xo --fix",
45-
"build-bundle": "browserify . -s mdastUtilCompact -o mdast-util-compact.js",
46-
"build-mangle": "browserify . -s mdastUtilCompact -o mdast-util-compact.min.js -p tinyify",
47-
"build": "npm run build-bundle && npm run build-mangle",
48-
"test-api": "node test",
49-
"test-coverage": "nyc --reporter lcov tape test.js",
50-
"test": "npm run format && npm run build && npm run test-coverage"
45+
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
46+
"test-api": "node test.js",
47+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
48+
"test": "npm run format && npm run test-coverage"
5149
},
5250
"prettier": {
5351
"tabWidth": 2,
@@ -59,16 +57,10 @@
5957
},
6058
"xo": {
6159
"prettier": true,
62-
"esnext": false,
63-
"ignores": [
64-
"mdast-util-compact.js"
65-
]
66-
},
67-
"nyc": {
68-
"check-coverage": true,
69-
"lines": 100,
70-
"functions": 100,
71-
"branches": 100
60+
"rules": {
61+
"no-var": "off",
62+
"prefer-arrow-callback": "off"
63+
}
7264
},
7365
"remarkConfig": {
7466
"plugins": [

readme.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ and blockquotes.
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 mdast-util-compact
2225
## Use
2326

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

2831
var tree = u('strong', [u('text', 'alpha'), u('text', ' '), u('text', 'bravo')])
2932

@@ -35,12 +38,17 @@ console.log(tree)
3538
Yields:
3639

3740
```js
38-
{ type: 'strong',
39-
children: [ { type: 'text', value: 'alpha bravo' } ] }
41+
{
42+
type: 'strong',
43+
children: [ { type: 'text', value: 'alpha bravo' } ]
44+
}
4045
```
4146

4247
## API
4348

49+
This package exports the following identifiers: `compact`.
50+
There is no default export.
51+
4452
### `compact(tree)`
4553

4654
Walk the [tree][] and collapse nodes.

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

75
test('compact()', function (t) {
86
t.same(

0 commit comments

Comments
 (0)