Skip to content

Commit eefc92c

Browse files
committed
Use ESM
1 parent 903e82c commit eefc92c

File tree

6 files changed

+49
-45
lines changed

6 files changed

+49
-45
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: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
'use strict'
2-
3-
var visit = require('unist-util-visit')
4-
5-
module.exports = normalizeHeadings
1+
import {visit} from 'unist-util-visit'
62

73
var max = 6
84

9-
function normalizeHeadings(tree) {
5+
export function normalizeHeadings(tree) {
106
var multiple
117
var first
128
var title

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,31 @@
2828
"Eugene Sharygin <eush77@gmail.com>",
2929
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
3030
],
31+
"sideEffects": false,
32+
"type": "module",
33+
"main": "index.js",
3134
"files": [
3235
"index.js"
3336
],
3437
"dependencies": {
35-
"unist-util-visit": "^2.0.0"
38+
"unist-util-visit": "^3.0.0"
3639
},
3740
"devDependencies": {
38-
"nyc": "^15.0.0",
41+
"c8": "^7.0.0",
3942
"prettier": "^2.0.0",
4043
"remark": "^13.0.0",
4144
"remark-cli": "^9.0.0",
4245
"remark-preset-wooorm": "^8.0.0",
4346
"tape": "^5.0.0",
44-
"unist-util-remove-position": "^3.0.0",
45-
"xo": "^0.38.0"
47+
"unist-util-remove-position": "^4.0.0",
48+
"xo": "^0.39.0"
4649
},
4750
"scripts": {
4851
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
49-
"test-api": "node test",
50-
"test-coverage": "nyc --reporter lcov tape test/index.js",
52+
"test-api": "node test/index.js",
53+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
5154
"test": "npm run format && npm run test-coverage"
5255
},
53-
"nyc": {
54-
"check-coverage": true,
55-
"lines": 100,
56-
"functions": 100,
57-
"branches": 100
58-
},
5956
"prettier": {
6057
"tabWidth": 2,
6158
"useTabs": false,
@@ -66,7 +63,10 @@
6663
},
6764
"xo": {
6865
"prettier": true,
69-
"esnext": false
66+
"rules": {
67+
"no-var": "off",
68+
"prefer-arrow-callback": "off"
69+
}
7070
},
7171
"remarkConfig": {
7272
"plugins": [

readme.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ contains some meta-information (usually title) about the document.
1717

1818
## Install
1919

20+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
21+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
22+
2023
[npm][]:
2124

2225
```sh
@@ -26,8 +29,8 @@ npm install mdast-normalize-headings
2629
## Use
2730

2831
```js
29-
var u = require('unist-builder')
30-
var normalizeHeadings = require('mdast-normalize-headings')
32+
import {u} from 'unist-builder'
33+
import {normalizeHeadings} from 'mdast-normalize-headings'
3134

3235
var tree = u('root', [
3336
u('heading', {depth: 1}, [u('text', 'title')]),
@@ -45,20 +48,29 @@ console.log(tree)
4548
Yields:
4649

4750
```js
48-
{ type: 'root',
49-
children:
50-
[ { type: 'heading', depth: 1, children: [Array] },
51-
{ type: 'heading', depth: 2, children: [Array] },
52-
{ type: 'heading', depth: 1, children: [Array] } ] }
53-
{ type: 'root',
54-
children:
55-
[ { type: 'heading', depth: 1, children: [Array] },
56-
{ type: 'heading', depth: 3, children: [Array] },
57-
{ type: 'heading', depth: 2, children: [Array] } ] }
51+
{
52+
type: 'root',
53+
children: [
54+
{type: 'heading', depth: 1, children: [Array]},
55+
{type: 'heading', depth: 2, children: [Array]},
56+
{type: 'heading', depth: 1, children: [Array]}
57+
]
58+
}
59+
{
60+
type: 'root',
61+
children: [
62+
{type: 'heading', depth: 1, children: [Array]},
63+
{type: 'heading', depth: 3, children: [Array]},
64+
{type: 'heading', depth: 2, children: [Array]}
65+
]
66+
}
5867
```
5968

6069
## API
6170

71+
This package exports the following identifiers: `normalizeHeadings`.
72+
There is no default export.
73+
6274
### `normalizeHeadings(tree)`
6375

6476
Modifies [tree][] in-place.

test/index.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
'use strict'
2-
3-
var fs = require('fs')
4-
var path = require('path')
5-
var test = require('tape')
6-
var remark = require('remark')
7-
var remove = require('unist-util-remove-position')
8-
var normalizeHeadings = require('..')
1+
import fs from 'fs'
2+
import path from 'path'
3+
import test from 'tape'
4+
import remark from 'remark'
5+
import {removePosition} from 'unist-util-remove-position'
6+
import {normalizeHeadings} from '../index.js'
97

108
test('Multiple top-level headings', function (t) {
119
check(t, 'no-headings', 'No-op if there is no headings')
@@ -22,12 +20,12 @@ test('Level 7', function (t) {
2220
})
2321

2422
function check(t, test, message) {
25-
var input = fs.readFileSync(path.join(__dirname, 'fixture', test + '.in'))
26-
var output = fs.readFileSync(path.join(__dirname, 'fixture', test + '.out'))
23+
var input = fs.readFileSync(path.join('test', 'fixture', test + '.in'))
24+
var output = fs.readFileSync(path.join('test', 'fixture', test + '.out'))
2725

2826
t.deepEqual(
29-
remove(normalizeHeadings(remark().parse(input)), true),
30-
remove(remark().parse(output), true),
27+
removePosition(normalizeHeadings(remark().parse(input)), true),
28+
removePosition(remark().parse(output), true),
3129
message
3230
)
3331
}

0 commit comments

Comments
 (0)