@tolki/num 2.2.5 → 2.3.0

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/README.md CHANGED
@@ -28,7 +28,7 @@ pnpm add @tolki/num
28
28
 
29
29
  ### Importing the Package
30
30
 
31
- You can import individual functions for better tree-shaking or the entire package (not recommended).:
31
+ You can import individual functions or the whole package as a namespace. Both tree-shake the same way:
32
32
 
33
33
  Importing individual functions:
34
34
 
@@ -41,10 +41,10 @@ const formattedNumber = format(1234567.89); // '1,234,567.89'
41
41
  const parsedNumber = parse("1,234,567.89"); // 1234567.89
42
42
  ```
43
43
 
44
- Importing the entire package:
44
+ Importing the package as a namespace:
45
45
 
46
46
  ```typescript
47
- // Import the entire package (not recommended for tree-shaking)
47
+ // Import the package as a namespace
48
48
  import * as Num from "@tolki/num";
49
49
 
50
50
  // Example usage
@@ -52,9 +52,21 @@ const formattedNumber = Num.format(1234567.89); // '1,234,567.89'
52
52
  const parsedNumber = Num.parse("1,234,567.89"); // 1234567.89
53
53
  ```
54
54
 
55
- The reason that importing the entire package is not recommended is that it will include all functions in your bundle, even the ones you don't use, which can lead to larger bundle sizes. Importing individual functions allows your end files to only include the code that is actually used, resulting in smaller and more efficient bundles.
55
+ A namespace import that reads its members by name, such as `Num.format(...)`, shakes exactly like named imports in Rollup, Rolldown (Vite 8), esbuild, webpack and Rspack: your bundle holds only the members you use. Passing the namespace object around, or reading a computed member such as `Num[name]`, keeps every function. See [Bundling and Tree-Shaking](https://tolki.abe.dev/tree-shaking.html#namespace-imports).
56
56
 
57
- However, if you are working on a backend project where bundle size is not a concern, importing the entire package can be more convenient.
57
+ ### Bundling
58
+
59
+ A helper call whose result nothing uses drops out of your bundle in Rollup, Rolldown (Vite 8), webpack and Rspack, because the helpers are marked as free of side effects. This holds for a call at the top level of a module too.
60
+
61
+ The exception is Rspack, where an unused top-level call to `spell` or `spellOrdinal` drops the call but keeps the loader code it needs for the dynamic `import()` of the `to-words` locale files. Writing `/* @__PURE__ */` before the call drops everything:
62
+
63
+ ```typescript
64
+ export const words = /* @__PURE__ */ spell(5);
65
+ ```
66
+
67
+ esbuild doesn't follow the mark across files, so it needs the same comment on any helper call. [Bundling and Tree-Shaking](https://tolki.abe.dev/tree-shaking.html) covers every bundler.
68
+
69
+ `useLocale` and `useCurrency` set the defaults that every formatter reads, and `withLocale` and `withCurrency` run a callback around a temporary swap of them. `normalizeLocalesUsing` sets how every formatter converts a locale. A call to any of the five is always kept.
58
70
 
59
71
  ## Tolki Number Utilities List
60
72
 
@@ -62,10 +74,12 @@ However, if you are working on a backend project where bundle size is not a conc
62
74
 
63
75
  These are the number utilities that can be used independently as single functions.
64
76
 
65
- [abbreviate](#abbreviate) [clamp](#clamp) [currency](#currency) [defaultCurrency](#defaultcurrency) [defaultLocale](#defaultlocale) [fileSize](#filesize) [forHumans](#forhumans) [format](#format) [minutesToHuman](#minutestohuman) [ordinal](#ordinal) [pairs](#pairs) [parse](#parse) [parseFloat](#parsefloat) [parseInt](#parseint) [percentage](#percentage) [spell](#spell) [spellOrdinal](#spellordinal) [secondsToHuman](#secondstohuman) [trim](#trim) [useLocale](#uselocale) [withLocale](#withlocale) [useCurrency](#usecurrency) [withCurrency](#withcurrency)
77
+ [abbreviate](#abbreviate) [clamp](#clamp) [currency](#currency) [defaultCurrency](#defaultcurrency) [defaultLocale](#defaultlocale) [fileSize](#filesize) [forHumans](#forhumans) [format](#format) [minutesToHuman](#minutestohuman) [normalizeLocalesUsing](#normalizelocalesusing) [ordinal](#ordinal) [pairs](#pairs) [parse](#parse) [parseFloat](#parsefloat) [parseInt](#parseint) [percentage](#percentage) [spell](#spell) [spellOrdinal](#spellordinal) [secondsToHuman](#secondstohuman) [trim](#trim) [useLocale](#uselocale) [withLocale](#withlocale) [useCurrency](#usecurrency) [withCurrency](#withcurrency)
66
78
 
67
79
  ### Number Utilities Details
68
80
 
81
+ Every function that takes a locale reads Laravel's spelling (`pt_BR`) and BCP 47 (`pt-BR`) alike, as Laravel does through ICU. An empty locale means the runtime's own. A locale the runtime has no data for throws an `Error` with Laravel's message. [normalizeLocalesUsing](#normalizelocalesusing) changes how a locale is converted.
82
+
69
83
  #### abbreviate
70
84
 
71
85
  Convert the number to its human-readable equivalent.
@@ -222,6 +236,10 @@ const result3 = format(100000.123, null, 2);
222
236
  const result4 = format(100000, null, null, "de");
223
237
 
224
238
  // result4 is "100.000"
239
+
240
+ const result5 = format(1234.5, 2, null, "pt_BR");
241
+
242
+ // result5 is "1.234,50"
225
243
  ```
226
244
 
227
245
  #### minutesToHuman
@@ -240,10 +258,38 @@ const result2 = minutesToHuman(61, false);
240
258
  // result2 is "1 hour, 1 minute"
241
259
  ```
242
260
 
261
+ #### normalizeLocalesUsing
262
+
263
+ `normalizeLocalesUsing` permanently changes the module-wide conversion for every other example on this page, so it doesn't have a live playground here — trying it would silently change the output of every other widget below.
264
+
265
+ Set the callback that turns every locale into the tag `Intl` reads, or `null` to pass locales through unchanged. The default is `localeTag`, which accepts `pt_BR` and `pt-BR` alike. `@tolki/num` exports it, and `normalizeLocalesUsing(localeTag)` restores the default.
266
+
267
+ ```javascript
268
+ import { format, localeTag, normalizeLocalesUsing } from "@tolki/num";
269
+
270
+ const result = format(1234.5, 2, null, "pt_BR");
271
+
272
+ // result is "1.234,50"
273
+
274
+ // Map your own aliases, and keep the default for everything else.
275
+ normalizeLocalesUsing((locale) =>
276
+ locale === "br" ? "pt-BR" : localeTag(locale),
277
+ );
278
+
279
+ const result2 = format(1234.5, 2, null, "br");
280
+
281
+ // result2 is "1.234,50"
282
+
283
+ // Hand locales to Intl exactly as written. "pt_BR" now throws.
284
+ normalizeLocalesUsing(null);
285
+ ```
286
+
243
287
  #### ordinal
244
288
 
245
289
  Convert the given number to ordinal form.
246
290
 
291
+ It follows each locale's ordinal rules, as Laravel does, so German writes `1.` and Portuguese `1º`. A negative number is written with the minus sign (U+2212), not a hyphen, and a number of four or more digits is grouped.
292
+
247
293
  ```javascript
248
294
  import { ordinal } from "@tolki/num";
249
295
 
@@ -262,6 +308,26 @@ const result3 = ordinal(21);
262
308
  const result4 = ordinal(13);
263
309
 
264
310
  // result4 is "13th"
311
+
312
+ const result5 = ordinal(1, "pt_BR");
313
+
314
+ // result5 is "1º"
315
+
316
+ const result6 = ordinal(1, "de");
317
+
318
+ // result6 is "1."
319
+
320
+ const result7 = ordinal(21, "fr");
321
+
322
+ // result7 is "21e"
323
+
324
+ const result8 = ordinal(-1);
325
+
326
+ // result8 is "−1st"
327
+
328
+ const result9 = ordinal(1000);
329
+
330
+ // result9 is "1,000th"
265
331
  ```
266
332
 
267
333
  #### pairs
@@ -360,11 +426,11 @@ const result4 = percentage(10, 2, null, "de");
360
426
 
361
427
  `spell` and `spellOrdinal` return a `Promise<string>` and dynamically import a locale bundle on first use. The playground component above doesn't yet support async functions, so these two don't have a live example — see the code samples below instead.
362
428
 
363
- Spell out the given number in the given locale. Returns a `Promise<string>`.
429
+ Spell out the given number in the given locale. Returns a `Promise<string>`. When no locale is given, it uses the default locale (see [useLocale](#uselocale)).
364
430
 
365
431
  Uses the [`to-words`](https://www.npmjs.com/package/to-words) package. Locales are loaded dynamically on demand, so only the locale you request is bundled (~3KB gzip per locale instead of ~54KB for all 94 locales).
366
432
 
367
- Supports 94 locales via [`to-words`](https://www.npmjs.com/package/to-words). You can pass a full locale code (e.g., `"fr-FR"`, `"en-IN"`) or a bare language code (e.g., `"fr"`, `"en"`) which will resolve to a sensible default. Unsupported locales fall back to `"en-US"`.
433
+ Supports 94 locales via [`to-words`](https://www.npmjs.com/package/to-words). You can pass a full locale code (e.g., `"fr-FR"`, `"en-IN"`) or a bare language code (e.g., `"fr"`, `"en"`) which will resolve to a sensible default. A locale that the runtime has no data for throws an `Error` with Laravel's message, as Laravel does. A locale the runtime knows but `to-words` has no words for, such as Welsh (`cy`), is spelled in English.
368
434
 
369
435
  ```javascript
370
436
  import { spell } from "@tolki/num";
@@ -400,7 +466,7 @@ const result = await spell(15, null, null, 10);
400
466
 
401
467
  #### spellOrdinal
402
468
 
403
- Spell out the given number in the given locale in ordinal form. Returns a `Promise<string>`.
469
+ Spell out the given number in the given locale in ordinal form. Returns a `Promise<string>`. When no locale is given, it uses the default locale (see [useLocale](#uselocale)). A locale that the runtime has no data for throws an `Error`.
404
470
 
405
471
  Uses [`to-words`](https://www.npmjs.com/package/to-words) v5 native ordinal support. See the [spell](#spell) function for details on locale handling.
406
472
 
@@ -462,6 +528,10 @@ import { useLocale } from "@tolki/num";
462
528
  useLocale("fr");
463
529
 
464
530
  // The default locale is now set to French
531
+
532
+ useLocale("pt_BR");
533
+
534
+ // defaultLocale() returns "pt_BR", the spelling as given
465
535
  ```
466
536
 
467
537
  #### withLocale
@@ -476,6 +546,8 @@ withLocale("fr", () => {
476
546
  }); // "1 234,56"
477
547
  ```
478
548
 
549
+ `withLocale("pt_BR", …)` reads either spelling, and `defaultLocale()` inside the callback returns it as given.
550
+
479
551
  #### useCurrency
480
552
 
481
553
  Set the default currency. This should be used at the start of your application to set the desired currency globally.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './num';
2
- export * from './speller';
1
+ export * from './num.js';
2
+ export * from './speller/index.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { abbreviate as e, clamp as t, currency as n, defaultCurrency as r, defaultLocale as i, fileSize as a, forHumans as o, format as s, minutesToHuman as c, ordinal as l, pairs as u, parse as d, parseFloat as f, parseInt as p, percentage as m, secondsToHuman as h, summarize as g, trim as _, useCurrency as v, useLocale as y, withCurrency as b, withLocale as x } from "./num.js";
2
- import { spell as S, spellOrdinal as C } from "./speller/index.js";
3
- export { e as abbreviate, t as clamp, n as currency, r as defaultCurrency, i as defaultLocale, a as fileSize, o as forHumans, s as format, c as minutesToHuman, l as ordinal, u as pairs, d as parse, f as parseFloat, p as parseInt, m as percentage, h as secondsToHuman, S as spell, C as spellOrdinal, g as summarize, _ as trim, v as useCurrency, y as useLocale, b as withCurrency, x as withLocale };
1
+ import { abbreviate as e, clamp as t, currency as n, defaultCurrency as r, defaultLocale as i, fileSize as a, forHumans as o, format as s, localeTag as c, minutesToHuman as l, normalizeLocalesUsing as u, ordinal as d, pairs as f, parse as p, parseFloat as m, parseInt as h, percentage as g, secondsToHuman as _, summarize as v, trim as y, useCurrency as b, useLocale as x, withCurrency as S, withLocale as C } from "./num.js";
2
+ import { spell as w, spellOrdinal as T } from "./speller/index.js";
3
+ export { e as abbreviate, t as clamp, n as currency, r as defaultCurrency, i as defaultLocale, a as fileSize, o as forHumans, s as format, c as localeTag, l as minutesToHuman, u as normalizeLocalesUsing, d as ordinal, f as pairs, p as parse, m as parseFloat, h as parseInt, g as percentage, _ as secondsToHuman, w as spell, T as spellOrdinal, v as summarize, y as trim, b as useCurrency, x as useLocale, S as withCurrency, C as withLocale };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Turns a locale into the tag `Intl` reads.
3
+ */
4
+ export type LocaleNormalizer = (locale: string) => string;
5
+ /**
6
+ * Set the callback that turns every locale into the tag `Intl` reads, or null to pass locales through unchanged.
7
+ *
8
+ * @sideEffects state writes the module locale normalizer
9
+ *
10
+ * @param callback - Turns a locale into a BCP 47 tag.
11
+ */
12
+ export declare function setLocaleNormalizer(callback: LocaleNormalizer | null): void;
13
+ /**
14
+ * Resolve a locale to the canonical tag `Intl` formats with, as PHP's NumberFormatter reads it through ICU.
15
+ *
16
+ * @param locale - The locale as the caller wrote it.
17
+ * @returns The canonical tag, or the runtime's own locale when empty.
18
+ * @throws Error when ICU has no data for the locale, as PHP's NumberFormatter throws its ValueError
19
+ */
20
+ export declare function intlLocale(locale: string): string;
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/locale/index.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;AAO1D;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAE3E;AAED;;;;;;GAMG;AAEH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAqBjD"}
@@ -0,0 +1,19 @@
1
+ import { localeTag as e } from "@tolki/utils";
2
+ // src/locale/index.ts
3
+ var t = e;
4
+ function n(e) {
5
+ t = e;
6
+ }
7
+ /* @__NO_SIDE_EFFECTS__ */
8
+ function r(e) {
9
+ if (e === "") return new Intl.NumberFormat().resolvedOptions().locale;
10
+ let n = t === null ? e : t(e), r;
11
+ try {
12
+ r = Intl.NumberFormat.supportedLocalesOf(n)[0];
13
+ } catch {
14
+ r = void 0;
15
+ }
16
+ if (r === void 0) throw Error(`NumberFormatter::__construct(): Argument #1 ($locale) "${e}" is invalid`);
17
+ return r;
18
+ }
19
+ export { r as intlLocale, n as setLocaleNormalizer };
package/dist/num.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { localeTag } from '@tolki/utils';
1
2
  /**
2
3
  * Convert the number to its human-readable equivalent.
3
4
  *
@@ -17,6 +18,7 @@ export declare function abbreviate(number: number, precision?: number, maxPrecis
17
18
  * @param maxPrecision - The maximum number of decimal places to use.
18
19
  * @param locale - The locale to use for formatting.
19
20
  * @returns The formatted number string.
21
+ * @throws Error when ICU has no data for the locale, as PHP's NumberFormatter throws its ValueError
20
22
  *
21
23
  * @see https://tolki.abe.dev/numbers/number-utilities-list.html#format
22
24
  */
@@ -27,6 +29,7 @@ export declare function format(number: number, precision?: number | null, maxPre
27
29
  * @param value - The string to parse.
28
30
  * @param locale - The locale to use for parsing.
29
31
  * @returns The parsed number.
32
+ * @throws Error when ICU has no data for the locale, as PHP's NumberFormatter throws its ValueError
30
33
  *
31
34
  * @example
32
35
  *
@@ -39,6 +42,7 @@ export declare function parse(value: string, locale?: string | null): number;
39
42
  * @param value - The string to parse.
40
43
  * @param locale - The locale to use for parsing.
41
44
  * @returns The parsed integer or false if parsing fails.
45
+ * @throws Error when ICU has no data for the locale, as PHP's NumberFormatter throws its ValueError
42
46
  *
43
47
  * @see https://tolki.abe.dev/numbers/number-utilities-list.html#parseint
44
48
  */
@@ -49,6 +53,7 @@ export declare function parseInt(value: string, locale?: string | null): number
49
53
  * @param value - The string to parse.
50
54
  * @param locale - The locale to use for parsing.
51
55
  * @returns The parsed float or false if parsing fails.
56
+ * @throws Error when ICU has no data for the locale, as PHP's NumberFormatter throws its ValueError
52
57
  *
53
58
  * @see https://tolki.abe.dev/numbers/number-utilities-list.html#parsefloat
54
59
  */
@@ -57,8 +62,9 @@ export declare function parseFloat(value: string, locale?: string | null): numbe
57
62
  * Convert the given number to ordinal form.
58
63
  *
59
64
  * @param value - The number to convert.
60
- * @param locale - The locale to use for determining ordinal rules.
65
+ * @param locale - The locale whose ordinal rules to use.
61
66
  * @returns The number in ordinal form.
67
+ * @throws Error when ICU has no data for the locale, as PHP's NumberFormatter throws its ValueError
62
68
  *
63
69
  * @see https://tolki.abe.dev/numbers/number-utilities-list.html#ordinal
64
70
  */
@@ -71,6 +77,7 @@ export declare function ordinal(value: number, locale?: string | null): string;
71
77
  * @param maxPrecision - The maximum number of decimal places to use.
72
78
  * @param locale - The locale to use for formatting.
73
79
  * @returns The formatted percentage string.
80
+ * @throws Error when ICU has no data for the locale, as PHP's NumberFormatter throws its ValueError
74
81
  *
75
82
  * @see https://tolki.abe.dev/numbers/number-utilities-list.html#percentage
76
83
  */
@@ -83,6 +90,7 @@ export declare function percentage(number: number | string, precision?: number,
83
90
  * @param locale - The locale to use for formatting.
84
91
  * @param precision - The number of decimal places to use.
85
92
  * @returns The formatted currency string.
93
+ * @throws Error when ICU has no data for the locale, as PHP's NumberFormatter throws its ValueError
86
94
  *
87
95
  * @see https://tolki.abe.dev/numbers/number-utilities-list.html#currency
88
96
  */
@@ -180,6 +188,8 @@ export declare function secondsToHuman(seconds: number | string, round?: boolean
180
188
  /**
181
189
  * Execute the given callback using the given locale.
182
190
  *
191
+ * @sideEffects callback runs the caller callback around a temporary locale swap
192
+ *
183
193
  * @param locale - The locale to use.
184
194
  * @param callback - The callback to execute.
185
195
  * @returns The result of the callback.
@@ -190,6 +200,8 @@ export declare function withLocale<TReturn>(locale: string, callback: () => TRet
190
200
  /**
191
201
  * Execute the given callback using the given currency.
192
202
  *
203
+ * @sideEffects callback runs the caller callback around a temporary currency swap
204
+ *
193
205
  * @param currency - The currency to use.
194
206
  * @param callback - The callback to execute.
195
207
  * @returns The result of the callback.
@@ -200,6 +212,8 @@ export declare function withCurrency<TReturn>(currency: string, callback: () =>
200
212
  /**
201
213
  * Set the default locale.
202
214
  *
215
+ * @sideEffects state writes the module default locale
216
+ *
203
217
  * @param locale - The locale to set.
204
218
  * @returns void
205
219
  *
@@ -209,6 +223,8 @@ export declare function useLocale(locale: string): void;
209
223
  /**
210
224
  * Set the default currency.
211
225
  *
226
+ * @sideEffects state writes the module default currency
227
+ *
212
228
  * @param currency - The currency to set.
213
229
  * @returns void
214
230
  *
@@ -231,4 +247,15 @@ export declare function defaultLocale(): string;
231
247
  * @see https://tolki.abe.dev/numbers/number-utilities-list.html#defaultcurrency
232
248
  */
233
249
  export declare function defaultCurrency(): string;
250
+ /**
251
+ * Set the callback that turns every locale into the tag `Intl` reads, or null to pass locales through unchanged.
252
+ *
253
+ * @sideEffects state writes the module locale normalizer
254
+ *
255
+ * @param callback - Turns a locale into a BCP 47 tag; `localeTag` by default
256
+ * @returns void
257
+ *
258
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#normalizelocalesusing
259
+ */
260
+ export declare function normalizeLocalesUsing(callback: ((locale: string) => string) | null): void;
234
261
  //# 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":"AAYA;;;;;;;;;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,CAqBhB;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,IA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9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAElD;AAED;;;;;;GAMG;AAEH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;;;GAMG;AAEH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACjC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,IAAI,GAC9C,IAAI,CAEN"}
package/dist/num.js CHANGED
@@ -1,90 +1,81 @@
1
- import { InvalidArgumentException as e } from "@tolki/utils";
1
+ import { intlLocale as e, setLocaleNormalizer as t } from "./locale/index.js";
2
+ import { formatOrdinal as n } from "./ordinal/index.js";
3
+ import { InvalidArgumentException as r, localeTag as i } from "@tolki/utils";
2
4
  // src/num.ts
3
- var t = "en", n = "USD";
4
- function r(e, t = 0, n = null) {
5
- return f(e, t, n, !0);
6
- }
7
- function i(e, n = null, r = null, i = null) {
8
- i ??= t;
9
- let a = {
5
+ var a = "en", o = "USD";
6
+ /* @__NO_SIDE_EFFECTS__ */
7
+ function s(e, t = 0, n = null) {
8
+ return /* @__PURE__ */ g(e, t, n, !0);
9
+ }
10
+ /* @__NO_SIDE_EFFECTS__ */
11
+ function c(t, n = null, r = null, i = null) {
12
+ let o = /* @__PURE__ */ e(i ?? a), s = {
10
13
  style: "decimal",
11
14
  useGrouping: !0
12
15
  };
13
- r == null ? n != null && (a.minimumFractionDigits = n, a.maximumFractionDigits = n) : (a.maximumFractionDigits = r, a.minimumFractionDigits = 0);
14
- let o = new Intl.NumberFormat(i, a);
15
- return o.format(T(e, o.format));
16
- }
17
- function a(e, n = null) {
18
- n ??= t;
19
- let r = new Intl.NumberFormat(n).formatToParts(12345.6), i = /* @__PURE__ */ new Set(), a = ".";
20
- for (let e of r) e.type === "group" ? i.add(e.value) : e.type === "decimal" && (a = e.value);
16
+ r == null ? n != null && (s.minimumFractionDigits = n, s.maximumFractionDigits = n) : (s.maximumFractionDigits = r, s.minimumFractionDigits = 0);
17
+ let c = new Intl.NumberFormat(o, s);
18
+ return c.format(A(t, c.format));
19
+ }
20
+ /* @__NO_SIDE_EFFECTS__ */
21
+ function l(t, n = null) {
22
+ let r = /* @__PURE__ */ e(n ?? a), i = new Intl.NumberFormat(r).formatToParts(12345.6), o = /* @__PURE__ */ new Set(), s = ".";
23
+ for (let e of i) e.type === "group" ? o.add(e.value) : e.type === "decimal" && (s = e.value);
21
24
  for (let e of [
22
25
  "\xA0",
23
26
  " ",
24
27
  " "
25
- ]) i.add(e);
26
- let o = e;
27
- for (let e of i) {
28
+ ]) o.add(e);
29
+ let c = t;
30
+ for (let e of o) {
28
31
  let t = new RegExp(e.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"), "g");
29
- o = o.replace(t, "");
32
+ c = c.replace(t, "");
30
33
  }
31
- if (a !== ".") {
32
- let e = new RegExp(a.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"), "g"), t = o.lastIndexOf(a);
33
- t !== -1 && (o = o.slice(0, t).replace(e, "") + "." + o.slice(t + a.length));
34
+ if (s !== ".") {
35
+ let e = new RegExp(s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"), "g"), t = c.lastIndexOf(s);
36
+ t !== -1 && (c = c.slice(0, t).replace(e, "") + "." + c.slice(t + s.length));
34
37
  }
35
- return o = o.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(o);
38
+ return c = c.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(c);
36
39
  }
37
- function o(e, t = null) {
38
- let n = a(e, t);
40
+ /* @__NO_SIDE_EFFECTS__ */
41
+ function u(e, t = null) {
42
+ let n = /* @__PURE__ */ l(e, t);
39
43
  return Number.isNaN(n) ? !1 : n < 0 ? Math.ceil(n) : Math.floor(n);
40
44
  }
41
- function s(e, t = null) {
42
- return a(e, t);
45
+ /* @__NO_SIDE_EFFECTS__ */
46
+ function d(e, t = null) {
47
+ return /* @__PURE__ */ l(e, t);
43
48
  }
44
- function c(e, n = null) {
45
- let r = n ?? t;
46
- try {
47
- let t = new Intl.PluralRules(r, { type: "ordinal" }).select(e), n = String(r.split("-")[0]), i = {
48
- one: "st",
49
- two: "nd",
50
- few: "rd",
51
- other: "th"
52
- }, a = { en: i }[n] ?? i;
53
- return `${e}${a[t] ?? a.other}`;
54
- } catch {
55
- let t = Math.abs(e), n = t % 100;
56
- if (n >= 11 && n <= 13) return `${e}th`;
57
- switch (t % 10) {
58
- case 1: return `${e}st`;
59
- case 2: return `${e}nd`;
60
- case 3: return `${e}rd`;
61
- default: return `${e}th`;
62
- }
63
- }
49
+ /* @__NO_SIDE_EFFECTS__ */
50
+ function f(t, r = null) {
51
+ return /* @__PURE__ */ n(t, /* @__PURE__ */ e(r ?? a));
64
52
  }
65
- function l(e, n = 0, r = null, i = null) {
66
- let o = i ?? t, s = typeof e == "string" ? a(e, o) : e, c = {
53
+ /* @__NO_SIDE_EFFECTS__ */
54
+ function p(t, n = 0, r = null, i = null) {
55
+ let o = i ?? a, s = typeof t == "string" ? /* @__PURE__ */ l(t, o) : t, c = /* @__PURE__ */ e(o), u = {
67
56
  style: "percent",
68
57
  useGrouping: !0
69
58
  };
70
- r == null ? (c.minimumFractionDigits = n, c.maximumFractionDigits = n) : (c.maximumFractionDigits = r, c.minimumFractionDigits = 0);
71
- let l = new Intl.NumberFormat(o, c);
72
- return l.format(T(s / 100, l.format));
59
+ r == null ? (u.minimumFractionDigits = n, u.maximumFractionDigits = n) : (u.maximumFractionDigits = r, u.minimumFractionDigits = 0);
60
+ let d = new Intl.NumberFormat(c, u);
61
+ return d.format(A(s / 100, d.format));
73
62
  }
74
- function u(e, r = "", i = null, o = null) {
75
- let s = i ?? t, c = typeof e == "string" ? a(e, s) : e, l = {
63
+ /* @__NO_SIDE_EFFECTS__ */
64
+ function m(t, n = "", r = null, i = null) {
65
+ let s = r ?? a, c = typeof t == "string" ? /* @__PURE__ */ l(t, s) : t, u = /* @__PURE__ */ e(s), d = {
76
66
  style: "currency",
77
- currency: r && r.length ? r : n,
67
+ currency: n && n.length ? n : o,
78
68
  useGrouping: !0
79
69
  };
80
- o != null && (l.minimumFractionDigits = o, l.maximumFractionDigits = o);
81
- let u = new Intl.NumberFormat(s, l);
82
- return u.format(T(c, u.format));
70
+ i != null && (d.minimumFractionDigits = i, d.maximumFractionDigits = i);
71
+ let f = new Intl.NumberFormat(u, d);
72
+ return f.format(A(c, f.format));
83
73
  }
84
- function d(e, t = 0, n = null) {
74
+ /* @__NO_SIDE_EFFECTS__ */
75
+ function h(e, t = 0, n = null) {
85
76
  let r = typeof e == "string" ? Number(e) : e;
86
- if (!Number.isFinite(r)) return `${i(r, t, n)} B`;
87
- let a = [
77
+ if (!Number.isFinite(r)) return `${/* @__PURE__ */ c(r, t, n)} B`;
78
+ let i = [
88
79
  "B",
89
80
  "KB",
90
81
  "MB",
@@ -94,12 +85,13 @@ function d(e, t = 0, n = null) {
94
85
  "EB",
95
86
  "ZB",
96
87
  "YB"
97
- ], o = a.length, s = 0;
98
- for (; Math.abs(r) / 1024 > .9 && s < o - 1;) r /= 1024, s++;
99
- return `${i(r, t, n)} ${a[s]}`;
88
+ ], a = i.length, o = 0;
89
+ for (; Math.abs(r) / 1024 > .9 && o < a - 1;) r /= 1024, o++;
90
+ return `${/* @__PURE__ */ c(r, t, n)} ${i[o]}`;
100
91
  }
101
- function f(e, t = 0, n = null, r = !1) {
102
- return p(e, t, n, r ? {} : {
92
+ /* @__NO_SIDE_EFFECTS__ */
93
+ function g(e, t = 0, n = null, r = !1) {
94
+ return /* @__PURE__ */ _(e, t, n, r ? {} : {
103
95
  3: " thousand",
104
96
  6: " million",
105
97
  9: " billion",
@@ -107,53 +99,59 @@ function f(e, t = 0, n = null, r = !1) {
107
99
  15: " quadrillion"
108
100
  });
109
101
  }
110
- function p(e, t = 0, n = null, r = {}) {
111
- if (!Number.isFinite(e)) return i(e, t, n);
102
+ /* @__NO_SIDE_EFFECTS__ */
103
+ function _(e, t = 0, n = null, r = {}) {
104
+ if (!Number.isFinite(e)) return /* @__PURE__ */ c(e, t, n);
112
105
  if (Object.keys(r).length === 0 && (r = {
113
106
  3: "K",
114
107
  6: "M",
115
108
  9: "B",
116
109
  12: "T",
117
110
  15: "Q"
118
- }), Number(e) === 0) return t > 0 ? i(0, t, n) : "0";
111
+ }), Number(e) === 0) return t > 0 ? /* @__PURE__ */ c(0, t, n) : "0";
119
112
  if (e < 0) {
120
- let i = p(Math.abs(e), t, n, r);
121
- return i === p(0, t, n, r) ? i : `-${i}`;
113
+ let i = /* @__PURE__ */ _(Math.abs(e), t, n, r);
114
+ return i === /* @__PURE__ */ _(0, t, n, r) ? i : `-${i}`;
122
115
  }
123
116
  if (e >= 0x38d7ea4c68000) {
124
117
  let i = Object.keys(r).map((e) => Number(e)).filter((e) => !Number.isNaN(e)).sort((e, t) => e - t), a = i[i.length - 1], o = r[a];
125
- return `${p(e / 0x38d7ea4c68000, t, n, r)}${o}`.trim();
118
+ return `${/* @__PURE__ */ _(e / 0x38d7ea4c68000, t, n, r)}${o}`.trim();
126
119
  }
127
- let o = Math.floor(Math.log10(e)), s = Math.max(0, o - o % 3), c = e / 10 ** s, l;
128
- if (l = n == null ? t > 0 ? i(c, t, null) : s === 3 && c < 10 && Math.abs(e) % 10 == 0 ? i(c, null, 1) : i(c, 0, null) : i(c, null, n), a(l) >= 1e3 && r[s + 3] !== void 0) {
129
- s += 3;
130
- let e = c / 1e3;
131
- l = n == null ? t > 0 ? i(e, t, null) : i(e, 0, null) : i(e, null, n);
120
+ let i = Math.floor(Math.log10(e)), a = Math.max(0, i - i % 3), o = e / 10 ** a, s;
121
+ if (s = n == null ? t > 0 ? /* @__PURE__ */ c(o, t, null) : a === 3 && o < 10 && Math.abs(e) % 10 == 0 ? /* @__PURE__ */ c(o, null, 1) : /* @__PURE__ */ c(o, 0, null) : /* @__PURE__ */ c(o, null, n), /* @__PURE__ */ l(s) >= 1e3 && r[a + 3] !== void 0) {
122
+ a += 3;
123
+ let e = o / 1e3;
124
+ s = n == null ? t > 0 ? /* @__PURE__ */ c(e, t, null) : /* @__PURE__ */ c(e, 0, null) : /* @__PURE__ */ c(e, null, n);
132
125
  }
133
- let u = r[s] ?? "";
134
- return `${l}${u}`.trim();
126
+ let u = r[a] ?? "";
127
+ return `${s}${u}`.trim();
135
128
  }
136
- function m(e, t, n) {
129
+ /* @__NO_SIDE_EFFECTS__ */
130
+ function v(e, t, n) {
137
131
  return Math.min(Math.max(e, t), n);
138
132
  }
139
- function h(t, n, r = 0, i = 1) {
140
- if (n === 0) throw new e("The $by argument must not be zero.");
141
- n = Math.abs(n);
142
- let a = [], o = r;
143
- for (; o < t; o += n) {
144
- let e = o + n - i;
145
- e > t && (e = t), a.push([o, e]);
133
+ /* @__NO_SIDE_EFFECTS__ */
134
+ function y(e, t, n = 0, i = 1) {
135
+ if (t === 0) throw new r("The $by argument must not be zero.");
136
+ t = Math.abs(t);
137
+ let a = [], o = n;
138
+ for (; o < e; o += t) {
139
+ let n = o + t - i;
140
+ n > e && (n = e), a.push([o, n]);
146
141
  }
147
142
  let s = a.at(-1);
148
- return s !== void 0 && o === t && s[1] < t && a.push([o, t]), a;
143
+ return s !== void 0 && o === e && s[1] < e && a.push([o, e]), a;
149
144
  }
150
- function g(e) {
145
+ /* @__NO_SIDE_EFFECTS__ */
146
+ function b(e) {
151
147
  return isFinite(e) ? JSON.parse(JSON.stringify(e)) : e;
152
148
  }
153
- function _(e, t = !0) {
154
- return v(Number(e) * 60, t);
149
+ /* @__NO_SIDE_EFFECTS__ */
150
+ function x(e, t = !0) {
151
+ return /* @__PURE__ */ S(Number(e) * 60, t);
155
152
  }
156
- function v(e, t = !0) {
153
+ /* @__NO_SIDE_EFFECTS__ */
154
+ function S(e, t = !0) {
157
155
  let n = Number(e);
158
156
  if ((!Number.isFinite(n) || n < 0) && (n = 0), n === 0) return "0 seconds";
159
157
  let r = 3600, i = 24 * r, a = 7 * i, o = 4 * a, s = [
@@ -179,37 +177,42 @@ function v(e, t = !0) {
179
177
  }
180
178
  return l.join(", ");
181
179
  }
182
- function y(e, n) {
183
- let r = t;
184
- x(e);
180
+ function C(e, t) {
181
+ let n = a;
182
+ T(e);
185
183
  try {
186
- return n();
184
+ return t();
187
185
  } finally {
188
- x(r);
186
+ T(n);
189
187
  }
190
188
  }
191
- function b(e, t) {
192
- let r = n;
193
- S(e);
189
+ function w(e, t) {
190
+ let n = o;
191
+ E(e);
194
192
  try {
195
193
  return t();
196
194
  } finally {
197
- S(r);
195
+ E(n);
198
196
  }
199
197
  }
200
- function x(e) {
201
- t = e;
198
+ function T(e) {
199
+ a = e;
200
+ }
201
+ function E(e) {
202
+ o = e;
202
203
  }
203
- function S(e) {
204
- n = e;
204
+ /* @__NO_SIDE_EFFECTS__ */
205
+ function D() {
206
+ return a;
205
207
  }
206
- function C() {
207
- return t;
208
+ /* @__NO_SIDE_EFFECTS__ */
209
+ function O() {
210
+ return o;
208
211
  }
209
- function w() {
210
- return n;
212
+ function k(e) {
213
+ t(e);
211
214
  }
212
- function T(e, t) {
215
+ function A(e, t) {
213
216
  return e === 0 || e < 0 && t(Math.abs(e)) === t(0) ? 0 : e;
214
217
  }
215
- export { r as abbreviate, m as clamp, u as currency, w as defaultCurrency, C as defaultLocale, d as fileSize, f as forHumans, i as format, _ as minutesToHuman, c as ordinal, h as pairs, a as parse, s as parseFloat, o as parseInt, l as percentage, v as secondsToHuman, p as summarize, g as trim, S as useCurrency, x as useLocale, b as withCurrency, y as withLocale };
218
+ export { s as abbreviate, v as clamp, m as currency, O as defaultCurrency, D as defaultLocale, h as fileSize, g as forHumans, c as format, i as localeTag, x as minutesToHuman, k as normalizeLocalesUsing, f as ordinal, y as pairs, l as parse, d as parseFloat, u as parseInt, p as percentage, S as secondsToHuman, _ as summarize, b as trim, E as useCurrency, T as useLocale, w as withCurrency, C as withLocale };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Convert a number to ordinal form the way PHP's `NumberFormatter::ORDINAL` does for a locale.
3
+ *
4
+ * @param value - The number to convert.
5
+ * @param tag - A canonical BCP 47 tag the runtime supports.
6
+ * @returns The ordinal, such as `1st`, `1º` or `第1`.
7
+ */
8
+ export declare function formatOrdinal(value: number, tag: string): string;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ordinal/index.ts"],"names":[],"mappings":"AAqBA;;;;;;GAMG;AAEH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAQhE"}
@@ -0,0 +1,56 @@
1
+ import { INDICATORS as e, ordinalRule as t } from "./rules.js";
2
+ import { isInteger as n, isString as r, isUndefined as i } from "@tolki/utils";
3
+ // src/ordinal/index.ts
4
+ var a = "−", o = 2147483647;
5
+ /* @__NO_SIDE_EFFECTS__ */
6
+ function s(e, n) {
7
+ let r = /* @__PURE__ */ t(n);
8
+ return c(r.indirect === !0 && Object.is(e, -0) ? 0 : e, n, r);
9
+ }
10
+ function c(e, t, r) {
11
+ if (Number.isNaN(e) || e === Infinity) return new Intl.NumberFormat(t).format(e);
12
+ if (e === -Infinity) {
13
+ let e = new Intl.NumberFormat(t).format(Infinity);
14
+ return r.indirect === !0 ? e : `${r.negative ?? a}${e}`;
15
+ }
16
+ if (e < 0) return i(r.negative) ? `${a}${c(-e, t, r)}` : `${r.negative}${p(-e, t, r, 0)}`;
17
+ if (r.fraction === !0 && !n(e)) return p(e, t, r, 1);
18
+ let o = r.whole?.[h(e)];
19
+ return i(o) ? `${r.prefix ?? ""}${p(e, t, r, 0)}${l(r.suffix, e, t)}` : o;
20
+ }
21
+ function l(e, t, n) {
22
+ return i(e) ? "" : r(e) ? e : "plural" in e ? e.plural[d(t, n)] ?? e.plural.other : u(e.indicator, t);
23
+ }
24
+ function u(t, n) {
25
+ let i = e[t], a = n;
26
+ for (;;) {
27
+ let t = h(a), [n, o] = i.findLast(([e]) => e <= t);
28
+ if (r(o)) return o;
29
+ let s = 10 ** Math.floor(Math.log10(n)), c = e[o.remainder];
30
+ a = a < s && c === i ? t % s : a % s, i = c;
31
+ }
32
+ }
33
+ function d(e, t) {
34
+ return Intl.PluralRules.supportedLocalesOf(t).length === 0 ? "other" : new Intl.PluralRules(t, { type: "ordinal" }).select(f(e));
35
+ }
36
+ function f(e) {
37
+ return e < 1 ? h(e) : n(e) ? e | 0 : Math.min(Math.trunc(e), o);
38
+ }
39
+ function p(e, t, n, r) {
40
+ let i = new Intl.NumberFormat(t, {
41
+ useGrouping: !1,
42
+ minimumFractionDigits: r,
43
+ maximumFractionDigits: r,
44
+ roundingMode: "halfEven"
45
+ }).formatToParts(e), a = new Intl.NumberFormat(t, { useGrouping: "always" }).formatToParts(1234567).find((e) => e.type === "group").value;
46
+ return i.map((e) => e.type === "integer" ? m(e.value, a, n.indian === !0) : e.value).join("");
47
+ }
48
+ function m(e, t, n) {
49
+ let r = Array.from(e), i = [], a = 3;
50
+ for (; r.length > a;) i.unshift(r.splice(-a).join("")), a = n ? 2 : 3;
51
+ return i.unshift(r.join("")), i.join(t);
52
+ }
53
+ function h(e) {
54
+ return Math.floor(e + .5);
55
+ }
56
+ export { s as formatOrdinal };
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The text an ordinal rule writes beside the number: a string as is, or picked by its plural category or its value.
3
+ */
4
+ export type OrdinalText = string | {
5
+ readonly plural: OrdinalPlural;
6
+ } | {
7
+ readonly indicator: IndicatorName;
8
+ };
9
+ /**
10
+ * The text for each ordinal plural category, as ICU's `$(ordinal,…)$` holds it.
11
+ */
12
+ export type OrdinalPlural = Readonly<Partial<Record<Intl.LDMLPluralRule, string>>> & {
13
+ readonly other: string;
14
+ };
15
+ /**
16
+ * The name of an RBNF indicator rule set.
17
+ */
18
+ export type IndicatorName = "af" | "bg" | "bg-larger" | "ee";
19
+ /**
20
+ * One rule of an indicator set: from `base` up, its text, or the set that reads the remainder by its power of ten.
21
+ */
22
+ export type IndicatorRule = readonly [
23
+ base: number,
24
+ text: string | {
25
+ readonly remainder: IndicatorName;
26
+ }
27
+ ];
28
+ /**
29
+ * ICU's default `%digits-ordinal` rule set for a locale, as the parts this port writes.
30
+ */
31
+ export interface OrdinalRule {
32
+ /** The text before the number. */
33
+ readonly prefix?: string;
34
+ /** The text after the number. */
35
+ readonly suffix?: OrdinalText;
36
+ /** The whole ordinal for a value that rounds to the key, as `ms` writes `No. 1`. */
37
+ readonly whole?: Readonly<Record<number, string>>;
38
+ /** Group digits in twos above the thousands, as `#,##,##0` does. */
39
+ readonly indian?: true;
40
+ /** Write a fraction with one decimal and no ordinal text, as an `x.x` rule does. */
41
+ readonly fraction?: true;
42
+ /** The text before a negative number written without its ordinal text; without it, U+2212 precedes the ordinal. */
43
+ readonly negative?: string;
44
+ /** The default rule hands the value to another rule set, which drops the sign of `-0` and `-INF`. */
45
+ readonly indirect?: true;
46
+ }
47
+ /**
48
+ * The indicator rule sets, each sorted by base. `bg` writes its `-` here, where ICU writes it in the rule.
49
+ */
50
+ export declare const INDICATORS: Readonly<Record<IndicatorName, readonly IndicatorRule[]>>;
51
+ /**
52
+ * The rule set of ICU's default locale, en, which a locale without its own rule set falls back to.
53
+ */
54
+ export declare const ROOT_ORDINAL: OrdinalRule;
55
+ /**
56
+ * The rule set that writes a period after the number.
57
+ */
58
+ export declare const DOT_ORDINAL: OrdinalRule;
59
+ /**
60
+ * The rule set of Spanish outside Spain, which writes `º.` where Spain writes `.º`.
61
+ */
62
+ export declare const LATIN_AMERICAN_SPANISH_ORDINAL: OrdinalRule;
63
+ /**
64
+ * ICU's default ordinal rule sets but en's (`ROOT_ORDINAL`), the dot and Latin American Spanish, keyed like `DOT_KEYS`.
65
+ */
66
+ export declare const ORDINAL_RULES: Readonly<Record<string, OrdinalRule>>;
67
+ /**
68
+ * The languages, script variants and scriptless region variants whose rule set writes a period after the number.
69
+ */
70
+ export declare const DOT_KEYS: readonly string[];
71
+ /**
72
+ * The regions whose Spanish uses the Latin American rule set.
73
+ */
74
+ export declare const LATIN_AMERICAN_REGIONS: readonly string[];
75
+ /**
76
+ * Find the ordinal rule set ICU formats a locale with, from the most specific part of its tag this table lists.
77
+ *
78
+ * @param tag - A canonical BCP 47 tag.
79
+ * @returns The listed rule set, or en's when the table lists no part of the tag.
80
+ */
81
+ export declare function ordinalRule(tag: string): OrdinalRule;
82
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/ordinal/rules.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,WAAW,GACjB,MAAM,GACN;IAAE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;CAAE,GAClC;IAAE,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAA;CAAE,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,CAChC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAC/C,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS;IACjC,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAA;KAAE;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,kCAAkC;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,iCAAiC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,oFAAoF;IACpF,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,oEAAoE;IACpE,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC;IACvB,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC;IACzB,mHAAmH;IACnH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,qGAAqG;IACrG,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAC7B,MAAM,CAAC,aAAa,EAAE,SAAS,aAAa,EAAE,CAAC,CA6BlD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,WAE1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,WAA6B,CAAC;AAYxD;;GAEG;AACH,eAAO,MAAM,8BAA8B,EAAE,WAG5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAkE/D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,MAAM,EAqGrC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAyBnD,CAAC;AAEF;;;;;GAKG;AAEH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CA6BpD"}
@@ -0,0 +1,203 @@
1
+ import { isUndefined as e } from "@tolki/utils";
2
+ // src/ordinal/rules.ts
3
+ var t = {
4
+ af: [
5
+ [0, "ste"],
6
+ [1, "ste"],
7
+ [2, "de"],
8
+ [20, "ste"],
9
+ [100, { remainder: "af" }]
10
+ ],
11
+ bg: [
12
+ [0, "-и"],
13
+ [1, "-ви"],
14
+ [2, "-ри"],
15
+ [3, "-ти"],
16
+ [5, "-и"],
17
+ [20, { remainder: "bg" }],
18
+ [100, { remainder: "bg-larger" }],
19
+ [1e3, { remainder: "bg" }]
20
+ ],
21
+ "bg-larger": [
22
+ [0, "-тен"],
23
+ [1, { remainder: "bg" }],
24
+ [100, { remainder: "bg-larger" }]
25
+ ],
26
+ ee: [
27
+ [0, " lia"],
28
+ [1, " tɔ"],
29
+ [2, " lia"]
30
+ ]
31
+ }, n = { suffix: { plural: {
32
+ one: "st",
33
+ two: "nd",
34
+ few: "rd",
35
+ other: "th"
36
+ } } }, r = { suffix: "." }, i = {}, a = {
37
+ prefix: "第",
38
+ negative: "第−"
39
+ }, o = {
40
+ suffix: "º.",
41
+ indirect: !0
42
+ }, s = {
43
+ af: { suffix: { indicator: "af" } },
44
+ am: { suffix: "ኛ" },
45
+ ar: i,
46
+ az: { suffix: "'inci" },
47
+ bg: {
48
+ suffix: { indicator: "bg" },
49
+ indirect: !0
50
+ },
51
+ ca: {
52
+ suffix: { plural: {
53
+ one: "r",
54
+ two: "n",
55
+ few: "t",
56
+ other: "è"
57
+ } },
58
+ indirect: !0
59
+ },
60
+ ee: { suffix: { indicator: "ee" } },
61
+ el: i,
62
+ es: {
63
+ suffix: ".º",
64
+ indirect: !0
65
+ },
66
+ fil: { prefix: "ika" },
67
+ fr: {
68
+ suffix: { plural: {
69
+ one: "er",
70
+ other: "e"
71
+ } },
72
+ indirect: !0
73
+ },
74
+ ga: { suffix: "ú" },
75
+ gu: {
76
+ suffix: { plural: {
77
+ one: "લા",
78
+ two: "જા",
79
+ few: "થા",
80
+ many: "્ઠા",
81
+ other: "મા"
82
+ } },
83
+ indian: !0,
84
+ fraction: !0,
85
+ indirect: !0
86
+ },
87
+ he: i,
88
+ hi: {
89
+ suffix: { plural: {
90
+ one: "ला",
91
+ two: "रा",
92
+ few: "था",
93
+ many: "ठा",
94
+ other: "वाँ"
95
+ } },
96
+ indian: !0,
97
+ fraction: !0,
98
+ indirect: !0
99
+ },
100
+ "hi-Latn": n,
101
+ id: {
102
+ prefix: "ke-",
103
+ negative: "−ke-"
104
+ },
105
+ it: {
106
+ suffix: "º",
107
+ indirect: !0
108
+ },
109
+ ja: a,
110
+ kk: { suffix: { plural: {
111
+ many: "-шы",
112
+ other: "-ші"
113
+ } } },
114
+ km: { prefix: "ទី" },
115
+ ko: { suffix: "번째" },
116
+ ky: { suffix: "'инчи" },
117
+ lo: {
118
+ prefix: "ที่​",
119
+ negative: "ที่−"
120
+ },
121
+ ms: {
122
+ prefix: "ke-",
123
+ whole: { 1: "No. 1" },
124
+ negative: "−ke-"
125
+ },
126
+ nl: { suffix: "e" },
127
+ pt: {
128
+ suffix: "º",
129
+ indirect: !0
130
+ },
131
+ ro: { suffix: "a" },
132
+ ru: {},
133
+ sv: {
134
+ suffix: { plural: {
135
+ one: ":a",
136
+ other: ":e"
137
+ } },
138
+ indirect: !0
139
+ },
140
+ ta: {
141
+ suffix: ".",
142
+ indian: !0
143
+ },
144
+ th: {
145
+ prefix: "ที่\xA0",
146
+ negative: "ที่\xA0−"
147
+ },
148
+ uk: {
149
+ suffix: { plural: {
150
+ few: "-ій",
151
+ other: "-ий"
152
+ } },
153
+ indirect: !0
154
+ },
155
+ vi: { prefix: "thứ " },
156
+ yue: a,
157
+ zh: a
158
+ }, c = /* @__PURE__ */ "ak.az-Arab.az-Cyrl.az-IQ.az-IR.az-RU.be.bm-Nkoo.bs.ccp.chr.cs.cy.da.de.dje-Arab.dyo-Arab.en-Dsrt.en-Shaw.eo.et.fa.ff.fi.fo.ha-Arab.ha-CM.ha-SD.hr.hu.hy.is.ka.kk-AF.kk-Arab.kk-CN.kk-IR.kk-MN.kl.kok-Latn.ks-Deva.ku-Arab.ku-IQ.ku-IR.ku-LB.kxv-Deva.kxv-Orya.kxv-Telu.ky-Arab.ky-CN.ky-Latn.lb.lrc.lt.lv.mk.ml-Arab.mn-CN.mn-Mong.mni-Mtei.ms-Arab.ms-CC.mt.my.nb.ne.nn.no.pa-Arab.pa-PK.pl.qu.sat-Deva.sd-Deva.sd-IN.sd-Khoj.sd-Sind.se.shi-Latn.sk.sl.so-Arab.sq.sr.su.sw.tg-Arab.tg-PK.tr.ug-Cyrl.ug-KZ.ug-MN.uz-AF.uz-Arab.uz-CN.uz-Cyrl.vai-Latn.vec.wo-Arab.yo-Arab".split("."), l = [
159
+ "419",
160
+ "AR",
161
+ "BO",
162
+ "BR",
163
+ "BZ",
164
+ "CL",
165
+ "CO",
166
+ "CR",
167
+ "CU",
168
+ "DO",
169
+ "EC",
170
+ "GT",
171
+ "HN",
172
+ "JP",
173
+ "MX",
174
+ "NI",
175
+ "PA",
176
+ "PE",
177
+ "PR",
178
+ "PY",
179
+ "SV",
180
+ "US",
181
+ "UY",
182
+ "VE"
183
+ ];
184
+ /* @__NO_SIDE_EFFECTS__ */
185
+ function u(t) {
186
+ let { language: i, script: a, region: u } = new Intl.Locale(t);
187
+ if (i === "es" && !e(u) && l.includes(u)) return o;
188
+ let d = (e(a) ? [[i, u], [i]] : [
189
+ [
190
+ i,
191
+ a,
192
+ u
193
+ ],
194
+ [i, a],
195
+ [i]
196
+ ]).map((t) => t.filter((t) => !e(t)).join("-"));
197
+ for (let e of d) {
198
+ if (Object.hasOwn(s, e)) return s[e];
199
+ if (c.includes(e)) return r;
200
+ }
201
+ return n;
202
+ }
203
+ export { c as DOT_KEYS, r as DOT_ORDINAL, t as INDICATORS, l as LATIN_AMERICAN_REGIONS, o as LATIN_AMERICAN_SPANISH_ORDINAL, s as ORDINAL_RULES, n as ROOT_ORDINAL, u as ordinalRule };
@@ -8,10 +8,11 @@
8
8
  * the number will be returned as a formatted string instead of spelled out.
9
9
  *
10
10
  * @param number - The number to spell out.
11
- * @param locale - The locale to use for spelling. Defaults to "en-US".
11
+ * @param locale - The locale to use for spelling. Defaults to the default locale.
12
12
  * @param after - If provided, numbers <= this value will be formatted instead of spelled.
13
13
  * @param until - If provided, numbers >= this value will be formatted instead of spelled.
14
14
  * @returns The number spelled out as words, or formatted as a string.
15
+ * @throws Error when ICU has no data for the locale, as PHP's NumberFormatter throws its ValueError
15
16
  *
16
17
  * @requires {@link https://www.npmjs.com/package/to-words to-words package}
17
18
  *
@@ -22,8 +23,9 @@ export declare function spell(number: number | string, locale?: string | null, a
22
23
  * Spell out the given number in the given locale in ordinal form.
23
24
  *
24
25
  * @param value - The number to spell out in ordinal form.
25
- * @param locale - The locale to use for spelling. Defaults to "en-US".
26
+ * @param locale - The locale to use for spelling. Defaults to the default locale.
26
27
  * @returns The number spelled out as ordinal words (e.g., "First", "Twenty First").
28
+ * @throws Error when ICU has no data for the locale, as PHP's NumberFormatter throws its ValueError
27
29
  *
28
30
  * @requires {@link https://www.npmjs.com/package/to-words to-words package}
29
31
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/speller/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,KAAK,CACvB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,KAAK,GAAE,MAAM,GAAG,IAAW,EAC3B,KAAK,GAAE,MAAM,GAAG,IAAW,GAC5B,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAC9B,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,OAAO,CAAC,MAAM,CAAC,CAKjB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/speller/index.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,wBAAsB,KAAK,CACvB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,KAAK,GAAE,MAAM,GAAG,IAAW,EAC3B,KAAK,GAAE,MAAM,GAAG,IAAW,GAC5B,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED;;;;;;;;;;;GAWG;AAEH,wBAAsB,YAAY,CAC9B,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,OAAO,CAAC,MAAM,CAAC,CAKjB"}
@@ -1,17 +1,20 @@
1
- import { format as e } from "../num.js";
2
- import { isString as t, toLower as n } from "@tolki/utils";
1
+ import { intlLocale as e } from "../locale/index.js";
2
+ import { defaultLocale as t, format as n } from "../num.js";
3
+ import { isString as r, toLower as i } from "@tolki/utils";
3
4
  // src/speller/index.ts
4
- async function r(r, i = null, o = null, s = null) {
5
- let c = t(r) ? parseFloat(r) : r;
6
- if (o !== null && c <= o || s !== null && c >= s) return e(c, null, null, i);
7
- let l = await a(i ?? "en-US");
8
- return n(l.convert(c));
5
+ /* @__NO_SIDE_EFFECTS__ */
6
+ async function a(a, o = null, c = null, l = null) {
7
+ let u = r(a) ? parseFloat(a) : a;
8
+ if (c !== null && u <= c || l !== null && u >= l) return /* @__PURE__ */ n(u, null, null, o);
9
+ let d = await s(/* @__PURE__ */ e(o ?? /* @__PURE__ */ t()));
10
+ return i(d.convert(u));
9
11
  }
10
- async function i(e, r = null) {
11
- let i = t(e) ? parseFloat(e) : e, o = await a(r ?? "en-US");
12
- return n(o.toOrdinal(Math.floor(i)));
12
+ /* @__NO_SIDE_EFFECTS__ */
13
+ async function o(n, a = null) {
14
+ let o = r(n) ? parseFloat(n) : n, c = await s(/* @__PURE__ */ e(a ?? /* @__PURE__ */ t()));
15
+ return i(c.toOrdinal(Math.floor(o)));
13
16
  }
14
- async function a(e) {
17
+ async function s(e) {
15
18
  try {
16
19
  return new (await (import(`to-words/${e}`))).ToWords();
17
20
  } catch {}
@@ -82,4 +85,4 @@ async function a(e) {
82
85
  } catch {}
83
86
  return new (await (import("to-words/en-US"))).ToWords();
84
87
  }
85
- export { r as spell, i as spellOrdinal };
88
+ export { a as spell, o as spellOrdinal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/num",
3
- "version": "2.2.5",
3
+ "version": "2.3.0",
4
4
  "description": "Utilities for working with numbers similar to Laravel's Num class facade.",
5
5
  "author": "Abraham Arango <https://github.com/abetwothree>",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "sideEffects": false,
27
27
  "dependencies": {
28
28
  "to-words": "^5.0.0",
29
- "@tolki/utils": "^1.6.3"
29
+ "@tolki/utils": "^1.7.0"
30
30
  },
31
31
  "files": [
32
32
  "dist"
@@ -44,23 +44,19 @@
44
44
  "types": "dist/index.d.ts",
45
45
  "exports": {
46
46
  ".": {
47
- "import": "./dist/index.js",
48
- "require": "./dist/index.js",
49
- "types": "./dist/index.d.ts"
47
+ "types": "./dist/index.d.ts",
48
+ "default": "./dist/index.js"
50
49
  },
51
50
  "./*": {
52
- "import": "./dist/*",
53
- "require": "./dist/*",
54
- "types": "./dist/*"
51
+ "types": "./dist/*",
52
+ "default": "./dist/*"
55
53
  },
56
54
  "./num": {
57
55
  "types": "./dist/num.d.ts",
58
- "import": "./dist/num.js",
59
56
  "default": "./dist/num.js"
60
57
  },
61
58
  "./speller": {
62
59
  "types": "./dist/speller/index.d.ts",
63
- "import": "./dist/speller/index.js",
64
60
  "default": "./dist/speller/index.js"
65
61
  }
66
62
  }