🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
23
node_modules/nlcst-to-string/lib/index.d.ts
generated
vendored
Normal file
23
node_modules/nlcst-to-string/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* @typedef {import('nlcst').Content} Content
|
||||
* @typedef {import('nlcst').Root} Root
|
||||
*/
|
||||
/**
|
||||
* Get the text content of a node or list of nodes.
|
||||
*
|
||||
* Prefers the node’s plain-text fields, otherwise serializes its children, and
|
||||
* if the given value is an array, serialize the nodes in it.
|
||||
*
|
||||
* @param {Root | Content | Array<Content>} value
|
||||
* Node or list of nodes to serialize.
|
||||
* @param {string | null | undefined} [separator='']
|
||||
* Separator to use.
|
||||
* @returns {string}
|
||||
* Result.
|
||||
*/
|
||||
export function toString(
|
||||
value: Root | Content | Array<Content>,
|
||||
separator?: string | null | undefined
|
||||
): string
|
||||
export type Content = import('nlcst').Content
|
||||
export type Root = import('nlcst').Root
|
||||
47
node_modules/nlcst-to-string/lib/index.js
generated
vendored
Normal file
47
node_modules/nlcst-to-string/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* @typedef {import('nlcst').Content} Content
|
||||
* @typedef {import('nlcst').Root} Root
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the text content of a node or list of nodes.
|
||||
*
|
||||
* Prefers the node’s plain-text fields, otherwise serializes its children, and
|
||||
* if the given value is an array, serialize the nodes in it.
|
||||
*
|
||||
* @param {Root | Content | Array<Content>} value
|
||||
* Node or list of nodes to serialize.
|
||||
* @param {string | null | undefined} [separator='']
|
||||
* Separator to use.
|
||||
* @returns {string}
|
||||
* Result.
|
||||
*/
|
||||
// To do next major: remove `separator`.
|
||||
export function toString(value, separator) {
|
||||
let index = -1
|
||||
|
||||
if (!value || (!Array.isArray(value) && !value.type)) {
|
||||
throw new Error('Expected node, not `' + value + '`')
|
||||
}
|
||||
|
||||
// @ts-expect-error Looks like a literal.
|
||||
if (typeof value.value === 'string') return value.value
|
||||
|
||||
/** @type {Array<Content|Root>} */
|
||||
// @ts-expect-error Looks like a list of nodes or parent.
|
||||
const children = (Array.isArray(value) ? value : value.children) || []
|
||||
|
||||
// Shortcut: This is pretty common, and a small performance win.
|
||||
if (children.length === 1 && 'value' in children[0]) {
|
||||
return children[0].value
|
||||
}
|
||||
|
||||
/** @type {Array<string>} */
|
||||
const values = []
|
||||
|
||||
while (++index < children.length) {
|
||||
values[index] = toString(children[index], separator)
|
||||
}
|
||||
|
||||
return values.join(separator || '')
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue