UNPKG

signal-template-forms

Version:

A powerful, type-safe Angular forms library built with signals, providing reactive form management with excellent developer experience and performance.

113 lines (112 loc) 3.46 kB
/** * Unit conversion function type - converts value from one unit to target unit */ export type UnitConverter = (value: number, fromUnit: string) => number; /** * Unit parsing function type - formats the value for display */ export type UnitParser = (value: number) => string; /** * Configuration for a single unit in the conversion system */ export interface UnitConfig { /** Display label for the unit */ label: string; /** Function to convert from any unit to this unit */ convert: UnitConverter; /** Optional unit-specific parser that overrides field-level parser */ parser?: UnitParser; } /** * Position of the unit dropdown relative to the input */ export type UnitPosition = 'prefix' | 'suffix'; /** * Complete unit conversion configuration for a number field */ export interface UnitConversionConfig { /** Map of unit keys to their configurations */ unitConversions: Record<string, UnitConfig>; /** Default unit to use when field is first rendered */ defaultUnit: string; /** Position of unit dropdown (prefix/suffix) */ unitPosition: UnitPosition; /** Optional field-level parser - can be overridden by unit-specific parsers */ parser?: UnitParser; /** Number of decimal places to round converted values to (default: 2) */ precision?: number; } export declare class ConversionUtils { /** * Weight conversions (base unit: kg) */ static weight: { kg: { label: string; convert: (value: number, fromUnit: string) => number; }; lbs: { label: string; convert: (value: number, fromUnit: string) => number; }; oz: { label: string; convert: (value: number, fromUnit: string) => number; }; g: { label: string; convert: (value: number, fromUnit: string) => number; }; }; /** * Length conversions (base unit: m) */ static length: { m: { label: string; convert: (value: number, fromUnit: string) => number; }; ft: { label: string; convert: (value: number, fromUnit: string) => number; }; in: { label: string; convert: (value: number, fromUnit: string) => number; }; cm: { label: string; convert: (value: number, fromUnit: string) => number; }; mm: { label: string; convert: (value: number, fromUnit: string) => number; }; }; /** * Temperature conversions (base unit: celsius) */ static temperature: { celsius: { label: string; convert: (value: number, fromUnit: string) => number; }; fahrenheit: { label: string; convert: (value: number, fromUnit: string) => number; }; kelvin: { label: string; convert: (value: number, fromUnit: string) => number; }; }; /** * Common parsers for different number formats */ static parsers: { currency: (value: number, locale?: string, currency?: string) => string; percentage: (value: number, locale?: string) => string; decimal: (value: number, locale?: string, fractionDigits?: number) => string; integer: (value: number, locale?: string) => string; }; }