@tolki/num 2.0.4 → 2.1.0

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
@@ -62,7 +62,7 @@ However, if you are working on a backend project where bundle size is not a conc
62
62
 
63
63
  These are the number utilities that can be used independently as single functions.
64
64
 
65
- [abbreviate](#abbreviate) [clamp](#clamp) [currency](#currency) [defaultCurrency](#defaultcurrency) [defaultLocale](#defaultlocale) [fileSize](#filesize) [forHumans](#forhumans) [format](#format) [minutesToHuman](#minutestohuman) [ordinal](#ordinal) [pairs](#pairs) [parseFloat](#parsefloat) [parseInt](#parseint) [percentage](#percentage) [spell](#spell) [spellOrdinal](#spellordinal) [secondsToHuman](#secondstohuman) [trim](#trim) [useLocale](#uselocale) [withLocale](#withlocale) [useCurrency](#usecurrency) [withCurrency](#withcurrency)
65
+ [abbreviate](#abbreviate) [clamp](#clamp) [currency](#currency) [defaultCurrency](#defaultcurrency) [defaultLocale](#defaultlocale) [fileSize](#filesize) [forHumans](#forhumans) [format](#format) [minutesToHuman](#minutestohuman) [ordinal](#ordinal) [pairs](#pairs) [parse](#parse) [parseFloat](#parsefloat) [parseInt](#parseint) [percentage](#percentage) [spell](#spell) [spellOrdinal](#spellordinal) [secondsToHuman](#secondstohuman) [trim](#trim) [useLocale](#uselocale) [withLocale](#withlocale) [useCurrency](#usecurrency) [withCurrency](#withcurrency)
66
66
 
67
67
  ### Number Utilities Details
68
68
 
@@ -278,6 +278,22 @@ const result2 = pairs(25, 10, 0, 0);
278
278
  // result2 is [[0, 10], [10, 20], [20, 25]]
279
279
  ```
280
280
 
281
+ #### parse
282
+
283
+ Parse a localized numeric string into a number.
284
+
285
+ ```javascript
286
+ import { parse } from "@tolki/num";
287
+
288
+ const result = parse("10,123", "en");
289
+
290
+ // result is 10123
291
+
292
+ const result2 = parse("10,123", "fr");
293
+
294
+ // result2 is 10.123
295
+ ```
296
+
281
297
  #### parseInt
282
298
 
283
299
  Parse a string into an integer according to the specified locale.
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,GAAG,IAAW,GAC7B,MAAM,GAAG,KAAK,CAqBhB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,C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BAAgB,eAAe,IAAI,MAAM,CAExC"}
package/dist/num.js CHANGED
@@ -1,8 +1,8 @@
1
- let p = "en", y = "USD";
1
+ let p = "en", $ = "USD";
2
2
  function x(t, n = 0, e = null) {
3
- return D(t, n, e, !0);
3
+ return S(t, n, e, !0);
4
4
  }
5
- function g(t, n = null, e = null, r = null) {
5
+ function f(t, n = null, e = null, r = null) {
6
6
  r = r ?? p;
7
7
  const o = {
8
8
  style: "decimal",
@@ -10,50 +10,50 @@ function g(t, n = null, e = null, r = null) {
10
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
12
  }
13
- function $(t, n = null) {
13
+ function y(t, n = null) {
14
14
  n = n ?? p;
15
15
  const r = new Intl.NumberFormat(n).formatToParts(12345.6), o = /* @__PURE__ */ new Set();
16
- let s = ".";
17
- for (const l of r)
18
- l.type === "group" ? o.add(l.value) : l.type === "decimal" && (s = l.value);
16
+ let l = ".";
17
+ for (const i of r)
18
+ i.type === "group" ? o.add(i.value) : i.type === "decimal" && (l = i.value);
19
19
  const u = [" ", " ", " "];
20
- for (const l of u) o.add(l);
21
- let i = t;
22
- for (const l of o) {
20
+ for (const i of u) o.add(i);
21
+ let s = t;
22
+ for (const i of o) {
23
23
  const c = new RegExp(
24
- l.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
24
+ i.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
25
25
  "g"
26
26
  );
27
- i = i.replace(c, "");
27
+ s = s.replace(c, "");
28
28
  }
29
- if (s !== ".") {
30
- const l = new RegExp(
31
- s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
29
+ if (l !== ".") {
30
+ const i = new RegExp(
31
+ l.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
32
32
  "g"
33
- ), c = i.lastIndexOf(s);
34
- c !== -1 && (i = i.slice(0, c).replace(l, "") + "." + i.slice(c + s.length));
33
+ ), c = s.lastIndexOf(l);
34
+ c !== -1 && (s = s.slice(0, c).replace(i, "") + "." + s.slice(c + l.length));
35
35
  }
36
- return i = i.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(i);
36
+ return s = s.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(s);
37
37
  }
38
38
  function E(t, n = null) {
39
- const e = $(t, n);
39
+ const e = y(t, n);
40
40
  return Number.isNaN(e) ? !1 : e < 0 ? Math.ceil(e) : Math.floor(e);
41
41
  }
42
42
  function B(t, n = null) {
43
- return $(t, n);
43
+ return y(t, n);
44
44
  }
45
45
  function O(t, n = null) {
46
46
  const e = n ?? p;
47
47
  try {
48
- const o = new Intl.PluralRules(e, { type: "ordinal" }).select(t), s = String(e.split("-")[0]), u = {
48
+ const o = new Intl.PluralRules(e, { type: "ordinal" }).select(t), l = String(e.split("-")[0]), u = {
49
49
  one: "st",
50
50
  two: "nd",
51
51
  few: "rd",
52
52
  other: "th"
53
- }, f = {
53
+ }, m = {
54
54
  en: u
55
- }[s] ?? u, l = f[o] ?? f.other;
56
- return `${t}${l}`;
55
+ }[l] ?? u, i = m[o] ?? m.other;
56
+ return `${t}${i}`;
57
57
  } catch {
58
58
  const r = Math.abs(t), o = r % 100;
59
59
  if (o >= 11 && o <= 13)
@@ -71,19 +71,19 @@ function O(t, n = null) {
71
71
  }
72
72
  }
73
73
  function I(t, n = 0, e = null, r = null) {
74
- const o = r ?? p, s = typeof t == "string" ? $(t, o) : t, u = {
74
+ const o = r ?? p, l = typeof t == "string" ? y(t, o) : t, u = {
75
75
  style: "percent",
76
76
  useGrouping: !0
77
77
  };
78
- return e != null ? (u.maximumFractionDigits = e, u.minimumFractionDigits = 0) : (u.minimumFractionDigits = n, u.maximumFractionDigits = n), new Intl.NumberFormat(o, u).format(s / 100);
78
+ return e != null ? (u.maximumFractionDigits = e, u.minimumFractionDigits = 0) : (u.minimumFractionDigits = n, u.maximumFractionDigits = n), new Intl.NumberFormat(o, u).format(l / 100);
79
79
  }
80
80
  function T(t, n = "", e = null, r = null) {
81
- const o = e ?? p, s = typeof t == "string" ? $(t, o) : t, i = {
81
+ const o = e ?? p, l = typeof t == "string" ? y(t, o) : t, s = {
82
82
  style: "currency",
83
- currency: n && n.length ? n : y,
83
+ currency: n && n.length ? n : $,
84
84
  useGrouping: !0
85
85
  };
86
- return r != null && (i.minimumFractionDigits = r, i.maximumFractionDigits = r), new Intl.NumberFormat(o, i).format(s);
86
+ return r != null && (s.minimumFractionDigits = r, s.maximumFractionDigits = r), new Intl.NumberFormat(o, s).format(l);
87
87
  }
88
88
  function R(t, n = 0, e = null) {
89
89
  let r = typeof t == "string" ? Number(t) : t;
@@ -98,14 +98,14 @@ function R(t, n = 0, e = null) {
98
98
  "EB",
99
99
  "ZB",
100
100
  "YB"
101
- ], s = o.length;
101
+ ], l = o.length;
102
102
  let u = 0;
103
- for (; r / 1024 > 0.9 && u < s - 1; )
103
+ for (; Math.abs(r) / 1024 > 0.9 && u < l - 1; )
104
104
  r /= 1024, u++;
105
- return `${g(r, n, e)} ${o[u]}`;
105
+ return `${f(r, n, e)} ${o[u]}`;
106
106
  }
107
- function D(t, n = 0, e = null, r = !1) {
108
- return b(
107
+ function S(t, n = 0, e = null, r = !1) {
108
+ return N(
109
109
  t,
110
110
  n,
111
111
  e,
@@ -118,7 +118,7 @@ function D(t, n = 0, e = null, r = !1) {
118
118
  }
119
119
  );
120
120
  }
121
- function b(t, n = 0, e = null, r = {}) {
121
+ function N(t, n = 0, e = null, r = {}) {
122
122
  if (Object.keys(r).length === 0 && (r = {
123
123
  3: "K",
124
124
  6: "M",
@@ -126,94 +126,104 @@ function b(t, n = 0, e = null, r = {}) {
126
126
  12: "T",
127
127
  15: "Q"
128
128
  }), Number(t) === 0)
129
- return n > 0 ? g(0, n, e) : "0";
129
+ return n > 0 ? f(0, n, e) : "0";
130
130
  if (t < 0)
131
- return `-${b(
131
+ return `-${N(
132
132
  Math.abs(t),
133
133
  n,
134
134
  e,
135
135
  r
136
136
  )}`;
137
137
  if (t >= 1e15) {
138
- const l = Object.keys(r).map((a) => Number(a)).filter((a) => !Number.isNaN(a)).sort((a, m) => a - m), c = l[l.length - 1], h = r[c];
139
- return `${b(
138
+ 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];
139
+ return `${N(
140
140
  t / 1e15,
141
141
  n,
142
142
  e,
143
143
  r
144
144
  )}${h}`.trim();
145
145
  }
146
- const o = Math.floor(Math.log10(t)), s = o - o % 3, u = t / Math.pow(10, s);
147
- let i;
146
+ const o = Math.floor(Math.log10(t));
147
+ let l = o - o % 3;
148
+ const u = t / Math.pow(10, l);
149
+ let s;
148
150
  if (e != null)
149
- i = g(u, null, e);
151
+ s = f(u, null, e);
150
152
  else if (n > 0)
151
- i = g(u, n, null);
153
+ s = f(u, n, null);
152
154
  else {
153
- const l = Math.abs(t);
154
- i = s === 3 && u < 10 && l % 10 === 0 ? g(u, null, 1) : g(u, 0, null);
155
+ const i = Math.abs(t);
156
+ s = l === 3 && u < 10 && i % 10 === 0 ? f(u, null, 1) : f(u, 0, null);
155
157
  }
156
- const f = r[s] ?? "";
157
- return `${i}${f}`.trim();
158
+ if (y(s) >= 1e3 && r[l + 3] !== void 0) {
159
+ l += 3;
160
+ const i = u / 1e3;
161
+ e != null ? s = f(i, null, e) : n > 0 ? s = f(i, n, null) : s = f(i, 0, null);
162
+ }
163
+ const m = r[l] ?? "";
164
+ return `${s}${m}`.trim();
158
165
  }
159
166
  function G(t, n, e) {
160
167
  return Math.min(Math.max(t, n), e);
161
168
  }
162
169
  function H(t, n, e = 0, r = 1) {
170
+ if (n === 0)
171
+ throw new Error("The $by argument must not be zero.");
172
+ n = Math.abs(n);
163
173
  const o = [];
164
- for (let s = e; s < t; s += n) {
165
- let u = s + n - r;
166
- u > t && (u = t), o.push([s, u]);
174
+ for (let l = e; l < t; l += n) {
175
+ let u = l + n - r;
176
+ u > t && (u = t), o.push([l, u]);
167
177
  }
168
178
  return o;
169
179
  }
170
180
  function k(t) {
171
- return JSON.parse(JSON.stringify(t));
181
+ return isFinite(t) ? JSON.parse(JSON.stringify(t)) : t;
172
182
  }
173
- function A(t, n = !0) {
183
+ function z(t, n = !0) {
174
184
  const e = Number(t) * 60;
175
- return S(e, n);
185
+ return D(e, n);
176
186
  }
177
- function S(t, n = !0) {
187
+ function D(t, n = !0) {
178
188
  let e = Number(t);
179
189
  if ((!Number.isFinite(e) || e < 0) && (e = 0), e === 0) return "0 seconds";
180
- const r = 1, o = 60 * r, s = 60 * o, u = 24 * s, i = 7 * u, f = 4 * i, c = [
181
- ["year", 12 * f],
182
- ["month", f],
183
- ["week", i],
190
+ const r = 1, o = 60 * r, l = 60 * o, u = 24 * l, s = 7 * u, m = 4 * s, c = [
191
+ ["year", 12 * m],
192
+ ["month", m],
193
+ ["week", s],
184
194
  ["day", u],
185
- ["hour", s],
195
+ ["hour", l],
186
196
  ["minute", o],
187
197
  ["second", r]
188
198
  ];
189
199
  if (n)
190
- for (const [a, m] of c) {
191
- const d = e / m;
192
- if (d >= 0.5 || m === r) {
193
- const F = Math.round(d);
194
- return `${F} ${a}${F === 1 ? "" : "s"}`;
200
+ for (const [a, d] of c) {
201
+ const g = e / d;
202
+ if (g >= 0.5 || d === r) {
203
+ const w = Math.round(g);
204
+ return `${w} ${a}${w === 1 ? "" : "s"}`;
195
205
  }
196
206
  }
197
207
  let h = e;
198
- const N = [];
199
- for (const [a, m] of c)
200
- if (h >= m) {
201
- const d = Math.floor(h / m);
202
- h -= d * m, N.push(`${d} ${a}${d === 1 ? "" : "s"}`);
208
+ const b = [];
209
+ for (const [a, d] of c)
210
+ if (h >= d) {
211
+ const g = Math.floor(h / d);
212
+ h -= g * d, b.push(`${g} ${a}${g === 1 ? "" : "s"}`);
203
213
  }
204
- return N.join(", ");
214
+ return b.join(", ");
205
215
  }
206
- function C(t, n) {
216
+ function A(t, n) {
207
217
  const e = p;
208
- w(t);
218
+ F(t);
209
219
  try {
210
220
  return n();
211
221
  } finally {
212
- w(e);
222
+ F(e);
213
223
  }
214
224
  }
215
- function K(t, n) {
216
- const e = y;
225
+ function C(t, n) {
226
+ const e = $;
217
227
  M(t);
218
228
  try {
219
229
  return n();
@@ -221,39 +231,39 @@ function K(t, n) {
221
231
  M(e);
222
232
  }
223
233
  }
224
- function w(t) {
234
+ function F(t) {
225
235
  p = t;
226
236
  }
227
237
  function M(t) {
228
- y = t;
238
+ $ = t;
229
239
  }
230
- function L() {
240
+ function K() {
231
241
  return p;
232
242
  }
233
- function Y() {
234
- return y;
243
+ function L() {
244
+ return $;
235
245
  }
236
246
  export {
237
247
  x as abbreviate,
238
248
  G as clamp,
239
249
  T as currency,
240
- Y as defaultCurrency,
241
- L as defaultLocale,
250
+ L as defaultCurrency,
251
+ K as defaultLocale,
242
252
  R as fileSize,
243
- D as forHumans,
244
- g as format,
245
- A as minutesToHuman,
253
+ S as forHumans,
254
+ f as format,
255
+ z as minutesToHuman,
246
256
  O as ordinal,
247
257
  H as pairs,
248
- $ as parse,
258
+ y as parse,
249
259
  B as parseFloat,
250
260
  E as parseInt,
251
261
  I as percentage,
252
- S as secondsToHuman,
253
- b as summarize,
262
+ D as secondsToHuman,
263
+ N as summarize,
254
264
  k as trim,
255
265
  M as useCurrency,
256
- w as useLocale,
257
- K as withCurrency,
258
- C as withLocale
266
+ F as useLocale,
267
+ C as withCurrency,
268
+ A as withLocale
259
269
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/num",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
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",