@tolki/num 2.0.5 → 2.2.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,5 +1,5 @@
1
1
  let p = "en", $ = "USD";
2
- function x(t, n = 0, e = null) {
2
+ function E(t, n = 0, e = null) {
3
3
  return S(t, n, e, !0);
4
4
  }
5
5
  function f(t, n = null, e = null, r = null) {
@@ -13,46 +13,46 @@ function f(t, n = null, e = null, r = null) {
13
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 = ".";
16
+ let l = ".";
17
17
  for (const i of r)
18
- i.type === "group" ? o.add(i.value) : i.type === "decimal" && (s = i.value);
18
+ i.type === "group" ? o.add(i.value) : i.type === "decimal" && (l = i.value);
19
19
  const u = [" ", " ", " "];
20
20
  for (const i of u) o.add(i);
21
- let l = t;
21
+ let s = t;
22
22
  for (const i of o) {
23
23
  const c = new RegExp(
24
24
  i.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
25
25
  "g"
26
26
  );
27
- l = l.replace(c, "");
27
+ s = s.replace(c, "");
28
28
  }
29
- if (s !== ".") {
29
+ if (l !== ".") {
30
30
  const i = new RegExp(
31
- s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
31
+ l.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
32
32
  "g"
33
- ), c = l.lastIndexOf(s);
34
- c !== -1 && (l = l.slice(0, c).replace(i, "") + "." + l.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 l = l.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(l);
36
+ return s = s.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(s);
37
37
  }
38
- function E(t, n = null) {
38
+ function B(t, n = null) {
39
39
  const e = y(t, n);
40
40
  return Number.isNaN(e) ? !1 : e < 0 ? Math.ceil(e) : Math.floor(e);
41
41
  }
42
- function B(t, n = null) {
42
+ function x(t, n = null) {
43
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
53
  }, m = {
54
54
  en: u
55
- }[s] ?? u, i = m[o] ?? m.other;
55
+ }[l] ?? u, i = m[o] ?? m.other;
56
56
  return `${t}${i}`;
57
57
  } catch {
58
58
  const r = Math.abs(t), o = r % 100;
@@ -71,23 +71,24 @@ 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" ? y(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" ? y(t, o) : t, l = {
81
+ const o = e ?? p, l = typeof t == "string" ? y(t, o) : t, s = {
82
82
  style: "currency",
83
83
  currency: n && n.length ? n : $,
84
84
  useGrouping: !0
85
85
  };
86
- return r != null && (l.minimumFractionDigits = r, l.maximumFractionDigits = r), new Intl.NumberFormat(o, l).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;
90
- Number.isFinite(r) || (r = 0);
90
+ if (!Number.isFinite(r))
91
+ return `${f(r, n, e)} B`;
91
92
  const o = [
92
93
  "B",
93
94
  "KB",
@@ -98,14 +99,14 @@ function R(t, n = 0, e = null) {
98
99
  "EB",
99
100
  "ZB",
100
101
  "YB"
101
- ], s = o.length;
102
+ ], l = o.length;
102
103
  let u = 0;
103
- for (; r / 1024 > 0.9 && u < s - 1; )
104
+ for (; Math.abs(r) / 1024 > 0.9 && u < l - 1; )
104
105
  r /= 1024, u++;
105
106
  return `${f(r, n, e)} ${o[u]}`;
106
107
  }
107
108
  function S(t, n = 0, e = null, r = !1) {
108
- return b(
109
+ return N(
109
110
  t,
110
111
  n,
111
112
  e,
@@ -118,7 +119,9 @@ function S(t, n = 0, e = null, r = !1) {
118
119
  }
119
120
  );
120
121
  }
121
- function b(t, n = 0, e = null, r = {}) {
122
+ function N(t, n = 0, e = null, r = {}) {
123
+ if (!Number.isFinite(t))
124
+ return f(t, n, e);
122
125
  if (Object.keys(r).length === 0 && (r = {
123
126
  3: "K",
124
127
  6: "M",
@@ -128,7 +131,7 @@ function b(t, n = 0, e = null, r = {}) {
128
131
  }), Number(t) === 0)
129
132
  return n > 0 ? f(0, n, e) : "0";
130
133
  if (t < 0)
131
- return `-${b(
134
+ return `-${N(
132
135
  Math.abs(t),
133
136
  n,
134
137
  e,
@@ -136,7 +139,7 @@ function b(t, n = 0, e = null, r = {}) {
136
139
  )}`;
137
140
  if (t >= 1e15) {
138
141
  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 `${b(
142
+ return `${N(
140
143
  t / 1e15,
141
144
  n,
142
145
  e,
@@ -144,52 +147,55 @@ function b(t, n = 0, e = null, r = {}) {
144
147
  )}${h}`.trim();
145
148
  }
146
149
  const o = Math.floor(Math.log10(t));
147
- let s = o - o % 3;
148
- const u = t / Math.pow(10, s);
149
- let l;
150
+ let l = o - o % 3;
151
+ const u = t / Math.pow(10, l);
152
+ let s;
150
153
  if (e != null)
151
- l = f(u, null, e);
154
+ s = f(u, null, e);
152
155
  else if (n > 0)
153
- l = f(u, n, null);
156
+ s = f(u, n, null);
154
157
  else {
155
158
  const i = Math.abs(t);
156
- l = s === 3 && u < 10 && i % 10 === 0 ? f(u, null, 1) : f(u, 0, null);
159
+ s = l === 3 && u < 10 && i % 10 === 0 ? f(u, null, 1) : f(u, 0, null);
157
160
  }
158
- if (y(l) >= 1e3 && r[s + 3] !== void 0) {
159
- s += 3;
161
+ if (y(s) >= 1e3 && r[l + 3] !== void 0) {
162
+ l += 3;
160
163
  const i = u / 1e3;
161
- e != null ? l = f(i, null, e) : n > 0 ? l = f(i, n, null) : l = f(i, 0, null);
164
+ e != null ? s = f(i, null, e) : n > 0 ? s = f(i, n, null) : s = f(i, 0, null);
162
165
  }
163
- const m = r[s] ?? "";
164
- return `${l}${m}`.trim();
166
+ const m = r[l] ?? "";
167
+ return `${s}${m}`.trim();
165
168
  }
166
169
  function G(t, n, e) {
167
170
  return Math.min(Math.max(t, n), e);
168
171
  }
169
172
  function H(t, n, e = 0, r = 1) {
173
+ if (n === 0)
174
+ throw new Error("The 'by' argument must not be zero.");
175
+ n = Math.abs(n);
170
176
  const o = [];
171
- for (let s = e; s < t; s += n) {
172
- let u = s + n - r;
173
- u > t && (u = t), o.push([s, u]);
177
+ for (let l = e; l < t; l += n) {
178
+ let u = l + n - r;
179
+ u > t && (u = t), o.push([l, u]);
174
180
  }
175
181
  return o;
176
182
  }
177
183
  function k(t) {
178
- return JSON.parse(JSON.stringify(t));
184
+ return isFinite(t) ? JSON.parse(JSON.stringify(t)) : t;
179
185
  }
180
- function A(t, n = !0) {
186
+ function z(t, n = !0) {
181
187
  const e = Number(t) * 60;
182
188
  return D(e, n);
183
189
  }
184
190
  function D(t, n = !0) {
185
191
  let e = Number(t);
186
192
  if ((!Number.isFinite(e) || e < 0) && (e = 0), e === 0) return "0 seconds";
187
- const r = 1, o = 60 * r, s = 60 * o, u = 24 * s, l = 7 * u, m = 4 * l, c = [
193
+ const r = 1, o = 60 * r, l = 60 * o, u = 24 * l, s = 7 * u, m = 4 * s, c = [
188
194
  ["year", 12 * m],
189
195
  ["month", m],
190
- ["week", l],
196
+ ["week", s],
191
197
  ["day", u],
192
- ["hour", s],
198
+ ["hour", l],
193
199
  ["minute", o],
194
200
  ["second", r]
195
201
  ];
@@ -202,15 +208,15 @@ function D(t, n = !0) {
202
208
  }
203
209
  }
204
210
  let h = e;
205
- const N = [];
211
+ const b = [];
206
212
  for (const [a, d] of c)
207
213
  if (h >= d) {
208
214
  const g = Math.floor(h / d);
209
- h -= g * d, N.push(`${g} ${a}${g === 1 ? "" : "s"}`);
215
+ h -= g * d, b.push(`${g} ${a}${g === 1 ? "" : "s"}`);
210
216
  }
211
- return N.join(", ");
217
+ return b.join(", ");
212
218
  }
213
- function C(t, n) {
219
+ function A(t, n) {
214
220
  const e = p;
215
221
  F(t);
216
222
  try {
@@ -219,7 +225,7 @@ function C(t, n) {
219
225
  F(e);
220
226
  }
221
227
  }
222
- function K(t, n) {
228
+ function C(t, n) {
223
229
  const e = $;
224
230
  M(t);
225
231
  try {
@@ -234,33 +240,33 @@ function F(t) {
234
240
  function M(t) {
235
241
  $ = t;
236
242
  }
237
- function L() {
243
+ function K() {
238
244
  return p;
239
245
  }
240
- function Y() {
246
+ function L() {
241
247
  return $;
242
248
  }
243
249
  export {
244
- x as abbreviate,
250
+ E as abbreviate,
245
251
  G as clamp,
246
252
  T as currency,
247
- Y as defaultCurrency,
248
- L as defaultLocale,
253
+ L as defaultCurrency,
254
+ K as defaultLocale,
249
255
  R as fileSize,
250
256
  S as forHumans,
251
257
  f as format,
252
- A as minutesToHuman,
258
+ z as minutesToHuman,
253
259
  O as ordinal,
254
260
  H as pairs,
255
261
  y as parse,
256
- B as parseFloat,
257
- E as parseInt,
262
+ x as parseFloat,
263
+ B as parseInt,
258
264
  I as percentage,
259
265
  D as secondsToHuman,
260
- b as summarize,
266
+ N as summarize,
261
267
  k as trim,
262
268
  M as useCurrency,
263
269
  F as useLocale,
264
- K as withCurrency,
265
- C as withLocale
270
+ C as withCurrency,
271
+ A as withLocale
266
272
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/num",
3
- "version": "2.0.5",
3
+ "version": "2.2.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",