import type { LooseLiteral, Mutable } from '../utils/types'; import type { $Area } from './area'; import type { $BaseConverter } from './base'; import type { UNITS } from './constants'; import type { $Data } from './data'; import type { $Length } from './length'; import type { $Mass } from './mass'; import type { $Temperature } from './temp'; import type { $Time } from './time'; import type { $Volume } from './volume'; /** - Type for Record of Units */ export type UnitsRecord = typeof UNITS; /** * Category of units supported by the converter. */ export type Category = keyof UnitsRecord; /** * Map of unit categories to their respective units. */ export type UnitMap = { [Key in Category]: UnitsRecord[Key][number]; }; /** * Union type of all supported units. May include any other strings. */ export type $Unit = LooseLiteral; /** * Type for array of all Units */ export type Units = Array; /** * Tuple type for Units in a specific Category */ export type UnitsTuple = Mutable; /** * Infer the category of a given unit type `U`. */ export type InferCategory = { [K in Category]: U extends UnitMap[K] ? K : never; }[Category]; /** * Infer Units belong to a specific Category */ export type CategoryUnits = UnitMap[Cat]; /** * Type for the returned converter instance based on the provided unit `U`. */ export type Converted = InferCategory extends never ? $BaseConverter : InferCategory extends 'area' ? $Area : InferCategory extends 'time' ? $Time : InferCategory extends 'length' ? $Length : InferCategory extends 'mass' ? $Mass : InferCategory extends 'data' ? $Data : InferCategory extends 'temp' ? $Temperature : InferCategory extends 'volume' ? $Volume : $BaseConverter; /** * Options for formatting converted values for unit converter method(s). */ export type FormatToOptions = { /** Style of formatting. Default is `'plural'`. */ style?: 'compact' | 'scientific' | 'plural'; /** Number of decimal places to include. Default is `2`. */ decimals?: number; }; /** Union type for all the area units */ export type $AreaUnit = UnitMap['area']; /** Union type for all the data units */ export type $DataUnit = UnitMap['data']; /** Union type for all the length/distance units */ export type $LengthUnit = UnitMap['length']; /** Union type for all the mass units */ export type $MassUnit = UnitMap['mass']; /** Union type for all the temperature units */ export type $TempUnit = UnitMap['temp']; /** Union type for all the time units */ export type $TimeUnit = UnitMap['time']; /** Union type for all the volume units */ export type $VolumeUnit = UnitMap['volume'];