@zinaid/num 0.0.7 → 0.0.8
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 +4 -5
- package/dist/speller/index.d.ts +33 -13
- package/dist/speller/index.d.ts.map +1 -1
- package/dist/speller/index.js +78 -16
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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
|
|
2
|
-
import {
|
|
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";
|
|
3
3
|
export {
|
|
4
|
-
T as Speller,
|
|
5
4
|
a as clamp,
|
|
6
5
|
l as currency,
|
|
7
6
|
o as defaultCurrency,
|
|
@@ -11,8 +10,8 @@ export {
|
|
|
11
10
|
t as format,
|
|
12
11
|
c as minutesToHuman,
|
|
13
12
|
m as ordinal,
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
i as pairs,
|
|
14
|
+
p as parse,
|
|
16
15
|
f as parseFloat,
|
|
17
16
|
d as parseInt,
|
|
18
17
|
y as percentage,
|
package/dist/speller/index.d.ts
CHANGED
|
@@ -1,28 +1,48 @@
|
|
|
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
1
|
/**
|
|
8
2
|
* Spell out the given number in the given locale.
|
|
9
3
|
*
|
|
10
|
-
*
|
|
4
|
+
* If `after` is provided and the number is less than or equal to `after`,
|
|
5
|
+
* the number will be returned as a formatted string instead of spelled out.
|
|
6
|
+
*
|
|
7
|
+
* If `until` is provided and the number is greater than or equal to `until`,
|
|
8
|
+
* the number will be returned as a formatted string instead of spelled out.
|
|
9
|
+
*
|
|
10
|
+
* @param number - The number to spell out.
|
|
11
|
+
* @param locale - The locale to use for spelling. Defaults to "en-US".
|
|
12
|
+
* @param after - If provided, numbers <= this value will be formatted instead of spelled.
|
|
13
|
+
* @param until - If provided, numbers >= this value will be formatted instead of spelled.
|
|
14
|
+
* @returns The number spelled out as words, or formatted as a string.
|
|
11
15
|
*
|
|
12
16
|
* @requires {@link https://www.npmjs.com/package/to-words to-words package}
|
|
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)
|
|
13
26
|
*/
|
|
14
|
-
export declare function spell(
|
|
27
|
+
export declare function spell(number: number | string, locale?: string | null, after?: number | null, until?: number | null): string;
|
|
15
28
|
/**
|
|
16
29
|
* Spell out the given number in the given locale in ordinal form.
|
|
17
|
-
*
|
|
30
|
+
*
|
|
31
|
+
* Note: The to-words package doesn't have native ordinal support, so this
|
|
32
|
+
* function spells out the cardinal number. True ordinal conversion would
|
|
33
|
+
* require locale-specific suffix rules (e.g., "first", "second", "third").
|
|
34
|
+
*
|
|
35
|
+
* @param value - The number to spell out in ordinal form.
|
|
36
|
+
* @param locale - The locale to use for spelling. Defaults to "en-US".
|
|
37
|
+
* @returns The number spelled out as words.
|
|
18
38
|
*
|
|
19
39
|
* @requires {@link https://www.npmjs.com/package/to-words to-words package}
|
|
20
40
|
*
|
|
21
41
|
* @example
|
|
22
42
|
*
|
|
23
|
-
* spellOrdinal(1); // "
|
|
24
|
-
* spellOrdinal(2); // "
|
|
25
|
-
* spellOrdinal(
|
|
43
|
+
* spellOrdinal(1); // "One"
|
|
44
|
+
* spellOrdinal(2); // "Two"
|
|
45
|
+
* spellOrdinal(21); // "Twenty One"
|
|
26
46
|
*/
|
|
27
|
-
export declare function spellOrdinal(
|
|
47
|
+
export declare function spellOrdinal(value: number, locale?: string | null): string;
|
|
28
48
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/speller/index.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/speller/index.js
CHANGED
|
@@ -1,21 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { format as s } from "@zinaid/num";
|
|
2
|
+
import { ToWords as u } from "to-words";
|
|
3
|
+
const l = /* @__PURE__ */ new Set([
|
|
4
|
+
"bn-IN",
|
|
5
|
+
"ee-EE",
|
|
6
|
+
"en-AE",
|
|
7
|
+
"en-AU",
|
|
8
|
+
"en-BD",
|
|
9
|
+
"en-GB",
|
|
10
|
+
"en-GH",
|
|
11
|
+
"en-IE",
|
|
12
|
+
"en-IN",
|
|
13
|
+
"en-MM",
|
|
14
|
+
"en-MA",
|
|
15
|
+
"en-MU",
|
|
16
|
+
"en-NG",
|
|
17
|
+
"en-NP",
|
|
18
|
+
"en-OM",
|
|
19
|
+
"en-PH",
|
|
20
|
+
"en-SA",
|
|
21
|
+
"en-US",
|
|
22
|
+
"es-AR",
|
|
23
|
+
"es-ES",
|
|
24
|
+
"es-MX",
|
|
25
|
+
"es-VE",
|
|
26
|
+
"fa-IR",
|
|
27
|
+
"fr-BE",
|
|
28
|
+
"fr-FR",
|
|
29
|
+
"fr-MA",
|
|
30
|
+
"fr-SA",
|
|
31
|
+
"gu-IN",
|
|
32
|
+
"hi-IN",
|
|
33
|
+
"kn-IN",
|
|
34
|
+
"ko-KR",
|
|
35
|
+
"lv-LV",
|
|
36
|
+
"mr-IN",
|
|
37
|
+
"nl-SR",
|
|
38
|
+
"np-NP",
|
|
39
|
+
"pt-BR",
|
|
40
|
+
"tr-TR",
|
|
41
|
+
"ur-PK",
|
|
42
|
+
"ar-AE",
|
|
43
|
+
"ar-MA",
|
|
44
|
+
"ar-SA"
|
|
45
|
+
]);
|
|
46
|
+
function f(n) {
|
|
47
|
+
if (l.has(n))
|
|
48
|
+
return n;
|
|
49
|
+
const o = (n.split("-")[0] || n).toLowerCase();
|
|
50
|
+
for (const t of l)
|
|
51
|
+
if (t.toLowerCase().startsWith(o + "-"))
|
|
52
|
+
return t;
|
|
53
|
+
return "en-US";
|
|
10
54
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
55
|
+
function S(n, r = null, o = null, t = null) {
|
|
56
|
+
const e = typeof n == "string" ? parseFloat(n) : n;
|
|
57
|
+
if (o !== null && e <= o)
|
|
58
|
+
return s(e, null, null, r) || String(e);
|
|
59
|
+
if (t !== null && e >= t)
|
|
60
|
+
return s(e, null, null, r) || String(e);
|
|
61
|
+
const i = f(r ?? "en-US");
|
|
62
|
+
return new u({
|
|
63
|
+
localeCode: i,
|
|
64
|
+
converterOptions: {
|
|
65
|
+
currency: !1,
|
|
66
|
+
ignoreDecimal: !1
|
|
67
|
+
}
|
|
68
|
+
}).convert(e);
|
|
13
69
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
70
|
+
function d(n, r = null) {
|
|
71
|
+
const o = f(r ?? "en-US");
|
|
72
|
+
return new u({
|
|
73
|
+
localeCode: o,
|
|
74
|
+
converterOptions: {
|
|
75
|
+
currency: !1,
|
|
76
|
+
ignoreDecimal: !0
|
|
77
|
+
}
|
|
78
|
+
}).convert(Math.floor(n));
|
|
16
79
|
}
|
|
17
80
|
export {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
i as spellOrdinal
|
|
81
|
+
S as spell,
|
|
82
|
+
d as spellOrdinal
|
|
21
83
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zinaid/num",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"sideEffects": false,
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@zinaid/utils": "^0.0.
|
|
12
|
+
"@zinaid/utils": "^0.0.5"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"to-words": "^4.7.0"
|