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.29 kB
import type { $Record } from '../object/types'; import type { Numeric } from '../types/index'; import { $BaseConverter } from './base'; import type { $LengthUnit, FormatToOptions } from './types'; /** * @class LengthConverter * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`. */ export declare class $Length extends $BaseConverter<$LengthUnit> { #private; /** * Convert length/distance value to other length/distance units * @param value Number or numeric string value to convert. * @param unit Base length/distance unit for the provided value. */ constructor(value: Numeric, unit: $LengthUnit); /** * @instance Converts to target length/distance unit. * @param target Target length/distance unit. */ to(target: $LengthUnit): number; /** * @instance Converts to all data units. * @returns Object with all unit conversions. */ toAll(): $Record<$LengthUnit, number>; /** * @instance Formats the converted value and unit. * @param target Target unit to format to. * @param options Formatting options. * @returns Formatted string like "5km", "5.12 miles", or "5e+3 meter". */ formatTo(target: $LengthUnit, options?: FormatToOptions): string; }