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

xcrap

v2.0.1

Published

**xcrap** is a powerful and flexible web scraping framework for Node.js. It bundles the best-in-class tools for data extraction and transformation into a single, easy-to-use package.

Readme

🕷️ xcrap

xcrap is a powerful and flexible web scraping framework for Node.js. It bundles the best-in-class tools for data extraction and transformation into a single, easy-to-use package.

With xcrap, you can extract data from HTML, JSON, and Markdown using declarative models, and then clean, validate, and transform that data using a robust pipeline system.


📦 Installation

Install xcrap using your preferred package manager:

npm install xcrap

Or with yarn/pnpm:

yarn add xcrap
pnpm add xcrap

🚀 Features

  • Declarative Extraction: Extract data from HTML, JSON, and Markdown using simple, readable models (@xcrap/extractor).
  • Data Transformation: Clean, validate, and transform your extracted data with a powerful pipeline (@xcrap/transformer).
  • Modular Design: Built on top of a solid core (@xcrap/core) for reliability and extensibility.
  • Type-Safe: Written in TypeScript with full type definitions included.

📚 Quick Start

Here's a complete example showing how to extract data from an HTML string and then transform it into a clean, structured format.

1. Extraction

First, let's extract raw data from an HTML source using HtmlParser and HtmlExtractionModel.

import { HtmlParser, HtmlExtractionModel, css, extract } from "xcrap/extractor"

const html = `
<html>
  <body>
    <div class="product">
      <h1 id="title">  Cool Gadget  </h1>
      <span class="price">$99.99</span>
      <div class="details">
        <span data-spec="weight">250g</span>
        <a href="/specs.pdf">Download Specs</a>
      </div>
    </div>
  </body>
</html>
`

// Define the extraction model
const extractionModel = new HtmlExtractionModel({
  name: {
    query: css("#title"),
    extractor: extract("innerText")
  },
  price: {
    query: css(".price"),
    extractor: extract("innerText")
  },
  weight: {
    query: css("[data-spec='weight']"),
    extractor: extract("innerText")
  },
  specsUrl: {
    query: css("a"),
    extractor: extract("href")
  }
})

// Run the extraction
const parser = new HtmlParser(html)
const rawData = await parser.extractModel({ model: extractionModel })

console.log(rawData)
/*
Output:
{
  name: "  Cool Gadget  ",
  price: "$99.99",
  weight: "250g",
  specsUrl: "/specs.pdf"
}
*/

2. Transformation

Now, let's clean up that raw data using Transformer and TransformingModel.

import { Transformer, TransformingModel, transform, StringTransformer, StringValidator } from "xcrap/transformer"

// Define the transformation model
const transformerModel = new TransformingModel({
  name: [
    transform({
      key: "name", // Use the 'name' field from rawData
      transformer: StringTransformer.trim // Trim whitespace
    })
  ],
  price: [
    transform({
      key: "price",
      transformer: (val) => parseFloat(val.replace("$", "")) // Custom cleanup
    })
  ],
  specsUrl: [
    transform({
      key: "specsUrl",
      transformer: StringTransformer.resolveUrl("https://myshop.com") // Resolve relative URL
    })
  ]
})

// Run the transformation
const transformer = new Transformer(rawData)
const cleanData = await transformer.transform(transformerModel)

console.log(cleanData)
/*
Output:
{
    name: "Cool Gadget",
    price: 99.99,
    specsUrl: "https://myshop.com/specs.pdf",
    weight: "250g",
}
*/

📖 Core Concepts

Extractor (@xcrap/extractor)

The extraction engine allows you to parse structured data from various sources.

  • HtmlParser: For parsing HTML documents.
  • JsonParser: For traversing and extracting from JSON objects.
  • MarkdownParser: For extracting content from Markdown files.
  • HtmlExtractionModel: Define the structure of the data you want to extract using query selectors (css, xpath) and extractors (extract).

Transformer (@xcrap/transformer)

The transformation engine allows you to process raw data into its final form.

  • Transformer: The main class that applies transformations to a dataset.
  • TransformingModel: Defines a declarative pipeline of transformations for each field.
  • StringTransformer: A collection of utility functions for common string operations (trim, replace, split, etc.).
  • StringValidator: A collection of utility functions for validating string content (isNumeric, isEmail, etc.).

🤝 Contributing

We welcome contributions! Whether it's fixing bugs, improving documentation, or adding new features.

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'Add some amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.