Skip to content
Shapemetry

@huukhanhnguyen/model / utils/unitConvert

utils/unitConvert

convertLiteral()

convertLiteral(expr, dataType, fromUnit, toUnit): string

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.

Parameters

expr

string

dataType

string

fromUnit

string

toUnit

string

Returns

string


fromBase()

fromBase(value, type, unit): number

Convert a base (internal) value to display unit. Non-unit types pass through unchanged.

Parameters

value

number

type

string

unit

string

Returns

number


isLiteralNumber()

isLiteralNumber(expr): boolean

Check if an expression string is a pure literal number (no refs, no operators). Only literal numbers are safe to convert when changing units.

Parameters

expr

string

Returns

boolean


toBase()

toBase(value, type, unit): number

Convert a display value to base (internal) unit. Non-unit types (number, boolean, text...) pass through unchanged.

Parameters

value

number

type

string

unit

string

Returns

number

Last updated: 📖 1 min readEdit on GitHub