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