@zinaid/num 0.0.5 → 0.0.7
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 +11 -11
- package/dist/num.d.ts +88 -19
- package/dist/num.d.ts.map +1 -1
- package/dist/num.js +62 -70
- package/dist/speller/index.d.ts +28 -0
- package/dist/speller/index.d.ts.map +1 -0
- package/dist/speller/index.js +21 -0
- package/package.json +17 -4
- package/dist/speller.d.ts +0 -7
- package/dist/speller.d.ts.map +0 -1
- package/dist/speller.js +0 -20
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 p, parse as i, parseFloat as f, parseInt as d, percentage as y, secondsToHuman as C,
|
|
2
|
-
import { Speller as F } from "./speller.js";
|
|
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 p, parse as i, 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 { Speller as T, spell as g, spellOrdinal as F } from "./speller/index.js";
|
|
3
3
|
export {
|
|
4
|
-
|
|
4
|
+
T as Speller,
|
|
5
5
|
a as clamp,
|
|
6
6
|
l as currency,
|
|
7
7
|
o as defaultCurrency,
|
|
@@ -17,12 +17,12 @@ export {
|
|
|
17
17
|
d as parseInt,
|
|
18
18
|
y as percentage,
|
|
19
19
|
C as secondsToHuman,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
g as spell,
|
|
21
|
+
F as spellOrdinal,
|
|
22
|
+
H as summarize,
|
|
23
|
+
L as trim,
|
|
24
|
+
h as useCurrency,
|
|
25
|
+
w as useLocale,
|
|
26
|
+
x as withCurrency,
|
|
27
|
+
z as withLocale
|
|
28
28
|
};
|
package/dist/num.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Format the given number according to the current locale.
|
|
3
3
|
*
|
|
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.
|
|
8
|
+
* @returns The formatted number string.
|
|
9
|
+
*
|
|
4
10
|
* @example
|
|
5
11
|
*
|
|
6
12
|
* format(1234.5678, 2); // "1,234.57"
|
|
@@ -11,6 +17,10 @@ export declare function format(number: number, precision?: number | null, maxPre
|
|
|
11
17
|
/**
|
|
12
18
|
* Parse the given string according to the specified format type.
|
|
13
19
|
*
|
|
20
|
+
* @param value The string to parse.
|
|
21
|
+
* @param locale The locale to use for parsing.
|
|
22
|
+
* @returns The parsed number.
|
|
23
|
+
*
|
|
14
24
|
* @example
|
|
15
25
|
*
|
|
16
26
|
* parse("1,234.57"); // 1234.57
|
|
@@ -19,6 +29,10 @@ export declare function parse(value: string, locale?: string | null): number;
|
|
|
19
29
|
/**
|
|
20
30
|
* Parse a string into an integer according to the specified locale.
|
|
21
31
|
*
|
|
32
|
+
* @param value The string to parse.
|
|
33
|
+
* @param locale The locale to use for parsing.
|
|
34
|
+
* @returns The parsed integer or false if parsing fails.
|
|
35
|
+
*
|
|
22
36
|
* @example
|
|
23
37
|
*
|
|
24
38
|
* parseInt("1,234", "en"); // 1234
|
|
@@ -27,19 +41,18 @@ export declare function parseInt(value: string, locale?: string | null): number
|
|
|
27
41
|
/**
|
|
28
42
|
* Parse a string into a float according to the specified locale.
|
|
29
43
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @
|
|
44
|
+
* @param value The string to parse.
|
|
45
|
+
* @param locale The locale to use for parsing.
|
|
46
|
+
* @returns The parsed float or false if parsing fails.
|
|
33
47
|
*/
|
|
34
48
|
export declare function parseFloat(value: string, locale?: string | null): number | false;
|
|
35
|
-
/**
|
|
36
|
-
* Spell out the given number in the given locale.
|
|
37
|
-
* @todo
|
|
38
|
-
*/
|
|
39
|
-
export declare function spell(_number: number | string, _locale?: string | null, _after?: number | null, _until?: number | null): string;
|
|
40
49
|
/**
|
|
41
50
|
* Convert the given number to ordinal form.
|
|
42
51
|
*
|
|
52
|
+
* @param value The number to convert.
|
|
53
|
+
* @param locale The locale to use for determining ordinal rules.
|
|
54
|
+
* @returns The number in ordinal form.
|
|
55
|
+
*
|
|
43
56
|
* @example
|
|
44
57
|
*
|
|
45
58
|
* ordinal(1); // "1st"
|
|
@@ -48,20 +61,15 @@ export declare function spell(_number: number | string, _locale?: string | null,
|
|
|
48
61
|
* ordinal(13); // "13th"
|
|
49
62
|
*/
|
|
50
63
|
export declare function ordinal(value: number, locale?: string | null): string;
|
|
51
|
-
/**
|
|
52
|
-
* Spell out the given number in the given locale in ordinal form.
|
|
53
|
-
* @todo
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
*
|
|
57
|
-
* spellOrdinal(1); // "first"
|
|
58
|
-
* spellOrdinal(2); // "second"
|
|
59
|
-
* spellOrdinal(3); // "third"
|
|
60
|
-
*/
|
|
61
|
-
export declare function spellOrdinal(_value: number, _locale?: string | null): string;
|
|
62
64
|
/**
|
|
63
65
|
* Convert the given number to its percentage equivalent.
|
|
64
66
|
*
|
|
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.
|
|
71
|
+
* @returns The formatted percentage string.
|
|
72
|
+
*
|
|
65
73
|
* @example
|
|
66
74
|
*
|
|
67
75
|
* percentage(1); // "1%"
|
|
@@ -72,6 +80,12 @@ export declare function percentage(number: number | string, precision?: number,
|
|
|
72
80
|
/**
|
|
73
81
|
* Convert the given number to its currency equivalent.
|
|
74
82
|
*
|
|
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.
|
|
87
|
+
* @returns The formatted currency string.
|
|
88
|
+
*
|
|
75
89
|
* @example
|
|
76
90
|
*
|
|
77
91
|
* currency(5.00); // "$5.00"
|
|
@@ -82,6 +96,11 @@ export declare function currency(amount: number | string, currencyCode?: string,
|
|
|
82
96
|
/**
|
|
83
97
|
* Convert the given number to its file size equivalent.
|
|
84
98
|
*
|
|
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.
|
|
102
|
+
* @returns The formatted file size string.
|
|
103
|
+
*
|
|
85
104
|
* @example
|
|
86
105
|
*
|
|
87
106
|
* fileSize(1024); // "1 KB"
|
|
@@ -92,6 +111,10 @@ export declare function fileSize(bytes: number | string, precision?: number, max
|
|
|
92
111
|
/**
|
|
93
112
|
* Convert the number to its human-readable equivalent.
|
|
94
113
|
*
|
|
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
|
+
*
|
|
95
118
|
* @example
|
|
96
119
|
*
|
|
97
120
|
* forHumans(1234); // "1.234 thousand"
|
|
@@ -102,6 +125,12 @@ export declare function forHumans(value: number, precision?: number, maxPrecisio
|
|
|
102
125
|
/**
|
|
103
126
|
* Convert the number to its human-readable equivalent.
|
|
104
127
|
*
|
|
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).
|
|
132
|
+
* @returns The summarized number string.
|
|
133
|
+
*
|
|
105
134
|
* @example
|
|
106
135
|
*
|
|
107
136
|
* summarize(1234); // "1.234 K"
|
|
@@ -112,6 +141,11 @@ export declare function summarize(value: number, precision?: number, maxPrecisio
|
|
|
112
141
|
/**
|
|
113
142
|
* Clamp the given number between the given minimum and maximum.
|
|
114
143
|
*
|
|
144
|
+
* @param value The number to clamp.
|
|
145
|
+
* @param min The minimum value.
|
|
146
|
+
* @param max The maximum value.
|
|
147
|
+
* @returns The clamped number.
|
|
148
|
+
*
|
|
115
149
|
* @example
|
|
116
150
|
*
|
|
117
151
|
* clamp(5, 1, 10); // 5
|
|
@@ -122,6 +156,12 @@ export declare function clamp(value: number, min: number, max: number): number;
|
|
|
122
156
|
/**
|
|
123
157
|
* Split the given number into pairs of min/max values.
|
|
124
158
|
*
|
|
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.
|
|
163
|
+
* @returns An array of [min, max] pairs.
|
|
164
|
+
*
|
|
125
165
|
* @example
|
|
126
166
|
*
|
|
127
167
|
* pairs(25, 10, 1, 1); // [[1, 11], [11, 21], [21, 25]]
|
|
@@ -130,6 +170,9 @@ export declare function pairs(to: number, by: number, start?: number, offset?: n
|
|
|
130
170
|
/**
|
|
131
171
|
* Remove any trailing zero digits after the decimal point of the given number.
|
|
132
172
|
*
|
|
173
|
+
* @param value The number to trim.
|
|
174
|
+
* @returns The trimmed number.
|
|
175
|
+
*
|
|
133
176
|
* @example
|
|
134
177
|
*
|
|
135
178
|
* trim(12.3456789); // 12.3456789
|
|
@@ -165,6 +208,10 @@ export declare function secondsToHuman(seconds: number | string, round?: boolean
|
|
|
165
208
|
/**
|
|
166
209
|
* Execute the given callback using the given locale.
|
|
167
210
|
*
|
|
211
|
+
* @param locale The locale to use.
|
|
212
|
+
* @param callback The callback to execute.
|
|
213
|
+
* @returns The result of the callback.
|
|
214
|
+
*
|
|
168
215
|
* @example
|
|
169
216
|
*
|
|
170
217
|
* withLocale("fr", () => {
|
|
@@ -175,6 +222,10 @@ export declare function withLocale(locale: string, callback: () => unknown): unk
|
|
|
175
222
|
/**
|
|
176
223
|
* Execute the given callback using the given currency.
|
|
177
224
|
*
|
|
225
|
+
* @param currency The currency to use.
|
|
226
|
+
* @param callback The callback to execute.
|
|
227
|
+
* @returns The result of the callback.
|
|
228
|
+
*
|
|
178
229
|
* @example
|
|
179
230
|
*
|
|
180
231
|
* withCurrency("EUR", () => {
|
|
@@ -184,18 +235,36 @@ export declare function withLocale(locale: string, callback: () => unknown): unk
|
|
|
184
235
|
export declare function withCurrency(currency: string, callback: () => unknown): unknown;
|
|
185
236
|
/**
|
|
186
237
|
* Set the default locale.
|
|
238
|
+
*
|
|
239
|
+
* @param locale The locale to set.
|
|
240
|
+
* @returns void
|
|
187
241
|
*/
|
|
188
242
|
export declare function useLocale(locale: string): void;
|
|
189
243
|
/**
|
|
190
244
|
* Set the default currency.
|
|
245
|
+
*
|
|
246
|
+
* @param currency The currency to set.
|
|
247
|
+
* @returns void
|
|
191
248
|
*/
|
|
192
249
|
export declare function useCurrency(currency: string): void;
|
|
193
250
|
/**
|
|
194
251
|
* Get the default locale.
|
|
252
|
+
*
|
|
253
|
+
* @returns The default locale.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
*
|
|
257
|
+
* defaultLocale(); // "en"
|
|
195
258
|
*/
|
|
196
259
|
export declare function defaultLocale(): string;
|
|
197
260
|
/**
|
|
198
261
|
* Get the default currency.
|
|
262
|
+
*
|
|
263
|
+
* @returns The default currency.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
*
|
|
267
|
+
* defaultCurrency(); // "USD"
|
|
199
268
|
*/
|
|
200
269
|
export declare function defaultCurrency(): string;
|
|
201
270
|
//# 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":"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AgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,GAAG,OAAO,CAU3E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,OAAO,GACxB,OAAO,CAUT;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAElD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
|
package/dist/num.js
CHANGED
|
@@ -10,27 +10,27 @@ function g(t, n = null, e = null, r = null) {
|
|
|
10
10
|
function $(t, n = null) {
|
|
11
11
|
n = n ?? m;
|
|
12
12
|
const r = new Intl.NumberFormat(n).formatToParts(12345.6), o = /* @__PURE__ */ new Set();
|
|
13
|
-
let
|
|
13
|
+
let l = ".";
|
|
14
14
|
for (const i of r)
|
|
15
|
-
i.type === "group" ? o.add(i.value) : i.type === "decimal" && (
|
|
16
|
-
const
|
|
17
|
-
for (const i of
|
|
18
|
-
let
|
|
15
|
+
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
19
|
for (const i of o) {
|
|
20
20
|
const c = new RegExp(
|
|
21
21
|
i.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
|
|
22
22
|
"g"
|
|
23
23
|
);
|
|
24
|
-
|
|
24
|
+
u = u.replace(c, "");
|
|
25
25
|
}
|
|
26
|
-
if (
|
|
26
|
+
if (l !== ".") {
|
|
27
27
|
const i = new RegExp(
|
|
28
|
-
|
|
28
|
+
l.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"),
|
|
29
29
|
"g"
|
|
30
|
-
), c =
|
|
31
|
-
c !== -1 && (
|
|
30
|
+
), c = u.lastIndexOf(l);
|
|
31
|
+
c !== -1 && (u = u.slice(0, c).replace(i, "") + "." + u.slice(c + l.length));
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return u = u.replace(/[\s\u00A0\u202F\u2009]+/g, "").trim(), globalThis.Number(u);
|
|
34
34
|
}
|
|
35
35
|
function S(t, n = null) {
|
|
36
36
|
const e = $(t, n);
|
|
@@ -39,15 +39,12 @@ function S(t, n = null) {
|
|
|
39
39
|
function x(t, n = null) {
|
|
40
40
|
return $(t, n);
|
|
41
41
|
}
|
|
42
|
-
function E(t, n = null
|
|
43
|
-
return "";
|
|
44
|
-
}
|
|
45
|
-
function O(t, n = null) {
|
|
42
|
+
function E(t, n = null) {
|
|
46
43
|
const e = n ?? m;
|
|
47
44
|
try {
|
|
48
|
-
const o = new Intl.PluralRules(e, { type: "ordinal" }).select(t),
|
|
45
|
+
const o = new Intl.PluralRules(e, { type: "ordinal" }).select(t), l = e.split("-")[0] || "en", s = {
|
|
49
46
|
en: { one: "st", two: "nd", few: "rd", other: "th" }
|
|
50
|
-
},
|
|
47
|
+
}, u = s[l] ?? s.en, p = u[o] ?? u.other;
|
|
51
48
|
return `${t}${p}`;
|
|
52
49
|
} catch {
|
|
53
50
|
const r = Math.abs(t), o = r % 100;
|
|
@@ -65,25 +62,22 @@ function O(t, n = null) {
|
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
64
|
}
|
|
68
|
-
function B(t, n = null) {
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
function I(t, n = 0, e = null, r = null) {
|
|
72
|
-
const o = r ?? m, s = typeof t == "string" ? $(t, o) : t, u = {
|
|
65
|
+
function B(t, n = 0, e = null, r = null) {
|
|
66
|
+
const o = r ?? m, l = typeof t == "string" ? $(t, o) : t, s = {
|
|
73
67
|
style: "percent",
|
|
74
68
|
useGrouping: !0
|
|
75
69
|
};
|
|
76
|
-
return e != null ? (
|
|
70
|
+
return e != null ? (s.maximumFractionDigits = e, s.minimumFractionDigits = 0) : (s.minimumFractionDigits = n, s.maximumFractionDigits = n), new Intl.NumberFormat(o, s).format(l / 100);
|
|
77
71
|
}
|
|
78
|
-
function
|
|
79
|
-
const o = e ?? m,
|
|
72
|
+
function O(t, n = "", e = null, r = null) {
|
|
73
|
+
const o = e ?? m, l = typeof t == "string" ? $(t, o) : t, u = {
|
|
80
74
|
style: "currency",
|
|
81
75
|
currency: n && n.length ? n : y,
|
|
82
76
|
useGrouping: !0
|
|
83
77
|
};
|
|
84
|
-
return r != null && (
|
|
78
|
+
return r != null && (u.minimumFractionDigits = r, u.maximumFractionDigits = r), new Intl.NumberFormat(o, u).format(l);
|
|
85
79
|
}
|
|
86
|
-
function
|
|
80
|
+
function I(t, n = 0, e = null) {
|
|
87
81
|
let r = typeof t == "string" ? Number(t) : t;
|
|
88
82
|
Number.isFinite(r) || (r = 0);
|
|
89
83
|
const o = [
|
|
@@ -96,13 +90,13 @@ function _(t, n = 0, e = null) {
|
|
|
96
90
|
"EB",
|
|
97
91
|
"ZB",
|
|
98
92
|
"YB"
|
|
99
|
-
],
|
|
100
|
-
let
|
|
101
|
-
for (; r / 1024 > 0.9 &&
|
|
102
|
-
r /= 1024,
|
|
103
|
-
return `${g(r, n, e)} ${o[
|
|
93
|
+
], 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]}`;
|
|
104
98
|
}
|
|
105
|
-
function
|
|
99
|
+
function T(t, n = 0, e = null, r = !1) {
|
|
106
100
|
return b(
|
|
107
101
|
t,
|
|
108
102
|
n,
|
|
@@ -141,46 +135,46 @@ function b(t, n = 0, e = null, r = {}) {
|
|
|
141
135
|
r
|
|
142
136
|
)}${h}`.trim();
|
|
143
137
|
}
|
|
144
|
-
const o = Math.floor(Math.log10(t)),
|
|
145
|
-
let
|
|
138
|
+
const o = Math.floor(Math.log10(t)), l = o - o % 3, s = t / Math.pow(10, l);
|
|
139
|
+
let u;
|
|
146
140
|
if (e != null)
|
|
147
|
-
|
|
141
|
+
u = g(s, null, e);
|
|
148
142
|
else if (n > 0)
|
|
149
|
-
|
|
143
|
+
u = g(s, n, null);
|
|
150
144
|
else {
|
|
151
145
|
const i = Math.abs(t);
|
|
152
|
-
|
|
146
|
+
u = l === 3 && s < 10 && i % 10 === 0 ? g(s, null, 1) : g(s, 0, null);
|
|
153
147
|
}
|
|
154
|
-
const p = r[
|
|
155
|
-
return `${
|
|
148
|
+
const p = r[l] ?? "";
|
|
149
|
+
return `${u}${p}`.trim();
|
|
156
150
|
}
|
|
157
|
-
function
|
|
151
|
+
function R(t, n, e) {
|
|
158
152
|
return Math.min(Math.max(t, n), e);
|
|
159
153
|
}
|
|
160
|
-
function
|
|
154
|
+
function G(t, n, e = 0, r = 1) {
|
|
161
155
|
const o = [];
|
|
162
|
-
for (let
|
|
163
|
-
let
|
|
164
|
-
|
|
156
|
+
for (let l = e; l < t; l += n) {
|
|
157
|
+
let s = l + n - r;
|
|
158
|
+
s > t && (s = t), o.push([l, s]);
|
|
165
159
|
}
|
|
166
160
|
return o;
|
|
167
161
|
}
|
|
168
|
-
function
|
|
162
|
+
function H(t) {
|
|
169
163
|
return JSON.parse(JSON.stringify(t));
|
|
170
164
|
}
|
|
171
|
-
function
|
|
165
|
+
function k(t, n = !0) {
|
|
172
166
|
const e = Number(t) * 60;
|
|
173
167
|
return D(e, n);
|
|
174
168
|
}
|
|
175
169
|
function D(t, n = !0) {
|
|
176
170
|
let e = Number(t);
|
|
177
171
|
if ((!Number.isFinite(e) || e < 0) && (e = 0), e === 0) return "0 seconds";
|
|
178
|
-
const r = 1, o = 60 * r,
|
|
172
|
+
const r = 1, o = 60 * r, l = 60 * o, s = 24 * l, u = 7 * s, p = 4 * u, c = [
|
|
179
173
|
["year", 12 * p],
|
|
180
174
|
["month", p],
|
|
181
|
-
["week",
|
|
182
|
-
["day",
|
|
183
|
-
["hour",
|
|
175
|
+
["week", u],
|
|
176
|
+
["day", s],
|
|
177
|
+
["hour", l],
|
|
184
178
|
["minute", o],
|
|
185
179
|
["second", r]
|
|
186
180
|
];
|
|
@@ -201,7 +195,7 @@ function D(t, n = !0) {
|
|
|
201
195
|
}
|
|
202
196
|
return N.join(", ");
|
|
203
197
|
}
|
|
204
|
-
function
|
|
198
|
+
function A(t, n) {
|
|
205
199
|
const e = m;
|
|
206
200
|
w(t);
|
|
207
201
|
try {
|
|
@@ -210,7 +204,7 @@ function C(t, n) {
|
|
|
210
204
|
w(e);
|
|
211
205
|
}
|
|
212
206
|
}
|
|
213
|
-
function
|
|
207
|
+
function C(t, n) {
|
|
214
208
|
const e = y;
|
|
215
209
|
M(t);
|
|
216
210
|
try {
|
|
@@ -225,34 +219,32 @@ function w(t) {
|
|
|
225
219
|
function M(t) {
|
|
226
220
|
y = t;
|
|
227
221
|
}
|
|
228
|
-
function
|
|
222
|
+
function K() {
|
|
229
223
|
return m;
|
|
230
224
|
}
|
|
231
|
-
function
|
|
225
|
+
function L() {
|
|
232
226
|
return y;
|
|
233
227
|
}
|
|
234
228
|
export {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
229
|
+
R as clamp,
|
|
230
|
+
O as currency,
|
|
231
|
+
L as defaultCurrency,
|
|
232
|
+
K as defaultLocale,
|
|
233
|
+
I as fileSize,
|
|
234
|
+
T as forHumans,
|
|
241
235
|
g as format,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
236
|
+
k as minutesToHuman,
|
|
237
|
+
E as ordinal,
|
|
238
|
+
G as pairs,
|
|
245
239
|
$ as parse,
|
|
246
240
|
x as parseFloat,
|
|
247
241
|
S as parseInt,
|
|
248
|
-
|
|
242
|
+
B as percentage,
|
|
249
243
|
D as secondsToHuman,
|
|
250
|
-
E as spell,
|
|
251
|
-
B as spellOrdinal,
|
|
252
244
|
b as summarize,
|
|
253
|
-
|
|
245
|
+
H as trim,
|
|
254
246
|
M as useCurrency,
|
|
255
247
|
w as useLocale,
|
|
256
|
-
|
|
257
|
-
|
|
248
|
+
C as withCurrency,
|
|
249
|
+
A as withLocale
|
|
258
250
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ToWords as ToWordsType, ToWords } from 'to-words';
|
|
2
|
+
export declare class Speller {
|
|
3
|
+
protected toWords: ToWordsType | undefined;
|
|
4
|
+
protected getToWords(): ToWords;
|
|
5
|
+
spellNumber(num: number): string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Spell out the given number in the given locale.
|
|
9
|
+
*
|
|
10
|
+
* @todo
|
|
11
|
+
*
|
|
12
|
+
* @requires {@link https://www.npmjs.com/package/to-words to-words package}
|
|
13
|
+
*/
|
|
14
|
+
export declare function spell(_number: number | string, _locale?: string | null, _after?: number | null, _until?: number | null): string;
|
|
15
|
+
/**
|
|
16
|
+
* Spell out the given number in the given locale in ordinal form.
|
|
17
|
+
* @todo
|
|
18
|
+
*
|
|
19
|
+
* @requires {@link https://www.npmjs.com/package/to-words to-words package}
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
*
|
|
23
|
+
* spellOrdinal(1); // "first"
|
|
24
|
+
* spellOrdinal(2); // "second"
|
|
25
|
+
* spellOrdinal(3); // "third"
|
|
26
|
+
*/
|
|
27
|
+
export declare function spellOrdinal(_value: number, _locale?: string | null): string;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/speller/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,qBAAa,OAAO;IAChB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;IAE3C,SAAS,CAAC,UAAU,IAAI,OAAO;IAOxB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAG1C;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CACjB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,OAAO,GAAE,MAAM,GAAG,IAAW,EAC7B,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAMR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CACxB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,MAAM,GAAG,IAAW,GAC9B,MAAM,CAIR"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ToWords as o } from "to-words";
|
|
2
|
+
class s {
|
|
3
|
+
toWords;
|
|
4
|
+
getToWords() {
|
|
5
|
+
return this.toWords || (this.toWords = new o()), this.toWords;
|
|
6
|
+
}
|
|
7
|
+
spellNumber(l) {
|
|
8
|
+
return this.getToWords().convert(l);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function u(r, l = null, t = null, e = null) {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
function i(r, l = null) {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
s as Speller,
|
|
19
|
+
u as spell,
|
|
20
|
+
i as spellOrdinal
|
|
21
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zinaid/num",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Utilities for working with numbers similar to Laravel's Num class facade.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,9 +11,17 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@zinaid/utils": "^0.0.4"
|
|
13
13
|
},
|
|
14
|
-
"
|
|
14
|
+
"devDependencies": {
|
|
15
15
|
"to-words": "^4.7.0"
|
|
16
16
|
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"to-words": "^4.7.0"
|
|
19
|
+
},
|
|
20
|
+
"peerDependenciesMeta": {
|
|
21
|
+
"to-words": {
|
|
22
|
+
"optional": true
|
|
23
|
+
}
|
|
24
|
+
},
|
|
17
25
|
"files": [
|
|
18
26
|
"dist"
|
|
19
27
|
],
|
|
@@ -27,13 +35,18 @@
|
|
|
27
35
|
"require": "./dist/index.js",
|
|
28
36
|
"types": "./dist/index.d.ts"
|
|
29
37
|
},
|
|
38
|
+
"./*": {
|
|
39
|
+
"import": "./dist/*",
|
|
40
|
+
"require": "./dist/*",
|
|
41
|
+
"types": "./dist/*"
|
|
42
|
+
},
|
|
30
43
|
"./num": {
|
|
31
44
|
"import": "./dist/num.js",
|
|
32
45
|
"types": "./dist/num.d.ts"
|
|
33
46
|
},
|
|
34
47
|
"./speller": {
|
|
35
|
-
"import": "./dist/speller.js",
|
|
36
|
-
"types": "./dist/speller.d.ts"
|
|
48
|
+
"import": "./dist/speller/index.js",
|
|
49
|
+
"types": "./dist/speller/index.d.ts"
|
|
37
50
|
}
|
|
38
51
|
}
|
|
39
52
|
}
|
package/dist/speller.d.ts
DELETED
package/dist/speller.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"speller.d.ts","sourceRoot":"","sources":["../src/speller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,qBAAa,OAAO;IAChB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAEvC,SAAS,CAAC,UAAU,IAAI,OAAO;IAWxB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAG1C"}
|
package/dist/speller.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { optionalRequire as s } from "@zinaid/utils";
|
|
2
|
-
class e {
|
|
3
|
-
toWords;
|
|
4
|
-
getToWords() {
|
|
5
|
-
if (!this.toWords) {
|
|
6
|
-
const o = s(
|
|
7
|
-
"to-words",
|
|
8
|
-
'The "to-words" package is required for spelling numbers. Please install it: npm install to-words'
|
|
9
|
-
).ToWords;
|
|
10
|
-
this.toWords = new o();
|
|
11
|
-
}
|
|
12
|
-
return this.toWords;
|
|
13
|
-
}
|
|
14
|
-
spellNumber(o) {
|
|
15
|
-
return this.getToWords().convert(o);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export {
|
|
19
|
-
e as Speller
|
|
20
|
-
};
|