@pragma-web-utils/bigint-utils
v0.4.1
Published
types
Downloads
1
Readme
BigInt utils
Types
type BI = bigint
type BIish = BI | string | number
Convert
toDecimals
Signature
function toDecimals(amount: BIish, decimals: number): string {}
Description
Convert BIish
to string by provided decimals
fromDecimals
Signature
function fromDecimals(
amount: string,
decimals: number,
options?: Partial<BIParseOption>,
): BI {}
Description
Convert string to BIish
by provided decimals
Parse options
type BIParseOption = {
isDecimalsCountOverflowPossible: boolean // throw error or ignore if string has more symbols than provided decimals
}
Default options
type BIParseOption = {
isDecimalsCountOverflowPossible: true
}
fromBIish
Signature
function fromBIish(amount: BIish): BI {}
Description
Convert BIish
to strict BI
fromBP
Signature
function fromBP(percentInBP: BI, percentDecimals = 2): number {}
Description
Convert BigPercent to number, by default percent decimals equal 2
Formatting
formattedNumber
Signature
function formattedNumber(
value: number,
formatOptions?: Intl.NumberFormatOptions,
): string {}
Description
Format number by formatOptions
. By default:
const defaultOptions = {
style: 'decimal',
minimumFractionDigits: 0,
maximumFractionDigits: 2,
}
formattedDecimals
Signature
function formattedDecimals(
amountTKN: BIish,
decimals: number,
formatOptions?: Intl.NumberFormatOptions,
): string {}
Description
Format BI
by decimals
and formatOptions
. By default:
const defaultOptions = {
style: 'decimal',
minimumFractionDigits: 0,
maximumFractionDigits: 2,
}
BIMath
BIMath.min
Signature
BIMath.min(...values: BI[]): BI
Description
Return min of provided values
BIMath.max
Signature
BIMath.max(...values: BI[]): BI
Description
Return max of provided values