MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / resolveUnit

Function resolveUnit

src/compute-engine/numerics/unit-data.ts:273–286  ·  view source on GitHub ↗

* Resolve a unit symbol — first by direct table lookup, then by prefix * parsing. Returns a synthetic `UnitEntry` (dimension + effective scale) * or `null` for unknown symbols.

(symbol: string)

Source from the content-addressed store, hash-verified

271 if (SI_PREFIXES[p2] !== undefined && PREFIXABLE_UNITS.has(rest2)) {
272 const base = UNIT_TABLE[rest2];
273 if (base) return { prefixScale: SI_PREFIXES[p2], baseEntry: base };
274 }
275 }
276
277 // Try 1-char prefix
278 if (symbol.length > 1) {
279 const p1 = symbol.slice(0, 1);
280 const rest1 = symbol.slice(1);
281 if (SI_PREFIXES[p1] !== undefined && PREFIXABLE_UNITS.has(rest1)) {
282 const base = UNIT_TABLE[rest1];
283 if (base) return { prefixScale: SI_PREFIXES[p1], baseEntry: base };
284 }
285 }
286
287 return null;
288}
289

Callers 3

getUnitDimensionFunction · 0.85
getUnitScaleFunction · 0.85
convertUnitFunction · 0.85

Calls 1

parsePrefixedUnitFunction · 0.85

Tested by

no test coverage detected