first-commit
Some checks failed
CI Pipeline / build (push) Failing after 3m23s

This commit is contained in:
2025-08-27 14:05:33 +08:00
commit 9e1b8bdc9d
5159 changed files with 1081326 additions and 0 deletions

196
node_modules/unist-util-is/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,196 @@
/**
* @typedef {import('unist').Node} Node
* @typedef {import('unist').Parent} Parent
*/
/**
* @template Fn
* @template Fallback
* @typedef {Fn extends (value: any) => value is infer Thing ? Thing : Fallback} Predicate
*/
/**
* @callback Check
* Check that an arbitrary value is a node.
* @param {unknown} this
* The given context.
* @param {unknown} [node]
* Anything (typically a node).
* @param {number | null | undefined} [index]
* The nodes position in its parent.
* @param {Parent | null | undefined} [parent]
* The nodes parent.
* @returns {boolean}
* Whether this is a node and passes a test.
*
* @typedef {Record<string, unknown> | Node} Props
* Object to check for equivalence.
*
* Note: `Node` is included as it is common but is not indexable.
*
* @typedef {Array<Props | TestFunction | string> | Props | TestFunction | string | null | undefined} Test
* Check for an arbitrary node.
*
* @callback TestFunction
* Check if a node passes a test.
* @param {unknown} this
* The given context.
* @param {Node} node
* A node.
* @param {number | undefined} [index]
* The nodes position in its parent.
* @param {Parent | undefined} [parent]
* The nodes parent.
* @returns {boolean | undefined | void}
* Whether this node passes the test.
*
* Note: `void` is included until TS sees no return as `undefined`.
*/
/**
* Check if `node` is a `Node` and whether it passes the given test.
*
* @param {unknown} node
* Thing to check, typically `Node`.
* @param {Test} test
* A check for a specific node.
* @param {number | null | undefined} index
* The nodes position in its parent.
* @param {Parent | null | undefined} parent
* The nodes parent.
* @param {unknown} context
* Context object (`this`) to pass to `test` functions.
* @returns {boolean}
* Whether `node` is a node and passes a test.
*/
export const is: (<Condition extends string>(
node: unknown,
test: Condition,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown
) => node is import('unist').Node & {
type: Condition
}) &
(<Condition_1 extends Props>(
node: unknown,
test: Condition_1,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown
) => node is import('unist').Node & Condition_1) &
(<Condition_2 extends TestFunction>(
node: unknown,
test: Condition_2,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown
) => node is import('unist').Node &
Predicate<Condition_2, import('unist').Node>) &
((node?: null | undefined) => false) &
((
node: unknown,
test?: null | undefined,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown
) => node is import('unist').Node) &
((
node: unknown,
test?: Test,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown
) => boolean)
/**
* Generate an assertion from a test.
*
* Useful if youre going to test many nodes, for example when creating a
* utility where something else passes a compatible test.
*
* The created function is a bit faster because it expects valid input only:
* a `node`, `index`, and `parent`.
*
* @param {Test} test
* * when nullish, checks if `node` is a `Node`.
* * when `string`, works like passing `(node) => node.type === test`.
* * when `function` checks if function passed the node is true.
* * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
* * when `array`, checks if any one of the subtests pass.
* @returns {Check}
* An assertion.
*/
export const convert: (<Condition extends string>(
test: Condition
) => (
node: unknown,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown
) => node is import('unist').Node & {
type: Condition
}) &
(<Condition_1 extends Props>(
test: Condition_1
) => (
node: unknown,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown
) => node is import('unist').Node & Condition_1) &
(<Condition_2 extends TestFunction>(
test: Condition_2
) => (
node: unknown,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown
) => node is import('unist').Node &
Predicate<Condition_2, import('unist').Node>) &
((
test?: null | undefined
) => (
node?: unknown,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown
) => node is import('unist').Node) &
((test?: Test) => Check)
export type Node = import('unist').Node
export type Parent = import('unist').Parent
export type Predicate<Fn, Fallback> = Fn extends (
value: any
) => value is infer Thing
? Thing
: Fallback
/**
* Check that an arbitrary value is a node.
*/
export type Check = (
this: unknown,
node?: unknown,
index?: number | null | undefined,
parent?: Parent | null | undefined
) => boolean
/**
* Object to check for equivalence.
*
* Note: `Node` is included as it is common but is not indexable.
*/
export type Props = Record<string, unknown> | Node
/**
* Check for an arbitrary node.
*/
export type Test =
| Array<Props | TestFunction | string>
| Props
| TestFunction
| string
| null
| undefined
/**
* Check if a node passes a test.
*/
export type TestFunction = (
this: unknown,
node: Node,
index?: number | undefined,
parent?: Parent | undefined
) => boolean | undefined | void

291
node_modules/unist-util-is/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,291 @@
/**
* @typedef {import('unist').Node} Node
* @typedef {import('unist').Parent} Parent
*/
/**
* @template Fn
* @template Fallback
* @typedef {Fn extends (value: any) => value is infer Thing ? Thing : Fallback} Predicate
*/
/**
* @callback Check
* Check that an arbitrary value is a node.
* @param {unknown} this
* The given context.
* @param {unknown} [node]
* Anything (typically a node).
* @param {number | null | undefined} [index]
* The nodes position in its parent.
* @param {Parent | null | undefined} [parent]
* The nodes parent.
* @returns {boolean}
* Whether this is a node and passes a test.
*
* @typedef {Record<string, unknown> | Node} Props
* Object to check for equivalence.
*
* Note: `Node` is included as it is common but is not indexable.
*
* @typedef {Array<Props | TestFunction | string> | Props | TestFunction | string | null | undefined} Test
* Check for an arbitrary node.
*
* @callback TestFunction
* Check if a node passes a test.
* @param {unknown} this
* The given context.
* @param {Node} node
* A node.
* @param {number | undefined} [index]
* The nodes position in its parent.
* @param {Parent | undefined} [parent]
* The nodes parent.
* @returns {boolean | undefined | void}
* Whether this node passes the test.
*
* Note: `void` is included until TS sees no return as `undefined`.
*/
/**
* Check if `node` is a `Node` and whether it passes the given test.
*
* @param {unknown} node
* Thing to check, typically `Node`.
* @param {Test} test
* A check for a specific node.
* @param {number | null | undefined} index
* The nodes position in its parent.
* @param {Parent | null | undefined} parent
* The nodes parent.
* @param {unknown} context
* Context object (`this`) to pass to `test` functions.
* @returns {boolean}
* Whether `node` is a node and passes a test.
*/
export const is =
// Note: overloads in JSDoc cant yet use different `@template`s.
/**
* @type {(
* (<Condition extends string>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
* (<Condition extends Props>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
* (<Condition extends TestFunction>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
* ((node?: null | undefined) => false) &
* ((node: unknown, test?: null | undefined, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
* ((node: unknown, test?: Test, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => boolean)
* )}
*/
(
/**
* @param {unknown} [node]
* @param {Test} [test]
* @param {number | null | undefined} [index]
* @param {Parent | null | undefined} [parent]
* @param {unknown} [context]
* @returns {boolean}
*/
// eslint-disable-next-line max-params
function (node, test, index, parent, context) {
const check = convert(test)
if (
index !== undefined &&
index !== null &&
(typeof index !== 'number' ||
index < 0 ||
index === Number.POSITIVE_INFINITY)
) {
throw new Error('Expected positive finite index')
}
if (
parent !== undefined &&
parent !== null &&
(!is(parent) || !parent.children)
) {
throw new Error('Expected parent node')
}
if (
(parent === undefined || parent === null) !==
(index === undefined || index === null)
) {
throw new Error('Expected both parent and index')
}
return looksLikeANode(node)
? check.call(context, node, index, parent)
: false
}
)
/**
* Generate an assertion from a test.
*
* Useful if youre going to test many nodes, for example when creating a
* utility where something else passes a compatible test.
*
* The created function is a bit faster because it expects valid input only:
* a `node`, `index`, and `parent`.
*
* @param {Test} test
* * when nullish, checks if `node` is a `Node`.
* * when `string`, works like passing `(node) => node.type === test`.
* * when `function` checks if function passed the node is true.
* * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
* * when `array`, checks if any one of the subtests pass.
* @returns {Check}
* An assertion.
*/
export const convert =
// Note: overloads in JSDoc cant yet use different `@template`s.
/**
* @type {(
* (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
* (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
* (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
* ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
* ((test?: Test) => Check)
* )}
*/
(
/**
* @param {Test} [test]
* @returns {Check}
*/
function (test) {
if (test === null || test === undefined) {
return ok
}
if (typeof test === 'function') {
return castFactory(test)
}
if (typeof test === 'object') {
return Array.isArray(test) ? anyFactory(test) : propsFactory(test)
}
if (typeof test === 'string') {
return typeFactory(test)
}
throw new Error('Expected function, string, or object as test')
}
)
/**
* @param {Array<Props | TestFunction | string>} tests
* @returns {Check}
*/
function anyFactory(tests) {
/** @type {Array<Check>} */
const checks = []
let index = -1
while (++index < tests.length) {
checks[index] = convert(tests[index])
}
return castFactory(any)
/**
* @this {unknown}
* @type {TestFunction}
*/
function any(...parameters) {
let index = -1
while (++index < checks.length) {
if (checks[index].apply(this, parameters)) return true
}
return false
}
}
/**
* Turn an object into a test for a node with a certain fields.
*
* @param {Props} check
* @returns {Check}
*/
function propsFactory(check) {
const checkAsRecord = /** @type {Record<string, unknown>} */ (check)
return castFactory(all)
/**
* @param {Node} node
* @returns {boolean}
*/
function all(node) {
const nodeAsRecord = /** @type {Record<string, unknown>} */ (
/** @type {unknown} */ (node)
)
/** @type {string} */
let key
for (key in check) {
if (nodeAsRecord[key] !== checkAsRecord[key]) return false
}
return true
}
}
/**
* Turn a string into a test for a node with a certain type.
*
* @param {string} check
* @returns {Check}
*/
function typeFactory(check) {
return castFactory(type)
/**
* @param {Node} node
*/
function type(node) {
return node && node.type === check
}
}
/**
* Turn a custom test into a test for a node that passes that test.
*
* @param {TestFunction} testFunction
* @returns {Check}
*/
function castFactory(testFunction) {
return check
/**
* @this {unknown}
* @type {Check}
*/
function check(value, index, parent) {
return Boolean(
looksLikeANode(value) &&
testFunction.call(
this,
value,
typeof index === 'number' ? index : undefined,
parent || undefined
)
)
}
}
function ok() {
return true
}
/**
* @param {unknown} value
* @returns {value is Node}
*/
function looksLikeANode(value) {
return value !== null && typeof value === 'object' && 'type' in value
}