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.23 kB
TypeScript
import type { $Record } from '../object/types';
import type { Numeric } from '../types/index';
import { $BaseConverter } from './base';
import type { $MassUnit, FormatToOptions } from './types';
/**
* @class MassConverter
* @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
*/
export declare class $Mass extends $BaseConverter<$MassUnit> {
#private;
/**
* Convert mass value to other mass units
* @param value Number or numeric string value to convert.
* @param unit Base mass unit for the provided value.
*/
constructor(value: Numeric, unit: $MassUnit);
/**
* @instance Converts to target mass unit.
* @param target Target mass unit.
*/
to(target: $MassUnit): number;
/**
* @instance Converts to all mass units at once.
* @returns Object with all unit conversions.
*/
toAll(): $Record<$MassUnit, number>;
/**
* @instance Formats the converted value and unit.
* @param target Target unit to format to.
* @param options Formatting options.
* @returns Formatted string like "5kg", "5.25 kilograms", or "5e+3 gram".
*/
formatTo(target: $MassUnit, options?: FormatToOptions): string;
}