npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

extra-dom

v0.6.1

Published

Utilities for DOM

Downloads

3,267

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 | undefined

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 | undefined

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.

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) | undefined

findInDescendantNodes

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

findInPrecedingSiblingNodes

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

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

findInFollowingSiblingNodes

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

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

parentNode

function parentNode(node: Node, distance: number = 1): (Node & ParentNode) | undefined

nextSibling

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

previousSibling

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

nextElementSibling

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

previousElementSibling

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

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>

isBefore

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

isAfter

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

createDOMParser

function createDOMParser(): DOMParser

NodeType

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
}