@tolki/num 2.2.2 → 2.2.4

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