UNPKG

774 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import { BigInt } from '@polkadot/x-bigint';
4import { hexToBigInt } from "../hex/toBigInt.js";
5import { isBn } from "../is/bn.js";
6import { isHex } from "../is/hex.js";
7import { isToBigInt } from "../is/toBigInt.js";
8import { isToBn } from "../is/toBn.js";
9/**
10 * @name nToBigInt
11 * @summary Creates a bigInt value from a BN, bigint, string (base 10 or hex) or number input.
12 */
13
14export function nToBigInt(value) {
15 return typeof value === 'bigint' ? value : !value ? BigInt(0) : isHex(value) ? hexToBigInt(value.toString()) : isBn(value) ? BigInt(value.toString()) : isToBigInt(value) ? value.toBigInt() : isToBn(value) ? BigInt(value.toBn().toString()) : BigInt(value);
16}
\No newline at end of file