@tolki/num 2.2.4 → 2.2.6
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 +17 -5
- package/dist/index.js +3 -28
- package/dist/num.d.ts +8 -0
- package/dist/num.d.ts.map +1 -1
- package/dist/num.js +233 -293
- package/dist/speller/index.d.ts.map +1 -1
- package/dist/speller/index.js +84 -93
- package/package.json +6 -4
- package/dist/en-US-Ct0OKCam.js +0 -431
package/dist/num.js
CHANGED
|
@@ -1,293 +1,233 @@
|
|
|
1
|
-
import { InvalidArgumentException as
|
|
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
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
return b.join(", ");
|
|
236
|
-
}
|
|
237
|
-
function L(t, n) {
|
|
238
|
-
const e = p;
|
|
239
|
-
M(t);
|
|
240
|
-
try {
|
|
241
|
-
return n();
|
|
242
|
-
} finally {
|
|
243
|
-
M(e);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
function Y(t, n) {
|
|
247
|
-
const e = N;
|
|
248
|
-
S(t);
|
|
249
|
-
try {
|
|
250
|
-
return n();
|
|
251
|
-
} finally {
|
|
252
|
-
S(e);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
function M(t) {
|
|
256
|
-
p = t;
|
|
257
|
-
}
|
|
258
|
-
function S(t) {
|
|
259
|
-
N = t;
|
|
260
|
-
}
|
|
261
|
-
function j() {
|
|
262
|
-
return p;
|
|
263
|
-
}
|
|
264
|
-
function U() {
|
|
265
|
-
return N;
|
|
266
|
-
}
|
|
267
|
-
function w(t, n) {
|
|
268
|
-
return t === 0 || t < 0 && n(Math.abs(t)) === n(0) ? 0 : t;
|
|
269
|
-
}
|
|
270
|
-
export {
|
|
271
|
-
I as abbreviate,
|
|
272
|
-
H as clamp,
|
|
273
|
-
A as currency,
|
|
274
|
-
U as defaultCurrency,
|
|
275
|
-
j as defaultLocale,
|
|
276
|
-
G as fileSize,
|
|
277
|
-
E as forHumans,
|
|
278
|
-
a as format,
|
|
279
|
-
K as minutesToHuman,
|
|
280
|
-
R as ordinal,
|
|
281
|
-
k as pairs,
|
|
282
|
-
y as parse,
|
|
283
|
-
T as parseFloat,
|
|
284
|
-
O as parseInt,
|
|
285
|
-
z as percentage,
|
|
286
|
-
x as secondsToHuman,
|
|
287
|
-
$ as summarize,
|
|
288
|
-
C as trim,
|
|
289
|
-
S as useCurrency,
|
|
290
|
-
M as useLocale,
|
|
291
|
-
Y as withCurrency,
|
|
292
|
-
L as withLocale
|
|
293
|
-
};
|
|
1
|
+
import { InvalidArgumentException as e } from "@tolki/utils";
|
|
2
|
+
// src/num.ts
|
|
3
|
+
var t = "en", n = "USD";
|
|
4
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
5
|
+
function r(e, t = 0, n = null) {
|
|
6
|
+
return /* @__PURE__ */ f(e, t, n, !0);
|
|
7
|
+
}
|
|
8
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
9
|
+
function i(e, n = null, r = null, i = null) {
|
|
10
|
+
i ??= t;
|
|
11
|
+
let a = {
|
|
12
|
+
style: "decimal",
|
|
13
|
+
useGrouping: !0
|
|
14
|
+
};
|
|
15
|
+
r == null ? n != null && (a.minimumFractionDigits = n, a.maximumFractionDigits = n) : (a.maximumFractionDigits = r, a.minimumFractionDigits = 0);
|
|
16
|
+
let o = new Intl.NumberFormat(i, a);
|
|
17
|
+
return o.format(T(e, o.format));
|
|
18
|
+
}
|
|
19
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
20
|
+
function a(e, n = null) {
|
|
21
|
+
n ??= t;
|
|
22
|
+
let r = new Intl.NumberFormat(n).formatToParts(12345.6), i = /* @__PURE__ */ new Set(), a = ".";
|
|
23
|
+
for (let e of r) e.type === "group" ? i.add(e.value) : e.type === "decimal" && (a = e.value);
|
|
24
|
+
for (let e of [
|
|
25
|
+
"\xA0",
|
|
26
|
+
" ",
|
|
27
|
+
" "
|
|
28
|
+
]) i.add(e);
|
|
29
|
+
let o = e;
|
|
30
|
+
for (let e of i) {
|
|
31
|
+
let t = new RegExp(e.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"), "g");
|
|
32
|
+
o = o.replace(t, "");
|
|
33
|
+
}
|
|
34
|
+
if (a !== ".") {
|
|
35
|
+
let e = new RegExp(a.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"), "g"), t = o.lastIndexOf(a);
|
|
36
|
+
t !== -1 && (o = o.slice(0, t).replace(e, "") + "." + o.slice(t + a.length));
|
|
37
|
+
}
|
|
38
|
+
return o = o.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(o);
|
|
39
|
+
}
|
|
40
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
41
|
+
function o(e, t = null) {
|
|
42
|
+
let n = /* @__PURE__ */ a(e, t);
|
|
43
|
+
return Number.isNaN(n) ? !1 : n < 0 ? Math.ceil(n) : Math.floor(n);
|
|
44
|
+
}
|
|
45
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
46
|
+
function s(e, t = null) {
|
|
47
|
+
return /* @__PURE__ */ a(e, t);
|
|
48
|
+
}
|
|
49
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
50
|
+
function c(e, n = null) {
|
|
51
|
+
let r = n ?? t;
|
|
52
|
+
try {
|
|
53
|
+
let t = new Intl.PluralRules(r, { type: "ordinal" }).select(e), n = String(r.split("-")[0]), i = {
|
|
54
|
+
one: "st",
|
|
55
|
+
two: "nd",
|
|
56
|
+
few: "rd",
|
|
57
|
+
other: "th"
|
|
58
|
+
}, a = { en: i }[n] ?? i;
|
|
59
|
+
return `${e}${a[t] ?? a.other}`;
|
|
60
|
+
} catch {
|
|
61
|
+
let t = Math.abs(e), n = t % 100;
|
|
62
|
+
if (n >= 11 && n <= 13) return `${e}th`;
|
|
63
|
+
switch (t % 10) {
|
|
64
|
+
case 1: return `${e}st`;
|
|
65
|
+
case 2: return `${e}nd`;
|
|
66
|
+
case 3: return `${e}rd`;
|
|
67
|
+
default: return `${e}th`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
72
|
+
function l(e, n = 0, r = null, i = null) {
|
|
73
|
+
let o = i ?? t, s = typeof e == "string" ? /* @__PURE__ */ a(e, o) : e, c = {
|
|
74
|
+
style: "percent",
|
|
75
|
+
useGrouping: !0
|
|
76
|
+
};
|
|
77
|
+
r == null ? (c.minimumFractionDigits = n, c.maximumFractionDigits = n) : (c.maximumFractionDigits = r, c.minimumFractionDigits = 0);
|
|
78
|
+
let l = new Intl.NumberFormat(o, c);
|
|
79
|
+
return l.format(T(s / 100, l.format));
|
|
80
|
+
}
|
|
81
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
82
|
+
function u(e, r = "", i = null, o = null) {
|
|
83
|
+
let s = i ?? t, c = typeof e == "string" ? /* @__PURE__ */ a(e, s) : e, l = {
|
|
84
|
+
style: "currency",
|
|
85
|
+
currency: r && r.length ? r : n,
|
|
86
|
+
useGrouping: !0
|
|
87
|
+
};
|
|
88
|
+
o != null && (l.minimumFractionDigits = o, l.maximumFractionDigits = o);
|
|
89
|
+
let u = new Intl.NumberFormat(s, l);
|
|
90
|
+
return u.format(T(c, u.format));
|
|
91
|
+
}
|
|
92
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
93
|
+
function d(e, t = 0, n = null) {
|
|
94
|
+
let r = typeof e == "string" ? Number(e) : e;
|
|
95
|
+
if (!Number.isFinite(r)) return `${/* @__PURE__ */ i(r, t, n)} B`;
|
|
96
|
+
let a = [
|
|
97
|
+
"B",
|
|
98
|
+
"KB",
|
|
99
|
+
"MB",
|
|
100
|
+
"GB",
|
|
101
|
+
"TB",
|
|
102
|
+
"PB",
|
|
103
|
+
"EB",
|
|
104
|
+
"ZB",
|
|
105
|
+
"YB"
|
|
106
|
+
], o = a.length, s = 0;
|
|
107
|
+
for (; Math.abs(r) / 1024 > .9 && s < o - 1;) r /= 1024, s++;
|
|
108
|
+
return `${/* @__PURE__ */ i(r, t, n)} ${a[s]}`;
|
|
109
|
+
}
|
|
110
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
111
|
+
function f(e, t = 0, n = null, r = !1) {
|
|
112
|
+
return /* @__PURE__ */ p(e, t, n, r ? {} : {
|
|
113
|
+
3: " thousand",
|
|
114
|
+
6: " million",
|
|
115
|
+
9: " billion",
|
|
116
|
+
12: " trillion",
|
|
117
|
+
15: " quadrillion"
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
121
|
+
function p(e, t = 0, n = null, r = {}) {
|
|
122
|
+
if (!Number.isFinite(e)) return /* @__PURE__ */ i(e, t, n);
|
|
123
|
+
if (Object.keys(r).length === 0 && (r = {
|
|
124
|
+
3: "K",
|
|
125
|
+
6: "M",
|
|
126
|
+
9: "B",
|
|
127
|
+
12: "T",
|
|
128
|
+
15: "Q"
|
|
129
|
+
}), Number(e) === 0) return t > 0 ? /* @__PURE__ */ i(0, t, n) : "0";
|
|
130
|
+
if (e < 0) {
|
|
131
|
+
let i = /* @__PURE__ */ p(Math.abs(e), t, n, r);
|
|
132
|
+
return i === /* @__PURE__ */ p(0, t, n, r) ? i : `-${i}`;
|
|
133
|
+
}
|
|
134
|
+
if (e >= 0x38d7ea4c68000) {
|
|
135
|
+
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];
|
|
136
|
+
return `${/* @__PURE__ */ p(e / 0x38d7ea4c68000, t, n, r)}${o}`.trim();
|
|
137
|
+
}
|
|
138
|
+
let o = Math.floor(Math.log10(e)), s = Math.max(0, o - o % 3), c = e / 10 ** s, l;
|
|
139
|
+
if (l = n == null ? t > 0 ? /* @__PURE__ */ i(c, t, null) : s === 3 && c < 10 && Math.abs(e) % 10 == 0 ? /* @__PURE__ */ i(c, null, 1) : /* @__PURE__ */ i(c, 0, null) : /* @__PURE__ */ i(c, null, n), /* @__PURE__ */ a(l) >= 1e3 && r[s + 3] !== void 0) {
|
|
140
|
+
s += 3;
|
|
141
|
+
let e = c / 1e3;
|
|
142
|
+
l = n == null ? t > 0 ? /* @__PURE__ */ i(e, t, null) : /* @__PURE__ */ i(e, 0, null) : /* @__PURE__ */ i(e, null, n);
|
|
143
|
+
}
|
|
144
|
+
let u = r[s] ?? "";
|
|
145
|
+
return `${l}${u}`.trim();
|
|
146
|
+
}
|
|
147
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
148
|
+
function m(e, t, n) {
|
|
149
|
+
return Math.min(Math.max(e, t), n);
|
|
150
|
+
}
|
|
151
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
152
|
+
function h(t, n, r = 0, i = 1) {
|
|
153
|
+
if (n === 0) throw new e("The $by argument must not be zero.");
|
|
154
|
+
n = Math.abs(n);
|
|
155
|
+
let a = [], o = r;
|
|
156
|
+
for (; o < t; o += n) {
|
|
157
|
+
let e = o + n - i;
|
|
158
|
+
e > t && (e = t), a.push([o, e]);
|
|
159
|
+
}
|
|
160
|
+
let s = a.at(-1);
|
|
161
|
+
return s !== void 0 && o === t && s[1] < t && a.push([o, t]), a;
|
|
162
|
+
}
|
|
163
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
164
|
+
function g(e) {
|
|
165
|
+
return isFinite(e) ? JSON.parse(JSON.stringify(e)) : e;
|
|
166
|
+
}
|
|
167
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
168
|
+
function _(e, t = !0) {
|
|
169
|
+
return /* @__PURE__ */ v(Number(e) * 60, t);
|
|
170
|
+
}
|
|
171
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
172
|
+
function v(e, t = !0) {
|
|
173
|
+
let n = Number(e);
|
|
174
|
+
if ((!Number.isFinite(n) || n < 0) && (n = 0), n === 0) return "0 seconds";
|
|
175
|
+
let r = 3600, i = 24 * r, a = 7 * i, o = 4 * a, s = [
|
|
176
|
+
["year", 12 * o],
|
|
177
|
+
["month", o],
|
|
178
|
+
["week", a],
|
|
179
|
+
["day", i],
|
|
180
|
+
["hour", r],
|
|
181
|
+
["minute", 60],
|
|
182
|
+
["second", 1]
|
|
183
|
+
];
|
|
184
|
+
if (t) for (let [e, t] of s) {
|
|
185
|
+
let r = n / t;
|
|
186
|
+
if (r >= .5 || t === 1) {
|
|
187
|
+
let t = Math.round(r);
|
|
188
|
+
return `${t} ${e}${t === 1 ? "" : "s"}`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
let c = n, l = [];
|
|
192
|
+
for (let [e, t] of s) if (c >= t) {
|
|
193
|
+
let n = Math.floor(c / t);
|
|
194
|
+
c -= n * t, l.push(`${n} ${e}${n === 1 ? "" : "s"}`);
|
|
195
|
+
}
|
|
196
|
+
return l.join(", ");
|
|
197
|
+
}
|
|
198
|
+
function y(e, n) {
|
|
199
|
+
let r = t;
|
|
200
|
+
x(e);
|
|
201
|
+
try {
|
|
202
|
+
return n();
|
|
203
|
+
} finally {
|
|
204
|
+
x(r);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function b(e, t) {
|
|
208
|
+
let r = n;
|
|
209
|
+
S(e);
|
|
210
|
+
try {
|
|
211
|
+
return t();
|
|
212
|
+
} finally {
|
|
213
|
+
S(r);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function x(e) {
|
|
217
|
+
t = e;
|
|
218
|
+
}
|
|
219
|
+
function S(e) {
|
|
220
|
+
n = e;
|
|
221
|
+
}
|
|
222
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
223
|
+
function C() {
|
|
224
|
+
return t;
|
|
225
|
+
}
|
|
226
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
227
|
+
function w() {
|
|
228
|
+
return n;
|
|
229
|
+
}
|
|
230
|
+
function T(e, t) {
|
|
231
|
+
return e === 0 || e < 0 && t(Math.abs(e)) === t(0) ? 0 : e;
|
|
232
|
+
}
|
|
233
|
+
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/speller/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/speller/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;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;;;;;;;;;;GAUG;AAEH,wBAAsB,YAAY,CAC9B,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,OAAO,CAAC,MAAM,CAAC,CAKjB"}
|