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

detxt

v0.5.0

Published

High-performance HTML cleaning and SEO analysis for AI pipelines

Readme

detxt

CI npm version license

High-performance HTML cleaning and SEO/keyword analysis for AI pipelines. The library builds a compact node tree, removes non-content nodes, and provides fast keyword/search utilities.

Features

  • Compact node tree with numeric IDs and children arrays.
  • Aggressive removal of non-content tags (script, style, svg, etc.) by default.
  • Fast keyword search with word-set, indexOf, or Aho-Corasick strategies.
  • Built-in heading extraction and hierarchical heading tree.
  • Lightweight dependency footprint (only htmlparser2).

Install

npm install detxt

Quick Start

import { analyzeHtml, searchKeywords } from "detxt";

const html = "<html><head><title>Example</title></head><body><h1>Hello</h1><p>Fast parsing.</p></body></html>";
const document = analyzeHtml(html);

console.log(document.meta.title); // "Example"
console.log(document.headings); // [{ level: 1, text: "Hello", nodeId: ... }]

const result = searchKeywords(document, ["fast", "hello"], {
  matchWholeWords: true,
});

console.log(result.hits.fast?.count); // 1

Heading Tree

import { analyzeHtml } from "detxt";

const html = `
  <h1>Main</h1>
  <h2>Section A</h2>
  <h3>Subsection A.1</h3>
  <h2>Section B</h2>
`;

const document = analyzeHtml(html);
console.log(document.headingTree);

The heading tree is a nested structure of { level, text, nodeId, children } built from <h1><h6> elements.

Heading Sections

import { analyzeHtml, buildHeadingSections } from "detxt";

const document = analyzeHtml(html);
const sections = buildHeadingSections(document);

console.log(sections);

Heading sections group the text content that follows each heading until the next heading of the same or higher level. Each section is { level, text, nodeId, content, children }.

If you want sections built during indexing:

const document = analyzeHtml(html, {
  indexOptions: { buildHeadingSections: true }
});

Keyword Research

import { analyzeHtml, getTopWords, searchKeywords } from "detxt";

const document = analyzeHtml(html);

const topWords = getTopWords(document.index, {
  limit: 10,
  minLength: 4,
});

const keywords = searchKeywords(document, ["seo", "html", "ai"], {
  matchWholeWords: true,
});

SEO Summary

import { analyzeHtml, analyzeSeo } from "detxt";

const document = analyzeHtml(html);
const summary = analyzeSeo(document, { baseUrl: "https://example.com" });

console.log(summary);

The summary includes title/meta lengths, heading counts, internal vs external links, nofollow links, image alt coverage, and canonical URL.

Image Analysis

import { analyzeHtml, analyzeImages } from "detxt";

const document = analyzeHtml(html);
const result = analyzeImages(document, { baseUrl: "https://example.com" });

console.log(result.summary);
console.log(result.images[0]);

Image analysis returns per-image details (src, alt, lazy, linked, etc.) and a fast summary.

Schema Extraction (JSON-LD + Microdata)

import { analyzeHtml } from "detxt";

const document = analyzeHtml(html);
const schema = document.schema;

console.log(schema.jsonLd);
console.log(schema.microdata);

JSON-LD scripts are parsed (with errors preserved), and Microdata (itemscope / itemprop) is extracted into structured objects.

API Overview

  • cleanHtml(html, options)
  • analyzeHtml(html, options)
  • buildIndex(document, options)
  • buildHeadingTree(document)
  • buildHeadingSections(document, options)
  • searchKeywords(documentOrIndex, keywords, options)
  • containsKeyword(documentOrIndex, keyword, options)
  • getTopWords(index, options)
  • analyzeSeo(document, options)
  • analyzeImages(document, options)
  • extractSchemas(html, options)

See src/types.ts for full option and type definitions.

Options Highlights

  • CleanOptions.removeTags overrides the default removal list.
  • CleanOptions.keepAttributes defaults to a minimal SEO-friendly set (href, rel, alt, src). Use [] to drop all attributes.
  • CleanOptions.extractJsonLd / extractMicrodata control schema extraction.
  • CleanOptions.parseJsonLd parses JSON-LD into objects (errors captured).
  • IndexOptions.buildTagIndex builds a tag -> nodeId[] map for fast lookups.
  • IndexOptions.buildHeadingSections builds heading sections during indexing.
  • KeywordSearchOptions.strategy chooses wordset, indexOf, or aho-corasick.
  • KeywordSearchOptions.matchWholeWords uses word boundaries for accurate counts.
  • SeoOptions.baseUrl enables internal vs external link classification.
  • ImageAnalysisOptions.baseUrl enables internal vs external image classification.
  • CleanOptions.extractJsonLd and CleanOptions.extractMicrodata toggle schema extraction.

Testing

npm test

Versioning

This project follows SemVer. Use npm version patch|minor|major to bump versions.

CI

GitHub Actions runs build and tests on every push and pull request. The badge above reflects the latest status.

Release (Git Tag Flow)

This repo publishes to npm automatically when you push a Git tag that matches the package version.

  1. Make sure your npm token is saved in GitHub as a secret named NPM_TOKEN.
  2. Bump version and create tag:
    • npm version patch (or minor / major)
  3. Push commits and tag:
    • git push origin main --tags

When the vX.Y.Z tag is pushed, GitHub Actions runs tests and publishes the package.