MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / parseUnits

Function parseUnits

lib.esm/utils/units.js:57–69  ·  view source on GitHub ↗
(value, unit)

Source from the content-addressed store, hash-verified

55 * or the name of a unit (e.g. ``"gwei"`` for 9 decimal places).
56 */
57export function parseUnits(value, unit) {
58 assertArgument(typeof (value) === "string", "value must be a string", "value", value);
59 let decimals = 18;
60 if (typeof (unit) === "string") {
61 const index = names.indexOf(unit);
62 assertArgument(index >= 0, "invalid unit", "unit", unit);
63 decimals = 3 * index;
64 }
65 else if (unit != null) {
66 decimals = getNumber(unit, "unit");
67 }
68 return FixedNumber.fromString(value, { decimals, width: 512 }).value;
69}
70/**
71 * Converts %%value%% into a //decimal string// using 18 decimal places.
72 */

Callers 3

parseEtherFunction · 0.70

Calls 3

assertArgumentFunction · 0.90
getNumberFunction · 0.90
fromStringMethod · 0.45

Tested by

no test coverage detected