forked from BenjaminVanRyseghem/numbro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
numbro.d.ts
147 lines (101 loc) · 3.65 KB
/
numbro.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Definitions by: Dan Poggi <https://github.com/dpoggi>
declare function numbro(value?: any): numbro.Numbro;
declare namespace numbro {
export const version: string;
export function isNumbro(value: any): value is Numbro;
export function language(): string;
export function registerLanguage(tag: NumbroLanguage, useLanguage ?: boolean): string;
export function setLanguage(tag: string, fallbackTag ?: string): void;
export function languages(): { [tag: string]: NumbroLanguage };
export function languageData(tag ?: string): NumbroLanguage;
export function zeroFormat(newFormat: string): void;
export function defaultFormat(): {};
export function setDefaults(format: Format | string): void;
export function defaultCurrencyFormat(newFormat: string): {};
export function validate(value: string, format: Format | string): boolean;
export function loadLanguagesInNode(): void;
export function unformat(input: string, format?: Format | string): number;
interface Numbro {
clone(): Numbro;
format(format?: Format | string): string;
formatCurrency(format?: Format | string): string;
formatTime(format?: Format | string): string;
binaryByteUnits(): string;
decimalByteUnits(): string;
byteUnits(): string;
difference(value: number): number;
add(value: number): this;
subtract(value: number): this;
multiply(value: number): this;
divide(value: number): this;
set(value: number): this;
value(): number;
valueOf(): number;
}
export interface Format {
output?: "currency" | "percent" | "byte" | "time" | "ordinal" | "number";
base?: "decimal" | "binary" | "general";
characteristic?: number;
prefix?: string;
postfix?: string;
forceAverage?: "trillion" | "billion" | "million" | "thousand";
average?: boolean;
currencyPosition?: "prefix" | "infix" | "postfix";
currencySymbol?: string;
totalLength?: number;
mantissa?: number;
optionalMantissa?: boolean;
trimMantissa?: boolean;
optionalCharacteristic?: boolean;
thousandSeparated?: boolean;
abbreviations?: {
thousand?: string;
million?: string;
billion?: string;
trillion?: string;
};
negative?: "sign" | "parenthesis";
forceSign?: boolean;
spaceSeparated?: boolean;
spaceSeparatedCurrency?: boolean;
spaceSeparatedAbbreviation?: boolean;
exponential?: boolean;
prefixSymbol?: boolean;
lowPrecision?: boolean;
roundingFunction?: (num: number) => number;
}
export interface NumbroLanguage {
languageTag: string;
delimiters: {
thousands: string;
decimal: string;
thousandsSize?: number;
};
abbreviations: {
thousand: string;
million: string;
billion: string;
trillion: string;
};
spaceSeparated?: boolean;
ordinal(num: number): string;
currency: {
symbol: string;
position: string;
code: string;
};
defaults?: Format;
ordinalFormat?: Format;
byteFormat?: Format;
percentageFormat?: Format;
currencyFormat?: Format;
timeDefaults?: Format;
formats: {
fourDigits: Format;
fullWithTwoDecimals: Format;
fullWithTwoDecimalsNoCurrency: Format;
fullWithNoDecimals: Format;
};
}
}
export default numbro;