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

domson

v1.0.0

Published

A library that structures data into a JSON object from the DOM and querying text based elements to form its structure.

Downloads

4

Readme

DOMSON

A library that structures data into a JSON object from the DOM and querying text based elements to form its structure.

This library helps to structure JSON data into something that you'd like to extract from HTML, in order to enrich your data by using CSS selectors to query elements to extract its text. This is particulary helpful with scraping. You can see examples down below.


How to use

The extract function consists of two arguments; first being the contents of the HTML, and the second being your schema of how your structured data will look. You can use TypeScript to validate the typings of your schema.

In your property value, if you set it as a string based selector, it will return the first matching element and its text contents by default - trimming the spaces for cleanness.

import { extract, type Schema, type Element } from 'domson'

// Your typed schema
type Data = {
  title: string
  description: string
  article: {
    body: string
    links: Array<{
      text: string
      href: string
    }>
  }
}

const schema: Schema<Data> = {
  title: 'title',
  description: ['meta[name="description"]', (el: Element) => el.attr('content') ?? ''],
  article: {
    title: 'h1',
    body: 'article .contents',
    links: ['article .foot-links a[href]', (el: Element) => ({
      text: el.text(),
      href: el.attr('href') as string
    })]
  }
} 

const data = extract(contents, schema)

Then having this example output:

// Output
{
  "title": "Government appoints new Health Secretary",
  "description": "Breaking: government appoints John Appleseed as the new Health Secretary",
  "article": {
    "title": "Health Secretary resigns and is replaced by John Appleseed",
    "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec consectetur quis lacus a vestibulum. Nam aliquet eros enim, vel ornare ligula pharetra sit amet. Nullam metus nisi, sagittis eu maximus eget, vestibulum in neque. Vivamus in dui risus. Vestibulum lacus neque, pretium vitae tincidunt non, molestie vel enim. Phasellus vitae nisl elit. Aliquam posuere pharetra justo id feugiat. Donec elementum consequat libero, id commodo ante. Phasellus eget tellus turpis. Cras consequat urna vel mi bibendum tempus. Vivamus commodo, nunc et porta sollicitudin, leo nibh tristique nunc, at pellentesque risus tellus quis arcu. Integer hendrerit, leo fringilla faucibus hendrerit, turpis lacus viverra lacus, ac lobortis est diam auctor ipsum. Pellentesque in aliquet est.",
    "links": [{
      "text": "Source #1",
      "href": "https://example.com"
    }, {
      "text": "Source #2",
      "href": "https://example.com"
    }]
  }
}