@zinaid/num 0.0.7 → 0.0.9

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,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 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";
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/index.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
- p as pairs,
15
- i as parse,
13
+ i as pairs,
14
+ p as parse,
16
15
  f as parseFloat,
17
16
  d as parseInt,
18
17
  y as percentage,
@@ -267,4 +267,4 @@ export declare function defaultLocale(): string;
267
267
  * defaultCurrency(); // "USD"
268
268
  */
269
269
  export declare function defaultCurrency(): string;
270
- //# sourceMappingURL=num.d.ts.map
270
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/num/index.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAClB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,YAAY,GAAE,MAAM,GAAG,IAA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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"}
@@ -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
- * @todo
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(_number: number | string, _locale?: string | null, _after?: number | null, _until?: number | null): string;
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
- * @todo
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); // "first"
24
- * spellOrdinal(2); // "second"
25
- * spellOrdinal(3); // "third"
43
+ * spellOrdinal(1); // "One"
44
+ * spellOrdinal(2); // "Two"
45
+ * spellOrdinal(21); // "Twenty One"
26
46
  */
27
- export declare function spellOrdinal(_value: number, _locale?: string | null): string;
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":"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"}
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,21 +1,83 @@
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
- }
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 u(r, l = null, t = null, e = null) {
12
- return "";
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 i(r, l = null) {
15
- return "";
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
- s as Speller,
19
- u as spell,
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.7",
3
+ "version": "0.0.9",
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.4"
12
+ "@zinaid/utils": "^0.0.5"
13
13
  },
14
14
  "devDependencies": {
15
15
  "to-words": "^4.7.0"
@@ -41,8 +41,8 @@
41
41
  "types": "./dist/*"
42
42
  },
43
43
  "./num": {
44
- "import": "./dist/num.js",
45
- "types": "./dist/num.d.ts"
44
+ "import": "./dist/num/index.js",
45
+ "types": "./dist/num/index.d.ts"
46
46
  },
47
47
  "./speller": {
48
48
  "import": "./dist/speller/index.js",
package/dist/num.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../src/num.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;GAcG;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;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CACpB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,GAAG,KAAK,CAQhB;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACtB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,GAAG,KAAK,CAEhB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CAwC3E;AAED;;;;;;;;;;;;;;GAcG;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;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CACpB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,YAAY,GAAE,MAAW,EACzB,MAAM,GAAE,M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