diff --git a/.gitignore b/.gitignore index 7f93ef7..735f4af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ .DS_Store *.log -.nyc_output/ coverage/ node_modules/ -unist-util-visit-children.js -unist-util-visit-children.min.js yarn.lock diff --git a/.prettierignore b/.prettierignore index 5e770e4..cebe81f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,2 @@ coverage/ -unist-util-visit-children.js -unist-util-visit-children.min.js -*.json *.md diff --git a/index.js b/index.js index 0b15d41..bf52b70 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,4 @@ -'use strict' - -module.exports = visitChildren - -function visitChildren(callback) { +export function visitChildren(callback) { return visitor // Visit `parent`, invoking `callback` for each child. diff --git a/package.json b/package.json index b603187..ed58cf0 100644 --- a/package.json +++ b/package.json @@ -21,33 +21,25 @@ "contributors": [ "Titus Wormer (https://wooorm.com)" ], + "sideEffects": false, + "type": "module", + "main": "index.js", "files": [ "index.js" ], "devDependencies": { - "browserify": "^17.0.0", - "nyc": "^15.0.0", + "c8": "^7.0.0", "prettier": "^2.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" }, "scripts": { "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", - "build-bundle": "browserify . -s unistUtilVisitChildren -o unist-util-visit-children.js", - "build-mangle": "browserify . -s unistUtilVisitChildren -o unist-util-visit-children.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": "npm run format && npm run build && npm run test-coverage" - }, - "nyc": { - "check-coverage": true, - "lines": 100, - "functions": 100, - "branches": 100 + "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, @@ -59,13 +51,10 @@ }, "xo": { "prettier": true, - "esnext": false, "rules": { - "guard-for-in": "off" - }, - "ignores": [ - "unist-util-visit-children.js" - ] + "no-var": "off", + "prefer-arrow-callback": "off" + } }, "remarkConfig": { "plugins": [ diff --git a/readme.md b/readme.md index 0390085..80a588e 100644 --- a/readme.md +++ b/readme.md @@ -12,6 +12,9 @@ ## 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 @@ -21,8 +24,8 @@ npm install unist-util-visit-children ## Use ```js -var u = require('unist-builder') -var visitChildren = require('unist-util-visit-children') +import u from 'unist-builder' +import {visitChildren} from 'unist-util-visit-children' var visit = visitChildren(function(node) { console.log(node) @@ -55,6 +58,9 @@ Yields: ## API +This package exports the following identifiers: `visitChildren`. +There is no default export. + ### `visit = visitChildren(visitor)` Wrap [`visitor`][visitor] to be invoked for each [child][] in the nodes later diff --git a/test.js b/test.js index bd184de..c0ea4ee 100644 --- a/test.js +++ b/test.js @@ -1,9 +1,7 @@ -'use strict' +import test from 'tape' +import {visitChildren} from './index.js' -var test = require('tape') -var visitChildren = require('.') - -var noop = Function.prototype +function noop() {} test('visitChildren()', function (t) { t.throws(