Represents a package resource on Bundlephobia, providing access to bundle size, version history, and similar packages.

Implements PromiseLike<BundleSize> so it can be awaited directly to fetch the bundle size for the latest version.

// Await directly — resolves with the latest version bundle size
const size = await client.package('react');

// Explicit call with optional version
const size18 = await client.package('react').size('18.2.0');

// Size history across all versions
const history = await client.package('react').history();

// Similar / alternative packages
const similar = await client.package('react').similar();

Implements

Methods

  • Fetches the bundle size history for this package across all published versions.

    GET /api/package-history?package={name}

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<PackageHistory>

    A map of version strings to their size and gzip values

    const history = await client.package('react').history();
    for (const [version, entry] of Object.entries(history)) {
    console.log(`${version}${entry.gzip}B gzip`);
    }
  • Fetches similar/alternative packages to this one.

    GET /api/similar-packages?package={name}

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<SimilarPackages>

    A list of alternative packages with their bundle sizes

    const similar = await client.package('react').similar();
    similar.alternativePackages.forEach(p => {
    console.log(`${p.name}@${p.version}${p.gzip}B gzip`);
    });
  • Fetches the bundle size for this package.

    GET /api/size?package={name}@{version}

    Parameters

    • Optionalversion: string

      Specific version to fetch (default: latest)

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<BundleSize>

    Bundle size data including minified and gzip sizes

    const size = await client.package('react').size();
    const size18 = await client.package('react').size('18.2.0');
    console.log(size18.gzip); // 2670