UNPKG

convert

Version:

The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript

38 lines (37 loc) 1.08 kB
import type { MeasureKind } from "../conversions/types.cjs"; import type { BestUnitsForMeasure } from "../types/units.cjs"; import type { LiteralToPrimitive } from "../types/utils.cjs"; /** * Convert a given duration of milliseconds to a string that best represents it. * * If you are very concerned about performance you should use the {@link convertMany} function directly. * * @example * ```ts * ms(-3 * 60000); // '-3min' * ``` * * @param quantity - Duration of milliseconds to convert * * @returns A duration string * * @public */ export declare function ms<Q extends number | bigint>(quantity: Q): `${LiteralToPrimitive<Q>}${BestUnitsForMeasure<MeasureKind.Time>}`; /** * Convert a duration string to a duration in milliseconds. * * If you are very concerned about performance you should use the {@link convertMany} function directly. * * @example * ```ts * ms('1d 2h 30min'); // 95400000 * ``` * * @param value - Duration string to convert * * @returns A duration in milliseconds * * @public */ export declare function ms(value: string): number;