UNPKG

1.5 kBTypeScriptView Raw
1/// <reference types="bn.js" />
2import type { BN } from '../bn/bn.js';
3import type { SiDef, ToBn } from '../types.js';
4interface Defaults {
5 decimals: number;
6 unit: string;
7}
8interface SetDefaults {
9 decimals?: number[] | number;
10 unit?: string[] | string;
11}
12interface Options {
13 /**
14 * @description The number of decimals
15 */
16 decimals?: number;
17 /**
18 * @description Format the number with this specific unit
19 */
20 forceUnit?: string;
21 /**
22 * @description Returns value using all available decimals
23 */
24 withAll?: boolean;
25 /**
26 * @description Format with SI, i.e. m/M/etc. (default = true)
27 */
28 withSi?: boolean;
29 /**
30 * @description Format with full SI, i.e. mili/Mega/etc.
31 */
32 withSiFull?: boolean;
33 /**
34 * @description Add the unit (useful in Balance formats)
35 */
36 withUnit?: boolean | string;
37 /**
38 * @description Returns all trailing zeros, otherwise removes (default = true)
39 */
40 withZero?: boolean;
41 /**
42 * @description The locale to use
43 */
44 locale?: string;
45}
46interface BalanceFormatter {
47 <ExtToBn extends ToBn>(input?: number | string | BN | bigint | ExtToBn, options?: Options): string;
48 calcSi(text: string, decimals?: number): SiDef;
49 findSi(type: string): SiDef;
50 getDefaults(): Defaults;
51 getOptions(decimals?: number): SiDef[];
52 setDefaults(defaults: SetDefaults): void;
53}
54export declare const formatBalance: BalanceFormatter;
55export {};