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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@osmn-byhn/htmlparser

v0.1.0

Published

Unified HTML/CSS/JS extractor that inlines styles and resolves script functions into a single JSON structure.

Downloads

90

Readme

@osmn-byhn/htmlparser 🚀

Unify HTML, CSS, and JS into a single, element-centric JSON structure.

This library is designed for developers who need to extract data from HTML while preserving its visual and functional context. Unlike traditional parsers, @osmn-byhn/htmlparser inlines styles from <style> tags and resolves JavaScript event handlers (like onclick) into their actual function bodies.

🌟 Why use this?

  • Deep Extraction: Don't just get the HTML; get the "computed" feel of it. Styles that live in the <head> are automatically mapped to the elements they target in the <body>.
  • Function Intelligence: If an element has an onclick="doSomething()", this library searches the <script> tags, finds doSomething, and includes its full source code in the JSON entry for that element.
  • AI Friendly: The unified, self-contained JSON output is perfect for feeding into LLMs (Large Language Models) for UI analysis, code generation, or automated testing.
  • Zero Heavy Dependencies: Built with performance and simplicity in mind.

📦 Installation

npm install @osmn-byhn/htmlparser
# or
pnpm add @osmn-byhn/htmlparser
# or
yarn add @osmn-byhn/htmlparser

🚀 Quick Start

TypeScript

import { extractUnifiedFromHTML } from "@osmn-byhn/htmlparser";

const html = `
  <html>
    <head>
      <style>.btn { color: red; }</style>
    </head>
    <body>
      <button class="btn" onclick="sayHi()">Click Me</button>
      <script>function sayHi() { console.log('Hi!'); }</script>
    </body>
  </html>
`;

async function main() {
  const result = await extractUnifiedFromHTML(html);
  
  const button = result.body.children[0];
  console.log(button.inlineStyle); // { color: 'red' }
  console.log(button.events.click.function); // "function sayHi() { ... }"
}

main();

JavaScript (ES Modules)

import { extractUnifiedFromHTML } from "@osmn-byhn/htmlparser";

const result = await extractUnifiedFromHTML('<div>Hello</div>');
console.log(result.body);

JavaScript (CommonJS)

const { extractUnifiedFromHTML } = require("@osmn-byhn/htmlparser");

extractUnifiedFromHTML('<div>Hello</div>').then(result => {
  console.log(result.body);
});

🛠️ Output Structure

The output is a UnifiedExtraction object:

| Field | Description | | :--- | :--- | | metadata | Stats: totalElements, maxDepth, totalTextNodes, etc. | | body | The root UnifiedElement (usually the <body> tag). |

The UnifiedElement object:

Every element in the tree has this structure:

{
  "tag": "div",
  "id": "main-container",
  "class": "active primitive",
  "attrs": { "data-custom": "value" },
  "inlineStyle": { 
    "color": "red", 
    "font-size": "16px" 
  },
  "events": {
    "click": {
      "handler": "myFunc()",
      "function": "function myFunc() { ... }"
    }
  },
  "children": [ ... ],
  "textContent": "Hello World"
}

🎯 Use Cases

  1. Web Scraping: Extract data from modern web pages while keeping the styling info associated with the data points.
  2. LLM / AI Processing: Convert messy HTML into a structured JSON format that AI can easily understand and reason about.
  3. UI-to-Code: Build tools that convert existing websites into React/Vue/Tailwind components by having all styles and logic per-element.
  4. Automated Audits: Programmatically check if elements have specific styles or correctly mapped event handlers.

📜 License

MIT © osmn-byhn