Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 13, 2021
1 parent 7a4b0f4 commit 1c06a3a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 39 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
coverage/
unist-util-visit-children.js
unist-util-visit-children.min.js
*.json
*.md
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
31 changes: 10 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,25 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (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,
Expand All @@ -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": [
Expand Down
10 changes: 8 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit 1c06a3a

Please sign in to comment.