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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@perfobyte/strucdom

v1.0.5

Published

HTML parser and serializer.

Downloads

14

Readme

strucdom

Installation:

npm i @perfobyte/strucdom

Imports:

import {
    DOCUMENT_NODE,
    ELEMENT_NODE,
    ATTRIBUTE_NODE,
    TEXT_NODE,
    COMMENT_NODE,

    NodeType,

    Node,
    parse,

    RawValueTags,
    SpaceCharacters,
    UnclosedHtmlTags,
    QuotesCharacters,
    HtmlTags,
    ResultCode,

    create_document,

} from '@perfobyte/strucdom';

console.dir(NodeType); // { DOCUMENT_NODE: 9, ELEMENT_NODE: 1, ... }

console.dir(RawValueTags); // ["script", "style"]
console.dir(HtmlTags); // ["a", "abbr", "acronym", "address", ... ]
console.dir(QuotesCharacters); // ['"', "'"]
console.dir(UnclosedHtmlTags); // [ "area", "base", "br", "col", ... ]
console.dir(SpaceCharacters); // [" ", "\t", "\n", "\f", "\r"]

ResultCode.SUCCESS;
ResultCode.TAG_NOT_OPENED;
  • Parsing of raw script and style tags is not yet supported.

Object initialization:

var
  html = `<div data-hello="world">textContent<!--comment--></div><!--comment2-->another text`,

  Container = Array,

  document = (
        new Node(
            DOCUMENT_NODE, // type
            "#document", // name
            
            new Container(), // children
            null, // parent
            null, // ownerDocument

            "", // data
            false, // specified
        )
  ),

  result_code = (
    parse(
      html, document,
      0, html.length,
      UnclosedHtmlTags, SpaceCharacters, QuotesCharacters,
      Node, Container,
    )
  ),

  separator = " / ",

  div = document.first_child()
;

div.set_attribute("data-hello", "new_value");

console.dir(
  document.outer_html(UnclosedHtmlTags)
);
// "<div data-hello="new_value">textContent<!--comment--></div><!--comment2-->another text"

console.dir(
  div.get_attribute("data-hello")
);
// "new_value"

console.dir(
  document.text_content(
    UnclosedHtmlTags,
    separator,
  )
);
// "textContent / another text"

Structure:

import {NodeType} from "@perfobyte/strucdom"

var
    document = create_document(new Array()),
    node = document.children[1],

    is_element = false,
    is_document = false,
    is_attribute = false,
    is_text = false,
    is_comment = false,

    type = "",
    name = ""
;

// Type of node:

type = node.type;

console.log(is_element = (type === NodeType.ELEMENT_NODE)); // true

console.log(is_document = (type === NodeType.DOCUMENT_NODE)); // false
console.log(is_attribute = (type === NodeType.ATTRIBUTE_NODE)); // false
console.log(is_text = (type === NodeType.TEXT_NODE)); // false
console.log(is_comment = (type === NodeType.COMMENT_NODE)); // false


// Name of a node:

name = node.name;

if (is_element) console.dir(name);
// "div"
// * or an another arbitrary value that does not include a space, a slash character, ">", "<"


if (is_document) console.dir(name); // "#document"
if (is_attribute) console.dir(name); // "new_value" or an another arbitrary value
if (is_text) console.dir(name); // "#text"
if (is_comment) console.dir(name); // "#comment"


// Children:

node.children; // Container of included nodes


// Parent node:
node.parent;

// Data:
node.data; // value of attribute, text and comment node;

// Specified:
node.specified;
// a boolean value that indicates whether the node object was modified after parsing

Methods:

General:

import {create_document, UnclosedHtmlTags} from '@perfobyte/strucdom';

var
    Container = Array,
    document_childs = new Container(),

    node = create_document(document_childs), // document
    separator = " | ",

    new_node = null,
    unclosed = UnclosedHtmlTags
;

node.text_content(UnclosedHtmlTags, separator); // ""
node.inner_html(UnclosedHtmlTags); // ""
node.outer_html(UnclosedHtmlTags); // ""

node.create_document(new Container());
node.create_text("text value");
node.create_comment("comment value");
node.create_attribute("key", "value");
node.create_element("div", new Container());

new_node = (
    node.append_child(
        node.create_text("hello_world")
    )
);

console.dir(
    (new_node === node.first_child())
    &&
    (new_node === node.last_child())
);
// true

node
.first_child()
.replace_with(
    new_node = node.create_comment("and now comment instead of comment")
)

node.remove_child(new_node);
// or:
new_node.remove();

console.dir(node.first_child() === null); // true
console.dir(node.last_child() === null); // true

console.dir(
    node.has_child_nodes()
);
// false

new_node = node.append_child(
    node.create_element("div", new Container())
);
new_node.append_child(new_node.create_text("first_div_text"));

new_node = node.create_element("div", new Container());
new_node.append_child(new_node.create_text("hello_world"));

node.append_child(new_node);

console.dir(
    node
    .first_child()
    .next_sibling()
    .text_content(unclosed,"") === "hello_world"
);
// true

console.dir(
    node
    .last_child()
    .previous_sibling()
    .text_content(unclosed,"") === "first_div_text"
);
// true

Element methods:

import {
    create_document,
    UnclosedHtmlTags as unclosed,
} from '@perfobyte/strucdom';

var
    document = create_document(new Array()),
    node = (
        document.append_child(
            document.create_element("div",new Array())
        )
    )
;

console.dir(node.outer_html(unclosed)); // '<div/>'
node.set_attribute('key', "value");

console.dir(node.outer_html(unclosed)); // '<div key="value"/>'
console.dir( node.get_attribute("key") ); // "value"

node.remove_attribute("key");
console.dir(node.outer_html(unclosed)); // '<div/>'
console.log(node.get_attribute("key") === null) // true

Next updates:

  • Methods:
  • querySelector
  • querySelectorAll