Skip to content

Commit 6ceffc0

Browse files
committed
Use ESM
1 parent 81b0954 commit 6ceffc0

File tree

6 files changed

+54
-64
lines changed

6 files changed

+54
-64
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-heading-style.js
7-
mdast-util-heading-style.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-heading-style.js
3-
mdast-util-heading-style.min.js
4-
*.json
52
*.md

index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
'use strict'
2-
3-
module.exports = style
4-
5-
function style(node, relative) {
1+
export function headingStyle(node, relative) {
62
var last = node.children[node.children.length - 1]
73
var depth = node.depth
84
var pos = node && node.position && node.position.end

package.json

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,26 @@
2424
"contributors": [
2525
"Titus Wormer <[email protected]> (https://wooorm.com)"
2626
],
27+
"sideEffects": false,
28+
"type": "module",
29+
"main": "index.js",
2730
"files": [
2831
"index.js"
2932
],
3033
"devDependencies": {
31-
"browserify": "^17.0.0",
32-
"nyc": "^15.0.0",
34+
"c8": "^7.0.0",
3335
"prettier": "^2.0.0",
3436
"remark": "^13.0.0",
3537
"remark-cli": "^9.0.0",
3638
"remark-preset-wooorm": "^8.0.0",
3739
"tape": "^5.0.0",
38-
"tinyify": "^3.0.0",
39-
"xo": "^0.38.0"
40+
"xo": "^0.39.0"
4041
},
4142
"scripts": {
4243
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
43-
"build-bundle": "browserify . -s mdastUtilHeadingStyle -o mdast-util-heading-style.js",
44-
"build-mangle": "browserify . -s mdastUtilHeadingStyle -o mdast-util-heading-style.min.js -p tinyify",
45-
"build": "npm run build-bundle && npm run build-mangle",
46-
"test-api": "node test",
47-
"test-coverage": "nyc --reporter lcov tape test.js",
48-
"test": "npm run format && npm run build && npm run test-coverage"
44+
"test-api": "node test.js",
45+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
46+
"test": "npm run format && npm run test-coverage"
4947
},
5048
"prettier": {
5149
"tabWidth": 2,
@@ -57,16 +55,10 @@
5755
},
5856
"xo": {
5957
"prettier": true,
60-
"esnext": false,
61-
"ignore": [
62-
"mdast-util-heading-style.js"
63-
]
64-
},
65-
"nyc": {
66-
"check-coverage": true,
67-
"lines": 100,
68-
"functions": 100,
69-
"branches": 100
58+
"rules": {
59+
"no-var": "off",
60+
"prefer-arrow-callback": "off"
61+
}
7062
},
7163
"remarkConfig": {
7264
"plugins": [

readme.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
## Install
1414

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+
1518
[npm][]:
1619

1720
```sh
@@ -21,23 +24,26 @@ npm install mdast-util-heading-style
2124
## Use
2225

2326
```js
24-
var style = require('mdast-util-heading-style')
25-
var unified = require('unified')
26-
var parse = require('remark-parse')
27+
import unified from 'unified'
28+
import remarkParse from 'remark-parse'
29+
import {headingStyle} from 'mdast-util-heading-style'
2730

28-
var processor = unified().use(parse)
31+
var processor = unified().use(remarkParse)
2932

30-
style(processor.parse('# ATX').children[0]) // => 'atx'
31-
style(processor.parse('# ATX #\n').children[0]) // => 'atx-closed'
32-
style(processor.parse('ATX\n===').children[0]) // => 'setext'
33+
headingStyle(processor.parse('# ATX').children[0]) // => 'atx'
34+
headingStyle(processor.parse('# ATX #\n').children[0]) // => 'atx-closed'
35+
headingStyle(processor.parse('ATX\n===').children[0]) // => 'setext'
3336

34-
style(processor.parse('### ATX').children[0]) // => null
35-
style(processor.parse('### ATX').children[0], 'setext') // => 'setext'
37+
headingStyle(processor.parse('### ATX').children[0]) // => null
38+
headingStyle(processor.parse('### ATX').children[0], 'setext') // => 'setext'
3639
```
3740

3841
## API
3942

40-
### `style(node[, relative])`
43+
This package exports the following identifiers: `headingStyle`.
44+
There is no default export.
45+
46+
### `headingStyle(node[, relative])`
4147

4248
Get the heading style of a node.
4349

test.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,107 @@
1-
'use strict'
1+
import test from 'tape'
2+
import remark from 'remark'
3+
import {headingStyle} from './index.js'
24

3-
var test = require('tape')
4-
var remark = require('remark')()
5-
var style = require('.')
6-
7-
test('mdast-util-heading-style', function (t) {
5+
test('headingStyle', function (t) {
86
t.throws(function () {
9-
style()
7+
headingStyle()
108
}, 'should fail without node')
119

1210
t.equal(
13-
style({
11+
headingStyle({
1412
type: 'heading',
1513
children: [{type: 'text', value: 'foo'}]
1614
}),
1715
null,
1816
'should NOT fail on undetectable nodes'
1917
)
2018

21-
t.equal(style(remark.parse('# ATX').children[0]), 'atx', 'should detect atx')
19+
t.equal(
20+
headingStyle(remark.parse('# ATX').children[0]),
21+
'atx',
22+
'should detect atx'
23+
)
2224

2325
t.equal(
24-
style(remark.parse('# ATX #').children[0]),
26+
headingStyle(remark.parse('# ATX #').children[0]),
2527
'atx-closed',
2628
'should detect closed atx'
2729
)
2830

2931
t.equal(
30-
style(remark.parse('ATX\n===').children[0]),
32+
headingStyle(remark.parse('ATX\n===').children[0]),
3133
'setext',
3234
'should detect closed setext'
3335
)
3436

3537
t.equal(
36-
style(remark.parse('### ATX').children[0]),
38+
headingStyle(remark.parse('### ATX').children[0]),
3739
null,
3840
'should work on ambiguous nodes'
3941
)
4042

4143
t.equal(
42-
style(remark.parse('### ATX').children[0], 'atx'),
44+
headingStyle(remark.parse('### ATX').children[0], 'atx'),
4345
'atx',
4446
'should work on ambiguous nodes (preference to atx)'
4547
)
4648

4749
t.equal(
48-
style(remark.parse('### ATX').children[0], 'setext'),
50+
headingStyle(remark.parse('### ATX').children[0], 'setext'),
4951
'setext',
5052
'should work on ambiguous nodes (preference to setext)'
5153
)
5254

5355
t.equal(
54-
style(remark.parse('###### ######').children[0]),
56+
headingStyle(remark.parse('###### ######').children[0]),
5557
'atx-closed',
5658
'should work on empty nodes (#1)'
5759
)
5860

5961
t.equal(
60-
style(remark.parse('### ###').children[0]),
62+
headingStyle(remark.parse('### ###').children[0]),
6163
'atx-closed',
6264
'should work on empty nodes (#2)'
6365
)
6466

6567
t.equal(
66-
style(remark.parse('# #').children[0]),
68+
headingStyle(remark.parse('# #').children[0]),
6769
'atx-closed',
6870
'should work on empty nodes (#3)'
6971
)
7072

7173
t.equal(
72-
style(remark.parse('###### ').children[0], 'atx'),
74+
headingStyle(remark.parse('###### ').children[0], 'atx'),
7375
'atx',
7476
'should work on empty nodes (#4)'
7577
)
7678

7779
t.equal(
78-
style(remark.parse('### ').children[0], 'atx'),
80+
headingStyle(remark.parse('### ').children[0], 'atx'),
7981
'atx',
8082
'should work on empty nodes (#5)'
8183
)
8284

8385
t.equal(
84-
style(remark.parse('## ').children[0]),
86+
headingStyle(remark.parse('## ').children[0]),
8587
'atx',
8688
'should work on empty nodes (#6)'
8789
)
8890

8991
t.equal(
90-
style(remark.parse('###### ').children[0], 'setext'),
92+
headingStyle(remark.parse('###### ').children[0], 'setext'),
9193
'setext',
9294
'should work on empty nodes (#7)'
9395
)
9496

9597
t.equal(
96-
style(remark.parse('### ').children[0], 'setext'),
98+
headingStyle(remark.parse('### ').children[0], 'setext'),
9799
'setext',
98100
'should work on empty nodes (#8)'
99101
)
100102

101103
t.equal(
102-
style(remark.parse('## ').children[0], 'setext'),
104+
headingStyle(remark.parse('## ').children[0], 'setext'),
103105
'atx',
104106
'should work on empty nodes (#9)'
105107
)

0 commit comments

Comments
 (0)