(value, name)
| 67 | * a BigInt, then an ArgumentError will be thrown for %%name%%. |
| 68 | */ |
| 69 | export function getBigInt(value, name) { |
| 70 | switch (typeof (value)) { |
| 71 | case "bigint": return value; |
| 72 | case "number": |
| 73 | assertArgument(Number.isInteger(value), "underflow", name || "value", value); |
| 74 | assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value); |
| 75 | return BigInt(value); |
| 76 | case "string": |
| 77 | try { |
| 78 | if (value === "") { |
| 79 | throw new Error("empty string"); |
| 80 | } |
| 81 | if (value[0] === "-" && value[1] !== "-") { |
| 82 | return -BigInt(value.substring(1)); |
| 83 | } |
| 84 | return BigInt(value); |
| 85 | } |
| 86 | catch (e) { |
| 87 | assertArgument(false, `invalid BigNumberish string: ${e.message}`, name || "value", value); |
| 88 | } |
| 89 | } |
| 90 | assertArgument(false, "invalid BigNumberish value", name || "value", value); |
| 91 | } |
| 92 | /** |
| 93 | * Returns %%value%% as a bigint, validating it is valid as a bigint |
| 94 | * value and that it is positive. |
no test coverage detected