🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
58
node_modules/unist-util-visit-children/lib/index.js
generated
vendored
Normal file
58
node_modules/unist-util-visit-children/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* @typedef {import('unist').Parent} Parent
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template {Parent} Kind
|
||||
* Node type.
|
||||
* @callback Visitor
|
||||
* Callback called for each `child` in `parent` later given to `visit`.
|
||||
* @param {Kind['children'][number]} child
|
||||
* Child of parent.
|
||||
* @param {number} index
|
||||
* Position of `child` in parent.
|
||||
* @param {Kind} parent
|
||||
* Parent node.
|
||||
* @returns {void}
|
||||
* Nothing.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template {Parent} Kind
|
||||
* Node type.
|
||||
* @callback Visit
|
||||
* Function to call the bound `visitor` for each child in `parent`.
|
||||
* @param {Kind} node
|
||||
* Parent node.
|
||||
* @returns {void}
|
||||
* Nothing.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Wrap `visitor` to be called for each child in the nodes later given to
|
||||
* `visit`.
|
||||
*
|
||||
* @template {Parent} Kind
|
||||
* Node type.
|
||||
* @param {Visitor<Kind>} visitor
|
||||
* Callback called for each `child` in `parent` later given to `visit`.
|
||||
* @returns {Visit<Kind>}
|
||||
* Function to call the bound `visitor` for each child in `parent`.
|
||||
*/
|
||||
export function visitChildren(visitor) {
|
||||
return visit
|
||||
|
||||
/** @type {Visit<Kind>} */
|
||||
function visit(parent) {
|
||||
const children = parent && parent.children
|
||||
let index = -1
|
||||
|
||||
if (!children) {
|
||||
throw new Error('Missing children in `parent` for `visit`')
|
||||
}
|
||||
|
||||
while (++index in children) {
|
||||
visitor(children[index], index, parent)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue