@tolki/num 1.0.0 → 1.0.2

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/index.js CHANGED
@@ -1,25 +1,26 @@
1
- import { clamp as a, currency as l, defaultCurrency as o, defaultLocale as n, fileSize as s, forHumans as u, format as t, minutesToHuman as c, ordinal as m, pairs as i, parse as p, parseFloat as f, parseInt as d, percentage as y, secondsToHuman as C, summarize as H, trim as L, useCurrency as h, useLocale as w, withCurrency as x, withLocale as z } from "./num.js";
2
- import { spell as g, spellOrdinal as F } from "./speller/index.js";
1
+ import { abbreviate as a, clamp as l, currency as o, defaultCurrency as n, defaultLocale as s, fileSize as t, forHumans as u, format as c, minutesToHuman as i, ordinal as m, pairs as p, parse as f, parseFloat as d, parseInt as y, percentage as C, secondsToHuman as H, summarize as L, trim as b, useCurrency as h, useLocale as w, withCurrency as x, withLocale as z } from "./num.js";
2
+ import { spell as g, spellOrdinal as v } from "./speller/index.js";
3
3
  export {
4
- a as clamp,
5
- l as currency,
6
- o as defaultCurrency,
7
- n as defaultLocale,
8
- s as fileSize,
4
+ a as abbreviate,
5
+ l as clamp,
6
+ o as currency,
7
+ n as defaultCurrency,
8
+ s as defaultLocale,
9
+ t as fileSize,
9
10
  u as forHumans,
10
- t as format,
11
- c as minutesToHuman,
11
+ c as format,
12
+ i as minutesToHuman,
12
13
  m as ordinal,
13
- i as pairs,
14
- p as parse,
15
- f as parseFloat,
16
- d as parseInt,
17
- y as percentage,
18
- C as secondsToHuman,
14
+ p as pairs,
15
+ f as parse,
16
+ d as parseFloat,
17
+ y as parseInt,
18
+ C as percentage,
19
+ H as secondsToHuman,
19
20
  g as spell,
20
- F as spellOrdinal,
21
- H as summarize,
22
- L as trim,
21
+ v as spellOrdinal,
22
+ L as summarize,
23
+ b as trim,
23
24
  h as useCurrency,
24
25
  w as useLocale,
25
26
  x as withCurrency,
package/dist/num.d.ts CHANGED
@@ -1,24 +1,31 @@
1
+ /**
2
+ * Convert the number to its human-readable equivalent.
3
+ *
4
+ * @param number - The number to convert.
5
+ * @param precision - The number of decimal places to use.
6
+ * @param maxPrecision - The maximum number of decimal places to use.
7
+ * @returns The human-readable number string.
8
+ *
9
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#abbreviate
10
+ */
11
+ export declare function abbreviate(number: number, precision?: number, maxPrecision?: number | null): string | false;
1
12
  /**
2
13
  * Format the given number according to the current locale.
3
14
  *
4
- * @param number The number to format.
5
- * @param precision The number of decimal places to use.
6
- * @param maxPrecision The maximum number of decimal places to use.
7
- * @param locale The locale to use for formatting.
15
+ * @param number - The number to format.
16
+ * @param precision - The number of decimal places to use.
17
+ * @param maxPrecision - The maximum number of decimal places to use.
18
+ * @param locale - The locale to use for formatting.
8
19
  * @returns The formatted number string.
9
20
  *
10
- * @example
11
- *
12
- * format(1234.5678, 2); // "1,234.57"
13
- * format(1234.5678, 2, 4); // "1,234.5678"
14
- * format(1234.5678, 2, 4, "de"); // "1.234,5678"
21
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#format
15
22
  */
16
23
  export declare function format(number: number, precision?: number | null, maxPrecision?: number | null, locale?: string | null): string | false;
17
24
  /**
18
25
  * Parse the given string according to the specified format type.
19
26
  *
20
- * @param value The string to parse.
21
- * @param locale The locale to use for parsing.
27
+ * @param value - The string to parse.
28
+ * @param locale - The locale to use for parsing.
22
29
  * @returns The parsed number.
23
30
  *
24
31
  * @example
@@ -29,106 +36,85 @@ export declare function parse(value: string, locale?: string | null): number;
29
36
  /**
30
37
  * Parse a string into an integer according to the specified locale.
31
38
  *
32
- * @param value The string to parse.
33
- * @param locale The locale to use for parsing.
39
+ * @param value - The string to parse.
40
+ * @param locale - The locale to use for parsing.
34
41
  * @returns The parsed integer or false if parsing fails.
35
42
  *
36
- * @example
37
- *
38
- * parseInt("1,234", "en"); // 1234
43
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#parseint
39
44
  */
40
45
  export declare function parseInt(value: string, locale?: string | null): number | false;
41
46
  /**
42
47
  * Parse a string into a float according to the specified locale.
43
48
  *
44
- * @param value The string to parse.
45
- * @param locale The locale to use for parsing.
49
+ * @param value - The string to parse.
50
+ * @param locale - The locale to use for parsing.
46
51
  * @returns The parsed float or false if parsing fails.
52
+ *
53
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#parsefloat
47
54
  */
48
55
  export declare function parseFloat(value: string, locale?: string | null): number | false;
49
56
  /**
50
57
  * Convert the given number to ordinal form.
51
58
  *
52
- * @param value The number to convert.
53
- * @param locale The locale to use for determining ordinal rules.
59
+ * @param value - The number to convert.
60
+ * @param locale - The locale to use for determining ordinal rules.
54
61
  * @returns The number in ordinal form.
55
62
  *
56
- * @example
57
- *
58
- * ordinal(1); // "1st"
59
- * ordinal(2); // "2nd"
60
- * ordinal(3); // "3rd"
61
- * ordinal(13); // "13th"
63
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#ordinal
62
64
  */
63
65
  export declare function ordinal(value: number, locale?: string | null): string;
64
66
  /**
65
67
  * Convert the given number to its percentage equivalent.
66
68
  *
67
- * @param number The number to convert.
68
- * @param precision The number of decimal places to use.
69
- * @param maxPrecision The maximum number of decimal places to use.
70
- * @param locale The locale to use for formatting.
69
+ * @param number - The number to convert.
70
+ * @param precision - The number of decimal places to use.
71
+ * @param maxPrecision - The maximum number of decimal places to use.
72
+ * @param locale - The locale to use for formatting.
71
73
  * @returns The formatted percentage string.
72
74
  *
73
- * @example
74
- *
75
- * percentage(1); // "1%"
76
- * percentage(1.75, 2); // "1.75%"
77
- * percentage(0.12345, 4); // "0.1235%"
75
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#percentage
78
76
  */
79
77
  export declare function percentage(number: number | string, precision?: number, maxPrecision?: number | null, locale?: string | null): string | false;
80
78
  /**
81
79
  * Convert the given number to its currency equivalent.
82
80
  *
83
- * @param amount The amount to convert.
84
- * @param currencyCode The currency code to use (e.g. "USD", "EUR").
85
- * @param locale The locale to use for formatting.
86
- * @param precision The number of decimal places to use.
81
+ * @param amount - The amount to convert.
82
+ * @param currencyCode - The currency code to use (e.g. "USD", "EUR").
83
+ * @param locale - The locale to use for formatting.
84
+ * @param precision - The number of decimal places to use.
87
85
  * @returns The formatted currency string.
88
86
  *
89
- * @example
90
- *
91
- * currency(5.00); // "$5.00"
92
- * currency(-5); // "-$5.00"
93
- * currency(10, 'EUR'); // "€10.00"
87
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#currency
94
88
  */
95
89
  export declare function currency(amount: number | string, currencyCode?: string, locale?: string | null, precision?: number | null): string | false;
96
90
  /**
97
91
  * Convert the given number to its file size equivalent.
98
92
  *
99
- * @param bytes The number of bytes.
100
- * @param precision The number of decimal places to use.
101
- * @param maxPrecision The maximum number of decimal places to use.
93
+ * @param bytes - The number of bytes.
94
+ * @param precision - The number of decimal places to use.
95
+ * @param maxPrecision - The maximum number of decimal places to use.
102
96
  * @returns The formatted file size string.
103
97
  *
104
- * @example
105
- *
106
- * fileSize(1024); // "1 KB"
107
- * fileSize(2048); // "2 KB"
108
- * fileSize(1264.12345, 3); // "1.234 KB"
98
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#filesize
109
99
  */
110
100
  export declare function fileSize(bytes: number | string, precision?: number, maxPrecision?: number | null): string;
111
101
  /**
112
102
  * Convert the number to its human-readable equivalent.
113
103
  *
114
- * @param value The number to convert.
115
- * @param precision The number of decimal places to use.
116
- * @param maxPrecision The maximum number of decimal places to use.
104
+ * @param value - The number to convert.
105
+ * @param precision - The number of decimal places to use.
106
+ * @param maxPrecision - The maximum number of decimal places to use.
117
107
  *
118
- * @example
119
- *
120
- * forHumans(1234); // "1.234 thousand"
121
- * forHumans(1234567); // "1.234 million"
122
- * forHumans(1234567890); // "1.234 billion"
108
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#forhumans
123
109
  */
124
110
  export declare function forHumans(value: number, precision?: number, maxPrecision?: number | null, abbreviate?: boolean): string | false;
125
111
  /**
126
112
  * Convert the number to its human-readable equivalent.
127
113
  *
128
- * @param value The number to convert.
129
- * @param precision The number of decimal places to use.
130
- * @param maxPrecision The maximum number of decimal places to use.
131
- * @param units Custom units mapping (exponent to suffix).
114
+ * @param value - The number to convert.
115
+ * @param precision - The number of decimal places to use.
116
+ * @param maxPrecision - The maximum number of decimal places to use.
117
+ * @param units - Custom units mapping (exponent to suffix).
132
118
  * @returns The summarized number string.
133
119
  *
134
120
  * @example
@@ -141,55 +127,43 @@ export declare function summarize(value: number, precision?: number, maxPrecisio
141
127
  /**
142
128
  * Clamp the given number between the given minimum and maximum.
143
129
  *
144
- * @param value The number to clamp.
145
- * @param min The minimum value.
146
- * @param max The maximum value.
130
+ * @param value - The number to clamp.
131
+ * @param min - The minimum value.
132
+ * @param max - The maximum value.
147
133
  * @returns The clamped number.
148
134
  *
149
- * @example
150
- *
151
- * clamp(5, 1, 10); // 5
152
- * clamp(0, 1, 10); // 1
153
- * clamp(15, 1, 10); // 10
135
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#clamp
154
136
  */
155
137
  export declare function clamp(value: number, min: number, max: number): number;
156
138
  /**
157
139
  * Split the given number into pairs of min/max values.
158
140
  *
159
- * @param to The maximum value.
160
- * @param by The size of each pair.
161
- * @param start The starting value.
162
- * @param offset The offset to apply to the upper bound of each pair.
141
+ * @param to - The maximum value.
142
+ * @param by - The size of each pair.
143
+ * @param start - The starting value.
144
+ * @param offset - The offset to apply to the upper bound of each pair.
163
145
  * @returns An array of [min, max] pairs.
164
146
  *
165
- * @example
166
- *
167
- * pairs(25, 10, 1, 1); // [[1, 11], [11, 21], [21, 25]]
147
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#pairs
168
148
  */
169
149
  export declare function pairs(to: number, by: number, start?: number, offset?: number): [number, number][];
170
150
  /**
171
151
  * Remove any trailing zero digits after the decimal point of the given number.
172
152
  *
173
- * @param value The number to trim.
153
+ * @param value - The number to trim.
174
154
  * @returns The trimmed number.
175
155
  *
176
- * @example
177
- *
178
- * trim(12.3456789); // 12.3456789
179
- * trim(12.34567890000); // 12.3456789
156
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#trim
180
157
  */
181
158
  export declare function trim(value: number): number;
182
159
  /**
183
160
  * Convert a duration in minutes to a human-readable format.
184
161
  *
185
- * @param minutes The duration in minutes.
186
- * @param round Whether to round to the nearest unit.
162
+ * @param minutes - The duration in minutes.
163
+ * @param round - Whether to round to the nearest unit.
187
164
  * @returns The human-readable duration string.
188
165
  *
189
- * @example
190
- *
191
- * minutesToHuman(61); // "1 hour"
192
- * minutesToHuman(61, false); // "1 hour, 1 minute"
166
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#minutestohuman
193
167
  */
194
168
  export declare function minutesToHuman(minutes: number | string, round?: boolean): string;
195
169
  /**
@@ -199,72 +173,61 @@ export declare function minutesToHuman(minutes: number | string, round?: boolean
199
173
  * @param round Whether to round to the nearest unit.
200
174
  * @returns The human-readable duration string.
201
175
  *
202
- * @example
203
- *
204
- * secondsToHuman(3661); // "1 hour"
205
- * secondsToHuman(3661, false); // "1 hour, 1 minute, 1 second"
176
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#secondstohuman
206
177
  */
207
178
  export declare function secondsToHuman(seconds: number | string, round?: boolean): string;
208
179
  /**
209
180
  * Execute the given callback using the given locale.
210
181
  *
211
- * @param locale The locale to use.
212
- * @param callback The callback to execute.
182
+ * @param locale - The locale to use.
183
+ * @param callback - The callback to execute.
213
184
  * @returns The result of the callback.
214
185
  *
215
- * @example
216
- *
217
- * withLocale("fr", () => {
218
- * return format(1234.56);
219
- * }); // "1 234,56"
186
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#withlocale
220
187
  */
221
- export declare function withLocale(locale: string, callback: () => unknown): unknown;
188
+ export declare function withLocale<TReturn>(locale: string, callback: () => TReturn): TReturn | void;
222
189
  /**
223
190
  * Execute the given callback using the given currency.
224
191
  *
225
- * @param currency The currency to use.
226
- * @param callback The callback to execute.
192
+ * @param currency - The currency to use.
193
+ * @param callback - The callback to execute.
227
194
  * @returns The result of the callback.
228
195
  *
229
- * @example
230
- *
231
- * withCurrency("EUR", () => {
232
- * return format(1234.56);
233
- * }); // "€1,234.56"
196
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#withcurrency
234
197
  */
235
- export declare function withCurrency(currency: string, callback: () => unknown): unknown;
198
+ export declare function withCurrency<TReturn>(currency: string, callback: () => TReturn): TReturn | void;
236
199
  /**
237
200
  * Set the default locale.
238
201
  *
239
- * @param locale The locale to set.
202
+ * @param locale - The locale to set.
240
203
  * @returns void
204
+ *
205
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#uselocale
241
206
  */
242
207
  export declare function useLocale(locale: string): void;
243
208
  /**
244
209
  * Set the default currency.
245
210
  *
246
- * @param currency The currency to set.
211
+ * @param currency - The currency to set.
247
212
  * @returns void
213
+ *
214
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#usecurrency
248
215
  */
249
216
  export declare function useCurrency(currency: string): void;
250
217
  /**
251
- * Get the default locale.
218
+ * Get the configured default locale.
252
219
  *
253
220
  * @returns The default locale.
254
221
  *
255
- * @example
256
- *
257
- * defaultLocale(); // "en"
222
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#defaultlocale
258
223
  */
259
224
  export declare function defaultLocale(): string;
260
225
  /**
261
- * Get the default currency.
226
+ * Get the configured default currency.
262
227
  *
263
228
  * @returns The default currency.
264
229
  *
265
- * @example
266
- *
267
- * defaultCurrency(); // "USD"
230
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#defaultcurrency
268
231
  */
269
232
  export declare function defaultCurrency(): string;
270
233
  //# sourceMappingURL=num.d.ts.map
package/dist/num.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../src/num.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAClB,MAAM,EAAE,MAAM,EAC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M,GAAE,MAAU,GACnB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAcpB;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,KAAK,GAAE,OAAc,GACtB,MAAM,CAIR;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,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,4 +1,7 @@
1
1
  let m = "en", y = "USD";
2
+ function x(t, n = 0, e = null) {
3
+ return D(t, n, e, !0);
4
+ }
2
5
  function g(t, n = null, e = null, r = null) {
3
6
  r = r ?? m;
4
7
  const o = {
@@ -13,38 +16,38 @@ function $(t, n = null) {
13
16
  let l = ".";
14
17
  for (const i of r)
15
18
  i.type === "group" ? o.add(i.value) : i.type === "decimal" && (l = i.value);
16
- const s = [" ", " ", " "];
17
- for (const i of s) o.add(i);
18
- let u = t;
19
+ const u = [" ", " ", " "];
20
+ for (const i of u) o.add(i);
21
+ let s = t;
19
22
  for (const i of o) {
20
23
  const c = new RegExp(
21
24
  i.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
22
25
  "g"
23
26
  );
24
- u = u.replace(c, "");
27
+ s = s.replace(c, "");
25
28
  }
26
29
  if (l !== ".") {
27
30
  const i = new RegExp(
28
31
  l.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
29
32
  "g"
30
- ), c = u.lastIndexOf(l);
31
- c !== -1 && (u = u.slice(0, c).replace(i, "") + "." + u.slice(c + l.length));
33
+ ), c = s.lastIndexOf(l);
34
+ c !== -1 && (s = s.slice(0, c).replace(i, "") + "." + s.slice(c + l.length));
32
35
  }
33
- return u = u.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(u);
36
+ return s = s.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(s);
34
37
  }
35
- function S(t, n = null) {
38
+ function E(t, n = null) {
36
39
  const e = $(t, n);
37
40
  return Number.isNaN(e) ? !1 : e < 0 ? Math.ceil(e) : Math.floor(e);
38
41
  }
39
- function x(t, n = null) {
42
+ function B(t, n = null) {
40
43
  return $(t, n);
41
44
  }
42
- function E(t, n = null) {
45
+ function O(t, n = null) {
43
46
  const e = n ?? m;
44
47
  try {
45
- const o = new Intl.PluralRules(e, { type: "ordinal" }).select(t), l = e.split("-")[0] || "en", s = {
48
+ const o = new Intl.PluralRules(e, { type: "ordinal" }).select(t), l = e.split("-")[0] || "en", u = {
46
49
  en: { one: "st", two: "nd", few: "rd", other: "th" }
47
- }, u = s[l] ?? s.en, p = u[o] ?? u.other;
50
+ }, s = u[l] ?? u.en, p = s[o] ?? s.other;
48
51
  return `${t}${p}`;
49
52
  } catch {
50
53
  const r = Math.abs(t), o = r % 100;
@@ -62,22 +65,22 @@ function E(t, n = null) {
62
65
  }
63
66
  }
64
67
  }
65
- function B(t, n = 0, e = null, r = null) {
66
- const o = r ?? m, l = typeof t == "string" ? $(t, o) : t, s = {
68
+ function I(t, n = 0, e = null, r = null) {
69
+ const o = r ?? m, l = typeof t == "string" ? $(t, o) : t, u = {
67
70
  style: "percent",
68
71
  useGrouping: !0
69
72
  };
70
- return e != null ? (s.maximumFractionDigits = e, s.minimumFractionDigits = 0) : (s.minimumFractionDigits = n, s.maximumFractionDigits = n), new Intl.NumberFormat(o, s).format(l / 100);
73
+ return e != null ? (u.maximumFractionDigits = e, u.minimumFractionDigits = 0) : (u.minimumFractionDigits = n, u.maximumFractionDigits = n), new Intl.NumberFormat(o, u).format(l / 100);
71
74
  }
72
- function O(t, n = "", e = null, r = null) {
73
- const o = e ?? m, l = typeof t == "string" ? $(t, o) : t, u = {
75
+ function T(t, n = "", e = null, r = null) {
76
+ const o = e ?? m, l = typeof t == "string" ? $(t, o) : t, s = {
74
77
  style: "currency",
75
78
  currency: n && n.length ? n : y,
76
79
  useGrouping: !0
77
80
  };
78
- return r != null && (u.minimumFractionDigits = r, u.maximumFractionDigits = r), new Intl.NumberFormat(o, u).format(l);
81
+ return r != null && (s.minimumFractionDigits = r, s.maximumFractionDigits = r), new Intl.NumberFormat(o, s).format(l);
79
82
  }
80
- function I(t, n = 0, e = null) {
83
+ function R(t, n = 0, e = null) {
81
84
  let r = typeof t == "string" ? Number(t) : t;
82
85
  Number.isFinite(r) || (r = 0);
83
86
  const o = [
@@ -91,12 +94,12 @@ function I(t, n = 0, e = null) {
91
94
  "ZB",
92
95
  "YB"
93
96
  ], l = o.length;
94
- let s = 0;
95
- for (; r / 1024 > 0.9 && s < l - 1; )
96
- r /= 1024, s++;
97
- return `${g(r, n, e)} ${o[s]}`;
97
+ let u = 0;
98
+ for (; r / 1024 > 0.9 && u < l - 1; )
99
+ r /= 1024, u++;
100
+ return `${g(r, n, e)} ${o[u]}`;
98
101
  }
99
- function T(t, n = 0, e = null, r = !1) {
102
+ function D(t, n = 0, e = null, r = !1) {
100
103
  return b(
101
104
  t,
102
105
  n,
@@ -135,45 +138,45 @@ function b(t, n = 0, e = null, r = {}) {
135
138
  r
136
139
  )}${h}`.trim();
137
140
  }
138
- const o = Math.floor(Math.log10(t)), l = o - o % 3, s = t / Math.pow(10, l);
139
- let u;
141
+ const o = Math.floor(Math.log10(t)), l = o - o % 3, u = t / Math.pow(10, l);
142
+ let s;
140
143
  if (e != null)
141
- u = g(s, null, e);
144
+ s = g(u, null, e);
142
145
  else if (n > 0)
143
- u = g(s, n, null);
146
+ s = g(u, n, null);
144
147
  else {
145
148
  const i = Math.abs(t);
146
- u = l === 3 && s < 10 && i % 10 === 0 ? g(s, null, 1) : g(s, 0, null);
149
+ s = l === 3 && u < 10 && i % 10 === 0 ? g(u, null, 1) : g(u, 0, null);
147
150
  }
148
151
  const p = r[l] ?? "";
149
- return `${u}${p}`.trim();
152
+ return `${s}${p}`.trim();
150
153
  }
151
- function R(t, n, e) {
154
+ function G(t, n, e) {
152
155
  return Math.min(Math.max(t, n), e);
153
156
  }
154
- function G(t, n, e = 0, r = 1) {
157
+ function H(t, n, e = 0, r = 1) {
155
158
  const o = [];
156
159
  for (let l = e; l < t; l += n) {
157
- let s = l + n - r;
158
- s > t && (s = t), o.push([l, s]);
160
+ let u = l + n - r;
161
+ u > t && (u = t), o.push([l, u]);
159
162
  }
160
163
  return o;
161
164
  }
162
- function H(t) {
165
+ function k(t) {
163
166
  return JSON.parse(JSON.stringify(t));
164
167
  }
165
- function k(t, n = !0) {
168
+ function A(t, n = !0) {
166
169
  const e = Number(t) * 60;
167
- return D(e, n);
170
+ return S(e, n);
168
171
  }
169
- function D(t, n = !0) {
172
+ function S(t, n = !0) {
170
173
  let e = Number(t);
171
174
  if ((!Number.isFinite(e) || e < 0) && (e = 0), e === 0) return "0 seconds";
172
- const r = 1, o = 60 * r, l = 60 * o, s = 24 * l, u = 7 * s, p = 4 * u, c = [
175
+ const r = 1, o = 60 * r, l = 60 * o, u = 24 * l, s = 7 * u, p = 4 * s, c = [
173
176
  ["year", 12 * p],
174
177
  ["month", p],
175
- ["week", u],
176
- ["day", s],
178
+ ["week", s],
179
+ ["day", u],
177
180
  ["hour", l],
178
181
  ["minute", o],
179
182
  ["second", r]
@@ -195,7 +198,7 @@ function D(t, n = !0) {
195
198
  }
196
199
  return N.join(", ");
197
200
  }
198
- function A(t, n) {
201
+ function C(t, n) {
199
202
  const e = m;
200
203
  w(t);
201
204
  try {
@@ -204,7 +207,7 @@ function A(t, n) {
204
207
  w(e);
205
208
  }
206
209
  }
207
- function C(t, n) {
210
+ function K(t, n) {
208
211
  const e = y;
209
212
  M(t);
210
213
  try {
@@ -219,32 +222,33 @@ function w(t) {
219
222
  function M(t) {
220
223
  y = t;
221
224
  }
222
- function K() {
225
+ function L() {
223
226
  return m;
224
227
  }
225
- function L() {
228
+ function Y() {
226
229
  return y;
227
230
  }
228
231
  export {
229
- R as clamp,
230
- O as currency,
231
- L as defaultCurrency,
232
- K as defaultLocale,
233
- I as fileSize,
234
- T as forHumans,
232
+ x as abbreviate,
233
+ G as clamp,
234
+ T as currency,
235
+ Y as defaultCurrency,
236
+ L as defaultLocale,
237
+ R as fileSize,
238
+ D as forHumans,
235
239
  g as format,
236
- k as minutesToHuman,
237
- E as ordinal,
238
- G as pairs,
240
+ A as minutesToHuman,
241
+ O as ordinal,
242
+ H as pairs,
239
243
  $ as parse,
240
- x as parseFloat,
241
- S as parseInt,
242
- B as percentage,
243
- D as secondsToHuman,
244
+ B as parseFloat,
245
+ E as parseInt,
246
+ I as percentage,
247
+ S as secondsToHuman,
244
248
  b as summarize,
245
- H as trim,
249
+ k as trim,
246
250
  M as useCurrency,
247
251
  w as useLocale,
248
- C as withCurrency,
249
- A as withLocale
252
+ K as withCurrency,
253
+ C as withLocale
250
254
  };
@@ -15,20 +15,14 @@
15
15
  *
16
16
  * @requires {@link https://www.npmjs.com/package/to-words to-words package}
17
17
  *
18
- * @example
19
- *
20
- * spell(123); // "One Hundred Twenty Three"
21
- * spell(123.45); // "One Hundred Twenty Three Point Forty Five"
22
- * spell(5, null, 10); // "5" (5 <= 10, so formatted instead of spelled)
23
- * spell(11, null, 10); // "Eleven" (11 > 10, so spelled out)
24
- * spell(100, null, null, 50); // "100" (100 >= 50, so formatted instead of spelled)
25
- * spell(49, null, null, 50); // "Forty Nine" (49 < 50, so spelled out)
18
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#spell
26
19
  */
27
20
  export declare function spell(number: number | string, locale?: string | null, after?: number | null, until?: number | null): string;
28
21
  /**
29
22
  * Spell out the given number in the given locale in ordinal form.
30
23
  *
31
- * Note: The to-words package doesn't have native ordinal support, so this
24
+ * TODO - Implement true ordinal conversion for all supported locales.
25
+ * The to-words package doesn't have native ordinal support, so this
32
26
  * function spells out the cardinal number. True ordinal conversion would
33
27
  * require locale-specific suffix rules (e.g., "first", "second", "third").
34
28
  *
@@ -38,11 +32,7 @@ export declare function spell(number: number | string, locale?: string | null, a
38
32
  *
39
33
  * @requires {@link https://www.npmjs.com/package/to-words to-words package}
40
34
  *
41
- * @example
42
- *
43
- * spellOrdinal(1); // "One"
44
- * spellOrdinal(2); // "Two"
45
- * spellOrdinal(21); // "Twenty One"
35
+ * @see https://tolki.abe.dev/numbers/number-utilities-list.html#spellordinal
46
36
  */
47
37
  export declare function spellOrdinal(value: number, locale?: string | null): string;
48
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/speller/index.ts"],"names":[],"mappings":"AA6EA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,KAAK,CACjB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,KAAK,GAAE,MAAM,GAAG,IAAW,EAC3B,KAAK,GAAE,MAAM,GAAG,IAAW,GAC5B,MAAM,CAwBR;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAcR"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/speller/index.ts"],"names":[],"mappings":"AA6EA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CACjB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,KAAK,GAAE,MAAM,GAAG,IAAW,EAC3B,KAAK,GAAE,MAAM,GAAG,IAAW,GAC5B,MAAM,CAwBR;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAcR"}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@tolki/num",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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",
7
+ "homepage": "https://tolki.abe.dev/numbers/",
7
8
  "repository": {
8
9
  "type": "git",
9
10
  "url": "git+https://github.com/abetwothree/tolki.git",
@@ -27,10 +28,10 @@
27
28
  "@tolki/utils": "^1.0.0"
28
29
  },
29
30
  "devDependencies": {
30
- "to-words": "^4.7.0"
31
+ "to-words": "^4.10.0"
31
32
  },
32
33
  "peerDependencies": {
33
- "to-words": "^4.7.0"
34
+ "to-words": "^4.10.0"
34
35
  },
35
36
  "files": [
36
37
  "dist"