extra-dom v0.6.1
extra-dom
Utilities for DOM.
Install
npm install --save extra-dom
# or
yarn add extra-domAPI
flatMap
function flatMap(node: Node, fn: (node: Node) => Node[]): Node[]Traverse the node tree and do flatMap.
[]: remove current node[node]: replace current node[node1, node2, ...nodeN]: replace current node with more nodes
map
function map(node: Node, fn: (node: Node) => Node): NodeTraverse the node tree and do map.
filter
function filter(node: Node, predicate: (node: Node) => unknown): Node | undefinedTraverse the node tree and do filter.
unwrap
function unwrap(node: Node, predicate: (node: Node) => unknown): Node[]Traverse the node tree and do unwrap.
find
function find(node: Node, predicate: (node: Node) => unknown): Node | undefinedTraverse the node tree and do find.
parse
function parse(html: string): Node[]stringify
function stringify(nodes: Node[]): stringnormalize
function normalize(html: string): stringIt is the shortcut for stringify(parse(html)).
removeAllChildren
function removeAllChildren(node: Node): voidremoveAttributes
function removeAttributes(node: Node, predicate: (name: string) => unknown): voidgetBySelector
function getBySelector<T extends Element>(
this: void | Element | Document
, selectors: string
): TReturn the first matched element.
If cannot find any elements, it throws.
getAllBySelector
function getAllBySelector<T extends Element>(
this: void | Element | Document
, selectors: string
): T[]Return matched elements.
If cannot find any elements, it throws.
traverseAncestorNodes
function traverseAncestorNodes(node: Node): Iterable<Node & ParentNode>traverseDescendantNodes
function traverseDescendantNodes(node: Node): Iterable<ChildNode>findInAncestorNodes
function findInAncestorNodes(
node: Node
, predicate: (node: Node & ParentNode) => unknown
): (Node & ParentNode) | undefinedfindInDescendantNodes
function find(node: Node, predicate: (node: ChildNode) => unknown): ChildNode | undefinedfindInPrecedingSiblingNodes
function findInPrecedingSiblingNodes(
node: Node
, predicate: (node: Node) => unknown
): Node | undefinedThis function uses Node.previousSibling to traverse the preceding sibling nodes.
findInFollowingSiblingNodes
function findInFollowingSiblingNodes(
node: Node
, predicate: (node: Node) => unknown
): Node | undefinedThis function uses Node.nextSibling to traverse the following sibling nodes.
parentNode
function parentNode(node: Node, distance: number = 1): (Node & ParentNode) | undefinednextSibling
function nextSibling(node: Node, distance: number = 1): ChildNode | undefinedpreviousSibling
function previousSibling(node: Node, distance: number = 1): ChildNode | undefinednextElementSibling
function nextElementSibling(node: Node, distance: number = 1): Element | undefinedpreviousElementSibling
function previousElementSibling(node: Node, distance: number = 1): Element | undefinedisDocument
function isDocument(val: any): val is DocumentisntDocument
function isntDocument<T>(val: T): val is Exclude<T, Document>isElement
function isElement(val: any): val is ElementisntElement
function isntElement<T>(val: T): val is Exclude<T, Element>isTextNode
function isTextNode(val: any): val is TextisntTextNode
function isntTextNode<T>(val: any): node is Exclude<T, Text>isNode
function isNode(val: any): val is NodeisntNode
function isntNode<T>(val: T): val is Exclude<T, Node>isParentNode
function isParentNode(val: any): val is Node & ParentNodeisntParentNode
function isntParentNode<T>(val: any): val is Exclude<T, Node & ParentNode>isBefore
function isBefore(subject: Node, object: Node): booleanisAfter
function isAfter(subject: Node, object: Node): booleancreateDOMParser
function createDOMParser(): DOMParserNodeType
enum NodeType {
ELEMENT_NODE
, ATTRIBUTE_NODE
, TEXT_NODE
, CDATA_SECTION_NODE
, ENTITY_REFERENCE_NODE
, ENTITY_NODE
, PROCESSING_INSTRUCTION_NODE
, COMMENT_NODE
, DOCUMENT_NODE
, DOCUMENT_TYPE_NODE
, DOCUMENT_FRAGMENT_NODE
, NOTATION_NODE
}XPathResultType
enum XPathResultType {
ANY_TYPE
, NUMBER_TYPE
, STRING_TYPE
, BOOLEAN_TYPE
, UNORDERED_NODE_ITERATOR_TYPE
, ORDERED_NODE_ITERATOR_TYPE
, UNORDERED_NODE_SNAPSHOT_TYPE
, ORDERED_NODE_SNAPSHOT_TYPE
, ANY_UNORDERED_NODE_TYPE
, FIRST_ORDERED_NODE_TYPE
}2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago