UNPKG

bytecon

Version:

A TypeScript utility for precise bit/byte conversions with BigInt support, parsing, and formatting.

62 lines 3.23 kB
//#region src/index.d.ts type UnitKey = "bit" | "byte" | "kbit" | "mbit" | "gbit" | "tbit" | "pbit" | "ebit" | "zbit" | "ybit" | "rbit" | "qbit" | "kib" | "mib" | "gib" | "tib" | "pib" | "eib" | "zib" | "yib" | "rib" | "qib" | "kb" | "mb" | "gb" | "tb" | "pb" | "eb" | "zb" | "yb" | "rb" | "qb"; declare const unitMap: Record<string, UnitKey>; declare const BI: (n: number) => bigint; declare const byteUnits: Record<UnitKey, bigint>; declare const binaryMap: Record<string, UnitKey>; type ValueInput = number | bigint | string; type ConvertResult = bigint | number | undefined; declare const parseInput: (value: ValueInput) => { asBig?: bigint; asNumber?: number; }; declare const convertStandard: (value: ValueInput, from: string, to: string) => ConvertResult; declare const convertBinary: (value: ValueInput, from: string, to: string) => ConvertResult; declare const convert: (value: ValueInput, from: string, to: string, mode?: "standard" | "binary") => ConvertResult; declare const convertToBigInt: (value: ValueInput, from: string, to: string, mode?: "standard" | "binary") => bigint; declare const convertToNumber: (value: ValueInput, from: string, to: string, mode?: "standard" | "binary") => number; interface FormatOptions { unit?: string; digits?: number; mode?: "standard" | "binary"; preferBigInt?: boolean; } declare const chooseBestUnit: (bitCount: bigint, preferBinary?: boolean) => { unit: UnitKey; value: bigint | number; }; declare const formatBytes: (value: ValueInput, fromUnit: string, opts?: FormatOptions) => string; declare const parseBytes: (input: string) => { value: number | bigint; unit: string; }; declare const toBigIntResult: (r: ConvertResult) => bigint | undefined; declare const toNumberResult: (r: ConvertResult) => number | undefined; declare const _default: { unitMap: Record<string, UnitKey>; BI: (n: number) => bigint; byteUnits: Record<UnitKey, bigint>; binaryMap: Record<string, UnitKey>; parseInput: (value: ValueInput) => { asBig?: bigint; asNumber?: number; }; convertStandard: (value: ValueInput, from: string, to: string) => ConvertResult; convertBinary: (value: ValueInput, from: string, to: string) => ConvertResult; convert: (value: ValueInput, from: string, to: string, mode?: "standard" | "binary") => ConvertResult; convertToBigInt: (value: ValueInput, from: string, to: string, mode?: "standard" | "binary") => bigint; convertToNumber: (value: ValueInput, from: string, to: string, mode?: "standard" | "binary") => number; chooseBestUnit: (bitCount: bigint, preferBinary?: boolean) => { unit: UnitKey; value: bigint | number; }; formatBytes: (value: ValueInput, fromUnit: string, opts?: FormatOptions) => string; parseBytes: (input: string) => { value: number | bigint; unit: string; }; toBigIntResult: (r: ConvertResult) => bigint | undefined; toNumberResult: (r: ConvertResult) => number | undefined; }; //#endregion export { BI, ConvertResult, FormatOptions, UnitKey, ValueInput, binaryMap, byteUnits, chooseBestUnit, convert, convertBinary, convertStandard, convertToBigInt, convertToNumber, _default as default, formatBytes, parseBytes, parseInput, toBigIntResult, toNumberResult, unitMap };