Utilities for DOM
npm install extra-domsh
npm install --save extra-dom
or
yarn add extra-dom
`API
$3
`ts
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$3
`ts
function map(node: Node, fn: (node: Node) => Node): Node
`Traverse the node tree and do
map.$3
`ts
function filter(node: Node, predicate: (node: Node) => unknown): Node | undefined
`Traverse the node tree and do
filter.$3
`ts
function unwrap(node: Node, predicate: (node: Node) => unknown): Node[]
`Traverse the node tree and do
unwrap.$3
`ts
function find(node: Node, predicate: (node: Node) => unknown): Node | undefined
`Traverse the node tree and do
find.$3
`ts
function parseNodes(htmlFragment: string): Node[]
`$3
`ts
function stringifyNodes(nodes: Node[]): string
`$3
`ts
function parseFragment(htmlFragment: string): DocumentFragment
`$3
`ts
function stringifyFragment(fragment: DocumentFragment): string
`$3
`ts
function removeAllChildren(node: Node): void
`$3
`ts
function removeAttributes(
node: Node
, predicate?: (attributeName: string) => unknown
): void
`$3
`ts
function getBySelector(
this: void | Element | Document
, selectors: string
): T
`Return the first matched element.
If cannot find any elements, it throws.
$3
`ts
function getAllBySelector(
this: void | Element | Document
, selectors: string
): T[]
`Return matched elements.
If cannot find any elements, it throws.
$3
`ts
function traverseAncestorNodes(node: Node): Iterable
`$3
`ts
function traverseDescendantNodes(node: Node): Iterable
`$3
`ts
function traversePrecedingSiblingNodes(node: Node): Iterable
`$3
`ts
function traverseFollowingSiblingNodes(node: Node): Iterable
`$3
`ts
function traverseDescendantNodes(node: Node): Iterable
`$3
`ts
function findInAncestorNodes(
node: Node
, predicate: (node: Node & ParentNode) => unknown
): (Node & ParentNode) | undefined
`$3
`ts
function find(node: Node, predicate: (node: ChildNode) => unknown): ChildNode | undefined
`$3
`ts
function findInPrecedingSiblingNodes(
node: Node
, predicate: (node: Node) => unknown
): Node | undefined
`This function uses
Node.previousSibling to traverse the preceding sibling nodes.$3
`ts
function findInFollowingSiblingNodes(
node: Node
, predicate: (node: Node) => unknown
): Node | undefined
`This function uses
Node.nextSibling to traverse the following sibling nodes.$3
`ts
function parentNode(node: Node, distance: number = 1): (Node & ParentNode) | undefined
`$3
`ts
function nextSibling(node: Node, distance: number = 1): ChildNode | undefined
`$3
`ts
function previousSibling(node: Node, distance: number = 1): ChildNode | undefined
`$3
`ts
function nextElementSibling(node: Node, distance: number = 1): Element | undefined
`$3
`ts
function previousElementSibling(node: Node, distance: number = 1): Element | undefined
`$3
`ts
function isDocument(val: unknown): val is Document
`$3
`ts
function isntDocument(val: T): val is Exclude
`$3
`ts
function isElement(val: unknown): val is Element
`$3
`ts
function isntElement(val: T): val is Exclude
`$3
`ts
function isTextNode(val: unknown): val is Text
`$3
`ts
function isntTextNode(val: unknown): node is Exclude
`$3
`ts
function isNode(val: unknown): val is Node
`$3
`ts
function isntNode(val: T): val is Exclude
`$3
`ts
function isParentNode(val: unknown): val is Node & ParentNode
`$3
`ts
function isntParentNode(val: unknown): val is Exclude
`$3
`ts
function isBefore(subject: Node, object: Node): boolean
`$3
`ts
function isAfter(subject: Node, object: Node): boolean
`$3
`ts
function createDOMParser(): DOMParser
`$3
`ts
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
}
`$3
`ts
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
}
``