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

Function getNumber

lib.esm/utils/maths.js:123–144  ·  view source on GitHub ↗
(value, name)

Source from the content-addressed store, hash-verified

121 * a //number//, then an ArgumentError will be thrown for %%name%%.
122 */
123export function getNumber(value, name) {
124 switch (typeof (value)) {
125 case "bigint":
126 assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value);
127 return Number(value);
128 case "number":
129 assertArgument(Number.isInteger(value), "underflow", name || "value", value);
130 assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value);
131 return value;
132 case "string":
133 try {
134 if (value === "") {
135 throw new Error("empty string");
136 }
137 return getNumber(BigInt(value), name);
138 }
139 catch (e) {
140 assertArgument(false, `invalid numeric string: ${e.message}`, name || "value", value);
141 }
142 }
143 assertArgument(false, "invalid numeric value", name || "value", value);
144}
145/**
146 * Converts %%value%% to a number. If %%value%% is a Uint8Array, it
147 * is treated as Big Endian data. Throws if the value is not safe.

Callers 15

vMethod · 0.90
fromMethod · 0.90
formatUnitsFunction · 0.90
parseUnitsFunction · 0.90
fromValueMethod · 0.90
getBlockNumberMethod · 0.90
_getBlockTagMethod · 0.90
getTransactionCountMethod · 0.90
_parseBytesFunction · 0.90
parseOffchainLookupFunction · 0.90
copyRequestFunction · 0.90
getFuzzyModeFunction · 0.90

Calls 1

assertArgumentFunction · 0.90

Tested by

no test coverage detected