Model - Unit convert
API reference for src/utils/unitConvert on @huukhanhnguyen/model, reachable from ..
See the Guide for the ModelJSON / evaluate pipeline.
API reference
Signatures are generated from the live package .d.ts - not hand-written.
convertLiteral
function
Convert an expression's literal value between units. Only converts if: expression is literal number AND type is a unit type. Returns the expression unchanged if not convertible.
convertLiteral(expr: string, dataType: string, fromUnit: string, toUnit: string): stringfromBase
function
Convert a base (internal) value to display unit. Non-unit types pass through unchanged.
fromBase(value: number, type: string, unit: string): numberisLiteralNumber
function
Check if an expression string is a pure literal number (no refs, no operators). Only literal numbers are safe to convert when changing units.
isLiteralNumber(expr: string): booleantoBase
function
Convert a display value to base (internal) unit. Non-unit types (number, boolean, text...) pass through unchanged.
toBase(value: number, type: string, unit: string): number