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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yorganci/npm-registry-api

v0.3.0

Published

Fully typesafe npm registry API client with optional caching.

Downloads

24

Readme

npm Registry API Client

npm version npm downloads bundle License

@yorganci/npm-registry-api is a fully typesafe npm registry API client with optional caching.

Features

  • Validates registry responses using zod.
  • Supports response caching with unstorage.
  • Compatible with both Node.js and browser environments.
  • Works seamlessly with third-party npm-compatible registries.

Useful Links

Usage

Install @yorganci/npm-registry-api npm package:

# yarn
yarn add @yorganci/npm-registry-api

# npm
npm install @yorganci/npm-registry-api

# pnpm
pnpm add @yorganci/npm-registry-api

Basic usage

import { Client } from "@yorganci/npm-registry-api";

const client = new Client();

await client.searchPackages({ text: "react", size: 1 });

npm Registry API

| Function Name | Description | | ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | | getAbbreviatedPackument | Fetches abbreviated packument (package document) containing only the metadata necessary to install a package. | | getBulkDailyPackageDownloads | Retrieves the total number of downloads for each day for some packages in the given time period. | | getBulkPackageDownloads | Fetches the total number of downloads for the given packages in the given time period. | | getDailyPackageDownloads | Retrieves the total number of downloads for each day for a package in the given time period. | | getDailyRegistryDownloads | Gets the total number of downloads for each day for all packages in the registry in the given time period. | | getPackageDownloads | Fetches total number of downloads for a package in the given time period. | | getPackageManifest | Retrieves the manifest describing a specific version of a package (e.g., [email protected]). | | getPackageVersionsDownloads | Gets the total number of downloads for each version of a package in the previous 7 days. | | getPackument | Fetches full packument (package document) containing all the metadata available about a package. | | getRegistryDownloads | Retrieves total number of downloads for all packages in the registry in the given time period. | | getRegistryMetadata | Fetches metadata describing the registry itself. | | getRegistrySigningKeys | Retrieves public signing keys used by the registry. | | searchPackages | Searches packages corresponding to a given query. |

Caching API

@yorganci/npm-registry-api/cache module provides basic factory function to create Cache object to be used by Client. By default createCache, uses ohash under the hood to generate cache keys from URL and HTTP headers and any Driver implementation from unstorage can be used for persistance the default is unstorage/drivers/memory.

Basic usage with default options.

import { Client } from "@yorganci/npm-registry-api";
import { createCache } from "@yorganci/npm-registry-api/cache";

// By default `Map<string, unknown>` is used as caching layer
const cachedClient = new Client({
  cache: createCache(),
});

Create a file-system backed cache client.

import { Client } from "@yorganci/npm-registry-api";
import { createCache } from "@yorganci/npm-registry-api/cache";
import fs from "unstorage/drivers/fs";

const cachedClient = new Client({
  cache: createCache({
    storage: fs({
      base: "./data",
    }),
  }),
});

License

MIT