mdast-util-definitions
Advanced tools
Comparing version 5.1.2 to 6.0.0
@@ -7,3 +7,3 @@ /** | ||
* | ||
* @param {Node} tree | ||
* @param {Nodes} tree | ||
* Tree to check. | ||
@@ -13,7 +13,5 @@ * @returns {GetDefinition} | ||
*/ | ||
export function definitions(tree: Node): GetDefinition | ||
export type Root = import('mdast').Root | ||
export type Content = import('mdast').Content | ||
export function definitions(tree: Nodes): GetDefinition | ||
export type Definition = import('mdast').Definition | ||
export type Node = Root | Content | ||
export type Nodes = import('mdast').Nodes | ||
/** | ||
@@ -24,2 +22,2 @@ * Get a definition by identifier. | ||
identifier?: string | null | undefined | ||
) => Definition | null | ||
) => Definition | undefined |
/** | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('mdast').Content} Content | ||
* @typedef {import('mdast').Definition} Definition | ||
* @typedef {import('mdast').Nodes} Nodes | ||
*/ | ||
/** | ||
* @typedef {Root | Content} Node | ||
* | ||
* @callback GetDefinition | ||
* Get a definition by identifier. | ||
* @param {string | null | undefined} [identifier] | ||
* Identifier of definition. | ||
* @returns {Definition | null} | ||
* Identifier of definition (optional). | ||
* @returns {Definition | undefined} | ||
* Definition corresponding to `identifier` or `null`. | ||
@@ -20,4 +17,2 @@ */ | ||
const own = {}.hasOwnProperty | ||
/** | ||
@@ -29,3 +24,3 @@ * Find definitions in `tree`. | ||
* | ||
* @param {Node} tree | ||
* @param {Nodes} tree | ||
* Tree to check. | ||
@@ -36,4 +31,4 @@ * @returns {GetDefinition} | ||
export function definitions(tree) { | ||
/** @type {Record<string, Definition>} */ | ||
const cache = Object.create(null) | ||
/** @type {Map<string, Definition>} */ | ||
const cache = new Map() | ||
@@ -44,6 +39,6 @@ if (!tree || !tree.type) { | ||
visit(tree, 'definition', (definition) => { | ||
visit(tree, 'definition', function (definition) { | ||
const id = clean(definition.identifier) | ||
if (id && !own.call(cache, id)) { | ||
cache[id] = definition | ||
if (id && !cache.get(id)) { | ||
cache.set(id, definition) | ||
} | ||
@@ -57,4 +52,3 @@ }) | ||
const id = clean(identifier) | ||
// To do: next major: return `undefined` when not found. | ||
return id && own.call(cache, id) ? cache[id] : null | ||
return cache.get(id) | ||
} | ||
@@ -61,0 +55,0 @@ } |
{ | ||
"name": "mdast-util-definitions", | ||
"version": "5.1.2", | ||
"version": "6.0.0", | ||
"description": "mdast utility to find definition nodes in a tree", | ||
@@ -31,4 +31,3 @@ "license": "MIT", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": "./index.js", | ||
"files": [ | ||
@@ -40,9 +39,9 @@ "lib/", | ||
"dependencies": { | ||
"@types/mdast": "^3.0.0", | ||
"@types/unist": "^2.0.0", | ||
"unist-util-visit": "^4.0.0" | ||
"@types/mdast": "^4.0.0", | ||
"@types/unist": "^3.0.0", | ||
"unist-util-visit": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.0.0", | ||
"c8": "^7.0.0", | ||
"@types/node": "^20.0.0", | ||
"c8": "^8.0.0", | ||
"mdast-util-from-markdown": "^1.0.0", | ||
@@ -53,4 +52,4 @@ "prettier": "^2.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.53.0" | ||
"typescript": "^5.0.0", | ||
"xo": "^0.54.0" | ||
}, | ||
@@ -62,19 +61,16 @@ "scripts": { | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"test-coverage": "c8 --100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false | ||
}, | ||
"xo": { | ||
"prettier": true | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
"remark-preset-wooorm" | ||
] | ||
@@ -85,4 +81,8 @@ }, | ||
"detail": true, | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"prettier": true | ||
} | ||
} |
@@ -42,3 +42,3 @@ # mdast-util-definitions | ||
This package is [ESM only][esm]. | ||
In Node.js (version 14.14+ and 16.0+), install with [npm][]: | ||
In Node.js (version 16+), install with [npm][]: | ||
@@ -52,3 +52,3 @@ ```sh | ||
```js | ||
import {definitions} from 'https://esm.sh/mdast-util-definitions@5' | ||
import {definitions} from 'https://esm.sh/mdast-util-definitions@6' | ||
``` | ||
@@ -60,3 +60,3 @@ | ||
<script type="module"> | ||
import {definitions} from 'https://esm.sh/mdast-util-definitions@5?bundle' | ||
import {definitions} from 'https://esm.sh/mdast-util-definitions@6?bundle' | ||
</script> | ||
@@ -68,4 +68,4 @@ ``` | ||
```js | ||
import {definitions} from 'mdast-util-definitions' | ||
import {fromMarkdown} from 'mdast-util-from-markdown' | ||
import {definitions} from 'mdast-util-definitions' | ||
@@ -80,3 +80,3 @@ const tree = fromMarkdown('[example]: https://example.com "Example"') | ||
definition('foo') | ||
// => null | ||
// => undefined | ||
``` | ||
@@ -117,3 +117,3 @@ | ||
Definition corresponding to `identifier` ([`Definition`][definition]) or | ||
`null`. | ||
`undefined`. | ||
@@ -127,7 +127,10 @@ ## Types | ||
Projects maintained by the unified collective are compatible with all maintained | ||
Projects maintained by the unified collective are compatible with maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 14.14+ and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
When we cut a new major release, we drop support for unmaintained versions of | ||
Node. | ||
This means we try to keep the current release line, | ||
`mdast-util-definitions@^6`, compatible with Node.js 16. | ||
## Security | ||
@@ -172,5 +175,5 @@ | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-definitions.svg | ||
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-definitions | ||
[size]: https://bundlephobia.com/result?p=mdast-util-definitions | ||
[size]: https://bundlejs.com/?q=mdast-util-definitions | ||
@@ -177,0 +180,0 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
215
10772
76
+ Added@types/mdast@4.0.4(transitive)
+ Added@types/unist@3.0.3(transitive)
+ Addedunist-util-is@6.0.0(transitive)
+ Addedunist-util-visit@5.0.0(transitive)
+ Addedunist-util-visit-parents@6.0.1(transitive)
- Removed@types/mdast@3.0.15(transitive)
- Removed@types/unist@2.0.11(transitive)
- Removedunist-util-is@5.2.1(transitive)
- Removedunist-util-visit@4.1.2(transitive)
- Removedunist-util-visit-parents@5.1.3(transitive)
Updated@types/mdast@^4.0.0
Updated@types/unist@^3.0.0
Updatedunist-util-visit@^5.0.0