UNPKG

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