/
Number.ts
170 lines (154 loc) · 7.06 KB
/
Number.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
* Extends the built-in javascript `Number` object's static API.
*
* The [[Format.Config.addUtilsToGlobals]] method must be called in order to access the definitions.
*/
interface NumberConstructor {
/**
* Determines whether the passed value is an integer.
*
* Must call [[Format.Config.addUtilsToGlobals]] to be defined.
* @param value The number to test.
* @returns `true` if the value parameter is an integer.
*/
isInteger(value: number): boolean;
/**
* Determines whether the passed value is a counting number (positive integer excluding `0`).
*
* Must call [[Format.Config.addUtilsToGlobals]] to be defined.
* @param value The number to test.
* @returns `true` if the value parameter is a positive integer excluding `0`.
*/
isCounting(value: number): boolean;
/**
* Determines whether the passed value is a whole number (positive integer including `0`).
*
* Must call [[Format.Config.addUtilsToGlobals]] to be defined.
* @param value The number to test.
* @returns `true` if the value parameter is a positive integer including `0`.
*/
isWhole(value: number): boolean;
/**
* Determines whether the passed value is an even number.
*
* Throws an error if the value is not an integer (when [[isInteger]] returns `false`).
*
* Must call [[Format.Config.addUtilsToGlobals]] to be defined.
* @param value The number to test.
* @returns `true` if the value parameter is an even number.
*/
isEven(value: number): boolean;
/**
* Returns the best fitting formatted value, returned by the `Number.toFixed` method, given a minimum and/or maximum digits precision.
*
* Must call [[Format.Config.addUtilsToGlobals]] to be defined.
* @param value The number to format.
* @param minDigits The minimum number of digits to include in the format.
* @param maxDigits The maximum number of digits to include in the format.
*/
toFixedMinMax(value: number, minDigits: number, maxDigits: number): string;
/**
* Returns the best fitting formatted value, returned by the `Number.toExponential` method, given a minimum and/or maximum digits precision.
*
* Must call [[Format.Config.addUtilsToGlobals]] to be defined.
* @param value The number to format.
* @param minDigits The minimum number of digits to include in the format.
* @param maxDigits The maximum number of digits to include in the format.
*/
toExponentialMinMax(value: number, minDigits: number, maxDigits: number): string;
/**
* Returns the best fitting formatted value, returned by the `Number.toPrecision` method, given a minimum and/or maximum digits precision.
*
* Must call [[Format.Config.addUtilsToGlobals]] to be defined.
* @param value The number to format.
* @param minDigits The minimum number of digits to include in the format.
* @param maxDigits The maximum number of digits to include in the format.
*/
toPrecisionMinMax(value: number, minDigits: number, maxDigits: number): string;
}
/**
* Extends the built-in javascript `Number` object's prototype.
*
* Various [[Format.Config]] methods can be called in order to access the additional definitions, see each method for more details.
*/
interface Number {
/**
* Converts the numeric value of this instance to its equivalent string representation, using the specified format.
*
* Must call [[Format.Config.addToStringOverload]] to be defined.
* @param format A standard or custom numeric format string.
* @returns The formatted numeric value.
*/
toString(format: string): string;
/**
* Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
*
* Must call [[Format.Config.addToStringOverload]] to be defined.
* @param provider An object that supplies culture-specific formatting information.
* @returns The formatted numeric value.
*/
toString(provider: Format.Globalization.FormatProvider): string;
/**
* Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.
*
* Must call [[Format.Config.addToStringOverload]] to be defined.
* @param format A standard or custom numeric format string.
* @param provider An object that supplies culture-specific formatting information.
* @returns The formatted numeric value.
*/
toString(format: string, provider: Format.Globalization.FormatProvider): string;
/**
* Determines whether the value is an integer.
*
* Must call [[Format.Config.addUtilsToPrototype]] to be defined.
* @returns `true` if the value is an integer.
*/
isInteger(): boolean;
/**
* Determines whether the passed value is a counting number (positive integer excluding `0`).
*
* Must call [[Format.Config.addUtilsToPrototype]] to be defined.
* @returns `true` if the value is a positive integer excluding `0`.
*/
isCounting(): boolean;
/**
* Determines whether the passed value is a whole number (positive integer including `0`).
*
* Must call [[Format.Config.addUtilsToPrototype]] to be defined.
* @returns `true` if the value is a positive integer including `0`.
*/
isWhole(): boolean;
/**
* Determines whether the value is an even number.
*
* Throws an error if the value is not an integer (when [[isInteger]] returns `false`).
*
* Must call [[Format.Config.addUtilsToPrototype]] to be defined.
* @returns `true` if the value is an even number.
*/
isEven(): boolean;
/**
* Returns the best fitting formatted value, returned by the `Number.toFixed` method, given a minimum and/or maximum digits precision.
*
* Must call [[Format.Config.addUtilsToPrototype]] to be defined.
* @param minDigits The minimum number of digits to include in the format.
* @param maxDigits The maximum number of digits to include in the format.
*/
toFixedMinMax(minDigits: number, maxDigits: number): string;
/**
* Returns the best fitting formatted value, returned by the `Number.toExponential` method, given a minimum and/or maximum digits precision.
*
* Must call [[Format.Config.addUtilsToPrototype]] to be defined.
* @param minDigits The minimum number of digits to include in the format.
* @param maxDigits The maximum number of digits to include in the format.
*/
toExponentialMinMax(minDigits: number, maxDigits: number): string;
/**
* Returns the best fitting formatted value, returned by the `Number.toPrecision` method, given a minimum and/or maximum digits precision.
*
* Must call [[Format.Config.addUtilsToPrototype]] to be defined.
* @param minDigits The minimum number of digits to include in the format.
* @param maxDigits The maximum number of digits to include in the format.
*/
toPrecisionMinMax(minDigits: number, maxDigits: number): string;
}