/** * @typedef {import('unist').Node} Node * @typedef {import('unist').Parent} Parent * @typedef {import('hast').Element} Element * * @typedef {string} TagName */ /** * Check if an element passes a test * * @callback TestFunctionAnything * @param {Element} element * @param {number} [index] * @param {Parent} [parent] * @returns {boolean|void} */ /** * Check if an element passes a certain node test * * @template {Element} X * @callback TestFunctionPredicate * @param {X} element * @param {number} [index] * @param {Parent} [parent] * @returns {element is X} */ /** * Check if a node is an element and passes a certain node test * * @callback AssertAnything * @param {unknown} [node] * @param {number} [index] * @param {Parent} [parent] * @returns {boolean} */ /** * Check if a node is an element and passes a certain node test * * @template {Element} Y * @callback AssertPredicate * @param {unknown} [node] * @param {number} [index] * @param {Parent} [parent] * @returns {node is Y} */ export const isElement: (( node: unknown, test: | T['tagName'] | TestFunctionPredicate | (T['tagName'] | TestFunctionPredicate)[], index?: number, parent?: Parent, context?: unknown ) => node is T) & (( node?: unknown, test?: | null | undefined | TagName | TestFunctionAnything | Array, index?: number, parent?: Parent, context?: unknown ) => boolean) export const convertElement: (( test: T['tagName'] | TestFunctionPredicate ) => AssertPredicate) & (( test?: | null | undefined | TagName | TestFunctionAnything | Array ) => AssertAnything) export type Node = import('unist').Node export type Parent = import('unist').Parent export type Element = import('hast').Element export type TagName = string /** * Check if an element passes a test */ export type TestFunctionAnything = ( element: Element, index?: number, parent?: Parent ) => boolean | void /** * Check if an element passes a certain node test */ export type TestFunctionPredicate = ( element: X, index?: number, parent?: Parent ) => element is X /** * Check if a node is an element and passes a certain node test */ export type AssertAnything = ( node?: unknown, index?: number, parent?: Parent ) => boolean /** * Check if a node is an element and passes a certain node test */ export type AssertPredicate = ( node?: unknown, index?: number, parent?: Parent ) => node is Y