UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

35 lines (34 loc) 1.21 kB
import type { $Record } from '../object/types'; import type { Numeric } from '../types/index'; import { $BaseConverter } from './base'; import type { $DataUnit, FormatToOptions } from './types'; /** * @class DataConverter * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`. */ export declare class $Data extends $BaseConverter<$DataUnit> { #private; /** * Convert data value to other data units * @param value Number or numeric string value to convert. * @param unit Base data unit for the provided value. */ constructor(value: Numeric, unit: $DataUnit); /** * @instance Converts to target data unit. * @param target Target data unit. */ to(target: $DataUnit): number; /** * @instance Converts to all data units. * @returns Object with all unit conversions. */ toAll(): $Record<$DataUnit, number>; /** * @instance Formats the converted value. * @param target Target data unit. * @param options Formatting options. * @returns Formatted string like "256MB", "256 megabytes", or "2.56e+2 MB". */ formatTo(target: $DataUnit, options?: FormatToOptions): string; }