/** * @typedef {import('unist').Node} Node * @typedef {import('unist').Parent} Parent * * @typedef {string} Type * @typedef {Object} Props * * @typedef {null|undefined|Type|Props|TestFunctionAnything|Array.} Test */ /** * Check if a node passes a test * * @callback TestFunctionAnything * @param {Node} node * @param {number|null|undefined} [index] * @param {Parent|null|undefined} [parent] * @returns {boolean|void} */ /** * Check if a node passes a certain node test * * @template {Node} X * @callback TestFunctionPredicate * @param {Node} node * @param {number|null|undefined} [index] * @param {Parent|null|undefined} [parent] * @returns {node is X} */ /** * @callback AssertAnything * @param {unknown} [node] * @param {number|null|undefined} [index] * @param {Parent|null|undefined} [parent] * @returns {boolean} */ /** * Check if a node passes a certain node test * * @template {Node} Y * @callback AssertPredicate * @param {unknown} [node] * @param {number|null|undefined} [index] * @param {Parent|null|undefined} [parent] * @returns {node is Y} */ export const is: (>( node: unknown, test: | T['type'] | Partial | TestFunctionPredicate | (T['type'] | Partial | TestFunctionPredicate)[], index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown ) => node is T) & (( node?: unknown, test?: Test, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown ) => boolean) export const convert: (>( test: T['type'] | Partial | TestFunctionPredicate ) => AssertPredicate) & ((test?: Test) => AssertAnything) export type Node = import('unist').Node export type Parent = import('unist').Parent export type Type = string export type Props = { [x: string]: unknown } export type Test = | null | undefined | Type | Props | TestFunctionAnything | Array /** * Check if a node passes a test */ export type TestFunctionAnything = ( node: Node, index?: number | null | undefined, parent?: Parent | null | undefined ) => boolean | void /** * Check if a node passes a certain node test */ export type TestFunctionPredicate< X extends import('unist').Node > = ( node: Node, index?: number | null | undefined, parent?: Parent | null | undefined ) => node is X export type AssertAnything = ( node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined ) => boolean /** * Check if a node passes a certain node test */ export type AssertPredicate< Y extends import('unist').Node > = ( node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined ) => node is Y