Represents an npm package resource, providing access to package metadata, versions, dist-tags, and download statistics.

Implements PromiseLike<NpmPackument> so it can be awaited directly to fetch the full packument, while also exposing sub-resource methods.

// Await directly to get full package metadata
const pkg = await npm.package('react');

// Get a specific version
const v18 = await npm.package('react').version('18.2.0');

// Get dist-tags
const tags = await npm.package('react').distTags();

// Get download stats for last month
const stats = await npm.package('react').downloads();

// Get daily download breakdown for a custom date range
const range = await npm.package('react').downloadRange('2024-01-01:2024-01-31');

Implements

Methods

  • Fetches CDN usage statistics for this package from jsDelivr.

    CDN stats reflect real browser/frontend usage, complementing npm download counts which measure install-time usage.

    GET /package/npm/{name}/stats/{groupBy}/{period} (via data.jsdelivr.com/v1)

    Parameters

    • groupBy: JsdelivrGroupBy = 'version'

      Group results by 'version' (default) or 'date'

    • period: JsdelivrPeriod = 'month'

      Time period: 'day', 'week', 'month' (default), or 'year'

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<JsdelivrStats>

    CDN hit counts, bandwidth, rank, and breakdown by version or date

    const stats = await npm.package('react').cdnStats();
    console.log(stats.rank); // 1
    console.log(stats.total); // 1234567890
  • Fetches all dist-tags for this package.

    GET /-/package/{name}/dist-tags

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<NpmDistTags>

    A map of tag names to version strings

    const tags = await npm.package('react').distTags();
    // { latest: '18.2.0', next: '19.0.0-beta.1' }
  • Fetches the per-day download breakdown for this package over a given period.

    GET /downloads/range/{period}/{name} (via api.npmjs.org)

    Parameters

    • period: NpmDownloadPeriod = 'last-month'

      Named period or date range (default: 'last-month')

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<NpmDownloadRange>

    Download range data with a per-day array

    const range = await npm.package('react').downloadRange('2024-01-01:2024-01-31');
    range.downloads.forEach(d => console.log(d.day, d.downloads));
  • Fetches the total download count for this package over a given period.

    GET /downloads/point/{period}/{name} (via api.npmjs.org)

    Parameters

    • period: NpmDownloadPeriod = 'last-month'

      Named period or date range (default: 'last-month')

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<NpmDownloadPoint>

    Download point data including total count and date range

    const stats = await npm.package('react').downloads('last-week');
    console.log(stats.downloads); // 12345678
  • Fetches the full packument (all versions metadata) for this package.

    GET /{name}

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<NpmPackument>

    The full packument object

  • Fetches the current maintainers of this package.

    Internally fetches the packument and returns the maintainers array.

    GET /{name}

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<NpmPerson[]>

    Array of maintainer entries (name, email, url)

    const maintainers = await npm.package('typescript').maintainers();
    maintainers.forEach(m => console.log(m.name, m.email));
  • Fetches the quality, maintenance, and popularity score for this package from npms.io.

    Returns a detailed breakdown of each score component, including test coverage, release frequency, community interest, and dependent package count.

    GET /package/{name} (via api.npms.io/v2)

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<NpmsScore>

    Detailed score and evaluation data

    const score = await npm.package('react').score();
    console.log(score.score.final); // 0.97
    console.log(score.evaluation.popularity.dependentsCount); // 15000
  • Fetches the publish size and full install size (including all transitive dependencies) for the latest version of this package from Packagephobia.

    GET /v2/api.json?p={name} (via packagephobia.com)

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<PackagephobiaSize>

    Publish and install size in bytes, file counts, and human-readable strings

    const size = await npm.package('react').size();
    console.log(size.install.pretty); // "300 kB"
    console.log(size.install.bytes); // 307200
  • Fetches all published versions of this package as an ordered array.

    Internally fetches the packument and converts the versions map to an array sorted from oldest to newest.

    GET /{name}

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<NpmPackageVersion[]>

    Array of version manifests sorted by publication order

    const versions = await npm.package('typescript').versions();
    console.log(versions.map(v => v.version).join(', '));