n2words 1.20.0 → 1.22.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.
Files changed (127) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/ar.js +2 -0
  4. package/dist/ar.js.map +1 -0
  5. package/dist/az.js +2 -0
  6. package/dist/az.js.map +1 -0
  7. package/dist/cz.js +2 -0
  8. package/dist/cz.js.map +1 -0
  9. package/dist/de.js +2 -0
  10. package/dist/de.js.map +1 -0
  11. package/dist/dk.js +2 -0
  12. package/dist/dk.js.map +1 -0
  13. package/dist/en.js +2 -0
  14. package/dist/en.js.map +1 -0
  15. package/dist/es.js +2 -0
  16. package/dist/es.js.map +1 -0
  17. package/dist/fa.js +2 -0
  18. package/dist/fa.js.map +1 -0
  19. package/dist/fr-BE.js +2 -0
  20. package/dist/fr-BE.js.map +1 -0
  21. package/dist/fr.js +2 -0
  22. package/dist/fr.js.map +1 -0
  23. package/dist/he.js +2 -0
  24. package/dist/he.js.map +1 -0
  25. package/dist/hr.js +2 -0
  26. package/dist/hr.js.map +1 -0
  27. package/dist/hu.js +2 -0
  28. package/dist/hu.js.map +1 -0
  29. package/dist/id.js +2 -0
  30. package/dist/id.js.map +1 -0
  31. package/dist/it.js +2 -0
  32. package/dist/it.js.map +1 -0
  33. package/dist/ko.js +2 -0
  34. package/dist/ko.js.map +1 -0
  35. package/dist/lt.js +2 -0
  36. package/dist/lt.js.map +1 -0
  37. package/dist/lv.js +2 -0
  38. package/dist/lv.js.map +1 -0
  39. package/dist/n2words.js +1 -1
  40. package/dist/n2words.js.map +1 -1
  41. package/dist/nl.js +2 -0
  42. package/dist/nl.js.map +1 -0
  43. package/dist/no.js +2 -0
  44. package/dist/no.js.map +1 -0
  45. package/dist/pl.js +2 -0
  46. package/dist/pl.js.map +1 -0
  47. package/dist/pt.js +2 -0
  48. package/dist/pt.js.map +1 -0
  49. package/dist/ro.js +2 -0
  50. package/dist/ro.js.map +1 -0
  51. package/dist/ru.js +2 -0
  52. package/dist/ru.js.map +1 -0
  53. package/dist/sr.js +2 -0
  54. package/dist/sr.js.map +1 -0
  55. package/dist/tr.js +2 -0
  56. package/dist/tr.js.map +1 -0
  57. package/dist/uk.js +2 -0
  58. package/dist/uk.js.map +1 -0
  59. package/dist/vi.js +2 -0
  60. package/dist/vi.js.map +1 -0
  61. package/dist/zh.js +2 -0
  62. package/dist/zh.js.map +1 -0
  63. package/lib/classes/{AbstractLanguage.d.ts → abstract-language.d.ts} +4 -3
  64. package/lib/classes/{AbstractLanguage.js → abstract-language.js} +14 -12
  65. package/lib/classes/{BaseLanguage.d.ts → base-language.d.ts} +6 -10
  66. package/lib/classes/{BaseLanguage.js → base-language.js} +23 -28
  67. package/lib/i18n/ar.d.ts +6 -6
  68. package/lib/i18n/ar.js +37 -45
  69. package/lib/i18n/az.d.ts +3 -3
  70. package/lib/i18n/az.js +15 -15
  71. package/lib/i18n/cz.d.ts +2 -2
  72. package/lib/i18n/cz.js +8 -9
  73. package/lib/i18n/de.d.ts +4 -4
  74. package/lib/i18n/de.js +33 -37
  75. package/lib/i18n/dk.d.ts +4 -4
  76. package/lib/i18n/dk.js +32 -32
  77. package/lib/i18n/en.d.ts +3 -3
  78. package/lib/i18n/en.js +18 -18
  79. package/lib/i18n/es.d.ts +4 -4
  80. package/lib/i18n/es.js +24 -24
  81. package/lib/i18n/fa.d.ts +3 -3
  82. package/lib/i18n/fa.js +9 -9
  83. package/lib/i18n/fr-BE.d.ts +2 -2
  84. package/lib/i18n/fr-BE.js +2 -2
  85. package/lib/i18n/fr.d.ts +4 -4
  86. package/lib/i18n/fr.js +29 -29
  87. package/lib/i18n/he.d.ts +2 -2
  88. package/lib/i18n/he.js +9 -12
  89. package/lib/i18n/hr.d.ts +2 -2
  90. package/lib/i18n/hr.js +10 -11
  91. package/lib/i18n/hu.d.ts +3 -3
  92. package/lib/i18n/hu.js +14 -14
  93. package/lib/i18n/id.d.ts +4 -4
  94. package/lib/i18n/id.js +25 -35
  95. package/lib/i18n/it.d.ts +3 -3
  96. package/lib/i18n/it.js +18 -38
  97. package/lib/i18n/ko.d.ts +3 -3
  98. package/lib/i18n/ko.js +16 -16
  99. package/lib/i18n/lt.d.ts +2 -2
  100. package/lib/i18n/lt.js +8 -9
  101. package/lib/i18n/lv.d.ts +2 -2
  102. package/lib/i18n/lv.js +10 -16
  103. package/lib/i18n/nl.d.ts +4 -4
  104. package/lib/i18n/nl.js +34 -34
  105. package/lib/i18n/no.d.ts +3 -3
  106. package/lib/i18n/no.js +20 -20
  107. package/lib/i18n/pl.d.ts +2 -2
  108. package/lib/i18n/pl.js +8 -9
  109. package/lib/i18n/pt.d.ts +4 -4
  110. package/lib/i18n/pt.js +25 -25
  111. package/lib/i18n/ro.d.ts +109 -0
  112. package/lib/i18n/ro.js +360 -0
  113. package/lib/i18n/ru.d.ts +4 -4
  114. package/lib/i18n/ru.js +15 -14
  115. package/lib/i18n/sr.d.ts +2 -2
  116. package/lib/i18n/sr.js +10 -11
  117. package/lib/i18n/tr.d.ts +3 -3
  118. package/lib/i18n/tr.js +15 -15
  119. package/lib/i18n/uk.d.ts +2 -2
  120. package/lib/i18n/uk.js +2 -2
  121. package/lib/i18n/vi.d.ts +3 -3
  122. package/lib/i18n/vi.js +4 -8
  123. package/lib/i18n/zh.d.ts +6 -6
  124. package/lib/i18n/zh.js +11 -11
  125. package/lib/n2words.d.ts +3 -1
  126. package/lib/n2words.js +17 -7
  127. package/package.json +32 -23
package/lib/i18n/no.js CHANGED
@@ -1,4 +1,4 @@
1
- import BaseLanguage from '../classes/BaseLanguage.js';
1
+ import BaseLanguage from '../classes/base-language.js';
2
2
 
3
3
  export class N2WordsNO extends BaseLanguage {
4
4
  constructor(options) {
@@ -9,16 +9,16 @@ export class N2WordsNO extends BaseLanguage {
9
9
  }, options);
10
10
 
11
11
  super(options, [
12
- [1000000000000000000000000000000000n, 'quintillard'],
13
- [1000000000000000000000000000000n, 'quintillion'],
14
- [1000000000000000000000000000n, 'quadrillard'],
15
- [1000000000000000000000000n, 'quadrillion'],
16
- [1000000000000000000000n, 'trillard'],
17
- [1000000000000000000n, 'trillion'],
18
- [1000000000000000n, 'billard'],
19
- [1000000000000n, 'billion'],
20
- [1000000000n, 'millard'],
21
- [1000000n, 'million'],
12
+ [1_000_000_000_000_000_000_000_000_000_000_000n, 'quintillard'],
13
+ [1_000_000_000_000_000_000_000_000_000_000n, 'quintillion'],
14
+ [1_000_000_000_000_000_000_000_000_000n, 'quadrillard'],
15
+ [1_000_000_000_000_000_000_000_000n, 'quadrillion'],
16
+ [1_000_000_000_000_000_000_000n, 'trillard'],
17
+ [1_000_000_000_000_000_000n, 'trillion'],
18
+ [1_000_000_000_000_000n, 'billard'],
19
+ [1_000_000_000_000n, 'billion'],
20
+ [1_000_000_000n, 'millard'],
21
+ [1_000_000n, 'million'],
22
22
  [1000n, 'tusen'],
23
23
  [100n, 'hundre'],
24
24
  [90n, 'nitti'],
@@ -55,13 +55,13 @@ export class N2WordsNO extends BaseLanguage {
55
55
  merge(lPair, rPair) { // {'one':1}, {'hundred':100}
56
56
  const lText = Object.keys(lPair)[0];
57
57
  const rText = Object.keys(rPair)[0];
58
- const lNum = BigInt(Object.values(lPair)[0]);
59
- const rNum = BigInt(Object.values(rPair)[0]);
60
- if (lNum == 1 && rNum < 100) return { [rText]: rNum };
61
- else if (lNum < 100 && lNum > rNum) return { [`${lText}-${rText}`]: lNum + rNum };
62
- else if (lNum >= 100 && rNum < 100) return { [`${lText} og ${rText}`]: lNum + rNum };
63
- else if (rNum > lNum) return { [`${lText} ${rText}`]: lNum * rNum };
64
- return { [`${lText}, ${rText}`]: lNum + rNum };
58
+ const lNumber = BigInt(Object.values(lPair)[0]);
59
+ const rNumber = BigInt(Object.values(rPair)[0]);
60
+ if (lNumber == 1 && rNumber < 100) return { [rText]: rNumber };
61
+ else if (lNumber < 100 && lNumber > rNumber) return { [`${lText}-${rText}`]: lNumber + rNumber };
62
+ else if (lNumber >= 100 && rNumber < 100) return { [`${lText} og ${rText}`]: lNumber + rNumber };
63
+ else if (rNumber > lNumber) return { [`${lText} ${rText}`]: lNumber * rNumber };
64
+ return { [`${lText}, ${rText}`]: lNumber + rNumber };
65
65
  }
66
66
  }
67
67
 
@@ -69,9 +69,9 @@ export class N2WordsNO extends BaseLanguage {
69
69
  * Converts a value to cardinal (written) form.
70
70
  * @param {number|string|bigint} value Number to be convert.
71
71
  * @param {object} [options] Options for class.
72
- * @throws {Error} Value cannot be invalid.
73
72
  * @returns {string} Value in cardinal (written) format.
73
+ * @throws {Error} Value cannot be invalid.
74
74
  */
75
- export default function (value, options = {}) {
75
+ export default function floatToCardinal (value, options = {}) {
76
76
  return new N2WordsNO(options).floatToCardinal(value);
77
77
  }
package/lib/i18n/pl.d.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  * Converts a value to cardinal (written) form.
3
3
  * @param {number|string|bigint} value Number to be convert.
4
4
  * @param {object} [options] Options for class.
5
- * @throws {Error} Value cannot be invalid.
6
5
  * @returns {string} Value in cardinal (written) format.
6
+ * @throws {Error} Value cannot be invalid.
7
7
  */
8
- export default function _default(value: number | string | bigint, options?: object): string;
8
+ export default function floatToCardinal(value: number | string | bigint, options?: object): string;
9
9
  export class N2WordsPL extends N2WordsRU {
10
10
  ones: {
11
11
  1: string;
package/lib/i18n/pl.js CHANGED
@@ -88,10 +88,9 @@ export class N2WordsPL extends N2WordsRU {
88
88
  }
89
89
  const words = [];
90
90
  const chunks = this.splitByX(number.toString(), 3);
91
- let i = chunks.length;
92
- for (let j = 0; j < chunks.length; j++) {
93
- const x = chunks[j];
94
- i = i - 1;
91
+ let index = chunks.length;
92
+ for (const x of chunks) {
93
+ index = index - 1;
95
94
  if (x == 0) {
96
95
  continue;
97
96
  }
@@ -104,11 +103,11 @@ export class N2WordsPL extends N2WordsRU {
104
103
  }
105
104
  if (n2 == 1) {
106
105
  words.push(this.tens[n1]);
107
- } else if (n1 > 0 && !(i > 0 && x == 1)) {
106
+ } else if (n1 > 0 && !(index > 0 && x == 1)) {
108
107
  words.push(this.ones[n1]);
109
108
  }
110
- if (i > 0) {
111
- words.push(this.pluralize(x, this.thousands[i]));
109
+ if (index > 0) {
110
+ words.push(this.pluralize(x, this.thousands[index]));
112
111
  }
113
112
  }
114
113
  return words.join(' ');
@@ -119,9 +118,9 @@ export class N2WordsPL extends N2WordsRU {
119
118
  * Converts a value to cardinal (written) form.
120
119
  * @param {number|string|bigint} value Number to be convert.
121
120
  * @param {object} [options] Options for class.
122
- * @throws {Error} Value cannot be invalid.
123
121
  * @returns {string} Value in cardinal (written) format.
122
+ * @throws {Error} Value cannot be invalid.
124
123
  */
125
- export default function (value, options = {}) {
124
+ export default function floatToCardinal (value, options = {}) {
126
125
  return new N2WordsPL(options).floatToCardinal(value);
127
126
  }
package/lib/i18n/pt.d.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  * Converts a value to cardinal (written) form.
3
3
  * @param {number|string|bigint} value Number to be convert.
4
4
  * @param {object} [options] Options for class.
5
- * @throws {Error} Value cannot be invalid.
6
5
  * @returns {string} Value in cardinal (written) format.
6
+ * @throws {Error} Value cannot be invalid.
7
7
  */
8
- export default function _default(value: number | string | bigint, options?: object): string;
8
+ export default function floatToCardinal(value: number | string | bigint, options?: object): string;
9
9
  export class N2WordsPT extends BaseLanguage {
10
10
  constructor(options: any);
11
11
  hundreds: {
@@ -19,8 +19,8 @@ export class N2WordsPT extends BaseLanguage {
19
19
  8: string;
20
20
  9: string;
21
21
  };
22
- merge(curr: any, next: any): {
22
+ merge(current: any, next: any): {
23
23
  [x: string]: bigint;
24
24
  };
25
25
  }
26
- import BaseLanguage from '../classes/BaseLanguage.js';
26
+ import BaseLanguage from '../classes/base-language.js';
package/lib/i18n/pt.js CHANGED
@@ -1,4 +1,4 @@
1
- import BaseLanguage from '../classes/BaseLanguage.js';
1
+ import BaseLanguage from '../classes/base-language.js';
2
2
 
3
3
  export class N2WordsPT extends BaseLanguage {
4
4
  hundreds = {
@@ -21,10 +21,10 @@ export class N2WordsPT extends BaseLanguage {
21
21
  }, options);
22
22
 
23
23
  super(options, [
24
- [1000000000000000000000000n, 'quatrilião'],
25
- [1000000000000000000n, 'trilião'],
26
- [1000000000000n, 'bilião'],
27
- [1000000n, 'milião'],
24
+ [1_000_000_000_000_000_000_000_000n, 'quatrilião'],
25
+ [1_000_000_000_000_000_000n, 'trilião'],
26
+ [1_000_000_000_000n, 'bilião'],
27
+ [1_000_000n, 'milião'],
28
28
  [1000n, 'mil'],
29
29
  [100n, 'cem'],
30
30
  [90n, 'noventa'],
@@ -61,48 +61,48 @@ export class N2WordsPT extends BaseLanguage {
61
61
  postClean(words) {
62
62
  const transforms = ['mil', 'milhão', 'milhões', 'mil milhões', 'bilião', 'biliões', 'mil biliões'];
63
63
 
64
- transforms.forEach(transform => {
65
- if (words.match(new RegExp(`.*${transform} e \\w*entos? (?=.*e)`))) {
66
- words = words.replace(new RegExp(`${transform} e`, 'g'), `${transform}`);
64
+ for (const transform of transforms) {
65
+ if (new RegExp(`.*${transform} e \\w*entos? (?=.*e)`).test(words)) {
66
+ words = words.replaceAll(new RegExp(`${transform} e`, 'g'), `${transform}`);
67
67
  }
68
- });
68
+ }
69
69
 
70
70
  return words;
71
71
  }
72
72
 
73
- merge(curr, next) {
74
- let cText = Object.keys(curr)[0];
73
+ merge(current, next) {
74
+ let cText = Object.keys(current)[0];
75
75
  let nText = Object.keys(next)[0];
76
- const cNum = BigInt(Object.values(curr)[0]);
77
- const nNum = BigInt(Object.values(next)[0]);
76
+ const cNumber = BigInt(Object.values(current)[0]);
77
+ const nNumber = BigInt(Object.values(next)[0]);
78
78
 
79
- if (cNum == 1) {
80
- if (nNum < 1000000) return { [nText]: nNum };
79
+ if (cNumber == 1) {
80
+ if (nNumber < 1_000_000) return { [nText]: nNumber };
81
81
  cText = 'um';
82
- } else if (cNum == 100 && nNum % 1000n != 0) {
82
+ } else if (cNumber == 100 && nNumber % 1000n != 0) {
83
83
  cText = 'cento';
84
84
  }
85
85
 
86
- if (nNum < cNum) {
86
+ if (nNumber < cNumber) {
87
87
  // if (cNum < 100) {
88
88
  // return { [`${cText} e ${nText}`]: cNum + nNum }
89
89
  // }
90
- return { [`${cText} e ${nText}`]: cNum + nNum };
91
- } else if (nNum % 1000000000n == 0 && cNum > 1) {
90
+ return { [`${cText} e ${nText}`]: cNumber + nNumber };
91
+ } else if (nNumber % 1_000_000_000n == 0 && cNumber > 1) {
92
92
  nText = nText.slice(0, -4) + 'liões';
93
- } else if (nNum % 1000000n == 0 && cNum > 1) {
93
+ } else if (nNumber % 1_000_000n == 0 && cNumber > 1) {
94
94
  nText = nText.slice(0, -4) + 'lhões';
95
95
  }
96
96
 
97
97
  if (nText == 'milião') nText = 'milhão';
98
98
 
99
- if (nNum == 100) {
100
- cText = this.hundreds[cNum];
99
+ if (nNumber == 100) {
100
+ cText = this.hundreds[cNumber];
101
101
  nText = '';
102
102
  } else {
103
103
  nText = ' ' + nText;
104
104
  }
105
- return { [`${cText}${nText}`]: cNum * nNum };
105
+ return { [`${cText}${nText}`]: cNumber * nNumber };
106
106
  }
107
107
  }
108
108
 
@@ -110,9 +110,9 @@ export class N2WordsPT extends BaseLanguage {
110
110
  * Converts a value to cardinal (written) form.
111
111
  * @param {number|string|bigint} value Number to be convert.
112
112
  * @param {object} [options] Options for class.
113
- * @throws {Error} Value cannot be invalid.
114
113
  * @returns {string} Value in cardinal (written) format.
114
+ * @throws {Error} Value cannot be invalid.
115
115
  */
116
- export default function (value, options = {}) {
116
+ export default function floatToCardinal (value, options = {}) {
117
117
  return new N2WordsPT(options).floatToCardinal(value);
118
118
  }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Converts a value to cardinal (written) form.
3
+ * @param {number|string|bigint} value Number to be convert.
4
+ * @param {object} [options] Options for class.
5
+ * @returns {string} Value in cardinal (written) format.
6
+ */
7
+ export default function floatToCardinal(value: number | string | bigint, options?: object): string;
8
+ export class N2WordsRO extends AbstractLanguage {
9
+ constructor(options: any);
10
+ /** @type {boolean} */
11
+ feminine: boolean;
12
+ /** @type {object} */
13
+ ones: object;
14
+ /** @type {object} */
15
+ onesFeminine: object;
16
+ /** @type {object} */
17
+ tens: object;
18
+ /** @type {object} */
19
+ tensMasculine: object;
20
+ /** @type {object} */
21
+ twenties: object;
22
+ /** @type {object} */
23
+ hundreds: object;
24
+ /**
25
+ * Romanian big units.
26
+ * For each power group we keep: singular, plural, feminineUnits?, needsDe?
27
+ * - 10^3: mie/mii (feminine units in chunk; "de" for chunk >= 20)
28
+ * - 10^6: milion/milioane ("de" for chunk >= 20)
29
+ * - 10^9: miliard/miliarde ("de" for chunk >= 20)
30
+ */
31
+ thousands: {
32
+ 1: {
33
+ singular: string;
34
+ plural: string;
35
+ feminine: boolean;
36
+ needsDe: boolean;
37
+ };
38
+ 2: {
39
+ singular: string;
40
+ plural: string;
41
+ feminine: boolean;
42
+ needsDe: boolean;
43
+ };
44
+ 3: {
45
+ singular: string;
46
+ plural: string;
47
+ feminine: boolean;
48
+ needsDe: boolean;
49
+ };
50
+ 4: {
51
+ singular: string;
52
+ plural: string;
53
+ feminine: boolean;
54
+ needsDe: boolean;
55
+ };
56
+ 5: {
57
+ singular: string;
58
+ plural: string;
59
+ feminine: boolean;
60
+ needsDe: boolean;
61
+ };
62
+ 6: {
63
+ singular: string;
64
+ plural: string;
65
+ feminine: boolean;
66
+ needsDe: boolean;
67
+ };
68
+ 7: {
69
+ singular: string;
70
+ plural: string;
71
+ feminine: boolean;
72
+ needsDe: boolean;
73
+ };
74
+ 8: {
75
+ singular: string;
76
+ plural: string;
77
+ feminine: boolean;
78
+ needsDe: boolean;
79
+ };
80
+ };
81
+ toCardinal(number: any): any;
82
+ /**
83
+ * Split numeric string into BigInt groups of size x from left to right.
84
+ * @param {string} n - The numeric string to split
85
+ * @param {number} x - The size of each group
86
+ * @returns {bigint[]} Array of BigInt groups
87
+ */
88
+ splitByX(n: string, x: number): bigint[];
89
+ getDigits(value: any): any;
90
+ /**
91
+ * Romanian pluralization & "de" rule for big units.
92
+ * - 1 → singular with article ("o mie", "un milion", "un miliard", …)
93
+ * - otherwise → spell chunk + (optional "de") + plural
94
+ * "de" is inserted when chunk >= 20 (e.g., "douăzeci de mii/milioane/miliarde").
95
+ * @param {bigint} chunk - The chunk value
96
+ * @param {object} form - The form object with singular, plural, feminine, needsDe properties
97
+ * @returns {string} The pluralized form
98
+ */
99
+ romanianPluralize(chunk: bigint, form: object): string;
100
+ spellUnder100(n: any, feminineUnits?: boolean): any;
101
+ spellUnder1000(n: any, feminineUnits?: boolean): any;
102
+ /**
103
+ * Convert number to cardinal form using masculine units
104
+ * @param {bigint} number Number to convert
105
+ * @returns {string} Value in written format
106
+ */
107
+ toCardinalWithMasculine(number: bigint): string;
108
+ }
109
+ import AbstractLanguage from '../classes/abstract-language.js';