diff --git a/.gitignore b/.gitignore index f1053d1..735f4af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ .DS_Store *.log -.nyc_output/ coverage/ node_modules/ -mdast-util-definitions.js -mdast-util-definitions.min.js yarn.lock diff --git a/.prettierignore b/.prettierignore index 05e7944..cebe81f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,2 @@ coverage/ -mdast-util-definitions.js -mdast-util-definitions.min.js -*.json *.md diff --git a/index.js b/index.js index 17cc583..56a50a1 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,9 @@ -'use strict' - -var visit = require('unist-util-visit') - -module.exports = createGetDefinition +import {visit} from 'unist-util-visit' var own = {}.hasOwnProperty // Get a definition in `node` by `identifier`. -function createGetDefinition(node) { +export function definitions(node) { var cache = {} if (!node || !node.type) { diff --git a/package.json b/package.json index 81c487d..627485e 100644 --- a/package.json +++ b/package.json @@ -26,42 +26,32 @@ "contributors": [ "Titus Wormer (https://wooorm.com)" ], + "sideEffects": false, + "type": "module", + "main": "index.js", "types": "types/index.d.ts", "files": [ "types", "index.js" ], "dependencies": { - "unist-util-visit": "^2.0.0" + "unist-util-visit": "^3.0.0" }, "devDependencies": { "@types/mdast": "^3.0.0", - "browserify": "^17.0.0", - "dtslint": "^4.0.0", - "nyc": "^15.0.0", + "c8": "^7.0.0", "prettier": "^2.0.0", "remark": "^13.0.0", "remark-cli": "^9.0.0", "remark-preset-wooorm": "^8.0.0", "tape": "^5.0.0", - "tinyify": "^3.0.0", - "xo": "^0.38.0" + "xo": "^0.39.0" }, "scripts": { - "format": "remark . -qfo && prettier . --write && xo --fix --ignore types", - "build-bundle": "browserify . -s mdastUtilDefinitions -o mdast-util-definitions.js", - "build-mangle": "browserify . -s mdastUtilDefinitions -o mdast-util-definitions.min.js -p tinyify", - "build": "npm run build-bundle && npm run build-mangle", - "test-api": "node test", - "test-coverage": "nyc --reporter lcov tape test.js", - "test-types": "dtslint types", - "test": "npm run format && npm run build && npm run test-coverage && npm run test-types" - }, - "nyc": { - "check-coverage": true, - "lines": 100, - "functions": 100, - "branches": 100 + "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "test-api": "node test.js", + "test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", + "test": "npm run format && npm run test-coverage" }, "prettier": { "tabWidth": 2, @@ -73,10 +63,12 @@ }, "xo": { "prettier": true, - "esnext": false, + "rules": { + "no-var": "off", + "prefer-arrow-callback": "off" + }, "ignore": [ - "types", - "mdast-util-definitions.js" + "types/" ] }, "remarkConfig": { diff --git a/readme.md b/readme.md index 6233ecf..a9b11ae 100644 --- a/readme.md +++ b/readme.md @@ -14,30 +14,27 @@ Supports funky keys, like `__proto__` or `toString`. ## Install +This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): +Node 12+ is needed to use it and it must be `import`ed instead of `require`d. + [npm][]: ```sh npm install mdast-util-definitions ``` -[npm][] with [TypeScript][] support: - -```sh -npm install mdast-util-definitions @types/mdast -``` - ## Use ```js -var remark = require('remark') -var definitions = require('mdast-util-definitions') +import remark from 'remark' +import {definitions} from 'mdast-util-definitions' -var ast = remark().parse('[example]: https://example.com "Example"') +var tree = remark().parse('[example]: https://example.com "Example"') -var definition = definitions(ast) +var definition = definitions(tree) definition('example') -// => {type: 'definition', 'title': 'Example', ...} +// => {type: 'definition', 'title': 'Example', …} definition('foo') // => null @@ -45,6 +42,9 @@ definition('foo') ## API +This package exports the following identifiers: `definitions`. +There is no default export. + ### `definitions(tree)` Create a cache of all [definition][]s in [`tree`][node]. @@ -126,8 +126,6 @@ abide by its terms. [npm]: https://docs.npmjs.com/cli/install -[typescript]: https://www.typescriptlang.org/ - [contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md [support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md diff --git a/test.js b/test.js index 7809cc0..82d574a 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,6 @@ -'use strict' - -var test = require('tape') -var remark = require('remark') -var definitions = require('.') +import test from 'tape' +import remark from 'remark' +import {definitions} from './index.js' test('mdast-util-definitions', function (t) { var tree