resolveUnit
function resolveUnit(unit): string;Defined in: packages/engine/src/uom/UomConverter.ts:68
Validate unit against the known unit table.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
unit | string |
Returns
Section titled “Returns”string
unit unchanged in all cases. This does NOT normalize casing
or aliasing (units are strictly case-sensitive, see the module note
above). A unit the table doesn’t recognize is still
returned as-is (not thrown), so callers must not assume a returned
string is actually convertible, check with isConvertibleUnit
or canConvert first if that matters.
Kept as an identity function purely for API compatibility. It used to guard a validity cache, which existed because validating a unit meant a throw/catch round trip through the old dependency. Validation is now a Map lookup, so the cache cost more than it saved: worse, it was capped at 1000 entries against a 1456-unit table, so any sweep over the full vocabulary (which is exactly what LanguageService does to build completions) evicted on almost every call. That one change took the full-table sweep from 7.7ms to under 20us.