JSPM

  • Created
  • Published
  • Downloads 282
  • Score
    100M100P100Q85978F
  • License MIT

Utilities for DOM

Package Exports

  • extra-dom

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (extra-dom) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

extra-dom

Utilities for DOM.

Install

npm install --save extra-dom
# or
yarn add extra-dom

API

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): Node

Traverse the node tree and do map.

filter

function filter(node: Node, predicate: (node: Node) => unknown): Node | null

Traverse 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 | null

Traverse the node tree and do find.

parse

function parse(html: string): Node[]

stringify

function stringify(nodes: Node[]): string

normalize

function normalize(html: string): string

It is the shortcut for stringify(parse(html)).

removeAllChildren

function removeAllChildren(node: Node): void

removeAttributes

function removeAttributes(node: Node, predicate: (name: string) => unknown): void

getBySelector

function getBySelector<T extends Element>(this: void | Element | Document, selectors: string): T

Return 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.

traverseDescendantNodes

function traverseDescendantNodes(node: Node): Iterable<ChildNode>

findInDescendantNodes

function find(node: Node, predicate: (node: ChildNode) => unknown): ChildNode | null

findInPrecedingSiblingNodes

function findInPrecedingSiblingNodes(node: Node, predicate: (node: Node) => unknown): Node | null

This function uses Node.previousSibling to traverse the preceding sibling nodes.

findInFollowingSiblingNodes

function findInFollowingSiblingNodes(node: Node, predicate: (node: Node) => unknown): Node | null

This function uses Node.nextSibling to traverse the following sibling nodes.

nextSibling

function nextSibling(node: Node, distance: number = 1): ChildNode | null

previousSibling

function previousSibling(node: Node, distance: number = 1): ChildNode | null

nextElementSibling

function nextElementSibling(node: Node, distance: number = 1): Element | null

previousElementSibling

function previousElementSibling(node: Node, distance: number = 1): Element | null

isDocument

function isDocument(val: any): val is Document

isntDocument

function isntDocument<T>(val: T): val is Exclude<T, Document>

isElement

function isElement(val: any): val is Element

isntElement

function isntElement<T>(val: T): val is Exclude<T, Element>

isTextNode

function isTextNode(val: any): val is Text

isntTextNode

function isntTextNode<T>(val: any): node is Exclude<T, Text>

isNode

function isNode(val: any): val is Node

isntNode

function isntNode<T>(val: T): val is Exclude<T, Node>

isParentNode

function isParentNode(val: any): val is Node & ParentNode

isntParentNode

function isntParentNode<T>(val: any): val is Exclude<T, Node & ParentNode>

replaceBrWithNewline

function replaceBrWithNewline(node: Node): Node

isBefore

function isBefore(subject: Node, object: Node): boolean

isAfter

function isAfter(subject: Node, object: Node): boolean

NodeConstants

enum NodeConstants {
  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
}

XPathResultConstants

enum XPathResultConstants {
  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
}