unist-util-map
Advanced tools
Comparing version 3.0.0 to 3.0.1
/** | ||
* @typedef {import('unist').Parent} Parent | ||
* @typedef {import('unist').Position} Position | ||
* @typedef {import('unist').Node} Node | ||
* @typedef {import('unist').Parent} Parent | ||
* @typedef {Record<string, unknown> & {type: string, position?: Position|undefined}} NodeLike | ||
*/ | ||
@@ -9,6 +11,6 @@ /** | ||
* @callback MapFunction | ||
* @param {Node} node Current node being processed | ||
* @param {NodeLike|Node} node Current node being processed | ||
* @param {number} [index] Index of `node`, or `null` | ||
* @param {Parent} [parent] Parent of `node`, or `null` | ||
* @returns {Node} Node to be used in the new tree. Its children are not used: if the original node has children, those are mapped. | ||
* @returns {NodeLike|Node} Node to be used in the new tree. Its children are not used: if the original node has children, those are mapped. | ||
*/ | ||
@@ -18,12 +20,24 @@ /** | ||
* | ||
* @param {Node} tree Tree to map | ||
* @param {NodeLike|Node} tree Tree to map | ||
* @param {MapFunction} iteratee Function that returns a new node | ||
* @returns {Node} New mapped tree. | ||
* @returns {NodeLike|Node} New mapped tree. | ||
*/ | ||
export function map(tree: Node, iteratee: MapFunction): Node | ||
export function map( | ||
tree: NodeLike | Node, | ||
iteratee: MapFunction | ||
): NodeLike | Node | ||
export type Parent = import('unist').Parent | ||
export type Position = import('unist').Position | ||
export type Node = import('unist').Node | ||
export type Parent = import('unist').Parent | ||
export type NodeLike = Record<string, unknown> & { | ||
type: string | ||
position?: Position | undefined | ||
} | ||
/** | ||
* Function called with a node to produce a new node. | ||
*/ | ||
export type MapFunction = (node: Node, index?: number, parent?: Parent) => Node | ||
export type MapFunction = ( | ||
node: NodeLike | Node, | ||
index?: number, | ||
parent?: Parent | ||
) => NodeLike | Node |
20
index.js
/** | ||
* @typedef {import('unist').Parent} Parent | ||
* @typedef {import('unist').Position} Position | ||
* @typedef {import('unist').Node} Node | ||
* @typedef {import('unist').Parent} Parent | ||
* @typedef {Record<string, unknown> & {type: string, position?: Position|undefined}} NodeLike | ||
*/ | ||
@@ -10,6 +12,6 @@ | ||
* @callback MapFunction | ||
* @param {Node} node Current node being processed | ||
* @param {NodeLike|Node} node Current node being processed | ||
* @param {number} [index] Index of `node`, or `null` | ||
* @param {Parent} [parent] Parent of `node`, or `null` | ||
* @returns {Node} Node to be used in the new tree. Its children are not used: if the original node has children, those are mapped. | ||
* @returns {NodeLike|Node} Node to be used in the new tree. Its children are not used: if the original node has children, those are mapped. | ||
*/ | ||
@@ -20,5 +22,5 @@ | ||
* | ||
* @param {Node} tree Tree to map | ||
* @param {NodeLike|Node} tree Tree to map | ||
* @param {MapFunction} iteratee Function that returns a new node | ||
* @returns {Node} New mapped tree. | ||
* @returns {NodeLike|Node} New mapped tree. | ||
*/ | ||
@@ -29,3 +31,3 @@ export function map(tree, iteratee) { | ||
/** | ||
* @param {Node} node | ||
* @param {NodeLike|Node} node | ||
* @param {number} [index] | ||
@@ -38,4 +40,4 @@ * @param {Parent} [parent] | ||
if (node.children) { | ||
// @ts-ignore Looks like a parent. | ||
if ('children' in node) { | ||
// @ts-expect-error Looks like a parent. | ||
newNode.children = node.children.map(function ( | ||
@@ -45,3 +47,3 @@ /** @type {Node} */ child, | ||
) { | ||
// @ts-ignore Looks like a parent. | ||
// @ts-expect-error Looks like a parent. | ||
return preorder(child, index, node) | ||
@@ -48,0 +50,0 @@ }) |
{ | ||
"name": "unist-util-map", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "unist utility to create a new tree by mapping all nodes", | ||
@@ -44,4 +44,4 @@ "license": "MIT", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-cli": "^10.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
@@ -51,5 +51,4 @@ "tape": "^5.0.0", | ||
"typescript": "^4.0.0", | ||
"unist-builder": "^2.0.0", | ||
"unist-util-is": "^4.0.0", | ||
"xo": "^0.38.0" | ||
"unist-builder": "^3.0.0", | ||
"xo": "^0.48.0" | ||
}, | ||
@@ -56,0 +55,0 @@ "scripts": { |
@@ -28,3 +28,3 @@ # unist-util-map | ||
```js | ||
import u from 'unist-builder' | ||
import {u} from 'unist-builder' | ||
import {map} from 'unist-util-map' | ||
@@ -31,0 +31,0 @@ |
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
10772
11
86