UNPKG

mancha

Version:

Javscript HTML rendering engine

56 lines (55 loc) 3.23 kB
export type ElementWithAttribs = Element & { dataset?: DOMStringMap; attribs?: { [key: string]: string; }; }; /** * Traverses the DOM tree starting from the given root node and yields each child node. * Nodes in the `skip` set will be skipped during traversal. * * @param root - The root node to start the traversal from. * @param skip - A set of nodes to skip during traversal. * @returns A generator that yields each child node in the DOM tree. */ export declare function traverse(root: Node | DocumentFragment | Document, skip?: Set<Node>): Generator<ChildNode>; export declare function hasProperty(obj: unknown, prop: string): boolean; export declare function hasFunction(obj: unknown, func: string): boolean; /** * Converts from an attribute name to camelCase, e.g. `foo-bar` becomes `fooBar`. * @param name attribute name * @returns camel-cased attribute name */ export declare function attributeNameToCamelCase(name: string): string; export declare function getAttribute(elem: ElementWithAttribs, name: string): string | null; export declare function hasAttribute(elem: ElementWithAttribs, name: string): boolean; export declare function getAttributeOrDataset(elem: ElementWithAttribs, name: string, attributePrefix?: string): string | null; export declare function hasAttributeOrDataset(elem: ElementWithAttribs, name: string, attributePrefix?: string): boolean; export declare function setAttribute(elem: ElementWithAttribs, name: string, value: string): void; export declare function safeSetAttribute(elem: ElementWithAttribs, name: string, value: string): void; export declare function setProperty(elem: ElementWithAttribs, name: string, value: unknown): void; export declare function removeAttribute(elem: ElementWithAttribs, name: string): void; export declare function setAttributeOrDataset(elem: ElementWithAttribs, name: string, value: string, prefix?: string): void; export declare function removeAttributeOrDataset(elem: ElementWithAttribs, name: string, prefix?: string): void; export declare function cloneAttribute(elemFrom: ElementWithAttribs, elemDest: ElementWithAttribs, name: string): void; export declare function firstElementChild(elem: Element): Element | null; export declare function replaceWith(original: ChildNode, ...replacement: Node[]): void; export declare function replaceChildren(parent: ParentNode, ...nodes: Node[]): void; export declare function appendChild(parent: Node, node: Node): Node; export declare function removeChild(parent: ParentNode, node: Node): Node; export declare function insertBefore(parent: Node, node: Node, reference: ChildNode | null): Node; export declare function ellipsize(str: string | null, maxLength?: number): string; export declare function nodeToString(node: Node, maxLength?: number): string; /** * Returns the directory name from a given file path. * @param fpath - The file path. * @returns The directory name. */ export declare function dirname(fpath: string): string; /** * Checks if a given file path is a relative path. * * @param fpath - The file path to check. * @returns A boolean indicating whether the file path is relative or not. */ export declare function isRelativePath(fpath: string): boolean;