/** * Minimal, dependency-free client for the Bundlephobia public API. * * Docs (unofficial): https://bundlephobia.com/api/size?package=@ */ /** A single dependency's approximate contribution to the bundle. */ export interface DependencySize { name: string; approximateSize: number; } /** * Where the size numbers came from. * - `bundle` — Bundlephobia minified / min+gzip (browser cost) * - `install` — npm registry unpacked / tarball (install cost; used when * Bundlephobia can't build RN/Expo/native/type packages) */ export type SizeSource = 'bundle' | 'install'; /** The subset of the Bundlephobia `size` payload we care about. */ export interface PackageSize { name: string; version: string; description?: string; repository?: string; /** Minified size (bundle) or unpacked size (install), in bytes. */ size: number; /** Minified+gzip (bundle) or tarball size (install), in bytes. */ gzip: number; /** Number of direct + transitive dependencies. */ dependencyCount: number; /** Per-dependency breakdown of the bundle (largest contributors). */ dependencySizes: DependencySize[]; /** Whether the package ships an ES module build (better tree-shaking). */ hasJSModule: boolean; hasJSNext: boolean; /** Whether the package declares side effects (hurts tree-shaking). */ hasSideEffects: boolean; scoped: boolean; /** Measurement source. Defaults to `bundle` for cached legacy entries. */ source?: SizeSource; } export type BundlephobiaErrorCode = 'PACKAGE_NOT_FOUND' | 'BUILD_ERROR' | 'RATE_LIMITED' | 'TIMEOUT' | 'NETWORK' | 'UNKNOWN'; /** Typed error so callers can render friendly, actionable messages. */ export declare class BundlephobiaError extends Error { code: BundlephobiaErrorCode; packageName: string; status?: number; constructor(code: BundlephobiaErrorCode, packageName: string, message: string, status?: number); } export interface FetchOptions { /** Per-request timeout in milliseconds. Default 20_000. */ timeoutMs?: number; /** Number of retry attempts on transient failures. Default 2. */ retries?: number; } /** * Fetch the bundle size for a single package spec (e.g. `lodash`, * `lodash@4.17.21`, or `@scope/pkg@1.2.3`). */ export declare function fetchPackageSize(spec: string, options?: FetchOptions): Promise; //# sourceMappingURL=bundlephobia.d.ts.map