UNPKG

891 BJavaScriptView Raw
1import { BigInt } from '@polkadot/x-bigint';
2import { hexToBigInt } from '../hex/toBigInt.js';
3import { isBn } from '../is/bn.js';
4import { isHex } from '../is/hex.js';
5import { isToBigInt } from '../is/toBigInt.js';
6import { isToBn } from '../is/toBn.js';
7/**
8 * @name nToBigInt
9 * @summary Creates a bigInt value from a BN, bigint, string (base 10 or hex) or number input.
10 */
11export function nToBigInt(value) {
12 return typeof value === 'bigint'
13 ? value
14 : !value
15 ? BigInt(0)
16 : isHex(value)
17 ? hexToBigInt(value.toString())
18 : isBn(value)
19 ? BigInt(value.toString())
20 : isToBigInt(value)
21 ? value.toBigInt()
22 : isToBn(value)
23 ? BigInt(value.toBn().toString())
24 : BigInt(value);
25}
\No newline at end of file