Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 18, 2021
1 parent 66c27d2 commit 3cc5f98
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 32 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
yarn.lock
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
coverage/
*.json
*.md
8 changes: 1 addition & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
'use strict'

var WeakMap = require('es6-weak-map')

var cache = new WeakMap()

module.exports = parents

function parents(ast) {
export function parents(ast) {
return wrapNode(ast, null)
}

Expand Down
23 changes: 8 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
"Eugene Sharygin <eush77@gmail.com>",
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js"
],
"dependencies": {
"es6-weak-map": "^2.0.0"
},
"devDependencies": {
"c8": "^7.0.0",
"clone": "^2.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
Expand All @@ -44,16 +44,10 @@
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"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"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
Expand All @@ -64,10 +58,9 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"unicorn/no-reduce": "off",
"unicorn/no-fn-reference-in-iterator": "off"
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
Expand Down
12 changes: 9 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ which it originated.

## 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 @@ -28,8 +31,8 @@ npm install unist-util-parents
## Use

```js
var u = require('unist-builder')
var parents = require('unist-util-parents')
import {u} from 'unist-builder'
import {parents} from 'unist-util-parents'

var tree = u('root', [
u('leaf', 'leaf 1'),
Expand Down Expand Up @@ -62,11 +65,14 @@ console.log(chain)
Yields:

```js
[ 'root', 'node', 'node', 'node', 'leaf' ]
['root', 'node', 'node', 'node', 'leaf']
```

## API

This package exports the following identifiers: `parents`.
There is no default export.

### `parents(tree)`

Returns a wrapped `tree` with a proxy that imposes two additional properties on
Expand Down
8 changes: 3 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'

var test = require('tape')
var clone = require('clone')
var parents = require('.')
import test from 'tape'
import clone from 'clone'
import {parents} from './index.js'

var ast = {
type: 'root',
Expand Down

0 comments on commit 3cc5f98

Please sign in to comment.