@tolki/num 2.2.1 → 2.2.3

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