@polkadot/util#hexToBn TypeScript Examples
The following examples show how to use
@polkadot/util#hexToBn.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From bodhi.js with Apache License 2.0 | 7 votes |
export function toBN(bigNumberis: BigNumberish = 0): BN {
if (isU8a(bigNumberis)) {
return u8aToBn(bigNumberis);
}
if (isHex(bigNumberis)) {
return hexToBn(bigNumberis);
}
if (BigNumber.isBigNumber(bigNumberis)) {
const hex = bigNumberis.toHexString();
if (hex[0] === '-') {
return new BN('-' + hex.substring(3), 16);
}
return new BN(hex.substring(2), 16);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new BN(bigNumberis as any);
}
Example #2
Source File: utils.ts From evm-provider.js with Apache License 2.0 | 7 votes |
export function toBN(bigNumberis: BigNumberish = 0): BN {
if (isU8a(bigNumberis)) {
return u8aToBn(bigNumberis);
}
if (isHex(bigNumberis)) {
return hexToBn(bigNumberis);
}
if (BigNumber.isBigNumber(bigNumberis)) {
const hex = bigNumberis.toHexString();
if (hex[0] === '-') {
return new BN('-' + hex.substring(3), 16);
}
return new BN(hex.substring(2), 16);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new BN(bigNumberis as any);
}
Example #3
Source File: pluralize.ts From subsocial-js with GNU General Public License v3.0 | 6 votes |
export function pluralize ({ count, singularText, pluralText, hideCount }: Props) {
if (!count) {
count = ZERO;
} else if (typeof count === 'string') {
if (count.startsWith('0x')) {
count = hexToBn(count);
} else if (count.startsWith('-0x')) {
count = hexToBn(count.substring(1), { isNegative: true });
} else {
count = new BN(count);
}
} else if (typeof count === 'number') {
count = new BN(count);
}
const plural = () => !pluralText
? singularText + 's'
: pluralText;
const text = count.eq(ONE)
? singularText
: plural();
const countMsg = hideCount ? '' : `${count.toNumber()} `
return `${countMsg}${text}`;
}