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/ro.js ADDED
@@ -0,0 +1,360 @@
1
+ import AbstractLanguage from '../classes/abstract-language.js';
2
+
3
+ export class N2WordsRO extends AbstractLanguage {
4
+ /** @type {boolean} */
5
+ feminine;
6
+
7
+ /** @type {object} */
8
+ ones = {
9
+ 1: 'unu',
10
+ 2: 'doi',
11
+ 3: 'trei',
12
+ 4: 'patru',
13
+ 5: 'cinci',
14
+ 6: 'șase',
15
+ 7: 'șapte',
16
+ 8: 'opt',
17
+ 9: 'nouă'
18
+ };
19
+
20
+ /** @type {object} */
21
+ onesFeminine = {
22
+ 1: 'una',
23
+ 2: 'două',
24
+ 3: 'trei',
25
+ 4: 'patru',
26
+ 5: 'cinci',
27
+ 6: 'șase',
28
+ 7: 'șapte',
29
+ 8: 'opt',
30
+ 9: 'nouă'
31
+ };
32
+
33
+ /** @type {object} */
34
+ tens = {
35
+ 0: 'zece',
36
+ 1: 'unsprezece',
37
+ 2: 'douăsprezece',
38
+ 3: 'treisprezece',
39
+ 4: 'paisprezece',
40
+ 5: 'cincisprezece',
41
+ 6: 'șaisprezece',
42
+ 7: 'șaptesprezece',
43
+ 8: 'optsprezece',
44
+ 9: 'nouăsprezece'
45
+ };
46
+
47
+ /** @type {object} */
48
+ tensMasculine = {
49
+ 0: 'zece',
50
+ 1: 'unsprezece',
51
+ 2: 'doisprezece',
52
+ 3: 'treisprezece',
53
+ 4: 'paisprezece',
54
+ 5: 'cincisprezece',
55
+ 6: 'șaisprezece',
56
+ 7: 'șaptesprezece',
57
+ 8: 'optsprezece',
58
+ 9: 'nouăsprezece'
59
+ };
60
+
61
+ /** @type {object} */
62
+ twenties = {
63
+ 2: 'douăzeci',
64
+ 3: 'treizeci',
65
+ 4: 'patruzeci',
66
+ 5: 'cincizeci',
67
+ 6: 'șaizeci',
68
+ 7: 'șaptezeci',
69
+ 8: 'optzeci',
70
+ 9: 'nouăzeci'
71
+ };
72
+
73
+ /** @type {object} */
74
+ hundreds = {
75
+ 1: 'o sută',
76
+ 2: 'două sute',
77
+ 3: 'trei sute',
78
+ 4: 'patru sute',
79
+ 5: 'cinci sute',
80
+ 6: 'șase sute',
81
+ 7: 'șapte sute',
82
+ 8: 'opt sute',
83
+ 9: 'nouă sute'
84
+ };
85
+
86
+ /**
87
+ * Romanian big units.
88
+ * For each power group we keep: singular, plural, feminineUnits?, needsDe?
89
+ * - 10^3: mie/mii (feminine units in chunk; "de" for chunk >= 20)
90
+ * - 10^6: milion/milioane ("de" for chunk >= 20)
91
+ * - 10^9: miliard/miliarde ("de" for chunk >= 20)
92
+ */
93
+ thousands = {
94
+ 1: { singular: 'mie', plural: 'mii', feminine: true, needsDe: true }, // 10^3
95
+ 2: { singular: 'milion', plural: 'milioane', feminine: false, needsDe: true }, // 10^6
96
+ 3: { singular: 'miliard', plural: 'miliarde', feminine: false, needsDe: true },// 10^9
97
+ 4: { singular: 'trilion', plural: 'trilioane', feminine: false, needsDe: true }, // 10^12
98
+ 5: { singular: 'cvadrilion', plural: 'cvadrilioane', feminine: false, needsDe: true }, // 10^15
99
+ 6: { singular: 'cvintilion', plural: 'cvintilioane', feminine: false, needsDe: true }, // 10^18
100
+ 7: { singular: 'sextilion', plural: 'sextilioane', feminine: false, needsDe: true }, // 10^21
101
+ 8: { singular: 'septilion', plural: 'septilioane', feminine: false, needsDe: true }, // 10^24
102
+ };
103
+
104
+ constructor(options) {
105
+ options = Object.assign({
106
+ negativeWord: 'minus',
107
+ separatorWord: 'virgulă',
108
+ zero: 'zero',
109
+ feminine: false
110
+ }, options);
111
+
112
+ super(options);
113
+ this.feminine = options.feminine;
114
+ }
115
+
116
+ toCardinal(number) {
117
+ if (number == 0) {
118
+ return this.zero;
119
+ }
120
+
121
+ const words = [];
122
+ const chunks = this.splitByX(number.toString(), 3);
123
+ let index = chunks.length;
124
+
125
+ for (const x of chunks) {
126
+ let onesMap = [];
127
+ index = index - 1;
128
+
129
+ if (x == 0n) continue;
130
+
131
+ const [n1, n2, n3] = this.getDigits(x); // units, tens, hundreds (as BigInt)
132
+
133
+ // hundreds (only for the last group, not for thousands)
134
+ if (n3 > 0n && index === 0) {
135
+ words.push(this.hundreds[Number(n3)]);
136
+ }
137
+
138
+ // tens & teens (only for the last group, not for thousands)
139
+ if (index === 0) {
140
+ if (n2 > 1n) {
141
+ words.push(this.twenties[Number(n2)]);
142
+ }
143
+
144
+ if (n2 == 1n) {
145
+ words.push(this.tens[Number(n1)]);
146
+ } else if (n1 > 0n) {
147
+ // pick masculine/feminine units (only for the last group, not for thousands)
148
+ const feminineUnits = this.feminine && index === 0;
149
+ onesMap = feminineUnits ? this.onesFeminine : this.ones;
150
+
151
+ // if there is a twenty/treizeci/etc AND ones > 0 → add "și"
152
+ if (n2 > 1n) words.push('și');
153
+ words.push(onesMap[Number(n1)]);
154
+ }
155
+ }
156
+
157
+ // big unit name (mie/mii, milion/milioane, …)
158
+ if (index > 0) {
159
+ const form = this.thousands[index];
160
+ if (form) {
161
+ words.push(this.romanianPluralize(x, form));
162
+ } else {
163
+ // For very large numbers beyond our defined units, just spell out the number
164
+ words.push(this.spellUnder1000(Number(x), true));
165
+ }
166
+ }
167
+ }
168
+
169
+ return words.join(' ').replaceAll(/\s+/g, ' ').trim();
170
+ }
171
+
172
+ /**
173
+ * Split numeric string into BigInt groups of size x from left to right.
174
+ * @param {string} n - The numeric string to split
175
+ * @param {number} x - The size of each group
176
+ * @returns {bigint[]} Array of BigInt groups
177
+ */
178
+ splitByX(n, x) {
179
+ const results = [];
180
+ const l = n.length;
181
+ let result;
182
+
183
+ if (l > x) {
184
+ const start = l % x;
185
+ if (start > 0) {
186
+ result = n.slice(0, start);
187
+ results.push(BigInt(result));
188
+ }
189
+ for (let index = start; index < l; index += x) {
190
+ result = n.slice(index, index + x);
191
+ results.push(BigInt(result));
192
+ }
193
+ } else {
194
+ results.push(BigInt(n));
195
+ }
196
+ return results;
197
+ }
198
+
199
+ getDigits(value) {
200
+ // returns [units, tens, hundreds] as BigInt
201
+ const stringValue = value.toString().padStart(3, '0').slice(-3);
202
+ const a = [...stringValue].toReversed();
203
+ return a.map(BigInt);
204
+ }
205
+
206
+ /**
207
+ * Romanian pluralization & "de" rule for big units.
208
+ * - 1 → singular with article ("o mie", "un milion", "un miliard", …)
209
+ * - otherwise → spell chunk + (optional "de") + plural
210
+ * "de" is inserted when chunk >= 20 (e.g., "douăzeci de mii/milioane/miliarde").
211
+ * @param {bigint} chunk - The chunk value
212
+ * @param {object} form - The form object with singular, plural, feminine, needsDe properties
213
+ * @returns {string} The pluralized form
214
+ */
215
+ romanianPluralize(chunk, form) {
216
+ const n = Number(chunk);
217
+
218
+ if (n === 1) {
219
+ // article differs for feminine "mie" (o mie) vs the rest (un milion/miliard…)
220
+ const article = form.feminine ? 'o' : 'un';
221
+ return `${article} ${form.singular}`;
222
+ }
223
+
224
+ // For 21 with big units, use feminine "una" with plural nouns
225
+ if (n === 21 && form.needsDe) {
226
+ return `douăzeci și una de ${form.plural}`;
227
+ }
228
+
229
+ // spell the chunk itself (use feminine units for big numbers)
230
+ const words = this.spellUnder1000(n, true);
231
+
232
+ // "de" after >= 20 (covers 20, 21, 100, 101, 999, etc.)
233
+ const needsDe = form.needsDe && n >= 20;
234
+ const de = needsDe ? ' de ' : ' ';
235
+
236
+ return `${words}${de}${form.plural}`;
237
+ }
238
+
239
+ spellUnder100(n, feminineUnits = false) {
240
+ if (n < 10) {
241
+ return (feminineUnits ? this.onesFeminine : this.ones)[n];
242
+ }
243
+ if (n < 20) {
244
+ return this.tens[n - 10];
245
+ }
246
+ const t = Math.floor(n / 10);
247
+ const u = n % 10;
248
+ return u
249
+ ? `${this.twenties[t]} și ${(feminineUnits ? this.onesFeminine : this.ones)[u]}`
250
+ : this.twenties[t];
251
+ }
252
+
253
+ spellUnder1000(n, feminineUnits = false) {
254
+ if (n < 100) return this.spellUnder100(n, feminineUnits);
255
+ const h = Math.floor(n / 100);
256
+ const r = n % 100;
257
+ const hundredWords = this.hundreds[h];
258
+ if (!r) return hundredWords;
259
+ // Standard readable form: "o sută unu" (for units) or "o sută cincizeci" (for tens)
260
+ const separator = r < 20 ? ' ' : ' ';
261
+ return `${hundredWords}${separator}${this.spellUnder100(r, feminineUnits)}`;
262
+ }
263
+
264
+ /**
265
+ * Override decimalToCardinal to use masculine forms for decimal places
266
+ * @param {string} decimal Decimal string to convert
267
+ * @returns {string} Value in written format
268
+ */
269
+ decimalToCardinal(decimal) {
270
+ const words = [];
271
+
272
+ // Split decimal string into an array of characters
273
+ const chars = [...decimal];
274
+
275
+ // Loop through characters adding leading zeros to words array
276
+ let index = 0;
277
+ while (index < chars.length && chars[index] === '0') {
278
+ words.push(this.zero);
279
+ index++;
280
+ }
281
+
282
+ // Prevent further processing if entire string was zeros
283
+ if (index === chars.length) {
284
+ return words;
285
+ }
286
+
287
+ // Convert and add remaining using masculine forms for decimal places
288
+ const decimalNumber = BigInt(decimal);
289
+ const masculineWords = this.toCardinalWithMasculine(decimalNumber);
290
+ return [...words, masculineWords];
291
+ }
292
+
293
+ /**
294
+ * Convert number to cardinal form using masculine units
295
+ * @param {bigint} number Number to convert
296
+ * @returns {string} Value in written format
297
+ */
298
+ toCardinalWithMasculine(number) {
299
+ if (number == 0) {
300
+ return this.zero;
301
+ }
302
+
303
+ const words = [];
304
+ const chunks = this.splitByX(number.toString(), 3);
305
+ let index = chunks.length;
306
+
307
+ for (const x of chunks) {
308
+ let onesMap = [];
309
+ index = index - 1;
310
+
311
+ if (x == 0n) continue;
312
+
313
+ const [n1, n2, n3] = this.getDigits(x); // units, tens, hundreds (as BigInt)
314
+
315
+ // hundreds
316
+ if (n3 > 0n) {
317
+ words.push(this.hundreds[Number(n3)]);
318
+ }
319
+
320
+ // tens & teens
321
+ if (n2 > 1n) {
322
+ words.push(this.twenties[Number(n2)]);
323
+ }
324
+
325
+ if (n2 == 1n) {
326
+ words.push(this.tensMasculine[Number(n1)]);
327
+ } else if (n1 > 0n) {
328
+ // Always use masculine units for decimal places
329
+ onesMap = this.ones;
330
+
331
+ // if there is a twenty/treizeci/etc AND ones > 0 → add "și"
332
+ if (n2 > 1n) words.push('și');
333
+ words.push(onesMap[Number(n1)]);
334
+ }
335
+
336
+ // big unit name (mie/mii, milion/milioane, …)
337
+ if (index > 0) {
338
+ const form = this.thousands[index];
339
+ if (form) {
340
+ words.push(this.romanianPluralize(x, form));
341
+ } else {
342
+ // For very large numbers beyond our defined units, just spell out the number
343
+ words.push(this.spellUnder1000(Number(x), false));
344
+ }
345
+ }
346
+ }
347
+
348
+ return words.join(' ').replaceAll(/\s+/g, ' ').trim();
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Converts a value to cardinal (written) form.
354
+ * @param {number|string|bigint} value Number to be convert.
355
+ * @param {object} [options] Options for class.
356
+ * @returns {string} Value in cardinal (written) format.
357
+ */
358
+ export default function floatToCardinal(value, options = {}) {
359
+ return new N2WordsRO(options).floatToCardinal(value);
360
+ }
package/lib/i18n/ru.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 N2WordsRU extends AbstractLanguage {
10
10
  constructor(options: any);
11
11
  /** @type {boolean} */
@@ -24,7 +24,7 @@ export class N2WordsRU extends AbstractLanguage {
24
24
  thousands: object;
25
25
  toCardinal(number: any): string;
26
26
  splitByX(n: any, x: any): bigint[];
27
- getDigits(value: any): bigint[];
27
+ getDigits(value: any): any;
28
28
  pluralize(n: any, forms: any): any;
29
29
  }
30
- import AbstractLanguage from '../classes/AbstractLanguage.js';
30
+ import AbstractLanguage from '../classes/abstract-language.js';
package/lib/i18n/ru.js CHANGED
@@ -1,4 +1,4 @@
1
- import AbstractLanguage from '../classes/AbstractLanguage.js';
1
+ import AbstractLanguage from '../classes/abstract-language.js';
2
2
 
3
3
  export class N2WordsRU extends AbstractLanguage {
4
4
  /** @type {boolean} */
@@ -105,12 +105,11 @@ export class N2WordsRU extends AbstractLanguage {
105
105
 
106
106
  const chunks = this.splitByX(number.toString(), 3);
107
107
 
108
- let i = chunks.length;
108
+ let index = chunks.length;
109
109
 
110
- for (let j = 0; j < chunks.length; j++) {
111
- const x = chunks[j];
110
+ for (const x of chunks) {
112
111
  let ones = [];
113
- i = i - 1;
112
+ index = index - 1;
114
113
 
115
114
  if (x == 0) {
116
115
  continue;
@@ -129,12 +128,12 @@ export class N2WordsRU extends AbstractLanguage {
129
128
  if (n2 == 1) {
130
129
  words.push(this.tens[n1]);
131
130
  } else if (n1 > 0) {
132
- ones = (i == 1 || this.feminine && i == 0) ? this.onesFeminine : this.ones;
131
+ ones = (index == 1 || this.feminine && index == 0) ? this.onesFeminine : this.ones;
133
132
  words.push(ones[n1]);
134
133
  }
135
134
 
136
- if (i > 0) {
137
- words.push(this.pluralize(x, this.thousands[i]));
135
+ if (index > 0) {
136
+ words.push(this.pluralize(x, this.thousands[index]));
138
137
  }
139
138
  }
140
139
 
@@ -155,8 +154,8 @@ export class N2WordsRU extends AbstractLanguage {
155
154
  results.push(BigInt(result));
156
155
  }
157
156
 
158
- for (let i = start; i < l; i += x) {
159
- result = n.slice(i, i + x);
157
+ for (let index = start; index < l; index += x) {
158
+ result = n.slice(index, index + x);
160
159
 
161
160
  results.push(BigInt(result));
162
161
  }
@@ -168,8 +167,10 @@ export class N2WordsRU extends AbstractLanguage {
168
167
  }
169
168
 
170
169
  getDigits(value) {
171
- const a = Array.from(value.toString().padStart(3, '0').slice(-3)).reverse();
172
- return a.map(e => BigInt(e));
170
+ // TODO ESLint suggestion
171
+ // eslint-disable-next-line unicorn/no-useless-spread
172
+ const a = [...value.toString().padStart(3, '0').slice(-3)].toReversed();
173
+ return a.map(BigInt);
173
174
  }
174
175
 
175
176
  pluralize(n, forms) {
@@ -189,9 +190,9 @@ export class N2WordsRU extends AbstractLanguage {
189
190
  * Converts a value to cardinal (written) form.
190
191
  * @param {number|string|bigint} value Number to be convert.
191
192
  * @param {object} [options] Options for class.
192
- * @throws {Error} Value cannot be invalid.
193
193
  * @returns {string} Value in cardinal (written) format.
194
+ * @throws {Error} Value cannot be invalid.
194
195
  */
195
- export default function (value, options = {}) {
196
+ export default function floatToCardinal (value, options = {}) {
196
197
  return new N2WordsRU(options).floatToCardinal(value);
197
198
  }
package/lib/i18n/sr.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 N2WordsSR extends N2WordsRU {
10
10
  ones: {
11
11
  1: string[];
package/lib/i18n/sr.js CHANGED
@@ -89,10 +89,9 @@ export class N2WordsSR extends N2WordsRU {
89
89
  }
90
90
  const words = [];
91
91
  const chunks = this.splitByX(number.toString(), 3);
92
- let i = chunks.length;
93
- for (let j = 0; j < chunks.length; j++) {
94
- const x = chunks[j];
95
- i = i - 1;
92
+ let index = chunks.length;
93
+ for (const x of chunks) {
94
+ index = index - 1;
96
95
  // if (x == 0) { continue; }
97
96
  const [n1, n2, n3] = this.getDigits(x);
98
97
  if (n3 > 0) {
@@ -104,12 +103,12 @@ export class N2WordsSR extends N2WordsRU {
104
103
  if (n2 == 1) {
105
104
  words.push(this.tens[n1]);
106
105
  } else if (n1 > 0) {
107
- const isFeminine = (this.feminine || this.SCALE[i][3]);
108
- const genderIdx = isFeminine ? 1 : 0;
109
- words.push(this.ones[n1][genderIdx]);
106
+ const isFeminine = (this.feminine || this.SCALE[index][3]);
107
+ const genderIndex = isFeminine ? 1 : 0;
108
+ words.push(this.ones[n1][genderIndex]);
110
109
  }
111
- if ((i > 0) && (x != 0)) {
112
- words.push(this.pluralize(x, this.SCALE[i]));
110
+ if ((index > 0) && (x != 0)) {
111
+ words.push(this.pluralize(x, this.SCALE[index]));
113
112
  }
114
113
  }
115
114
  return words.join(' ');
@@ -120,9 +119,9 @@ export class N2WordsSR extends N2WordsRU {
120
119
  * Converts a value to cardinal (written) form.
121
120
  * @param {number|string|bigint} value Number to be convert.
122
121
  * @param {object} [options] Options for class.
123
- * @throws {Error} Value cannot be invalid.
124
122
  * @returns {string} Value in cardinal (written) format.
123
+ * @throws {Error} Value cannot be invalid.
125
124
  */
126
- export default function (value, options = {}) {
125
+ export default function floatToCardinal (value, options = {}) {
127
126
  return new N2WordsSR(options).floatToCardinal(value);
128
127
  }
package/lib/i18n/tr.d.ts CHANGED
@@ -2,14 +2,14 @@
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 N2WordsTR extends BaseLanguage {
10
10
  constructor(options?: {});
11
11
  merge(lPair: any, rPair: any): {
12
12
  [x: string]: bigint;
13
13
  };
14
14
  }
15
- import BaseLanguage from '../classes/BaseLanguage.js';
15
+ import BaseLanguage from '../classes/base-language.js';
package/lib/i18n/tr.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 N2WordsTR extends BaseLanguage {
4
4
  constructor(options = {}) {
@@ -8,11 +8,11 @@ export class N2WordsTR extends BaseLanguage {
8
8
  zero: 'sıfır',
9
9
  spaceSeparator: (options.dropSpaces === true ? '' : ' '),
10
10
  }, options), [
11
- [1000000000000000000n, 'kentilyon'],
12
- [1000000000000000n, 'katrilyon'],
13
- [1000000000000n, 'trilyon'],
14
- [1000000000n, 'milyar'],
15
- [1000000n, 'milyon'],
11
+ [1_000_000_000_000_000_000n, 'kentilyon'],
12
+ [1_000_000_000_000_000n, 'katrilyon'],
13
+ [1_000_000_000_000n, 'trilyon'],
14
+ [1_000_000_000n, 'milyar'],
15
+ [1_000_000n, 'milyon'],
16
16
  [1000n, 'bin'],
17
17
  [100n, 'yüz'],
18
18
  [90n, 'doksan'],
@@ -40,14 +40,14 @@ export class N2WordsTR extends BaseLanguage {
40
40
  merge(lPair, rPair) {
41
41
  const lText = Object.keys(lPair)[0];
42
42
  const rText = Object.keys(rPair)[0];
43
- const lNum = BigInt(Object.values(lPair)[0]);
44
- const rNum = BigInt(Object.values(rPair)[0]);
45
- if (lNum == 1 && (rNum <= 100 || rNum == 1000)) {
46
- return { [rText]: rNum };
47
- } else if (rNum > lNum) {
48
- return { [`${lText}${this.spaceSeparator}${rText}`]: lNum * rNum };
43
+ const lNumber = BigInt(Object.values(lPair)[0]);
44
+ const rNumber = BigInt(Object.values(rPair)[0]);
45
+ if (lNumber == 1 && (rNumber <= 100 || rNumber == 1000)) {
46
+ return { [rText]: rNumber };
47
+ } else if (rNumber > lNumber) {
48
+ return { [`${lText}${this.spaceSeparator}${rText}`]: lNumber * rNumber };
49
49
  } else {
50
- return { [`${lText}${this.spaceSeparator}${rText}`]: lNum + rNum };
50
+ return { [`${lText}${this.spaceSeparator}${rText}`]: lNumber + rNumber };
51
51
  }
52
52
  }
53
53
  }
@@ -56,9 +56,9 @@ export class N2WordsTR extends BaseLanguage {
56
56
  * Converts a value to cardinal (written) form.
57
57
  * @param {number|string|bigint} value Number to be convert.
58
58
  * @param {object} [options] Options for class.
59
- * @throws {Error} Value cannot be invalid.
60
59
  * @returns {string} Value in cardinal (written) format.
60
+ * @throws {Error} Value cannot be invalid.
61
61
  */
62
- export default function (value, options = {}) {
62
+ export default function floatToCardinal (value, options = {}) {
63
63
  return new N2WordsTR(options).floatToCardinal(value);
64
64
  }
package/lib/i18n/uk.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 N2WordsUK extends N2WordsRU {
10
10
  ones: {
11
11
  1: string;
package/lib/i18n/uk.js CHANGED
@@ -87,9 +87,9 @@ export class N2WordsUK extends N2WordsRU {
87
87
  * Converts a value to cardinal (written) form.
88
88
  * @param {number|string|bigint} value Number to be convert.
89
89
  * @param {object} [options] Options for class.
90
- * @throws {Error} Value cannot be invalid.
91
90
  * @returns {string} Value in cardinal (written) format.
91
+ * @throws {Error} Value cannot be invalid.
92
92
  */
93
- export default function (value, options = {}) {
93
+ export default function floatToCardinal (value, options = {}) {
94
94
  return new N2WordsUK(options).floatToCardinal(value);
95
95
  }
package/lib/i18n/vi.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 N2WordsID extends AbstractLanguage {
10
10
  constructor(options: any);
11
11
  base: {
@@ -67,4 +67,4 @@ export class N2WordsID extends AbstractLanguage {
67
67
  convertMore1000(number: any): any;
68
68
  toCardinal(number: any): any;
69
69
  }
70
- import AbstractLanguage from '../classes/AbstractLanguage.js';
70
+ import AbstractLanguage from '../classes/abstract-language.js';
package/lib/i18n/vi.js CHANGED
@@ -1,4 +1,4 @@
1
- import AbstractLanguage from '../classes/AbstractLanguage.js';
1
+ import AbstractLanguage from '../classes/abstract-language.js';
2
2
 
3
3
  export class N2WordsID extends AbstractLanguage {
4
4
  base = {
@@ -133,11 +133,7 @@ export class N2WordsID extends AbstractLanguage {
133
133
  if (number < 100n) {
134
134
  return this.convertLess100(Number(number));
135
135
  } else {
136
- if (number < 1000n) {
137
- return this.convertLess1000(Number(number));
138
- } else { // number >= 1000
139
- return this.convertMore1000(number);
140
- }
136
+ return (number < 1000n ? this.convertLess1000(Number(number)) : this.convertMore1000(number));
141
137
  }
142
138
  }
143
139
  }
@@ -147,9 +143,9 @@ export class N2WordsID extends AbstractLanguage {
147
143
  * Converts a value to cardinal (written) form.
148
144
  * @param {number|string|bigint} value Number to be convert.
149
145
  * @param {object} [options] Options for class.
150
- * @throws {Error} Value cannot be invalid.
151
146
  * @returns {string} Value in cardinal (written) format.
147
+ * @throws {Error} Value cannot be invalid.
152
148
  */
153
- export default function (value, options = {}) {
149
+ export default function floatToCardinal (value, options = {}) {
154
150
  return new N2WordsID(options).floatToCardinal(value);
155
151
  }