Skip to content

Commit d263503

Browse files
committed
Use ESM
1 parent ea60ca9 commit d263503

File tree

6 files changed

+27
-29
lines changed

6 files changed

+27
-29
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: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
'use strict'
2-
3-
module.exports = headingRank
4-
51
// Rank of a heading: H1 -> 1, H2 -> 2, etc.
6-
function headingRank(node) {
2+
export function headingRank(node) {
73
var name =
84
(node && node.type === 'element' && node.tagName.toLowerCase()) || ''
95
var code =

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,25 @@
2525
"contributors": [
2626
"Titus Wormer <[email protected]> (https://wooorm.com)"
2727
],
28+
"sideEffects": false,
29+
"type": "module",
30+
"main": "index.js",
2831
"files": [
2932
"index.js"
3033
],
3134
"devDependencies": {
32-
"hastscript": "^6.0.0",
33-
"nyc": "^15.0.0",
35+
"c8": "^7.0.0",
36+
"hastscript": "^7.0.0",
3437
"prettier": "^2.0.0",
3538
"remark-cli": "^9.0.0",
3639
"remark-preset-wooorm": "^8.0.0",
3740
"tape": "^5.0.0",
38-
"xo": "^0.38.0"
41+
"xo": "^0.39.0"
3942
},
4043
"scripts": {
4144
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
42-
"test-api": "node test",
43-
"test-coverage": "nyc --reporter lcov tape test.js",
45+
"test-api": "node test.js",
46+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
4447
"test": "npm run format && npm run test-coverage"
4548
},
4649
"prettier": {
@@ -53,13 +56,10 @@
5356
},
5457
"xo": {
5558
"prettier": true,
56-
"esnext": false
57-
},
58-
"nyc": {
59-
"check-coverage": true,
60-
"lines": 100,
61-
"functions": 100,
62-
"branches": 100
59+
"rules": {
60+
"no-var": "off",
61+
"prefer-arrow-callback": "off"
62+
}
6363
},
6464
"remarkConfig": {
6565
"plugins": [

readme.md

Lines changed: 6 additions & 0 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
@@ -30,6 +33,9 @@ rank(h('h5', 'Alpha')) //=> 5
3033

3134
## API
3235

36+
This package exports the following identifiers: `headingRank`.
37+
There is no default export.
38+
3339
### `headingRank(node)`
3440

3541
Get the rank (`1` to `6`) of headings (`h1` to `h6`).

test.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
'use strict'
1+
import test from 'tape'
2+
import {h} from 'hastscript'
3+
import {headingRank} from './index.js'
24

3-
var test = require('tape')
4-
var h = require('hastscript')
5-
var rank = require('.')
6-
7-
test('rank', function (t) {
8-
t.equal(rank(), null, 'should return null for non-nodes')
5+
test('headingRank', function (t) {
6+
t.equal(headingRank(), null, 'should return null for non-nodes')
97

108
t.equal(
11-
rank({type: 'text', value: '!'}),
9+
headingRank({type: 'text', value: '!'}),
1210
null,
1311
'should return null for non-elements'
1412
)
1513

16-
t.equal(rank(h('p', '!')), null, 'should return null for non-headings')
14+
t.equal(headingRank(h('p', '!')), null, 'should return null for non-headings')
1715

18-
t.equal(rank(h('h5', '!')), 5, 'should return the rank of a heading')
16+
t.equal(headingRank(h('h5', '!')), 5, 'should return the rank of a heading')
1917

2018
t.end()
2119
})

0 commit comments

Comments
 (0)