Skip to content

sizium - API documentation

Classes

Sizium

Represents the main class for handling package size.

Examples

ts
const size = new Sizium( 'chalk' )
const data = await size.get()

console.log(data) // all data
console.log(data.size) // total size on bytes
ts
// Directory input
const size = new Sizium( './' )
const data = await size.get()
ts
// package.json input
const size = new Sizium( './package.json' )
const data = await size.get()
ts
// remote package.json input
const size = new Sizium( 'https://raw.githubusercontent.com/chalk/chalk/refs/heads/main/package.json' )
const data = await size.get()
ts
// package.json string input
const pkg = {name: 'chalk', ... }
const size = new Sizium(JSON.stringify(pkg) )
const data = await size.get()

Constructors

new Sizium()
ts
new Sizium(input: string): Sizium
Parameters
ParameterType
inputstring
Returns

Sizium

Methods

get()
ts
get(): Promise<SiziumResponse>

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

Properties

PropertyType
filterSiziumFilter
inputstring
inputType"string" | "url" | "json" | "path"
pkgundefined | SiziumResponse

SiziumFilter

A class to filter and sort package information based on various criteria.

Constructors

new SiziumFilter()
ts
new SiziumFilter(pkg?: SiziumResponse): SiziumFilter
Parameters
ParameterType
pkg?SiziumResponse
Returns

SiziumFilter

Methods

byDependenceCount()
ts
byDependenceCount(): 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.

byDependenceLevel()
ts
byDependenceLevel(): 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.

byDependenceSize()
ts
byDependenceSize(): 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.

byName()
ts
byName(type?: "atoz" | "ztoa"): Promise<PackageInfo[]>

Sorts the packages alphabetically by name.

Parameters
ParameterTypeDescription
type?"atoz" | "ztoa"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.

bySize()
ts
bySize(): Promise<PackageInfo[]>

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.

Properties

PropertyType
pkg?SiziumResponse

SiziumLocal

Represents the class to get the true package size from local enviroment.

Examples

ts
// Directory input
const size = new SiziumLocal( './' )
const data = await size.get()
ts
// package.json input
const size = new SiziumLocal( './package.json' )
const data = await size.get()
ts
// remote package.json input
const size = new SiziumLocal( 'https://raw.githubusercontent.com/chalk/chalk/refs/heads/main/package.json' )
const data = await size.get()
ts
// package.json string input
const pkg = {name: 'chalk', ... }
const size = new SiziumLocal(JSON.stringify(pkg) )
const data = await size.get()

Extends

  • PackageSuper

Constructors

new SiziumLocal()
ts
new SiziumLocal(input: string, opts?: {
  skipError: boolean;
 }): SiziumLocal
Parameters
ParameterTypeDescription
inputstring-
opts?object-
opts.skipError?booleanSkip error on package dependence and return undefined
Returns

SiziumLocal

Inherited from

PackageSuper.constructor

Methods

get()
ts
get(): Promise<SiziumResponse>
Returns

Promise<SiziumResponse>

Properties

PropertyModifierTypeDescriptionInherited from
Errorpublictypeof SiziumError-PackageSuper.Error
ERROR_IDpublic{ GETTING_LOCAL_DATA: "GETTING_LOCAL_DATA"; GETTING_PKG_NAME: "GETTING_PKG_NAME"; GETTING_REGISTRY_DATA: "GETTING_REGISTRY_DATA"; INVALID_PKG_NAME: "INVALID_PKG_NAME"; }-PackageSuper.ERROR_ID
ERROR_ID.GETTING_LOCAL_DATAreadonly"GETTING_LOCAL_DATA"--
ERROR_ID.GETTING_PKG_NAMEreadonly"GETTING_PKG_NAME"--
ERROR_ID.GETTING_REGISTRY_DATAreadonly"GETTING_REGISTRY_DATA"--
ERROR_ID.INVALID_PKG_NAMEreadonly"INVALID_PKG_NAME"--
inputpublicstring-PackageSuper.input
opts?public{ skipError: boolean; }-PackageSuper.opts
opts.skipErrorpublicbooleanSkip error on package dependence and return undefined-

SiziumRegistry

Represents the class to get the true package size from the npm registry URL.

Example

ts
const size = new SiziumRegistry( 'chalk' )
const data = await size.get()

console.log(data) // all data
console.log(data.size) // total size on bytes

Extends

  • PackageSuper

Constructors

new SiziumRegistry()
ts
new SiziumRegistry(input: string, opts?: {
  skipError: boolean;
 }): SiziumRegistry
Parameters
ParameterTypeDescription
inputstring-
opts?object-
opts.skipError?booleanSkip error on package dependence and return undefined
Returns

SiziumRegistry

Inherited from

PackageSuper.constructor

Methods

get()
ts
get(): Promise<SiziumResponse>
Returns

Promise<SiziumResponse>

Properties

PropertyModifierTypeDescriptionInherited from
Errorpublictypeof SiziumError-PackageSuper.Error
ERROR_IDpublic{ GETTING_LOCAL_DATA: "GETTING_LOCAL_DATA"; GETTING_PKG_NAME: "GETTING_PKG_NAME"; GETTING_REGISTRY_DATA: "GETTING_REGISTRY_DATA"; INVALID_PKG_NAME: "INVALID_PKG_NAME"; }-PackageSuper.ERROR_ID
ERROR_ID.GETTING_LOCAL_DATAreadonly"GETTING_LOCAL_DATA"--
ERROR_ID.GETTING_PKG_NAMEreadonly"GETTING_PKG_NAME"--
ERROR_ID.GETTING_REGISTRY_DATAreadonly"GETTING_REGISTRY_DATA"--
ERROR_ID.INVALID_PKG_NAMEreadonly"INVALID_PKG_NAME"--
inputpublicstring-PackageSuper.input
opts?public{ skipError: boolean; }-PackageSuper.opts
opts.skipErrorpublicbooleanSkip error on package dependence and return undefined-

Functions

getPackageSize()

ts
function getPackageSize(input: string): Promise<SiziumResponse>

Retrieves the size information of a given package.

Parameters

ParameterTypeDescription
inputstringThe input string representing a package name, path, or URL.

Returns

Promise<SiziumResponse>

A promise that resolves with the package response data.

Example

ts
const data = await getPackageSize( 'chalk' )

console.log(data) // all data
console.log(data.size) // total size on bytes

Type Aliases

PackageInfo

ts
type PackageInfo: {
  author: {
     name: string;
     url: string;
    };
  dependencies: PackageJSON["dependencies"];
  description: string;
  devDependencies: PackageJSON["devDependencies"];
  installedBy: string[];
  isCommonJS: boolean;
  isESM: boolean;
  level: number;
  license: string;
  lifeCycleScripts: { [key in lifeCycleScripts]?: string };
  name: string;
  types: boolean;
  unpackedSize: number;
  unpackedSizeKB: number;
  unpackedSizeMB: number;
  url: {
     funding: string;
     homepage: string;
     npm: string;
     repository: string;
     unpkg: string;
    };
  version: string;
};

Type declaration

NameTypeDescription
author?{ name: string; url: string; }-
author.namestring-
author.urlstring-
dependencies?PackageJSON["dependencies"]-
description?string-
devDependencies?PackageJSON["devDependencies"]-
installedBy?string[]-
isCommonJSboolean-
isESMboolean-
levelnumberLevel of the dependence installation. Main packages is 0
license?string-
lifeCycleScripts?{ [key in lifeCycleScripts]?: string }-
namestring-
typesboolean-
unpackedSizenumberUnpacked size in bytes
unpackedSizeKBnumber-
unpackedSizeMBnumber-
url{ funding: string; homepage: string; npm: string; repository: string; unpkg: string; }-
url.funding?string-
url.homepage?string-
url.npmstring-
url.repository?string-
url.unpkg?string-
versionstring-

PackageJSON

ts
type PackageJSON: JSONSchemaForNPMPackageJsonFiles & {
  name: string;
  version: string;
};

Type declaration

NameType
namestring
versionstring

SiziumResponse

ts
type SiziumResponse: {
  id: string;
  packageNum: number;
  packages: PackageInfo[];
  size: number;
  sizeKB: number;
  sizeMB: number;
};

Type declaration

NameTypeDescription
idstring-
packageNumnumberNumber of total packages installed
packagesPackageInfo[]All data from packages
sizenumberSize in bytes
sizeKBnumberSize in kylobytes
sizeMBnumberSize in megabytes