shelving
Version:
Toolkit for using data in JavaScript.
33 lines (32 loc) • 1.46 kB
TypeScript
/** Set of valid props for a JSX element. */
export interface JSXProps {
readonly [key: string]: unknown;
readonly children?: JSXNode;
}
/** JSX element (similar to `React.ReactElement`) */
export interface JSXElement<P extends JSXProps = JSXProps> {
readonly type: string | ((props: P) => JSXNode | null);
readonly props: P;
readonly key: string | null;
readonly $$typeof?: symbol;
}
/** JSX node (similar to `React.ReactNode`) */
export type JSXNode = undefined | null | string | JSXElement | readonly JSXNode[];
/** Is an unknown value a JSX element? */
export declare function isJSXElement(value: unknown): value is JSXElement;
/** Is an unknown value a JSX node? */
export declare function isJSXNode(value: unknown): value is JSXNode;
/**
* Take a Markup JSX node and strip all tags from it to produce a plain text string.
*
* @param node A JsxNode, e.g. either a JSX element, a plain string, or null/undefined (or an array of those things).
* @returns The combined string made from the JSX node.
*
* @example `- Item with *strong*\n- Item with _em_` becomes `Item with strong Item with em`
*/
export declare function getJSXNodeText(node?: JSXNode): string;
/**
* Iterate through all elements in a node.
* - This is useful if you, e.g. want to apply a `className` to all `<h1>` elements, or make a list of all URLs found in a Node.
*/
export declare function getJSXNodeElements(node: JSXNode): Iterable<JSXElement>;