@tolki/num 2.2.3 → 2.2.5

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
@@ -278,6 +278,10 @@ const result = pairs(25, 10);
278
278
  const result2 = pairs(25, 10, 0, 0);
279
279
 
280
280
  // result2 is [[0, 10], [10, 20], [20, 25]]
281
+
282
+ const result3 = pairs(20, 10);
283
+
284
+ // result3 is [[0, 9], [10, 19], [20, 20]]
281
285
  ```
282
286
 
283
287
  #### parse
package/dist/index.js CHANGED
@@ -1,28 +1,3 @@
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
- export {
4
- a as abbreviate,
5
- l as clamp,
6
- o as currency,
7
- n as defaultCurrency,
8
- s as defaultLocale,
9
- t as fileSize,
10
- u as forHumans,
11
- c as format,
12
- i as minutesToHuman,
13
- m as ordinal,
14
- p as pairs,
15
- f as parse,
16
- d as parseFloat,
17
- y as parseInt,
18
- C as percentage,
19
- H as secondsToHuman,
20
- g as spell,
21
- v as spellOrdinal,
22
- L as summarize,
23
- b as trim,
24
- h as useCurrency,
25
- w as useLocale,
26
- x as withCurrency,
27
- z as withLocale
28
- };
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 };
package/dist/num.d.ts CHANGED
@@ -143,6 +143,7 @@ export declare function clamp(value: number, min: number, max: number): number;
143
143
  * @param start - The starting value.
144
144
  * @param offset - The offset to apply to the upper bound of each pair.
145
145
  * @returns An array of [min, max] pairs.
146
+ * @throws InvalidArgumentException if by is zero.
146
147
  *
147
148
  * @see https://tolki.abe.dev/numbers/number-utilities-list.html#pairs
148
149
  */
package/dist/num.d.ts.map CHANGED
@@ -1 +1 @@
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,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,G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AAI,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,288 +1,215 @@
1
- let g = "en", N = "USD";
2
- function B(t, n = 0, e = null) {
3
- return D(t, n, e, !0);
4
- }
5
- function a(t, n = null, e = null, r = null) {
6
- r = r ?? g;
7
- const o = {
8
- style: "decimal",
9
- useGrouping: !0
10
- };
11
- e != null ? (o.maximumFractionDigits = e, o.minimumFractionDigits = 0) : n != null && (o.minimumFractionDigits = n, o.maximumFractionDigits = n);
12
- const u = new Intl.NumberFormat(r, o);
13
- return u.format(w(t, u.format));
14
- }
15
- function y(t, n = null) {
16
- n = n ?? g;
17
- const r = new Intl.NumberFormat(n).formatToParts(12345.6), o = /* @__PURE__ */ new Set();
18
- let u = ".";
19
- for (const i of r)
20
- i.type === "group" ? o.add(i.value) : i.type === "decimal" && (u = i.value);
21
- const l = [" ", " ", " "];
22
- for (const i of l) o.add(i);
23
- let s = t;
24
- for (const i of o) {
25
- const c = new RegExp(
26
- i.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
27
- "g"
28
- );
29
- s = s.replace(c, "");
30
- }
31
- if (u !== ".") {
32
- const i = new RegExp(
33
- u.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
34
- "g"
35
- ), c = s.lastIndexOf(u);
36
- c !== -1 && (s = s.slice(0, c).replace(i, "") + "." + s.slice(c + u.length));
37
- }
38
- return s = s.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(s);
39
- }
40
- function x(t, n = null) {
41
- const e = y(t, n);
42
- return Number.isNaN(e) ? !1 : e < 0 ? Math.ceil(e) : Math.floor(e);
43
- }
44
- function O(t, n = null) {
45
- return y(t, n);
46
- }
47
- function I(t, n = null) {
48
- const e = n ?? g;
49
- try {
50
- const o = new Intl.PluralRules(e, { type: "ordinal" }).select(t), u = String(e.split("-")[0]), l = {
51
- one: "st",
52
- two: "nd",
53
- few: "rd",
54
- other: "th"
55
- }, f = {
56
- en: l
57
- }[u] ?? l, i = f[o] ?? f.other;
58
- return `${t}${i}`;
59
- } catch {
60
- const r = Math.abs(t), o = r % 100;
61
- if (o >= 11 && o <= 13)
62
- return `${t}th`;
63
- switch (r % 10) {
64
- case 1:
65
- return `${t}st`;
66
- case 2:
67
- return `${t}nd`;
68
- case 3:
69
- return `${t}rd`;
70
- default:
71
- return `${t}th`;
72
- }
73
- }
74
- }
75
- function T(t, n = 0, e = null, r = null) {
76
- const o = r ?? g, u = typeof t == "string" ? y(t, o) : t, l = {
77
- style: "percent",
78
- useGrouping: !0
79
- };
80
- e != null ? (l.maximumFractionDigits = e, l.minimumFractionDigits = 0) : (l.minimumFractionDigits = n, l.maximumFractionDigits = n);
81
- const s = new Intl.NumberFormat(o, l);
82
- return s.format(w(u / 100, s.format));
83
- }
84
- function R(t, n = "", e = null, r = null) {
85
- const o = e ?? g, u = typeof t == "string" ? y(t, o) : t, s = {
86
- style: "currency",
87
- currency: n && n.length ? n : N,
88
- useGrouping: !0
89
- };
90
- r != null && (s.minimumFractionDigits = r, s.maximumFractionDigits = r);
91
- const f = new Intl.NumberFormat(o, s);
92
- return f.format(w(u, f.format));
93
- }
94
- function z(t, n = 0, e = null) {
95
- let r = typeof t == "string" ? Number(t) : t;
96
- if (!Number.isFinite(r))
97
- return `${a(r, n, e)} B`;
98
- const o = [
99
- "B",
100
- "KB",
101
- "MB",
102
- "GB",
103
- "TB",
104
- "PB",
105
- "EB",
106
- "ZB",
107
- "YB"
108
- ], u = o.length;
109
- let l = 0;
110
- for (; Math.abs(r) / 1024 > 0.9 && l < u - 1; )
111
- r /= 1024, l++;
112
- return `${a(r, n, e)} ${o[l]}`;
113
- }
114
- function D(t, n = 0, e = null, r = !1) {
115
- return $(
116
- t,
117
- n,
118
- e,
119
- r ? {} : {
120
- 3: " thousand",
121
- 6: " million",
122
- 9: " billion",
123
- 12: " trillion",
124
- 15: " quadrillion"
125
- }
126
- );
127
- }
128
- function $(t, n = 0, e = null, r = {}) {
129
- if (!Number.isFinite(t))
130
- return a(t, n, e);
131
- if (Object.keys(r).length === 0 && (r = {
132
- 3: "K",
133
- 6: "M",
134
- 9: "B",
135
- 12: "T",
136
- 15: "Q"
137
- }), Number(t) === 0)
138
- return n > 0 ? a(0, n, e) : "0";
139
- if (t < 0) {
140
- const i = $(
141
- Math.abs(t),
142
- n,
143
- e,
144
- r
145
- ), c = $(
146
- 0,
147
- n,
148
- e,
149
- r
150
- );
151
- return i === c ? i : `-${i}`;
152
- }
153
- if (t >= 1e15) {
154
- const i = Object.keys(r).map((m) => Number(m)).filter((m) => !Number.isNaN(m)).sort((m, d) => m - d), c = i[i.length - 1], p = r[c];
155
- return `${$(
156
- t / 1e15,
157
- n,
158
- e,
159
- r
160
- )}${p}`.trim();
161
- }
162
- const o = Math.floor(Math.log10(t));
163
- let u = Math.max(0, o - o % 3);
164
- const l = t / 10 ** u;
165
- let s;
166
- if (e != null)
167
- s = a(l, null, e);
168
- else if (n > 0)
169
- s = a(l, n, null);
170
- else {
171
- const i = Math.abs(t);
172
- s = u === 3 && l < 10 && i % 10 === 0 ? a(l, null, 1) : a(l, 0, null);
173
- }
174
- if (y(s) >= 1e3 && r[u + 3] !== void 0) {
175
- u += 3;
176
- const i = l / 1e3;
177
- e != null ? s = a(i, null, e) : n > 0 ? s = a(i, n, null) : s = a(i, 0, null);
178
- }
179
- const f = r[u] ?? "";
180
- return `${s}${f}`.trim();
181
- }
182
- function G(t, n, e) {
183
- return Math.min(Math.max(t, n), e);
184
- }
185
- function H(t, n, e = 0, r = 1) {
186
- if (n === 0)
187
- throw new Error("The 'by' argument must not be zero.");
188
- n = Math.abs(n);
189
- const o = [];
190
- for (let u = e; u < t; u += n) {
191
- let l = u + n - r;
192
- l > t && (l = t), o.push([u, l]);
193
- }
194
- return o;
195
- }
196
- function k(t) {
197
- return isFinite(t) ? JSON.parse(JSON.stringify(t)) : t;
198
- }
199
- function A(t, n = !0) {
200
- const e = Number(t) * 60;
201
- return E(e, n);
202
- }
203
- function E(t, n = !0) {
204
- let e = Number(t);
205
- if ((!Number.isFinite(e) || e < 0) && (e = 0), e === 0) return "0 seconds";
206
- const r = 1, o = 60 * r, u = 60 * o, l = 24 * u, s = 7 * l, f = 4 * s, c = [
207
- ["year", 12 * f],
208
- ["month", f],
209
- ["week", s],
210
- ["day", l],
211
- ["hour", u],
212
- ["minute", o],
213
- ["second", r]
214
- ];
215
- if (n)
216
- for (const [m, d] of c) {
217
- const h = e / d;
218
- if (h >= 0.5 || d === r) {
219
- const F = Math.round(h);
220
- return `${F} ${m}${F === 1 ? "" : "s"}`;
221
- }
222
- }
223
- let p = e;
224
- const b = [];
225
- for (const [m, d] of c)
226
- if (p >= d) {
227
- const h = Math.floor(p / d);
228
- p -= h * d, b.push(`${h} ${m}${h === 1 ? "" : "s"}`);
229
- }
230
- return b.join(", ");
231
- }
232
- function C(t, n) {
233
- const e = g;
234
- M(t);
235
- try {
236
- return n();
237
- } finally {
238
- M(e);
239
- }
240
- }
241
- function K(t, n) {
242
- const e = N;
243
- S(t);
244
- try {
245
- return n();
246
- } finally {
247
- S(e);
248
- }
249
- }
250
- function M(t) {
251
- g = t;
252
- }
253
- function S(t) {
254
- N = t;
255
- }
256
- function L() {
257
- return g;
258
- }
259
- function Y() {
260
- return N;
261
- }
262
- function w(t, n) {
263
- return t === 0 || t < 0 && n(Math.abs(t)) === n(0) ? 0 : t;
264
- }
265
- export {
266
- B as abbreviate,
267
- G as clamp,
268
- R as currency,
269
- Y as defaultCurrency,
270
- L as defaultLocale,
271
- z as fileSize,
272
- D as forHumans,
273
- a as format,
274
- A as minutesToHuman,
275
- I as ordinal,
276
- H as pairs,
277
- y as parse,
278
- O as parseFloat,
279
- x as parseInt,
280
- T as percentage,
281
- E as secondsToHuman,
282
- $ as summarize,
283
- k as trim,
284
- S as useCurrency,
285
- M as useLocale,
286
- K as withCurrency,
287
- C as withLocale
288
- };
1
+ import { InvalidArgumentException as e } from "@tolki/utils";
2
+ // 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 = {
10
+ style: "decimal",
11
+ useGrouping: !0
12
+ };
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);
21
+ for (let e of [
22
+ "\xA0",
23
+ " ",
24
+ " "
25
+ ]) i.add(e);
26
+ let o = e;
27
+ for (let e of i) {
28
+ let t = new RegExp(e.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"), "g");
29
+ o = o.replace(t, "");
30
+ }
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
+ }
35
+ return o = o.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(o);
36
+ }
37
+ function o(e, t = null) {
38
+ let n = a(e, t);
39
+ return Number.isNaN(n) ? !1 : n < 0 ? Math.ceil(n) : Math.floor(n);
40
+ }
41
+ function s(e, t = null) {
42
+ return a(e, t);
43
+ }
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
+ }
64
+ }
65
+ function l(e, n = 0, r = null, i = null) {
66
+ let o = i ?? t, s = typeof e == "string" ? a(e, o) : e, c = {
67
+ style: "percent",
68
+ useGrouping: !0
69
+ };
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));
73
+ }
74
+ function u(e, r = "", i = null, o = null) {
75
+ let s = i ?? t, c = typeof e == "string" ? a(e, s) : e, l = {
76
+ style: "currency",
77
+ currency: r && r.length ? r : n,
78
+ useGrouping: !0
79
+ };
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));
83
+ }
84
+ function d(e, t = 0, n = null) {
85
+ let r = typeof e == "string" ? Number(e) : e;
86
+ if (!Number.isFinite(r)) return `${i(r, t, n)} B`;
87
+ let a = [
88
+ "B",
89
+ "KB",
90
+ "MB",
91
+ "GB",
92
+ "TB",
93
+ "PB",
94
+ "EB",
95
+ "ZB",
96
+ "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]}`;
100
+ }
101
+ function f(e, t = 0, n = null, r = !1) {
102
+ return p(e, t, n, r ? {} : {
103
+ 3: " thousand",
104
+ 6: " million",
105
+ 9: " billion",
106
+ 12: " trillion",
107
+ 15: " quadrillion"
108
+ });
109
+ }
110
+ function p(e, t = 0, n = null, r = {}) {
111
+ if (!Number.isFinite(e)) return i(e, t, n);
112
+ if (Object.keys(r).length === 0 && (r = {
113
+ 3: "K",
114
+ 6: "M",
115
+ 9: "B",
116
+ 12: "T",
117
+ 15: "Q"
118
+ }), Number(e) === 0) return t > 0 ? i(0, t, n) : "0";
119
+ if (e < 0) {
120
+ let i = p(Math.abs(e), t, n, r);
121
+ return i === p(0, t, n, r) ? i : `-${i}`;
122
+ }
123
+ if (e >= 0x38d7ea4c68000) {
124
+ 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();
126
+ }
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);
132
+ }
133
+ let u = r[s] ?? "";
134
+ return `${l}${u}`.trim();
135
+ }
136
+ function m(e, t, n) {
137
+ return Math.min(Math.max(e, t), n);
138
+ }
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]);
146
+ }
147
+ let s = a.at(-1);
148
+ return s !== void 0 && o === t && s[1] < t && a.push([o, t]), a;
149
+ }
150
+ function g(e) {
151
+ return isFinite(e) ? JSON.parse(JSON.stringify(e)) : e;
152
+ }
153
+ function _(e, t = !0) {
154
+ return v(Number(e) * 60, t);
155
+ }
156
+ function v(e, t = !0) {
157
+ let n = Number(e);
158
+ if ((!Number.isFinite(n) || n < 0) && (n = 0), n === 0) return "0 seconds";
159
+ let r = 3600, i = 24 * r, a = 7 * i, o = 4 * a, s = [
160
+ ["year", 12 * o],
161
+ ["month", o],
162
+ ["week", a],
163
+ ["day", i],
164
+ ["hour", r],
165
+ ["minute", 60],
166
+ ["second", 1]
167
+ ];
168
+ if (t) for (let [e, t] of s) {
169
+ let r = n / t;
170
+ if (r >= .5 || t === 1) {
171
+ let t = Math.round(r);
172
+ return `${t} ${e}${t === 1 ? "" : "s"}`;
173
+ }
174
+ }
175
+ let c = n, l = [];
176
+ for (let [e, t] of s) if (c >= t) {
177
+ let n = Math.floor(c / t);
178
+ c -= n * t, l.push(`${n} ${e}${n === 1 ? "" : "s"}`);
179
+ }
180
+ return l.join(", ");
181
+ }
182
+ function y(e, n) {
183
+ let r = t;
184
+ x(e);
185
+ try {
186
+ return n();
187
+ } finally {
188
+ x(r);
189
+ }
190
+ }
191
+ function b(e, t) {
192
+ let r = n;
193
+ S(e);
194
+ try {
195
+ return t();
196
+ } finally {
197
+ S(r);
198
+ }
199
+ }
200
+ function x(e) {
201
+ t = e;
202
+ }
203
+ function S(e) {
204
+ n = e;
205
+ }
206
+ function C() {
207
+ return t;
208
+ }
209
+ function w() {
210
+ return n;
211
+ }
212
+ function T(e, t) {
213
+ return e === 0 || e < 0 && t(Math.abs(e)) === t(0) ? 0 : e;
214
+ }
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 };
@@ -1,96 +1,85 @@
1
- import { isString as i, toLower as e } from "@tolki/utils";
2
- import { format as l } from "../num.js";
3
- async function d(t, o = null, a = null, n = null) {
4
- const r = i(t) ? parseFloat(t) : t;
5
- if (a !== null && r <= a)
6
- return l(r, null, null, o);
7
- if (n !== null && r >= n)
8
- return l(r, null, null, o);
9
- const s = await u(o ?? "en-US");
10
- return e(s.convert(r));
1
+ import { format as e } from "../num.js";
2
+ import { isString as t, toLower as n } from "@tolki/utils";
3
+ // 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));
11
9
  }
12
- async function h(t, o = null) {
13
- const a = i(t) ? parseFloat(t) : t, n = await u(o ?? "en-US");
14
- return e(n.toOrdinal(Math.floor(a)));
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)));
15
13
  }
16
- async function u(t) {
17
- try {
18
- const s = await import(`to-words/${t}`);
19
- return new s.ToWords();
20
- } catch {
21
- }
22
- const o = String(t.split("-")[0]).toLowerCase(), n = {
23
- af: "af-ZA",
24
- am: "am-ET",
25
- ar: "ar-SA",
26
- az: "az-AZ",
27
- be: "be-BY",
28
- bg: "bg-BG",
29
- bn: "bn-IN",
30
- ca: "ca-ES",
31
- cs: "cs-CZ",
32
- da: "da-DK",
33
- de: "de-DE",
34
- ee: "ee-EE",
35
- el: "el-GR",
36
- en: "en-US",
37
- es: "es-ES",
38
- fa: "fa-IR",
39
- fi: "fi-FI",
40
- fil: "fil-PH",
41
- fr: "fr-FR",
42
- gu: "gu-IN",
43
- ha: "ha-NG",
44
- hbo: "hbo-IL",
45
- he: "he-IL",
46
- hi: "hi-IN",
47
- hr: "hr-HR",
48
- hu: "hu-HU",
49
- id: "id-ID",
50
- is: "is-IS",
51
- it: "it-IT",
52
- ja: "ja-JP",
53
- ka: "ka-GE",
54
- kn: "kn-IN",
55
- ko: "ko-KR",
56
- lt: "lt-LT",
57
- lv: "lv-LV",
58
- mr: "mr-IN",
59
- ms: "ms-MY",
60
- nb: "nb-NO",
61
- nl: "nl-NL",
62
- np: "np-NP",
63
- pa: "pa-IN",
64
- pl: "pl-PL",
65
- pt: "pt-BR",
66
- ro: "ro-RO",
67
- ru: "ru-RU",
68
- sk: "sk-SK",
69
- sl: "sl-SI",
70
- sq: "sq-AL",
71
- sr: "sr-RS",
72
- sv: "sv-SE",
73
- sw: "sw-KE",
74
- ta: "ta-IN",
75
- te: "te-IN",
76
- th: "th-TH",
77
- tr: "tr-TR",
78
- uk: "uk-UA",
79
- ur: "ur-PK",
80
- vi: "vi-VN",
81
- yo: "yo-NG",
82
- zh: "zh-CN"
83
- }[o];
84
- if (n && n !== t)
85
- try {
86
- const s = await import(`to-words/${n}`);
87
- return new s.ToWords();
88
- } catch {
89
- }
90
- const r = await import("../en-US-Ct0OKCam.js");
91
- return new r.ToWords();
14
+ async function a(e) {
15
+ try {
16
+ return new (await (import(`to-words/${e}`))).ToWords();
17
+ } catch {}
18
+ let t = {
19
+ af: "af-ZA",
20
+ am: "am-ET",
21
+ ar: "ar-SA",
22
+ az: "az-AZ",
23
+ be: "be-BY",
24
+ bg: "bg-BG",
25
+ bn: "bn-IN",
26
+ ca: "ca-ES",
27
+ cs: "cs-CZ",
28
+ da: "da-DK",
29
+ de: "de-DE",
30
+ ee: "ee-EE",
31
+ el: "el-GR",
32
+ en: "en-US",
33
+ es: "es-ES",
34
+ fa: "fa-IR",
35
+ fi: "fi-FI",
36
+ fil: "fil-PH",
37
+ fr: "fr-FR",
38
+ gu: "gu-IN",
39
+ ha: "ha-NG",
40
+ hbo: "hbo-IL",
41
+ he: "he-IL",
42
+ hi: "hi-IN",
43
+ hr: "hr-HR",
44
+ hu: "hu-HU",
45
+ id: "id-ID",
46
+ is: "is-IS",
47
+ it: "it-IT",
48
+ ja: "ja-JP",
49
+ ka: "ka-GE",
50
+ kn: "kn-IN",
51
+ ko: "ko-KR",
52
+ lt: "lt-LT",
53
+ lv: "lv-LV",
54
+ mr: "mr-IN",
55
+ ms: "ms-MY",
56
+ nb: "nb-NO",
57
+ nl: "nl-NL",
58
+ np: "np-NP",
59
+ pa: "pa-IN",
60
+ pl: "pl-PL",
61
+ pt: "pt-BR",
62
+ ro: "ro-RO",
63
+ ru: "ru-RU",
64
+ sk: "sk-SK",
65
+ sl: "sl-SI",
66
+ sq: "sq-AL",
67
+ sr: "sr-RS",
68
+ sv: "sv-SE",
69
+ sw: "sw-KE",
70
+ ta: "ta-IN",
71
+ te: "te-IN",
72
+ th: "th-TH",
73
+ tr: "tr-TR",
74
+ uk: "uk-UA",
75
+ ur: "ur-PK",
76
+ vi: "vi-VN",
77
+ yo: "yo-NG",
78
+ zh: "zh-CN"
79
+ }[String(e.split("-")[0]).toLowerCase()];
80
+ if (t && t !== e) try {
81
+ return new (await (import(`to-words/${t}`))).ToWords();
82
+ } catch {}
83
+ return new (await (import("to-words/en-US"))).ToWords();
92
84
  }
93
- export {
94
- d as spell,
95
- h as spellOrdinal
96
- };
85
+ export { r as spell, i as spellOrdinal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/num",
3
- "version": "2.2.3",
3
+ "version": "2.2.5",
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.4.0"
29
+ "@tolki/utils": "^1.6.3"
30
30
  },
31
31
  "files": [
32
32
  "dist"
@@ -54,12 +54,14 @@
54
54
  "types": "./dist/*"
55
55
  },
56
56
  "./num": {
57
+ "types": "./dist/num.d.ts",
57
58
  "import": "./dist/num.js",
58
- "types": "./dist/num.d.ts"
59
+ "default": "./dist/num.js"
59
60
  },
60
61
  "./speller": {
62
+ "types": "./dist/speller/index.d.ts",
61
63
  "import": "./dist/speller/index.js",
62
- "types": "./dist/speller/index.d.ts"
64
+ "default": "./dist/speller/index.js"
63
65
  }
64
66
  }
65
67
  }
@@ -1,431 +0,0 @@
1
- const x = {
2
- currency: !1,
3
- ignoreDecimal: !1,
4
- ignoreZeroCurrency: !1,
5
- doNotAddOnly: !1
6
- }, F = {
7
- localeCode: "en-IN",
8
- converterOptions: x
9
- }, M = /* @__PURE__ */ new WeakMap(), I = 0n, S = 1n, C = 2n, w = 10n, O = 11n, W = 100n, A = 1000n, L = BigInt(Number.MAX_SAFE_INTEGER);
10
- class E {
11
- options = {};
12
- locale = void 0;
13
- localeClass = void 0;
14
- constructor(e = {}) {
15
- this.options = Object.assign({}, F, e);
16
- }
17
- /**
18
- * Set a locale class directly.
19
- * @internal Used by per-locale entry points
20
- */
21
- setLocale(e) {
22
- return this.localeClass = e, this.locale = void 0, this;
23
- }
24
- /**
25
- * Get the locale class. Must be set via setLocale() or overridden in subclass.
26
- */
27
- getLocaleClass() {
28
- if (this.localeClass)
29
- return this.localeClass;
30
- throw new Error('No locale set. Use setLocale() or import from a locale-specific entry point (e.g., "to-words/en-IN")');
31
- }
32
- getLocale() {
33
- if (this.locale === void 0) {
34
- const e = this.getLocaleClass();
35
- this.locale = new e(), this.initLocaleCache(this.locale);
36
- }
37
- return this.locale;
38
- }
39
- initLocaleCache(e) {
40
- if (M.has(e))
41
- return;
42
- const r = e.config, l = r.numberWordsMapping.map((o) => ({
43
- ...o,
44
- numberBigInt: BigInt(o.number),
45
- resolvedValue: Array.isArray(o.value) ? o.value[0] : o.value
46
- })), n = /* @__PURE__ */ new Map();
47
- if (r.exactWordsMapping)
48
- for (const o of r.exactWordsMapping) {
49
- const f = {
50
- ...o,
51
- numberBigInt: BigInt(o.number),
52
- resolvedValue: Array.isArray(o.value) ? o.value[0] : o.value
53
- };
54
- n.set(f.numberBigInt, f);
55
- }
56
- const i = /* @__PURE__ */ new Map();
57
- let t = I;
58
- for (const o of l)
59
- o.numberBigInt <= W && (i.set(o.numberBigInt, o), o.numberBigInt > t && (t = o.numberBigInt));
60
- const a = l.filter((o) => o.numberBigInt >= W), m = new Set(r.pluralWords ?? []), s = new Set(r.pluralWordsOnlyWhenTrailing ?? []), d = new Set(r.ignoreOneForWords ?? []), u = new Set(r.noSplitWordAfter ?? []);
61
- M.set(e, {
62
- numberWordsMappingBigInt: l,
63
- exactWordsMap: n,
64
- smallNumbersMap: i,
65
- unitMappings: a,
66
- smallNumbersBoundary: t,
67
- pluralWordsSet: m,
68
- pluralWordsOnlyWhenTrailingSet: s,
69
- ignoreOneForWordsSet: d,
70
- noSplitWordAfterSet: u
71
- });
72
- }
73
- getLocaleCache(e) {
74
- let r = M.get(e);
75
- return r || (this.initLocaleCache(e), r = M.get(e)), r;
76
- }
77
- convert(e, r = {}) {
78
- const l = this.options.converterOptions, n = Object.keys(r).length === 0 ? l ?? {} : {
79
- currency: r.currency ?? l?.currency ?? !1,
80
- ignoreDecimal: r.ignoreDecimal ?? l?.ignoreDecimal ?? !1,
81
- ignoreZeroCurrency: r.ignoreZeroCurrency ?? l?.ignoreZeroCurrency ?? !1,
82
- doNotAddOnly: r.doNotAddOnly ?? l?.doNotAddOnly ?? !1,
83
- currencyOptions: r.currencyOptions ?? l?.currencyOptions
84
- };
85
- if (!this.isValidNumber(e))
86
- throw new Error(`Invalid Number "${e}"`);
87
- const i = typeof e == "bigint";
88
- let t = i ? e : Number(e);
89
- n.ignoreDecimal && !i && (t = Math.trunc(t));
90
- let a = [];
91
- return n.currency ? a = this.convertCurrency(t, n) : a = this.convertNumber(t), this.locale?.config.trim ? a.join("") : a.join(" ");
92
- }
93
- toOrdinal(e, r = {}) {
94
- if (!this.isValidNumber(e))
95
- throw new Error(`Invalid Number "${e}"`);
96
- const l = this.getLocale(), n = l.config, i = Number(e);
97
- if (!Number.isInteger(i) || i < 0)
98
- throw new Error(`Ordinal numbers must be non-negative integers, got "${e}"`);
99
- if (!n.ordinalWordsMapping && !n.ordinalSuffix)
100
- throw new Error(`Ordinal conversion not supported for locale "${this.options.localeCode}"`);
101
- const t = this.convertOrdinal(i, r, l);
102
- return n.trim ? t.join("") : t.join(" ");
103
- }
104
- convertOrdinal(e, r, l) {
105
- const n = l.config;
106
- if (n.ordinalExactWordsMapping) {
107
- const t = n.ordinalExactWordsMapping.find((a) => a.number === e);
108
- if (t)
109
- return [t.value];
110
- }
111
- if (e <= 20 && n.ordinalWordsMapping) {
112
- const t = n.ordinalWordsMapping.find((a) => a.number === e);
113
- if (t)
114
- return [t.value];
115
- }
116
- const i = this.convertInternal(BigInt(e), !0, void 0, l);
117
- if (i.length > 0) {
118
- const t = i.length - 1, a = i[t], m = this.getLastNumberComponent(e, n);
119
- if (n.ordinalWordsMapping) {
120
- const s = n.ordinalWordsMapping.find((d) => d.number === m);
121
- if (s)
122
- return i[t] = s.value, i;
123
- }
124
- n.ordinalSuffix && (i[t] = a + n.ordinalSuffix);
125
- }
126
- return i;
127
- }
128
- getLastNumberComponent(e, r) {
129
- if (e <= 20)
130
- return e;
131
- const l = r.numberWordsMapping.filter((i) => Number(i.number) >= 100).sort((i, t) => Number(t.number) - Number(i.number));
132
- for (const i of l) {
133
- const t = Number(i.number);
134
- if (e % t === 0)
135
- return t;
136
- }
137
- const n = e % 100;
138
- return n >= 1 && n <= 99 && r.numberWordsMapping.some((t) => Number(t.number) === n) || n % 10 === 0 ? n : e % 10;
139
- }
140
- convertNumber(e) {
141
- const r = this.getLocale(), l = r.config, n = e < 0 || typeof e == "bigint" && e < 0n;
142
- n && (e = typeof e == "bigint" ? -e : Math.abs(e));
143
- const i = typeof e == "bigint", t = !i && this.isFloat(e);
144
- let a, m = "";
145
- if (i)
146
- a = e;
147
- else if (t) {
148
- const f = e.toString().split(".");
149
- a = BigInt(f[0]), m = f[1] ?? "";
150
- } else
151
- a = BigInt(Math.trunc(e));
152
- const s = this.isNumberZero(e) && l.ignoreZeroInDecimals;
153
- let d = this.convertInternal(a, !0, void 0, r);
154
- t && s && (d = []);
155
- const u = [];
156
- if (t) {
157
- if (s || u.push(l.texts.point), m.startsWith("0") && !l?.decimalLengthWordMapping) {
158
- const f = [];
159
- for (const h of m)
160
- f.push(...this.convertInternal(BigInt(h), !0, void 0, r));
161
- u.push(...f);
162
- } else if (m.length) {
163
- u.push(...this.convertInternal(BigInt(m), !0, void 0, r));
164
- const f = l?.decimalLengthWordMapping?.[m.length];
165
- f && u.push(f);
166
- }
167
- }
168
- return !(d.length <= 0) && n && d.unshift(l.texts.minus), d.push(...u), d;
169
- }
170
- convertCurrency(e, r = {}) {
171
- const l = this.getLocale(), n = l.config, i = r.currencyOptions ?? n.currency, t = e < 0 || typeof e == "bigint" && e < 0n;
172
- t && (e = typeof e == "bigint" ? -e : Math.abs(e));
173
- const a = typeof e == "bigint";
174
- a || (e = this.toFixed(e));
175
- const m = !a && this.isFloat(e);
176
- let s, d = "";
177
- if (a)
178
- s = e;
179
- else if (m) {
180
- const v = e.toString().split(".");
181
- s = BigInt(v[0]), d = v[1] ?? "";
182
- } else
183
- s = BigInt(Math.trunc(e));
184
- let u = [];
185
- const o = s <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(s) : -1;
186
- if (o !== -1 && i.numberSpecificForms?.[o])
187
- u = [i.numberSpecificForms[o]];
188
- else {
189
- const v = n.useTrailingForCurrency ?? !1;
190
- u = [...this.convertInternal(s, v, void 0, l)], s === 1n && i.singular ? u.push(i.singular) : i.plural && u.push(i.plural);
191
- }
192
- const f = this.isNumberZero(e) && (r.ignoreZeroCurrency || n?.ignoreZeroInDecimals && e !== 0 && e !== 0n);
193
- f && (u = []);
194
- const h = [];
195
- if (m) {
196
- f || h.push(n.texts.and);
197
- const v = !n.decimalLengthWordMapping && d.length ? Math.pow(10, Math.max(0, 2 - d.length)) : 1, p = Number(d || "0") * v, N = n?.decimalLengthWordMapping?.[d.length];
198
- i.fractionalUnit.numberSpecificForms?.[p] ? h.push(i.fractionalUnit.numberSpecificForms[p]) : (h.push(...this.convertInternal(BigInt(p), !1, void 0, l)), N?.length && h.push(N), p === 1 && i.fractionalUnit.singular ? h.push(i.fractionalUnit.singular) : h.push(i.fractionalUnit.plural));
199
- } else n.decimalLengthWordMapping && u.length && h.push(i.fractionalUnit.plural);
200
- const b = u.length <= 0 && h.length <= 0;
201
- return !b && t && u.unshift(n.texts.minus), !b && n.texts.only && !r.doNotAddOnly && !n.onlyInFront && h.push(n.texts.only), h.length && u.push(...h), !b && !r.doNotAddOnly && n.onlyInFront && u.splice(0, 0, n.texts.only), u;
202
- }
203
- convertInternal(e, r = !1, l = void 0, n) {
204
- const i = n ?? this.getLocale(), t = i.config, a = this.getLocaleCache(i);
205
- if (l) {
206
- const c = e <= L ? Number(e) : -1;
207
- if (c !== -1 && l[c])
208
- return [l[c]];
209
- }
210
- const m = a.exactWordsMap.get(e);
211
- if (m)
212
- return [r && Array.isArray(m.value) ? m.value[1] : m.resolvedValue];
213
- let s;
214
- if (e <= W) {
215
- const c = a.smallNumbersMap.get(e);
216
- if (c)
217
- return [r && Array.isArray(c.value) ? c.value[1] : c.resolvedValue];
218
- s = this.binarySearchDescending(a.numberWordsMappingBigInt, e);
219
- } else
220
- s = this.binarySearchDescending(a.numberWordsMappingBigInt, e);
221
- const d = s.numberBigInt, u = [];
222
- if (e <= W || e < A && t.namedLessThan1000) {
223
- u.push(s.resolvedValue);
224
- const c = e - d;
225
- if (c > I) {
226
- t.splitWord && u.push(t.splitWord);
227
- const g = this.convertInternal(c, r, l, i);
228
- for (let y = 0; y < g.length; y++)
229
- u.push(g[y]);
230
- }
231
- return u;
232
- }
233
- const o = e / d, f = e % d;
234
- let h = s.resolvedValue;
235
- const b = s.resolvedValue, v = Number(d), p = t.pluralForms?.[v];
236
- let N = !1;
237
- const T = a.ignoreOneForWordsSet.has(b);
238
- if (p) {
239
- const c = Number(o % W), g = o >= O && c >= 3 && c <= 10;
240
- o === C && p.dual ? (h = p.dual, N = !0) : o >= BigInt(t.paucalConfig?.min ?? 3) && o <= BigInt(t.paucalConfig?.max ?? 10) || g ? p.paucal && (h = p.paucal) : o >= O && p.plural && (h = p.plural);
241
- } else {
242
- const c = s.value, g = a.pluralWordsSet.has(c), y = a.pluralWordsOnlyWhenTrailingSet.has(c);
243
- o > S && t.pluralMark && (g || y && f === I) && (h += t.pluralMark), o % w === S && !T && (h = s.singularValue || (Array.isArray(h) ? h[0] : h));
244
- }
245
- if (o === S && T || N) {
246
- const c = o === S && s.singularValue ? s.singularValue : h;
247
- u.push(c);
248
- } else {
249
- const c = this.convertInternal(o, !1, l, i);
250
- for (let g = 0; g < c.length; g++)
251
- u.push(c[g]);
252
- u.push(h);
253
- }
254
- if (f > I) {
255
- t.splitWord && (a.noSplitWordAfterSet.has(s.resolvedValue) || u.push(t.splitWord));
256
- const c = this.convertInternal(f, r, l, i);
257
- for (let g = 0; g < c.length; g++)
258
- u.push(c[g]);
259
- }
260
- return u;
261
- }
262
- /**
263
- * Binary search on a descending-sorted array of CachedNumberWordMap.
264
- * Finds the first element where numberBigInt <= target.
265
- */
266
- binarySearchDescending(e, r) {
267
- let l = 0, n = e.length - 1, i = e[n];
268
- for (; l <= n; ) {
269
- const t = l + n >> 1;
270
- e[t].numberBigInt <= r ? (i = e[t], n = t - 1) : l = t + 1;
271
- }
272
- return i;
273
- }
274
- toFixed(e, r = 2) {
275
- return Number(Number(e).toFixed(r));
276
- }
277
- isFloat(e) {
278
- return Number(e) === e && e % 1 !== 0;
279
- }
280
- isValidNumber(e) {
281
- const r = typeof e;
282
- if (r === "bigint")
283
- return !0;
284
- if (r === "number")
285
- return !Number.isNaN(e) && Number.isFinite(e);
286
- const l = e;
287
- if (l.trim() === "")
288
- return !1;
289
- const n = Number(l);
290
- return !Number.isNaN(n) && Number.isFinite(n);
291
- }
292
- isNumberZero(e) {
293
- return typeof e == "bigint" ? e === I : e >= 0 && e < 1;
294
- }
295
- }
296
- class D {
297
- config = {
298
- currency: {
299
- name: "Dollar",
300
- plural: "Dollars",
301
- singular: "Dollar",
302
- symbol: "$",
303
- fractionalUnit: {
304
- name: "Cent",
305
- plural: "Cents",
306
- singular: "Cent",
307
- symbol: "¢"
308
- }
309
- },
310
- texts: {
311
- and: "And",
312
- minus: "Minus",
313
- only: "Only",
314
- point: "Point"
315
- },
316
- numberWordsMapping: [
317
- { number: 1000000000000000000000000000000000000000000000000000000000000000n, value: "Vigintillion" },
318
- { number: 1000000000000000000000000000000000000000000000000000000000000n, value: "Novemdecillion" },
319
- { number: 1000000000000000000000000000000000000000000000000000000000n, value: "Octodecillion" },
320
- { number: 1000000000000000000000000000000000000000000000000000000n, value: "Septendecillion" },
321
- { number: 1000000000000000000000000000000000000000000000000000n, value: "Sexdecillion" },
322
- { number: 1000000000000000000000000000000000000000000000000n, value: "Quindecillion" },
323
- { number: 1000000000000000000000000000000000000000000000n, value: "Quattuordecillion" },
324
- { number: 1000000000000000000000000000000000000000000n, value: "Tredecillion" },
325
- { number: 1000000000000000000000000000000000000000n, value: "Duodecillion" },
326
- { number: 1000000000000000000000000000000000000n, value: "Undecillion" },
327
- { number: 1000000000000000000000000000000000n, value: "Decillion" },
328
- { number: 1000000000000000000000000000000n, value: "Nonillion" },
329
- { number: 1000000000000000000000000000n, value: "Octillion" },
330
- { number: 1000000000000000000000000n, value: "Septillion" },
331
- { number: 1000000000000000000000n, value: "Sextillion" },
332
- { number: 1000000000000000000n, value: "Quintillion" },
333
- { number: 1e15, value: "Quadrillion" },
334
- { number: 1e12, value: "Trillion" },
335
- { number: 1e9, value: "Billion" },
336
- { number: 1e6, value: "Million" },
337
- { number: 1e3, value: "Thousand" },
338
- { number: 100, value: "Hundred" },
339
- { number: 90, value: "Ninety" },
340
- { number: 80, value: "Eighty" },
341
- { number: 70, value: "Seventy" },
342
- { number: 60, value: "Sixty" },
343
- { number: 50, value: "Fifty" },
344
- { number: 40, value: "Forty" },
345
- { number: 30, value: "Thirty" },
346
- { number: 20, value: "Twenty" },
347
- { number: 19, value: "Nineteen" },
348
- { number: 18, value: "Eighteen" },
349
- { number: 17, value: "Seventeen" },
350
- { number: 16, value: "Sixteen" },
351
- { number: 15, value: "Fifteen" },
352
- { number: 14, value: "Fourteen" },
353
- { number: 13, value: "Thirteen" },
354
- { number: 12, value: "Twelve" },
355
- { number: 11, value: "Eleven" },
356
- { number: 10, value: "Ten" },
357
- { number: 9, value: "Nine" },
358
- { number: 8, value: "Eight" },
359
- { number: 7, value: "Seven" },
360
- { number: 6, value: "Six" },
361
- { number: 5, value: "Five" },
362
- { number: 4, value: "Four" },
363
- { number: 3, value: "Three" },
364
- { number: 2, value: "Two" },
365
- { number: 1, value: "One" },
366
- { number: 0, value: "Zero" }
367
- ],
368
- exactWordsMapping: [{ number: 100, value: "One Hundred" }],
369
- ordinalWordsMapping: [
370
- { number: 1000000000000000000000000000000000000000000000000000000000000000n, value: "Vigintillionth" },
371
- { number: 1000000000000000000000000000000000000000000000000000000000000n, value: "Novemdecillionth" },
372
- { number: 1000000000000000000000000000000000000000000000000000000000n, value: "Octodecillionth" },
373
- { number: 1000000000000000000000000000000000000000000000000000000n, value: "Septendecillionth" },
374
- { number: 1000000000000000000000000000000000000000000000000000n, value: "Sexdecillionth" },
375
- { number: 1000000000000000000000000000000000000000000000000n, value: "Quindecillionth" },
376
- { number: 1000000000000000000000000000000000000000000000n, value: "Quattuordecillionth" },
377
- { number: 1000000000000000000000000000000000000000000n, value: "Tredecillionth" },
378
- { number: 1000000000000000000000000000000000000000n, value: "Duodecillionth" },
379
- { number: 1000000000000000000000000000000000000n, value: "Undecillionth" },
380
- { number: 1000000000000000000000000000000000n, value: "Decillionth" },
381
- { number: 1000000000000000000000000000000n, value: "Nonillionth" },
382
- { number: 1000000000000000000000000000n, value: "Octillionth" },
383
- { number: 1000000000000000000000000n, value: "Septillionth" },
384
- { number: 1000000000000000000000n, value: "Sextillionth" },
385
- { number: 1000000000000000000n, value: "Quintillionth" },
386
- { number: 1e15, value: "Quadrillionth" },
387
- { number: 1e12, value: "Trillionth" },
388
- { number: 1e9, value: "Billionth" },
389
- { number: 1e6, value: "Millionth" },
390
- { number: 1e3, value: "Thousandth" },
391
- { number: 100, value: "Hundredth" },
392
- { number: 90, value: "Ninetieth" },
393
- { number: 80, value: "Eightieth" },
394
- { number: 70, value: "Seventieth" },
395
- { number: 60, value: "Sixtieth" },
396
- { number: 50, value: "Fiftieth" },
397
- { number: 40, value: "Fortieth" },
398
- { number: 30, value: "Thirtieth" },
399
- { number: 20, value: "Twentieth" },
400
- { number: 19, value: "Nineteenth" },
401
- { number: 18, value: "Eighteenth" },
402
- { number: 17, value: "Seventeenth" },
403
- { number: 16, value: "Sixteenth" },
404
- { number: 15, value: "Fifteenth" },
405
- { number: 14, value: "Fourteenth" },
406
- { number: 13, value: "Thirteenth" },
407
- { number: 12, value: "Twelfth" },
408
- { number: 11, value: "Eleventh" },
409
- { number: 10, value: "Tenth" },
410
- { number: 9, value: "Ninth" },
411
- { number: 8, value: "Eighth" },
412
- { number: 7, value: "Seventh" },
413
- { number: 6, value: "Sixth" },
414
- { number: 5, value: "Fifth" },
415
- { number: 4, value: "Fourth" },
416
- { number: 3, value: "Third" },
417
- { number: 2, value: "Second" },
418
- { number: 1, value: "First" },
419
- { number: 0, value: "Zeroth" }
420
- ],
421
- ordinalExactWordsMapping: [{ number: 100, value: "One Hundredth" }]
422
- };
423
- }
424
- class V extends E {
425
- constructor(e = {}) {
426
- super(e), this.setLocale(D);
427
- }
428
- }
429
- export {
430
- V as ToWords
431
- };