@kodex-data/prototypes
Version:
A library of TypeScript prototypes that extend built-in types in JavaScript, providing additional functionality to make development easier and more efficient. This library includes prototypes for working with big numbers, Ethereum Virtual Machine (EVM) fu
110 lines (109 loc) • 4.95 kB
TypeScript
import type { Fraction } from './types';
import BN from 'bn.js';
import { BigNumber } from '@ethersproject/bignumber';
import { BigNumber as BigNumberJS } from 'bignumber.js';
declare global {
interface BigInt {
toNumber(): number;
shiftedBy(n: number): bigint;
shiftedBy(n: number, asBN: undefined | false | null): bigint;
shiftedBy(n: number, asBN: true): BigNumberJS;
/**
* Converts the string to a big number using the specified library.
* @date 8.3.2023 - 08:42:19
* @param {?BnTypes} type The library to use for big number conversion. Defaults to 'bignumber.js'.
* @param {?number} base - The base to use when converting from a string. Only used for 'bignumber.js'.
* @returns {BigNumberJS | BN | BigNumber}
*/
toBN(): BigNumberJS;
toBN(type: 'bn.js'): BN;
toBN(type: 'ethers-bn'): BigNumber;
toBN(type: 'bignumber.js'): BigNumberJS;
toBN(type: 'bignumber.js', base?: number): BigNumberJS;
toBN(type: 'bigint', base?: number): bigint;
}
/** Extends the built-in String object with methods for working with big numbers and fractions. */
interface String {
/**
* Converts the string to a big number using the specified library.
* @date 8.3.2023 - 08:42:19
* @param {?BnTypes} type The library to use for big number conversion. Defaults to 'bignumber.js'.
* @param {?number} base - The base to use when converting from a string. Only used for 'bignumber.js'.
* @returns {BigNumberJS | BN | BigNumber}
*/
toBN(): BigNumberJS;
toBN(type: 'bn.js'): BN;
toBN(type: 'ethers-bn'): BigNumber;
toBN(type: 'bignumber.js'): BigNumberJS;
toBN(type: 'bignumber.js', base?: number): BigNumberJS;
toBN(type: 'bigint', base?: number): bigint;
shiftedBy(n: number): string;
shiftedBy(n: number, asBN: undefined | false | null): string;
shiftedBy(n: number, asBN: true): BigNumberJS;
toFraction(_?: undefined): Fraction<string>;
toFraction(asBigInt: true): Fraction<BigNumberJS>;
toFraction(asBigInt?: false): Fraction<string>;
toFraction(asBigInt: 'bigint'): Fraction<bigint>;
toFraction(asBigInt?: boolean | false): Fraction<string | BigNumberJS>;
prettyNum(): string;
}
interface Number {
/**
* Converts the string to a big number using the specified library.
* @date 8.3.2023 - 08:42:19
* @param {?BnTypes} type The library to use for big number conversion. Defaults to 'bignumber.js'.
* @param {?number} base - The base to use when converting from a string. Only used for 'bignumber.js'.
* @returns {BigNumberJS | BN | BigNumber}
*/
toBN(): BigNumberJS;
toBN(type: 'bn.js'): BN;
toBN(type: 'ethers-bn'): BigNumber;
toBN(type: 'bignumber.js'): BigNumberJS;
toBN(type: 'bignumber.js', base?: number): BigNumberJS;
toBN(type: 'bigint', base?: number): bigint;
toUint(add0x?: boolean): string;
shiftedBy(n: number): string;
shiftedBy(n: number, asBN: boolean): BigNumber;
noExponents(): string;
prettyNum(): string;
}
}
declare module '@ethersproject/bignumber' {
interface BigNumber {
/**
* Converts the string to a big number using the specified library.
* @date 8.3.2023 - 08:42:19
* @param {?BnTypes} type The library to use for big number conversion. Defaults to 'bignumber.js'.
* @param {?number} base - The base to use when converting from a string. Only used for 'bignumber.js'.
* @returns {BigNumberJS | BN | BigNumber}
*/
toBN(): BigNumberJS;
toBN(type: 'bn.js'): BN;
toBN(type: 'ethers-bn'): BigNumber;
toBN(type: 'bignumber.js'): BigNumberJS;
toBN(type: 'bignumber.js', base?: number): BigNumberJS;
toBN(type: 'bigint', base?: number): bigint;
shiftedBy(n: number): string;
pretty(): string;
toFraction(): Fraction<string>;
}
}
declare module 'bignumber.js' {
interface BigNumber {
pretty(): string;
/**
* Converts the string to a big number using the specified library.
* @date 8.3.2023 - 08:42:19
* @param {?BnTypes} type The library to use for big number conversion. Defaults to 'bignumber.js'.
* @param {?number} base - The base to use when converting from a string. Only used for 'bignumber.js'.
* @returns {BigNumberJS | BN | BigNumber}
*/
toBN(): BigNumberJS;
toBN(type: 'bn.js'): BN;
toBN(type: 'ethers-bn'): BigNumber;
toBN(type: 'bignumber.js'): BigNumberJS;
toBN(type: 'bignumber.js', base?: number): BigNumberJS;
toBN(type: 'bigint', base?: number): bigint;
}
}
export {};