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/factory

v0.1.0

Published

Xcrap Factory is a set of utilities for dynamically creating instances of clients, extractors, and extraction models, making it easier to configure and extend scraping and extraction pipelines.

Readme

🕷️ Xcrap Factory: Instantiate clients, extraction models, and extractors from configuration objects

Xcrap Factory is a set of utilities for dynamically creating instances of clients, extractors, and extraction models, making it easier to configure and extend scraping and extraction pipelines.

📦 Installation

Installation is straightforward—just use your favorite dependency manager. Here’s an example using NPM:

npm i @xcrap/factory

🛠️ Features

  • createClient: Instantiates clients from a registry of allowed classes.
  • createExtractor: Creates extractor functions from configurable text and a registry of allowed extractors.
  • createExtractionModel: Builds validated and nested extraction models with customizable extractors.
  • Flexible Queries: Supports query as a simple string (defaults to CSS) or a structured object { value: string, type: 'css' | 'xpath' }.
  • 100% Test Coverage: Fully tested for reliability and edge cases.

🚀 Usage

1. Creating a Client

import { GotScrapingClient } from "@xcrap/got-scraping-client"
import { AxiosClient } from "@xcrap/axios-client"
import { createClient } from "@xcrap/factory"

const config = {
    allowedClients: {
        "got-scraping": GotScrapingClient,
        "axios": AxiosClient 
    }
}

const client = createClient({
    config,
    type: "axios",
    options: { /* Axios options */ }
})

2. Creating an Extractor

import { extractInnerText, extractAttribute } from "@xcrap/extractor"
import { createExtractor } from "@xcrap/factory"

const config = {
    allowedExtractors: {
        innerText: extractInnerText,
        attribute: extractAttribute // Generic extractor generator
    },
    argumentSeparator: ":" 
}

// Simple extractor
const simple = createExtractor({
    extractorText: "innerText",
    config
})

// Extractor with arguments (e.g., extract "href" attribute)
const withArgs = createExtractor({
    extractorText: "attribute:href",
    config
})

3. Creating a Extraction Model

The factory automatically converts string queries into CSS BuildedQuery objects, but you can also provide XPath queries explicitly.

import { HtmlExtractionModel } from "@xcrap/extractor"
import { createExtractionModel } from "@xcrap/factory"

const config = {
    allowedExtractors: {
        innerText: extractInnerText,
        content: extractAttribute("content")
    },
    allowedModels: {
        html: HtmlExtractionModel
    }
}

const extractionModel = createExtractionModel({
    config,
    model: {
        type: "html",
        model: {
            title: {
                query: "title", // Auto-converted to { value: "title", type: "css" }
                extractor: "innerText",
            },
            description: {
                // Structured query support
                query: { value: "//meta[@name='description']/@content", type: "xpath" },
                extractor: "innerText"
            },
            body: {
                query: "body",
                nested: {
                    type: "html",
                    model: {
                        paragraph: {
                            query: "p",
                            extractor: "innerText",
                            multiple: true,
                            limit: 5
                        }
                    }
                }
            }
        }
    }
})

🧪 Testing

The library is fully covered by unit and integration tests.

# Run tests
npm test

# Run tests with coverage report
npm test -- --coverage

🤝 Contributing

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

📝 License

This project is licensed under the MIT License.