UNPKG

@sizium/core

Version:

Get the actual size of any local or remote package

111 lines (106 loc) 4.38 kB
import { S as SiziumResponse, P as PackageInfo } from './shared/core.D1SNe5o-.mjs'; export { a as PackageJSON } from './shared/core.D1SNe5o-.mjs'; export { SiziumLocal } from './search/local.mjs'; export { SiziumRegistry } from './search/registry.mjs'; import '@schemastore/package'; declare const getInputType: (value: string) => "url" | "json" | "path" | "string"; /** * A class to filter and sort package information based on various criteria. */ declare class SiziumFilter { pkg?: SiziumResponse | undefined; constructor(pkg?: SiziumResponse | undefined); /** * Sorts the packages by their unpacked size in descending order. * * @returns {Promise<PackageInfo[]>} A promise that resolves to an array of `PackageInfo` sorted by unpacked size. * @throws An error if `this.pkg` is undefined. */ bySize(): Promise<PackageInfo[]>; /** * Sorts the packages alphabetically by name. * * @param {'atoz' | 'ztoa'} type - The sorting order, either `'atoz'` (A-Z) or `'ztoa'` (Z-A). Default is `'atoz'`. * @returns {Promise<PackageInfo[]>} A promise that resolves to an array of `PackageInfo` sorted by name. * @throws An error if `this.pkg` is undefined. */ byName(type?: 'atoz' | 'ztoa'): Promise<PackageInfo[]>; /** * Sorts the packages by the total number of dependencies (both dependencies and devDependencies) in descending order. * * @returns {Promise<PackageInfo[]>} A promise that resolves to an array of `PackageInfo` sorted by total dependency size. * @throws An error if `this.pkg` is undefined. */ byDependenceSize(): Promise<PackageInfo[]>; /** * Sorts the packages by the number of direct dependencies in descending order. * * @returns {Promise<PackageInfo[]>} A promise that resolves to an array of `PackageInfo` sorted by the number of dependencies. * @throws An error if `this.pkg` is undefined. */ byDependenceCount(): Promise<PackageInfo[]>; /** * Sorts the packages by their dependency level in ascending order. * The dependency level indicates how "deep" the package is in the dependency tree. * * @returns {Promise<PackageInfo[]>} A promise that resolves to an array of `PackageInfo` sorted by dependency level. * @throws An error if `this.pkg` is undefined. */ byDependenceLevel(): Promise<PackageInfo[]>; } /** * Represents the main class for handling package size. * * @example * const size = new Sizium( 'chalk' ) * const data = await size.get() * * console.log(data) // all data * console.log(data.size) // total size on bytes * @example * // Directory input * const size = new Sizium( './' ) * const data = await size.get() * @example * // package.json input * const size = new Sizium( './package.json' ) * const data = await size.get() * @example * // remote package.json input * const size = new Sizium( 'https://raw.githubusercontent.com/chalk/chalk/refs/heads/main/package.json' ) * const data = await size.get() * @example * // package.json string input * const pkg = {name: 'chalk', ... } * const size = new Sizium(JSON.stringify(pkg) ) * const data = await size.get() */ declare class Sizium { #private; input: string; inputType: ReturnType<typeof getInputType>; pkg: SiziumResponse | undefined; filter: SiziumFilter; constructor(input: string); /** * Retrieves the package information based on the input. * It uses either the registry or local search mechanism depending on the input type. * * @returns {Promise<SiziumResponse>} A promise that resolves with the package response data. * @see https://sizium.pigeonposse.com/guide/core/api#siziumresponse */ get(): Promise<SiziumResponse>; } /** * Retrieves the size information of a given package. * * @param {string} input - The input string representing a package name, path, or URL. * @returns {Promise<SiziumResponse>} A promise that resolves with the package response data. * @example * const data = await getPackageSize( 'chalk' ) * * console.log(data) // all data * console.log(data.size) // total size on bytes */ declare const getPackageSize: (input: string) => Promise<SiziumResponse>; export { PackageInfo, Sizium, SiziumFilter, SiziumResponse, getPackageSize };