Skip to content

Commit e64f656

Browse files
committed
Use ESM
1 parent 3310157 commit e64f656

File tree

6 files changed

+31
-53
lines changed

6 files changed

+31
-53
lines changed

.gitignore

-3
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-definitions.js
7-
mdast-util-definitions.min.js
85
yarn.lock

.prettierignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
coverage/
2-
mdast-util-definitions.js
3-
mdast-util-definitions.min.js
4-
*.json
52
*.md

index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
'use strict'
2-
3-
var visit = require('unist-util-visit')
4-
5-
module.exports = createGetDefinition
1+
import {visit} from 'unist-util-visit'
62

73
var own = {}.hasOwnProperty
84

95
// Get a definition in `node` by `identifier`.
10-
function createGetDefinition(node) {
6+
export function definitions(node) {
117
var cache = {}
128

139
if (!node || !node.type) {

package.json

+15-23
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,32 @@
2626
"contributors": [
2727
"Titus Wormer <[email protected]> (https://wooorm.com)"
2828
],
29+
"sideEffects": false,
30+
"type": "module",
31+
"main": "index.js",
2932
"types": "types/index.d.ts",
3033
"files": [
3134
"types",
3235
"index.js"
3336
],
3437
"dependencies": {
35-
"unist-util-visit": "^2.0.0"
38+
"unist-util-visit": "^3.0.0"
3639
},
3740
"devDependencies": {
3841
"@types/mdast": "^3.0.0",
39-
"browserify": "^17.0.0",
40-
"dtslint": "^4.0.0",
41-
"nyc": "^15.0.0",
42+
"c8": "^7.0.0",
4243
"prettier": "^2.0.0",
4344
"remark": "^13.0.0",
4445
"remark-cli": "^9.0.0",
4546
"remark-preset-wooorm": "^8.0.0",
4647
"tape": "^5.0.0",
47-
"tinyify": "^3.0.0",
48-
"xo": "^0.38.0"
48+
"xo": "^0.39.0"
4949
},
5050
"scripts": {
51-
"format": "remark . -qfo && prettier . --write && xo --fix --ignore types",
52-
"build-bundle": "browserify . -s mdastUtilDefinitions -o mdast-util-definitions.js",
53-
"build-mangle": "browserify . -s mdastUtilDefinitions -o mdast-util-definitions.min.js -p tinyify",
54-
"build": "npm run build-bundle && npm run build-mangle",
55-
"test-api": "node test",
56-
"test-coverage": "nyc --reporter lcov tape test.js",
57-
"test-types": "dtslint types",
58-
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
59-
},
60-
"nyc": {
61-
"check-coverage": true,
62-
"lines": 100,
63-
"functions": 100,
64-
"branches": 100
51+
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
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",
54+
"test": "npm run format && npm run test-coverage"
6555
},
6656
"prettier": {
6757
"tabWidth": 2,
@@ -73,10 +63,12 @@
7363
},
7464
"xo": {
7565
"prettier": true,
76-
"esnext": false,
66+
"rules": {
67+
"no-var": "off",
68+
"prefer-arrow-callback": "off"
69+
},
7770
"ignore": [
78-
"types",
79-
"mdast-util-definitions.js"
71+
"types/"
8072
]
8173
},
8274
"remarkConfig": {

readme.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,37 @@ Supports funky keys, like `__proto__` or `toString`.
1414

1515
## Install
1616

17+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
18+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
19+
1720
[npm][]:
1821

1922
```sh
2023
npm install mdast-util-definitions
2124
```
2225

23-
[npm][] with [TypeScript][] support:
24-
25-
```sh
26-
npm install mdast-util-definitions @types/mdast
27-
```
28-
2926
## Use
3027

3128
```js
32-
var remark = require('remark')
33-
var definitions = require('mdast-util-definitions')
29+
import remark from 'remark'
30+
import {definitions} from 'mdast-util-definitions'
3431

35-
var ast = remark().parse('[example]: https://example.com "Example"')
32+
var tree = remark().parse('[example]: https://example.com "Example"')
3633

37-
var definition = definitions(ast)
34+
var definition = definitions(tree)
3835

3936
definition('example')
40-
// => {type: 'definition', 'title': 'Example', ...}
37+
// => {type: 'definition', 'title': 'Example', }
4138

4239
definition('foo')
4340
// => null
4441
```
4542

4643
## API
4744

45+
This package exports the following identifiers: `definitions`.
46+
There is no default export.
47+
4848
### `definitions(tree)`
4949

5050
Create a cache of all [definition][]s in [`tree`][node].
@@ -126,8 +126,6 @@ abide by its terms.
126126

127127
[npm]: https://docs.npmjs.com/cli/install
128128

129-
[typescript]: https://www.typescriptlang.org/
130-
131129
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
132130

133131
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md

test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var remark = require('remark')
5-
var definitions = require('.')
1+
import test from 'tape'
2+
import remark from 'remark'
3+
import {definitions} from './index.js'
64

75
test('mdast-util-definitions', function (t) {
86
var tree

0 commit comments

Comments
 (0)