@tolki/num 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +19 -18
- package/dist/num.d.ts +35 -72
- package/dist/num.d.ts.map +1 -1
- package/dist/num.js +102 -93
- package/dist/speller/index.d.ts +4 -14
- package/dist/speller/index.d.ts.map +1 -1
- package/dist/speller/index.js +17 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { spell as g, spellOrdinal as
|
|
1
|
+
import { abbreviate as a, clamp as l, currency as o, defaultCurrency as n, defaultLocale as s, fileSize as t, forHumans as u, format as c, minutesToHuman as i, ordinal as m, pairs as p, parse as f, parseFloat as d, parseInt as y, percentage as C, secondsToHuman as H, summarize as L, trim as b, useCurrency as h, useLocale as w, withCurrency as x, withLocale as z } from "./num.js";
|
|
2
|
+
import { spell as g, spellOrdinal as v } from "./speller/index.js";
|
|
3
3
|
export {
|
|
4
|
-
a as
|
|
5
|
-
l as
|
|
6
|
-
o as
|
|
7
|
-
n as
|
|
8
|
-
s as
|
|
4
|
+
a as abbreviate,
|
|
5
|
+
l as clamp,
|
|
6
|
+
o as currency,
|
|
7
|
+
n as defaultCurrency,
|
|
8
|
+
s as defaultLocale,
|
|
9
|
+
t as fileSize,
|
|
9
10
|
u as forHumans,
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
c as format,
|
|
12
|
+
i as minutesToHuman,
|
|
12
13
|
m as ordinal,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
p as pairs,
|
|
15
|
+
f as parse,
|
|
16
|
+
d as parseFloat,
|
|
17
|
+
y as parseInt,
|
|
18
|
+
C as percentage,
|
|
19
|
+
H as secondsToHuman,
|
|
19
20
|
g as spell,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
v as spellOrdinal,
|
|
22
|
+
L as summarize,
|
|
23
|
+
b as trim,
|
|
23
24
|
h as useCurrency,
|
|
24
25
|
w as useLocale,
|
|
25
26
|
x as withCurrency,
|
package/dist/num.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert the number to its human-readable equivalent.
|
|
3
|
+
*
|
|
4
|
+
* @param number - The number to convert.
|
|
5
|
+
* @param precision - The number of decimal places to use.
|
|
6
|
+
* @param maxPrecision - The maximum number of decimal places to use.
|
|
7
|
+
* @returns The human-readable number string.
|
|
8
|
+
*
|
|
9
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#abbreviate
|
|
10
|
+
*/
|
|
11
|
+
export declare function abbreviate(number: number, precision?: number, maxPrecision?: number | null): string | false;
|
|
1
12
|
/**
|
|
2
13
|
* Format the given number according to the current locale.
|
|
3
14
|
*
|
|
@@ -7,11 +18,7 @@
|
|
|
7
18
|
* @param locale - The locale to use for formatting.
|
|
8
19
|
* @returns The formatted number string.
|
|
9
20
|
*
|
|
10
|
-
* @
|
|
11
|
-
*
|
|
12
|
-
* format(1234.5678, 2); // "1,234.57"
|
|
13
|
-
* format(1234.5678, 2, 4); // "1,234.5678"
|
|
14
|
-
* format(1234.5678, 2, 4, "de"); // "1.234,5678"
|
|
21
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#format
|
|
15
22
|
*/
|
|
16
23
|
export declare function format(number: number, precision?: number | null, maxPrecision?: number | null, locale?: string | null): string | false;
|
|
17
24
|
/**
|
|
@@ -33,9 +40,7 @@ export declare function parse(value: string, locale?: string | null): number;
|
|
|
33
40
|
* @param locale - The locale to use for parsing.
|
|
34
41
|
* @returns The parsed integer or false if parsing fails.
|
|
35
42
|
*
|
|
36
|
-
* @
|
|
37
|
-
*
|
|
38
|
-
* parseInt("1,234", "en"); // 1234
|
|
43
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#parseint
|
|
39
44
|
*/
|
|
40
45
|
export declare function parseInt(value: string, locale?: string | null): number | false;
|
|
41
46
|
/**
|
|
@@ -44,6 +49,8 @@ export declare function parseInt(value: string, locale?: string | null): number
|
|
|
44
49
|
* @param value - The string to parse.
|
|
45
50
|
* @param locale - The locale to use for parsing.
|
|
46
51
|
* @returns The parsed float or false if parsing fails.
|
|
52
|
+
*
|
|
53
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#parsefloat
|
|
47
54
|
*/
|
|
48
55
|
export declare function parseFloat(value: string, locale?: string | null): number | false;
|
|
49
56
|
/**
|
|
@@ -53,12 +60,7 @@ export declare function parseFloat(value: string, locale?: string | null): numbe
|
|
|
53
60
|
* @param locale - The locale to use for determining ordinal rules.
|
|
54
61
|
* @returns The number in ordinal form.
|
|
55
62
|
*
|
|
56
|
-
* @
|
|
57
|
-
*
|
|
58
|
-
* ordinal(1); // "1st"
|
|
59
|
-
* ordinal(2); // "2nd"
|
|
60
|
-
* ordinal(3); // "3rd"
|
|
61
|
-
* ordinal(13); // "13th"
|
|
63
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#ordinal
|
|
62
64
|
*/
|
|
63
65
|
export declare function ordinal(value: number, locale?: string | null): string;
|
|
64
66
|
/**
|
|
@@ -70,11 +72,7 @@ export declare function ordinal(value: number, locale?: string | null): string;
|
|
|
70
72
|
* @param locale - The locale to use for formatting.
|
|
71
73
|
* @returns The formatted percentage string.
|
|
72
74
|
*
|
|
73
|
-
* @
|
|
74
|
-
*
|
|
75
|
-
* percentage(1); // "1%"
|
|
76
|
-
* percentage(1.75, 2); // "1.75%"
|
|
77
|
-
* percentage(0.12345, 4); // "0.1235%"
|
|
75
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#percentage
|
|
78
76
|
*/
|
|
79
77
|
export declare function percentage(number: number | string, precision?: number, maxPrecision?: number | null, locale?: string | null): string | false;
|
|
80
78
|
/**
|
|
@@ -86,11 +84,7 @@ export declare function percentage(number: number | string, precision?: number,
|
|
|
86
84
|
* @param precision - The number of decimal places to use.
|
|
87
85
|
* @returns The formatted currency string.
|
|
88
86
|
*
|
|
89
|
-
* @
|
|
90
|
-
*
|
|
91
|
-
* currency(5.00); // "$5.00"
|
|
92
|
-
* currency(-5); // "-$5.00"
|
|
93
|
-
* currency(10, 'EUR'); // "€10.00"
|
|
87
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#currency
|
|
94
88
|
*/
|
|
95
89
|
export declare function currency(amount: number | string, currencyCode?: string, locale?: string | null, precision?: number | null): string | false;
|
|
96
90
|
/**
|
|
@@ -101,11 +95,7 @@ export declare function currency(amount: number | string, currencyCode?: string,
|
|
|
101
95
|
* @param maxPrecision - The maximum number of decimal places to use.
|
|
102
96
|
* @returns The formatted file size string.
|
|
103
97
|
*
|
|
104
|
-
* @
|
|
105
|
-
*
|
|
106
|
-
* fileSize(1024); // "1 KB"
|
|
107
|
-
* fileSize(2048); // "2 KB"
|
|
108
|
-
* fileSize(1264.12345, 3); // "1.234 KB"
|
|
98
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#filesize
|
|
109
99
|
*/
|
|
110
100
|
export declare function fileSize(bytes: number | string, precision?: number, maxPrecision?: number | null): string;
|
|
111
101
|
/**
|
|
@@ -115,11 +105,7 @@ export declare function fileSize(bytes: number | string, precision?: number, max
|
|
|
115
105
|
* @param precision - The number of decimal places to use.
|
|
116
106
|
* @param maxPrecision - The maximum number of decimal places to use.
|
|
117
107
|
*
|
|
118
|
-
* @
|
|
119
|
-
*
|
|
120
|
-
* forHumans(1234); // "1.234 thousand"
|
|
121
|
-
* forHumans(1234567); // "1.234 million"
|
|
122
|
-
* forHumans(1234567890); // "1.234 billion"
|
|
108
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#forhumans
|
|
123
109
|
*/
|
|
124
110
|
export declare function forHumans(value: number, precision?: number, maxPrecision?: number | null, abbreviate?: boolean): string | false;
|
|
125
111
|
/**
|
|
@@ -146,11 +132,7 @@ export declare function summarize(value: number, precision?: number, maxPrecisio
|
|
|
146
132
|
* @param max - The maximum value.
|
|
147
133
|
* @returns The clamped number.
|
|
148
134
|
*
|
|
149
|
-
* @
|
|
150
|
-
*
|
|
151
|
-
* clamp(5, 1, 10); // 5
|
|
152
|
-
* clamp(0, 1, 10); // 1
|
|
153
|
-
* clamp(15, 1, 10); // 10
|
|
135
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#clamp
|
|
154
136
|
*/
|
|
155
137
|
export declare function clamp(value: number, min: number, max: number): number;
|
|
156
138
|
/**
|
|
@@ -162,9 +144,7 @@ export declare function clamp(value: number, min: number, max: number): number;
|
|
|
162
144
|
* @param offset - The offset to apply to the upper bound of each pair.
|
|
163
145
|
* @returns An array of [min, max] pairs.
|
|
164
146
|
*
|
|
165
|
-
* @
|
|
166
|
-
*
|
|
167
|
-
* pairs(25, 10, 1, 1); // [[1, 11], [11, 21], [21, 25]]
|
|
147
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#pairs
|
|
168
148
|
*/
|
|
169
149
|
export declare function pairs(to: number, by: number, start?: number, offset?: number): [number, number][];
|
|
170
150
|
/**
|
|
@@ -173,10 +153,7 @@ export declare function pairs(to: number, by: number, start?: number, offset?: n
|
|
|
173
153
|
* @param value - The number to trim.
|
|
174
154
|
* @returns The trimmed number.
|
|
175
155
|
*
|
|
176
|
-
* @
|
|
177
|
-
*
|
|
178
|
-
* trim(12.3456789); // 12.3456789
|
|
179
|
-
* trim(12.34567890000); // 12.3456789
|
|
156
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#trim
|
|
180
157
|
*/
|
|
181
158
|
export declare function trim(value: number): number;
|
|
182
159
|
/**
|
|
@@ -186,10 +163,7 @@ export declare function trim(value: number): number;
|
|
|
186
163
|
* @param round - Whether to round to the nearest unit.
|
|
187
164
|
* @returns The human-readable duration string.
|
|
188
165
|
*
|
|
189
|
-
* @
|
|
190
|
-
*
|
|
191
|
-
* minutesToHuman(61); // "1 hour"
|
|
192
|
-
* minutesToHuman(61, false); // "1 hour, 1 minute"
|
|
166
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#minutestohuman
|
|
193
167
|
*/
|
|
194
168
|
export declare function minutesToHuman(minutes: number | string, round?: boolean): string;
|
|
195
169
|
/**
|
|
@@ -199,10 +173,7 @@ export declare function minutesToHuman(minutes: number | string, round?: boolean
|
|
|
199
173
|
* @param round Whether to round to the nearest unit.
|
|
200
174
|
* @returns The human-readable duration string.
|
|
201
175
|
*
|
|
202
|
-
* @
|
|
203
|
-
*
|
|
204
|
-
* secondsToHuman(3661); // "1 hour"
|
|
205
|
-
* secondsToHuman(3661, false); // "1 hour, 1 minute, 1 second"
|
|
176
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#secondstohuman
|
|
206
177
|
*/
|
|
207
178
|
export declare function secondsToHuman(seconds: number | string, round?: boolean): string;
|
|
208
179
|
/**
|
|
@@ -212,11 +183,7 @@ export declare function secondsToHuman(seconds: number | string, round?: boolean
|
|
|
212
183
|
* @param callback - The callback to execute.
|
|
213
184
|
* @returns The result of the callback.
|
|
214
185
|
*
|
|
215
|
-
* @
|
|
216
|
-
*
|
|
217
|
-
* withLocale("fr", () => {
|
|
218
|
-
* return format(1234.56);
|
|
219
|
-
* }); // "1 234,56"
|
|
186
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#withlocale
|
|
220
187
|
*/
|
|
221
188
|
export declare function withLocale<TReturn>(locale: string, callback: () => TReturn): TReturn | void;
|
|
222
189
|
/**
|
|
@@ -226,11 +193,7 @@ export declare function withLocale<TReturn>(locale: string, callback: () => TRet
|
|
|
226
193
|
* @param callback - The callback to execute.
|
|
227
194
|
* @returns The result of the callback.
|
|
228
195
|
*
|
|
229
|
-
* @
|
|
230
|
-
*
|
|
231
|
-
* withCurrency("EUR", () => {
|
|
232
|
-
* return format(1234.56);
|
|
233
|
-
* }); // "€1,234.56"
|
|
196
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#withcurrency
|
|
234
197
|
*/
|
|
235
198
|
export declare function withCurrency<TReturn>(currency: string, callback: () => TReturn): TReturn | void;
|
|
236
199
|
/**
|
|
@@ -238,6 +201,8 @@ export declare function withCurrency<TReturn>(currency: string, callback: () =>
|
|
|
238
201
|
*
|
|
239
202
|
* @param locale - The locale to set.
|
|
240
203
|
* @returns void
|
|
204
|
+
*
|
|
205
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#uselocale
|
|
241
206
|
*/
|
|
242
207
|
export declare function useLocale(locale: string): void;
|
|
243
208
|
/**
|
|
@@ -245,26 +210,24 @@ export declare function useLocale(locale: string): void;
|
|
|
245
210
|
*
|
|
246
211
|
* @param currency - The currency to set.
|
|
247
212
|
* @returns void
|
|
213
|
+
*
|
|
214
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#usecurrency
|
|
248
215
|
*/
|
|
249
216
|
export declare function useCurrency(currency: string): void;
|
|
250
217
|
/**
|
|
251
|
-
* Get the default locale.
|
|
218
|
+
* Get the configured default locale.
|
|
252
219
|
*
|
|
253
220
|
* @returns The default locale.
|
|
254
221
|
*
|
|
255
|
-
* @
|
|
256
|
-
*
|
|
257
|
-
* defaultLocale(); // "en"
|
|
222
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#defaultlocale
|
|
258
223
|
*/
|
|
259
224
|
export declare function defaultLocale(): string;
|
|
260
225
|
/**
|
|
261
|
-
* Get the default currency.
|
|
226
|
+
* Get the configured default currency.
|
|
262
227
|
*
|
|
263
228
|
* @returns The default currency.
|
|
264
229
|
*
|
|
265
|
-
* @
|
|
266
|
-
*
|
|
267
|
-
* defaultCurrency(); // "USD"
|
|
230
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#defaultcurrency
|
|
268
231
|
*/
|
|
269
232
|
export declare function defaultCurrency(): string;
|
|
270
233
|
//# sourceMappingURL=num.d.ts.map
|
package/dist/num.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../src/num.ts"],"names":[],"mappings":"AAUA
|
|
1
|
+
{"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../src/num.ts"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACtB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,MAAU,EACrB,YAAY,GAAE,MAAM,GAAG,IAAW,GACnC,MAAM,GAAG,KAAK,CAEhB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAClB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,YAAY,GAAE,MAAM,GAAG,IAAW,EAClC,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,GAAG,KAAK,CAmBhB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CA2DzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CACpB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,GAAG,KAAK,CAQhB;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACtB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,GAAG,KAAK,CAEhB;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CA2C3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACtB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,SAAS,GAAE,MAAU,EACrB,YAAY,GAAE,MAAM,GAAG,IAAW,EAClC,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,GAAG,KAAK,CAqBhB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CACpB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,YAAY,GAAE,MAAW,EACzB,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,SAAS,GAAE,MAAM,GAAG,IAAW,GAChC,MAAM,GAAG,KAAK,CAiBhB;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CACpB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,SAAS,GAAE,MAAU,EACrB,YAAY,GAAE,MAAM,GAAG,IAAW,GACnC,MAAM,CA6BR;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACrB,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAU,EACrB,YAAY,GAAE,MAAM,GAAG,IAAW,EAClC,UAAU,GAAE,OAAe,GAC5B,MAAM,GAAG,KAAK,CAehB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CACrB,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAU,EACrB,YAAY,GAAE,MAAM,GAAG,IAAW,EAClC,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,MAAM,GAAG,KAAK,CA4EhB;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CACjB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,KAAK,GAAE,MAAU,EACjB,MAAM,GAAE,MAAU,GACnB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAcpB;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,KAAK,GAAE,OAAc,GACtB,MAAM,CAIR;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,KAAK,GAAE,OAAc,GACtB,MAAM,CAoDR;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAC9B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,OAAO,GACxB,OAAO,GAAG,IAAI,CAUhB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,OAAO,GACxB,OAAO,GAAG,IAAI,CAUhB;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAElD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
|
package/dist/num.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
let
|
|
1
|
+
let p = "en", y = "USD";
|
|
2
|
+
function x(t, n = 0, e = null) {
|
|
3
|
+
return D(t, n, e, !0);
|
|
4
|
+
}
|
|
2
5
|
function g(t, n = null, e = null, r = null) {
|
|
3
|
-
r = r ??
|
|
6
|
+
r = r ?? p;
|
|
4
7
|
const o = {
|
|
5
8
|
style: "decimal",
|
|
6
9
|
useGrouping: !0
|
|
@@ -8,44 +11,49 @@ function g(t, n = null, e = null, r = null) {
|
|
|
8
11
|
return e != null ? (o.maximumFractionDigits = e, o.minimumFractionDigits = 0) : n != null && (o.minimumFractionDigits = n, o.maximumFractionDigits = n), new Intl.NumberFormat(r, o).format(t);
|
|
9
12
|
}
|
|
10
13
|
function $(t, n = null) {
|
|
11
|
-
n = n ??
|
|
14
|
+
n = n ?? p;
|
|
12
15
|
const r = new Intl.NumberFormat(n).formatToParts(12345.6), o = /* @__PURE__ */ new Set();
|
|
13
|
-
let
|
|
14
|
-
for (const
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
for (const
|
|
18
|
-
let
|
|
19
|
-
for (const
|
|
16
|
+
let s = ".";
|
|
17
|
+
for (const l of r)
|
|
18
|
+
l.type === "group" ? o.add(l.value) : l.type === "decimal" && (s = l.value);
|
|
19
|
+
const u = [" ", " ", " "];
|
|
20
|
+
for (const l of u) o.add(l);
|
|
21
|
+
let i = t;
|
|
22
|
+
for (const l of o) {
|
|
20
23
|
const c = new RegExp(
|
|
21
|
-
|
|
24
|
+
l.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
|
|
22
25
|
"g"
|
|
23
26
|
);
|
|
24
|
-
|
|
27
|
+
i = i.replace(c, "");
|
|
25
28
|
}
|
|
26
|
-
if (
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
+
if (s !== ".") {
|
|
30
|
+
const l = new RegExp(
|
|
31
|
+
s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
|
|
29
32
|
"g"
|
|
30
|
-
), c =
|
|
31
|
-
c !== -1 && (
|
|
33
|
+
), c = i.lastIndexOf(s);
|
|
34
|
+
c !== -1 && (i = i.slice(0, c).replace(l, "") + "." + i.slice(c + s.length));
|
|
32
35
|
}
|
|
33
|
-
return
|
|
36
|
+
return i = i.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(i);
|
|
34
37
|
}
|
|
35
|
-
function
|
|
38
|
+
function E(t, n = null) {
|
|
36
39
|
const e = $(t, n);
|
|
37
40
|
return Number.isNaN(e) ? !1 : e < 0 ? Math.ceil(e) : Math.floor(e);
|
|
38
41
|
}
|
|
39
|
-
function
|
|
42
|
+
function B(t, n = null) {
|
|
40
43
|
return $(t, n);
|
|
41
44
|
}
|
|
42
|
-
function
|
|
43
|
-
const e = n ??
|
|
45
|
+
function O(t, n = null) {
|
|
46
|
+
const e = n ?? p;
|
|
44
47
|
try {
|
|
45
|
-
const o = new Intl.PluralRules(e, { type: "ordinal" }).select(t),
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
const o = new Intl.PluralRules(e, { type: "ordinal" }).select(t), s = String(e.split("-")[0]), u = {
|
|
49
|
+
one: "st",
|
|
50
|
+
two: "nd",
|
|
51
|
+
few: "rd",
|
|
52
|
+
other: "th"
|
|
53
|
+
}, f = {
|
|
54
|
+
en: u
|
|
55
|
+
}[s] ?? u, l = f[o] ?? f.other;
|
|
56
|
+
return `${t}${l}`;
|
|
49
57
|
} catch {
|
|
50
58
|
const r = Math.abs(t), o = r % 100;
|
|
51
59
|
if (o >= 11 && o <= 13)
|
|
@@ -62,22 +70,22 @@ function E(t, n = null) {
|
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
|
-
function
|
|
66
|
-
const o = r ??
|
|
73
|
+
function I(t, n = 0, e = null, r = null) {
|
|
74
|
+
const o = r ?? p, s = typeof t == "string" ? $(t, o) : t, u = {
|
|
67
75
|
style: "percent",
|
|
68
76
|
useGrouping: !0
|
|
69
77
|
};
|
|
70
|
-
return e != null ? (
|
|
78
|
+
return e != null ? (u.maximumFractionDigits = e, u.minimumFractionDigits = 0) : (u.minimumFractionDigits = n, u.maximumFractionDigits = n), new Intl.NumberFormat(o, u).format(s / 100);
|
|
71
79
|
}
|
|
72
|
-
function
|
|
73
|
-
const o = e ??
|
|
80
|
+
function T(t, n = "", e = null, r = null) {
|
|
81
|
+
const o = e ?? p, s = typeof t == "string" ? $(t, o) : t, i = {
|
|
74
82
|
style: "currency",
|
|
75
83
|
currency: n && n.length ? n : y,
|
|
76
84
|
useGrouping: !0
|
|
77
85
|
};
|
|
78
|
-
return r != null && (
|
|
86
|
+
return r != null && (i.minimumFractionDigits = r, i.maximumFractionDigits = r), new Intl.NumberFormat(o, i).format(s);
|
|
79
87
|
}
|
|
80
|
-
function
|
|
88
|
+
function R(t, n = 0, e = null) {
|
|
81
89
|
let r = typeof t == "string" ? Number(t) : t;
|
|
82
90
|
Number.isFinite(r) || (r = 0);
|
|
83
91
|
const o = [
|
|
@@ -90,13 +98,13 @@ function I(t, n = 0, e = null) {
|
|
|
90
98
|
"EB",
|
|
91
99
|
"ZB",
|
|
92
100
|
"YB"
|
|
93
|
-
],
|
|
94
|
-
let
|
|
95
|
-
for (; r / 1024 > 0.9 &&
|
|
96
|
-
r /= 1024,
|
|
97
|
-
return `${g(r, n, e)} ${o[
|
|
101
|
+
], s = o.length;
|
|
102
|
+
let u = 0;
|
|
103
|
+
for (; r / 1024 > 0.9 && u < s - 1; )
|
|
104
|
+
r /= 1024, u++;
|
|
105
|
+
return `${g(r, n, e)} ${o[u]}`;
|
|
98
106
|
}
|
|
99
|
-
function
|
|
107
|
+
function D(t, n = 0, e = null, r = !1) {
|
|
100
108
|
return b(
|
|
101
109
|
t,
|
|
102
110
|
n,
|
|
@@ -127,7 +135,7 @@ function b(t, n = 0, e = null, r = {}) {
|
|
|
127
135
|
r
|
|
128
136
|
)}`;
|
|
129
137
|
if (t >= 1e15) {
|
|
130
|
-
const
|
|
138
|
+
const l = Object.keys(r).map((a) => Number(a)).filter((a) => !Number.isNaN(a)).sort((a, m) => a - m), c = l[l.length - 1], h = r[c];
|
|
131
139
|
return `${b(
|
|
132
140
|
t / 1e15,
|
|
133
141
|
n,
|
|
@@ -135,68 +143,68 @@ function b(t, n = 0, e = null, r = {}) {
|
|
|
135
143
|
r
|
|
136
144
|
)}${h}`.trim();
|
|
137
145
|
}
|
|
138
|
-
const o = Math.floor(Math.log10(t)),
|
|
139
|
-
let
|
|
146
|
+
const o = Math.floor(Math.log10(t)), s = o - o % 3, u = t / Math.pow(10, s);
|
|
147
|
+
let i;
|
|
140
148
|
if (e != null)
|
|
141
|
-
|
|
149
|
+
i = g(u, null, e);
|
|
142
150
|
else if (n > 0)
|
|
143
|
-
|
|
151
|
+
i = g(u, n, null);
|
|
144
152
|
else {
|
|
145
|
-
const
|
|
146
|
-
|
|
153
|
+
const l = Math.abs(t);
|
|
154
|
+
i = s === 3 && u < 10 && l % 10 === 0 ? g(u, null, 1) : g(u, 0, null);
|
|
147
155
|
}
|
|
148
|
-
const
|
|
149
|
-
return `${
|
|
156
|
+
const f = r[s] ?? "";
|
|
157
|
+
return `${i}${f}`.trim();
|
|
150
158
|
}
|
|
151
|
-
function
|
|
159
|
+
function G(t, n, e) {
|
|
152
160
|
return Math.min(Math.max(t, n), e);
|
|
153
161
|
}
|
|
154
|
-
function
|
|
162
|
+
function H(t, n, e = 0, r = 1) {
|
|
155
163
|
const o = [];
|
|
156
|
-
for (let
|
|
157
|
-
let
|
|
158
|
-
|
|
164
|
+
for (let s = e; s < t; s += n) {
|
|
165
|
+
let u = s + n - r;
|
|
166
|
+
u > t && (u = t), o.push([s, u]);
|
|
159
167
|
}
|
|
160
168
|
return o;
|
|
161
169
|
}
|
|
162
|
-
function
|
|
170
|
+
function k(t) {
|
|
163
171
|
return JSON.parse(JSON.stringify(t));
|
|
164
172
|
}
|
|
165
|
-
function
|
|
173
|
+
function A(t, n = !0) {
|
|
166
174
|
const e = Number(t) * 60;
|
|
167
|
-
return
|
|
175
|
+
return S(e, n);
|
|
168
176
|
}
|
|
169
|
-
function
|
|
177
|
+
function S(t, n = !0) {
|
|
170
178
|
let e = Number(t);
|
|
171
179
|
if ((!Number.isFinite(e) || e < 0) && (e = 0), e === 0) return "0 seconds";
|
|
172
|
-
const r = 1, o = 60 * r,
|
|
173
|
-
["year", 12 *
|
|
174
|
-
["month",
|
|
175
|
-
["week",
|
|
176
|
-
["day",
|
|
177
|
-
["hour",
|
|
180
|
+
const r = 1, o = 60 * r, s = 60 * o, u = 24 * s, i = 7 * u, f = 4 * i, c = [
|
|
181
|
+
["year", 12 * f],
|
|
182
|
+
["month", f],
|
|
183
|
+
["week", i],
|
|
184
|
+
["day", u],
|
|
185
|
+
["hour", s],
|
|
178
186
|
["minute", o],
|
|
179
187
|
["second", r]
|
|
180
188
|
];
|
|
181
189
|
if (n)
|
|
182
|
-
for (const [a,
|
|
183
|
-
const d = e /
|
|
184
|
-
if (d >= 0.5 ||
|
|
190
|
+
for (const [a, m] of c) {
|
|
191
|
+
const d = e / m;
|
|
192
|
+
if (d >= 0.5 || m === r) {
|
|
185
193
|
const F = Math.round(d);
|
|
186
194
|
return `${F} ${a}${F === 1 ? "" : "s"}`;
|
|
187
195
|
}
|
|
188
196
|
}
|
|
189
197
|
let h = e;
|
|
190
198
|
const N = [];
|
|
191
|
-
for (const [a,
|
|
192
|
-
if (h >=
|
|
193
|
-
const d = Math.floor(h /
|
|
194
|
-
h -= d *
|
|
199
|
+
for (const [a, m] of c)
|
|
200
|
+
if (h >= m) {
|
|
201
|
+
const d = Math.floor(h / m);
|
|
202
|
+
h -= d * m, N.push(`${d} ${a}${d === 1 ? "" : "s"}`);
|
|
195
203
|
}
|
|
196
204
|
return N.join(", ");
|
|
197
205
|
}
|
|
198
|
-
function
|
|
199
|
-
const e =
|
|
206
|
+
function C(t, n) {
|
|
207
|
+
const e = p;
|
|
200
208
|
w(t);
|
|
201
209
|
try {
|
|
202
210
|
return n();
|
|
@@ -204,7 +212,7 @@ function A(t, n) {
|
|
|
204
212
|
w(e);
|
|
205
213
|
}
|
|
206
214
|
}
|
|
207
|
-
function
|
|
215
|
+
function K(t, n) {
|
|
208
216
|
const e = y;
|
|
209
217
|
M(t);
|
|
210
218
|
try {
|
|
@@ -214,37 +222,38 @@ function C(t, n) {
|
|
|
214
222
|
}
|
|
215
223
|
}
|
|
216
224
|
function w(t) {
|
|
217
|
-
|
|
225
|
+
p = t;
|
|
218
226
|
}
|
|
219
227
|
function M(t) {
|
|
220
228
|
y = t;
|
|
221
229
|
}
|
|
222
|
-
function K() {
|
|
223
|
-
return m;
|
|
224
|
-
}
|
|
225
230
|
function L() {
|
|
231
|
+
return p;
|
|
232
|
+
}
|
|
233
|
+
function Y() {
|
|
226
234
|
return y;
|
|
227
235
|
}
|
|
228
236
|
export {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
237
|
+
x as abbreviate,
|
|
238
|
+
G as clamp,
|
|
239
|
+
T as currency,
|
|
240
|
+
Y as defaultCurrency,
|
|
241
|
+
L as defaultLocale,
|
|
242
|
+
R as fileSize,
|
|
243
|
+
D as forHumans,
|
|
235
244
|
g as format,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
245
|
+
A as minutesToHuman,
|
|
246
|
+
O as ordinal,
|
|
247
|
+
H as pairs,
|
|
239
248
|
$ as parse,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
249
|
+
B as parseFloat,
|
|
250
|
+
E as parseInt,
|
|
251
|
+
I as percentage,
|
|
252
|
+
S as secondsToHuman,
|
|
244
253
|
b as summarize,
|
|
245
|
-
|
|
254
|
+
k as trim,
|
|
246
255
|
M as useCurrency,
|
|
247
256
|
w as useLocale,
|
|
248
|
-
|
|
249
|
-
|
|
257
|
+
K as withCurrency,
|
|
258
|
+
C as withLocale
|
|
250
259
|
};
|
package/dist/speller/index.d.ts
CHANGED
|
@@ -15,20 +15,14 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @requires {@link https://www.npmjs.com/package/to-words to-words package}
|
|
17
17
|
*
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
20
|
-
* spell(123); // "One Hundred Twenty Three"
|
|
21
|
-
* spell(123.45); // "One Hundred Twenty Three Point Forty Five"
|
|
22
|
-
* spell(5, null, 10); // "5" (5 <= 10, so formatted instead of spelled)
|
|
23
|
-
* spell(11, null, 10); // "Eleven" (11 > 10, so spelled out)
|
|
24
|
-
* spell(100, null, null, 50); // "100" (100 >= 50, so formatted instead of spelled)
|
|
25
|
-
* spell(49, null, null, 50); // "Forty Nine" (49 < 50, so spelled out)
|
|
18
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#spell
|
|
26
19
|
*/
|
|
27
20
|
export declare function spell(number: number | string, locale?: string | null, after?: number | null, until?: number | null): string;
|
|
28
21
|
/**
|
|
29
22
|
* Spell out the given number in the given locale in ordinal form.
|
|
30
23
|
*
|
|
31
|
-
*
|
|
24
|
+
* TODO - Implement true ordinal conversion for all supported locales.
|
|
25
|
+
* The to-words package doesn't have native ordinal support, so this
|
|
32
26
|
* function spells out the cardinal number. True ordinal conversion would
|
|
33
27
|
* require locale-specific suffix rules (e.g., "first", "second", "third").
|
|
34
28
|
*
|
|
@@ -38,11 +32,7 @@ export declare function spell(number: number | string, locale?: string | null, a
|
|
|
38
32
|
*
|
|
39
33
|
* @requires {@link https://www.npmjs.com/package/to-words to-words package}
|
|
40
34
|
*
|
|
41
|
-
* @
|
|
42
|
-
*
|
|
43
|
-
* spellOrdinal(1); // "One"
|
|
44
|
-
* spellOrdinal(2); // "Two"
|
|
45
|
-
* spellOrdinal(21); // "Twenty One"
|
|
35
|
+
* @see https://tolki.abe.dev/numbers/number-utilities-list.html#spellordinal
|
|
46
36
|
*/
|
|
47
37
|
export declare function spellOrdinal(value: number, locale?: string | null): string;
|
|
48
38
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/speller/index.ts"],"names":[],"mappings":"AA6EA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/speller/index.ts"],"names":[],"mappings":"AA6EA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CACjB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,KAAK,GAAE,MAAM,GAAG,IAAW,EAC3B,KAAK,GAAE,MAAM,GAAG,IAAW,GAC5B,MAAM,CAwBR;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAcR"}
|
package/dist/speller/index.js
CHANGED
|
@@ -43,34 +43,34 @@ const l = /* @__PURE__ */ new Set([
|
|
|
43
43
|
"ar-MA",
|
|
44
44
|
"ar-SA"
|
|
45
45
|
]);
|
|
46
|
-
function
|
|
46
|
+
function c(n) {
|
|
47
47
|
if (l.has(n))
|
|
48
48
|
return n;
|
|
49
|
-
const
|
|
50
|
-
for (const
|
|
51
|
-
if (
|
|
52
|
-
return
|
|
49
|
+
const e = n.split("-"), r = String(e[0]).toLowerCase();
|
|
50
|
+
for (const o of l)
|
|
51
|
+
if (o.toLowerCase().startsWith(r + "-"))
|
|
52
|
+
return o;
|
|
53
53
|
return "en-US";
|
|
54
54
|
}
|
|
55
|
-
function S(n,
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
return s(
|
|
59
|
-
if (
|
|
60
|
-
return s(
|
|
61
|
-
const
|
|
55
|
+
function S(n, e = null, r = null, o = null) {
|
|
56
|
+
const t = typeof n == "string" ? parseFloat(n) : n;
|
|
57
|
+
if (r !== null && t <= r)
|
|
58
|
+
return s(t, null, null, e);
|
|
59
|
+
if (o !== null && t >= o)
|
|
60
|
+
return s(t, null, null, e);
|
|
61
|
+
const f = c(e ?? "en-US");
|
|
62
62
|
return new u({
|
|
63
|
-
localeCode:
|
|
63
|
+
localeCode: f,
|
|
64
64
|
converterOptions: {
|
|
65
65
|
currency: !1,
|
|
66
66
|
ignoreDecimal: !1
|
|
67
67
|
}
|
|
68
|
-
}).convert(
|
|
68
|
+
}).convert(t);
|
|
69
69
|
}
|
|
70
|
-
function d(n,
|
|
71
|
-
const
|
|
70
|
+
function d(n, e = null) {
|
|
71
|
+
const r = c(e ?? "en-US");
|
|
72
72
|
return new u({
|
|
73
|
-
localeCode:
|
|
73
|
+
localeCode: r,
|
|
74
74
|
converterOptions: {
|
|
75
75
|
currency: !1,
|
|
76
76
|
ignoreDecimal: !0
|
package/package.json
CHANGED