@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 +4 -0
- package/dist/index.js +3 -28
- package/dist/num.d.ts +1 -0
- package/dist/num.d.ts.map +1 -1
- package/dist/num.js +215 -288
- package/dist/speller/index.js +82 -93
- package/package.json +6 -4
- package/dist/en-US-Ct0OKCam.js +0 -431
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
import { abbreviate as
|
|
2
|
-
import { spell as
|
|
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":"
|
|
1
|
+
{"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../src/num.ts"],"names":[],"mappings":"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"}
|
package/dist/num.js
CHANGED
|
@@ -1,288 +1,215 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
function
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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 };
|
package/dist/speller/index.js
CHANGED
|
@@ -1,96 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
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
|
+
"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.
|
|
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
|
-
"
|
|
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
|
-
"
|
|
64
|
+
"default": "./dist/speller/index.js"
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
}
|
package/dist/en-US-Ct0OKCam.js
DELETED
|
@@ -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
|
-
};
|