/** * @enum {String} */ export declare class NodeType { static TEXT: string; static ROOT: string; } export interface NodeHandler { (n: Node): void; } export interface NodeFilter { (n: Node): boolean; } export declare type AttType = string | boolean | number; export default class Node { type: string; value: string; children: Node[]; /** * Ancestor nodes of the current node. Can possess multiple * parents. * @type {Array.} */ parents: Node[]; /** * Attributes of the node, defined in XML as ``, * where the key is the attribute name. * @type {Object.} */ att: Map; /** * The name of the tag. e.g. `` would return `foo`. * Only set on nodes that are parsed from XML text * @type {String} */ tagName: string; /** * @param {NodeType} type The type the current node is. * @param {String} value The value stored in this current node. * @constructor */ constructor(type: string, value?: string); /** * @param {NodeType} type The type of node being created. * @param {String} value The value stored in this node. */ cloneShallow(): Node; /** * @return {Node} A copy of the current node its entire sub-tree. */ cloneDeep(): Node; /** * Returns the value of an attribute given its name. * @param {String} name The name of the attribute. * @return {AttType} The value of the attribute. */ getAttribute(name: string): AttType; /** * Returns a numeric attribute. * @param {String} name The name of the attribute. * @return {number} The value of the attribute. */ getNumberAtt(name: string): number; /** * Returns the value of an attribute given its name. * @param {String} name The name of the attribute. * @param {String} value The name of the attribute. */ setAttribute(name: string, value: AttType): void; /** * Returns the value of an attribute given its name. * @param {String} name The name of the attribute. * @param {Function.} modifier A modifier function. */ modifyAttribute(name: string, modifier: (oldVal: AttType) => AttType): void; /** * Whether or not the current node is a terminal leaf node without any * children. * @return {Boolean} If the current node is a terminal leaf node. */ isLeaf(): boolean; /** * Attaches a child node to the current one. * @param {Node} node Node to attach as a child. */ addChild(node: any): void; /** * Removes all the parents to the current node. */ clearParents(): void; /** * Disconnects all the child nodes from this current node. */ removeAllChildren(): void; /** * Removes a child node from the current node. * @param {Node} child Child node to remove. */ removeChild(child: any): void; /** * Returns the first child that matches a given filter criteria. * @param {Function} filter Function to determine if child meets criteria. * @return {?Node} The first child node to meet the criteria or none. */ findFirstChild(filter: NodeFilter): Node; findFirstChildType(type: string, filter?: NodeFilter): Node; findFirstDescendant(filter: NodeFilter): Node; _findFirstDescendantRec(filter: NodeFilter): Node; findFirstDescendantType(type: string, filter?: NodeFilter): Node; findFirstParent(filter: NodeFilter): Node; findFirstParentType(type: string, filter?: NodeFilter): Node; findFirstAncestor(filter: NodeFilter): Node; _findFirstAncestorRec(filter: NodeFilter): Node; findFirstAncestorType(type: string, filter?: NodeFilter): Node; forEachAncestor(handler: NodeHandler, filter?: NodeFilter): void; _forEachAncestorRecursive(handler: NodeHandler, filter?: NodeFilter): void; forEachAncestorType(type: string, handler: NodeHandler, filter?: NodeFilter): void; /** * Iterates through all Descendants of node * @param {Function} handler * @param {Function} [filter] */ forEachDescendant(handler: NodeHandler, filter?: NodeFilter): void; _forEachDescendantRecursive(handler: NodeHandler, filter?: NodeFilter): void; forEachDescendantType(type: string, handler: NodeHandler, filter?: NodeFilter): void; gatherChildren(filter?: NodeFilter): Node[]; gatherChildrenType(type: string, filter?: NodeFilter): Node[]; /** * @param {Function} filter Filtering function to apply to each node to * determine if the node should be included in the returned list by * returning true. * @return {List.} */ gatherDescendants(filter?: NodeFilter): Node[]; gatherDescendantsType(type: string, filter?: NodeFilter): Node[]; gatherParents(filter?: NodeFilter): Node[]; gatherParentsType(type: string, filter?: NodeFilter): Node[]; gatherAncestors(filter?: NodeFilter): Node[]; gatherAncestorsType(type: string, filter?: NodeFilter): Node[]; forEachChildType(type: string, handler: NodeHandler, filter?: NodeFilter): void; forEachChild(handler: NodeHandler, filter?: NodeFilter): void; forEachParentType(type: string, handler: NodeHandler, filter?: NodeFilter): void; forEachParent(handler: NodeHandler, filter?: NodeFilter): void; toStringClosingTag(): string; toStringTagOnly(indents?: number): string; /** * Prints the current tree. * @param {Boolean} [hierarchy] * @param {Number} [indents] * @return {String} * @override */ toString(hierarchy?: boolean, indents?: number): string; toStringHierarchy(): string; _toStringHierarchy(indents: any, lines: any): void; }