Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 23, 2021
1 parent 3310157 commit e64f656
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 53 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/
mdast-util-definitions.js
mdast-util-definitions.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/
mdast-util-definitions.js
mdast-util-definitions.min.js
*.json
*.md
8 changes: 2 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
38 changes: 15 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,32 @@
"contributors": [
"Titus Wormer <[email protected]> (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,
Expand All @@ -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": {
Expand Down
24 changes: 11 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ 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
```

## 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].
Expand Down Expand Up @@ -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
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 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
Expand Down

0 comments on commit e64f656

Please sign in to comment.