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

html2json-utils

v1.0.1

Published

HTML to JSON conversion utilities - core parsing, styling, and element classification

Readme

html2json-utils

HTML to JSON conversion utilities - core parsing, styling, and element classification library.

Installation

npm install html2json-utils

Features

  • HTML Parser: Recursively parse HTML DOM and extract elements
  • Element Classification: Automatically classify elements as image, text, or shape
  • Style Extraction: Extract computed styles from HTML elements
  • Color Utilities: Convert CSS colors to hex format
  • Type Safe: Full TypeScript support with comprehensive type definitions

Quick Start

import { htmlToJson } from 'html2json-utils';

const html = '<div><h1>Hello</h1><p>World</p></div>';
const json = await htmlToJson(html);
console.log(json);

API

Core Functions

htmlToJson(html: string): Promise<JsonDocument>

Convert HTML string to JSON format.

const result = await htmlToJson('<div>Content</div>');

HtmlParser.parse(element: HTMLElement, parentElement: Element | null): Promise<Element | null>

Parse a single DOM element.

const parser = new HtmlParser();
const element = await parser.parse(domElement, null);

classifyElement(element: HTMLElement, style: Style): ElementType

Classify an element as 'image', 'text', 'shape', or null.

import { classifyElement } from 'html2json-utils';

const type = classifyElement(element, computedStyle);

toHexColor(color: string): string | undefined

Convert CSS color to hex format.

import { toHexColor } from 'html2json-utils';

const hex = toHexColor('rgb(255, 0, 0)'); // '#ff0000'

Types

interface JsonDocument {
  filename: string;
  presentation: {
    width: number;
    height: number;
    title: string;
    slides: Slide[];
  };
}

interface Slide {
  id: string;
  elements: Element[];
}

type Element = ImageElement | TextElement | ShapeElement;

interface ElementStyles {
  backgroundColor?: string;
  outline?: Outline;
  opacity: number;
  left: number;
  top: number;
  width: number;
  height: number;
  rotate: number;
}

Sub-exports

Import specific modules:

// Main converter
import { htmlToJson } from 'html2json-utils/converter';

// Parser
import { HtmlParser } from 'html2json-utils/parser';

// Classifier
import { classifyElement } from 'html2json-utils/classifier';

// Color utilities
import { toHexColor } from 'html2json-utils/colors';

// Types
import type { JsonDocument, Element } from 'html2json-utils/types';

Project Structure

src/
├── Element/                 # Element classes
│   ├── BaseElement.ts
│   ├── ImageElement.ts
│   ├── TextElement.ts
│   └── ShapeElement.ts
├── style/                   # Style extraction and processing
│   ├── baseStyle.ts
│   ├── gradient.ts
│   ├── lineHeight.ts
│   ├── outline.ts
│   ├── rotate.ts
│   ├── textShadow.ts
│   ├── textStyle.ts
│   └── index.ts
├── computedStyle/           # Computed style utilities
│   ├── index.ts
│   └── type.ts
├── index.ts                 # Main entry point
├── converter.ts             # HTML to JSON converter
├── classifier.ts            # Element classifier
├── colorUtils.ts            # Color conversion utilities
├── HtmlParser.ts            # HTML DOM parser
└── types.ts                 # Type definitions

License

MIT