n2words 1.12.2 → 1.13.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.
@@ -0,0 +1,57 @@
1
+ import N2WordsBase from '../classes/N2WordsBase.mjs';
2
+
3
+ export class N2WordsAZ extends N2WordsBase {
4
+ constructor() {
5
+ super();
6
+
7
+ this.negativeWord = 'mənfi';
8
+ this.separatorWord = 'nöqtə';
9
+ this.zero = 'sıfır';
10
+ this.cards = [
11
+ { '1000000000000000000': 'kentilyon' },
12
+ { '1000000000000000': 'katrilyon' },
13
+ { '1000000000000': 'trilyon' },
14
+ { '1000000000': 'milyar' },
15
+ { '1000000': 'milyon' },
16
+ { '1000': 'min' },
17
+ { '100': 'yüz' },
18
+ { '90': 'doxsan' },
19
+ { '80': 'səksən' },
20
+ { '70': 'yetmiş' },
21
+ { '60': 'altmış' },
22
+ { '50': 'əlli' },
23
+ { '40': 'qırx' },
24
+ { '30': 'otuz' },
25
+ { '20': 'iyirmi' },
26
+ { '10': 'on' },
27
+ { '9': 'doqquz' },
28
+ { '8': 'səkkiz' },
29
+ { '7': 'yeddi' },
30
+ { '6': 'altı' },
31
+ { '5': 'beş' },
32
+ { '4': 'dörd' },
33
+ { '3': 'üç' },
34
+ { '2': 'iki' },
35
+ { '1': 'bir' },
36
+ { '0': 'sıfır' }
37
+ ];
38
+ }
39
+
40
+ merge(lPair, rPair) {
41
+ const lText = Object.keys(lPair)[0];
42
+ const rText = Object.keys(rPair)[0];
43
+ const lNum = parseInt(Object.values(lPair)[0]);
44
+ const rNum = parseInt(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 };
49
+ } else {
50
+ return { [`${lText}${this.spaceSeparator}${rText}`]: lNum + rNum };
51
+ }
52
+ }
53
+ }
54
+
55
+ export default function(n) {
56
+ return new N2WordsAZ().floatToCardinal(n);
57
+ }
package/lib/i18n/TR.mjs CHANGED
@@ -12,358 +12,48 @@ export class N2WordsTR extends N2WordsBase {
12
12
  this.separatorWord = 'virgül';
13
13
  this.zero = 'sıfır';
14
14
  this.spaceSeparator = (this.options.dropSpaces) ? '' : ' ';
15
- this.precision = 2;
16
-
17
- this.cardinalOnes = {
18
- 1: 'bir',
19
- 2: 'iki',
20
- 3: 'üç',
21
- 4: 'dört',
22
- 5: 'beş',
23
- 6: 'altı',
24
- 7: 'yedi',
25
- 8: 'sekiz',
26
- 9: 'dokuz',
27
- };
28
- this.cardinalTens = {
29
- 1: 'on',
30
- 2: 'yirmi',
31
- 3: 'otuz',
32
- 4: 'kırk',
33
- 5: 'elli',
34
- 6: 'altmış',
35
- 7: 'yetmiş',
36
- 8: 'seksen',
37
- 9: 'doksan',
38
- };
39
- this.hundreds = {
40
- 2: 'iki',
41
- 3: 'üç',
42
- 4: 'dört',
43
- 5: 'beş',
44
- 6: 'altı',
45
- 7: 'yedi',
46
- 8: 'sekiz',
47
- 9: 'dokuz',
48
- };
49
- this.cardinalHundred = ['yüz', ''];
50
- this.cardinalTriplets = {
51
- 1: 'bin',
52
- 2: 'milyon',
53
- 3: 'milyar',
54
- 4: 'trilyon',
55
- 5: 'katrilyon',
56
- 6: 'kentilyon',
57
- };
58
- this.integersToRead = [];
59
- this.totalTripletsToRead = 0;
60
- this.totalDigitsOutsideTriplets = 0;
61
- this.lastZeroDigitOrder = 0;
15
+ this.cards = [
16
+ { '1000000000000000000': 'kentilyon' },
17
+ { '1000000000000000': 'katrilyon' },
18
+ { '1000000000000': 'trilyon' },
19
+ { '1000000000': 'milyar' },
20
+ { '1000000': 'milyon' },
21
+ { '1000': 'bin' },
22
+ { '100': 'yüz' },
23
+ { '90': 'doksan' },
24
+ { '80': 'seksen' },
25
+ { '70': 'yetmiş' },
26
+ { '60': 'altmış' },
27
+ { '50': 'elli' },
28
+ { '40': 'kırk' },
29
+ { '30': 'otuz' },
30
+ { '20': 'yirmi' },
31
+ { '10': 'on' },
32
+ { '9': 'dokuz' },
33
+ { '8': 'sekiz' },
34
+ { '7': 'yedi' },
35
+ { '6': 'altı' },
36
+ { '5': 'beş' },
37
+ { '4': 'dört' },
38
+ { '3': 'üç' },
39
+ { '2': 'iki' },
40
+ { '1': 'bir' },
41
+ { '0': 'sıfır' }
42
+ ];
62
43
  }
63
44
 
64
- splitNum(value) {
65
- const floatDigits = JSON.stringify(value * 10 ** this.precision);
66
- if (parseInt(value) != 0) {
67
- this.integersToRead = [
68
- JSON.stringify(parseInt(value)),
69
- floatDigits.slice(floatDigits.length - this.precision, floatDigits.length),
70
- ];
45
+ merge(lPair, rPair) {
46
+ const lText = Object.keys(lPair)[0];
47
+ const rText = Object.keys(rPair)[0];
48
+ const lNum = parseInt(Object.values(lPair)[0]);
49
+ const rNum = parseInt(Object.values(rPair)[0]);
50
+ if (lNum == 1 && (rNum <= 100 || rNum == 1000)) {
51
+ return { [rText]: rNum };
52
+ } else if (rNum > lNum) {
53
+ return { [`${lText}${this.spaceSeparator}${rText}`]: lNum * rNum };
71
54
  } else {
72
- this.integersToRead = [
73
- '0',
74
- '0'.repeat(this.precision - floatDigits.length) +
75
- floatDigits.slice(floatDigits.length - this.precision, floatDigits.length),
76
- ];
77
- }
78
- if (this.integersToRead[0].length % 3 > 0) {
79
- this.totalTripletsToRead = Math.floor(this.integersToRead[0].length / 3) + 1;
80
- } else if (this.integersToRead[0].length % 3 == 0) {
81
- this.totalTripletsToRead = Math.floor(this.integersToRead[0].length / 3);
82
- }
83
- this.totalDigitsOutsideTriplets = this.integersToRead[0].length % 3;
84
-
85
- const okunacak = this.integersToRead[0].split('').reverse();
86
- this.lastZeroDigitOrder = 0;
87
- let found = 0;
88
- for (let i = 0; i < okunacak.length; i++) {
89
- if (parseInt(okunacak[i]) == 0 && found == 0) {
90
- this.lastZeroDigitOrder = i + 1;
91
- } else {
92
- found = 1;
93
- }
94
- }
95
- }
96
-
97
- joinWords(wordArray) {
98
- return wordArray.join(this.spaceSeparator).trim();
99
- }
100
-
101
- toCardinal(value) {
102
- if (parseInt(value) == 0) {
103
- return 'sıfır';
104
- }
105
- this.splitNum(value);
106
- let wordArray = [];
107
- if (this.lastZeroDigitOrder >= this.integersToRead[0].length) {
108
- return this.joinWords(wordArray);
109
- }
110
- if (this.totalTripletsToRead == 1) {
111
- if (this.totalDigitsOutsideTriplets == 2) {
112
- if (this.lastZeroDigitOrder == 1) {
113
- if(this.cardinalTens[this.integersToRead[0][0]]) {
114
- wordArray.push(this.cardinalTens[this.integersToRead[0][0]]);
115
- }
116
- return this.joinWords(wordArray);
117
- }
118
- if (this.lastZeroDigitOrder == 0) {
119
- if(this.cardinalTens[this.integersToRead[0][0]]) {
120
- wordArray.push(this.cardinalTens[this.integersToRead[0][0]]);
121
- }
122
- if(this.cardinalOnes[this.integersToRead[0][1]]) {
123
- wordArray.push(this.cardinalOnes[this.integersToRead[0][1]]);
124
- }
125
- }
126
- return this.joinWords(wordArray);
127
- }
128
- if (this.totalDigitsOutsideTriplets == 1) {
129
- if (this.lastZeroDigitOrder == 0) {
130
- if(this.cardinalOnes[this.integersToRead[0][0]]) {
131
- wordArray.push(this.cardinalOnes[this.integersToRead[0][0]]);
132
- }
133
- return this.joinWords(wordArray);
134
- }
135
- }
136
- if (this.totalDigitsOutsideTriplets == 0) {
137
- if (this.lastZeroDigitOrder == 2) {
138
- if(this.hundreds[this.integersToRead[0][0]]) {
139
- wordArray.push(this.hundreds[this.integersToRead[0][0]]);
140
- }
141
- wordArray.push(this.cardinalHundred[0]);
142
- return this.joinWords(wordArray);
143
- }
144
- if (this.lastZeroDigitOrder == 1) {
145
- if(this.hundreds[this.integersToRead[0][0]]) {
146
- wordArray.push(this.hundreds[this.integersToRead[0][0]]);
147
- }
148
- wordArray.push(this.cardinalHundred[0]);
149
- if(this.cardinalTens[this.integersToRead[0][1]]) {
150
- wordArray.push(this.cardinalTens[this.integersToRead[0][1]]);
151
- }
152
- return this.joinWords(wordArray);
153
- }
154
- if (this.lastZeroDigitOrder == 0) {
155
- if(this.hundreds[this.integersToRead[0][0]]) {
156
- wordArray.push(this.hundreds[this.integersToRead[0][0]]);
157
- }
158
- wordArray.push(this.cardinalHundred[0]);
159
- if(this.cardinalTens[this.integersToRead[0][1]]) {
160
- wordArray.push(this.cardinalTens[this.integersToRead[0][1]]);
161
- }
162
- if(this.cardinalOnes[this.integersToRead[0][2]]) {
163
- wordArray.push(this.cardinalOnes[this.integersToRead[0][2]]);
164
- }
165
- return this.joinWords(wordArray);
166
- }
167
- }
168
- }
169
- if (this.totalTripletsToRead >= 2) {
170
- if (this.totalDigitsOutsideTriplets == 2) {
171
- if (this.lastZeroDigitOrder == this.integersToRead[0].length - 1) {
172
- if(this.cardinalTens[this.integersToRead[0][0]]) {
173
- wordArray.push(this.cardinalTens[this.integersToRead[0][0]]);
174
- }
175
- wordArray.push(this.cardinalTriplets[this.totalTripletsToRead - 1]);
176
- return this.joinWords(wordArray);
177
- }
178
- if (this.lastZeroDigitOrder == this.integersToRead[0].length - 2) {
179
- if(this.cardinalTens[this.integersToRead[0][0]]) {
180
- wordArray.push(this.cardinalTens[this.integersToRead[0][0]]);
181
- }
182
- if(this.cardinalOnes[this.integersToRead[0][1]]) {
183
- wordArray.push(this.cardinalOnes[this.integersToRead[0][1]]);
184
- }
185
- wordArray.push(this.cardinalTriplets[this.totalTripletsToRead - 1]);
186
- return this.joinWords(wordArray);
187
- }
188
- if (this.lastZeroDigitOrder < this.integersToRead[0].length - 2) {
189
- if(this.cardinalTens[this.integersToRead[0][0]]) {
190
- wordArray.push(this.cardinalTens[this.integersToRead[0][0]]);
191
- }
192
- if(this.cardinalOnes[this.integersToRead[0][1]]) {
193
- wordArray.push(this.cardinalOnes[this.integersToRead[0][1]]);
194
- }
195
- wordArray.push(this.cardinalTriplets[this.totalTripletsToRead - 1]);
196
- }
197
- }
198
- if (this.totalDigitsOutsideTriplets == 1) {
199
- if (this.lastZeroDigitOrder == this.integersToRead[0].length - 1) {
200
- if (!(this.totalTripletsToRead == 2 && this.integersToRead[0][0] == '1')) {
201
- if(this.cardinalOnes[this.integersToRead[0][0]]) {
202
- wordArray.push(this.cardinalOnes[this.integersToRead[0][0]]);
203
- }
204
- }
205
- wordArray.push(this.cardinalTriplets[this.totalTripletsToRead - 1]);
206
- return this.joinWords(wordArray);
207
- }
208
- if (this.lastZeroDigitOrder < this.integersToRead[0].length - 1) {
209
- if (!(this.totalTripletsToRead == 2 && this.integersToRead[0][0] == '1')) {
210
- if(this.cardinalOnes[this.integersToRead[0][0]]) {
211
- wordArray.push(this.cardinalOnes[this.integersToRead[0][0]]);
212
- }
213
- }
214
- wordArray.push(this.cardinalTriplets[this.totalTripletsToRead - 1]);
215
- }
216
- }
217
- if (this.totalDigitsOutsideTriplets == 0) {
218
- if (this.lastZeroDigitOrder == this.integersToRead[0].length - 1) {
219
- if(this.hundreds[this.integersToRead[0][0]]) {
220
- wordArray.push(this.hundreds[this.integersToRead[0][0]]);
221
- }
222
- wordArray.push(this.cardinalHundred[0]);
223
- wordArray.push(this.cardinalTriplets[this.totalTripletsToRead - 1]);
224
- return this.joinWords(wordArray);
225
- }
226
- if (this.lastZeroDigitOrder == this.integersToRead[0].length - 2) {
227
- if(this.hundreds[this.integersToRead[0][0]]) {
228
- wordArray.push(this.hundreds[this.integersToRead[0][0]]);
229
- }
230
- wordArray.push(this.cardinalHundred[0]);
231
- if(this.cardinalTens[this.integersToRead[0][1]]) {
232
- wordArray.push(this.cardinalTens[this.integersToRead[0][1]]);
233
- }
234
- wordArray.push(this.cardinalTriplets[this.totalTripletsToRead - 1]);
235
- return this.joinWords(wordArray);
236
- }
237
- if (this.lastZeroDigitOrder == this.integersToRead[0].length - 3) {
238
- if(this.hundreds[this.integersToRead[0][0]]) {
239
- wordArray.push(this.hundreds[this.integersToRead[0][0]]);
240
- }
241
- wordArray.push(this.cardinalHundred[0]);
242
- if(this.cardinalTens[this.integersToRead[0][1]]) {
243
- wordArray.push(this.cardinalTens[this.integersToRead[0][1]]);
244
- }
245
- if(this.cardinalOnes[this.integersToRead[0][2]]) {
246
- wordArray.push(this.cardinalOnes[this.integersToRead[0][2]]);
247
- }
248
- wordArray.push(this.cardinalTriplets[this.totalTripletsToRead - 1]);
249
- return this.joinWords(wordArray);
250
- }
251
- if (this.lastZeroDigitOrder < this.integersToRead[0].length - 3) {
252
- if(this.hundreds[this.integersToRead[0][0]]) {
253
- wordArray.push(this.hundreds[this.integersToRead[0][0]]);
254
- }
255
- wordArray.push(this.cardinalHundred[0]);
256
- if(this.cardinalTens[this.integersToRead[0][1]]) {
257
- wordArray.push(this.cardinalTens[this.integersToRead[0][1]]);
258
- }
259
- if (!(this.totalTripletsToRead == 2 && this.integersToRead[0][2] == '1')) {
260
- if(this.cardinalOnes[this.integersToRead[0][2]]) {
261
- wordArray.push(this.cardinalOnes[this.integersToRead[0][2]]);
262
- }
263
- }
264
- wordArray.push(this.cardinalTriplets[this.totalTripletsToRead - 1]);
265
- }
266
- }
267
- for (let i = this.totalTripletsToRead - 1; i > 0; i--) {
268
- const readingTripletOrder = this.totalTripletsToRead - i;
269
- let lastReadDigitOrder;
270
- if (this.totalDigitsOutsideTriplets == 0) {
271
- lastReadDigitOrder = readingTripletOrder * 3;
272
- } else {
273
- lastReadDigitOrder = (readingTripletOrder - 1) * 3 + this.totalDigitsOutsideTriplets;
274
- }
275
- if (this.integersToRead[0].slice(lastReadDigitOrder, lastReadDigitOrder + 3) != '000') {
276
- if (this.integersToRead[0][lastReadDigitOrder] != '0') {
277
- if(this.hundreds[this.integersToRead[0][lastReadDigitOrder]]) {
278
- wordArray.push(this.hundreds[this.integersToRead[0][lastReadDigitOrder]]);
279
- }
280
- if (this.lastZeroDigitOrder == this.integersToRead[0].length - lastReadDigitOrder - 1) {
281
- if (i == 1) {
282
- wordArray.push(this.cardinalHundred[0]);
283
- return this.joinWords(wordArray);
284
- } else if (i > 1) {
285
- wordArray.push(this.cardinalHundred[0]);
286
- wordArray.push(this.cardinalTriplets[i - 1]);
287
- return this.joinWords(wordArray);
288
- }
289
- } else {
290
- wordArray.push(this.cardinalHundred[0]);
291
- }
292
- }
293
- if (this.integersToRead[0][lastReadDigitOrder + 1] != '0') {
294
- if (this.lastZeroDigitOrder == this.integersToRead[0].length - lastReadDigitOrder - 2) {
295
- if (i == 1) {
296
- if(this.cardinalTens[this.integersToRead[0][lastReadDigitOrder + 1]]) {
297
- wordArray.push(this.cardinalTens[this.integersToRead[0][lastReadDigitOrder + 1]]);
298
- }
299
- return this.joinWords(wordArray);
300
- } else if (i > 1) {
301
- if(this.cardinalTens[this.integersToRead[0][lastReadDigitOrder + 1]]) {
302
- wordArray.push(this.cardinalTens[this.integersToRead[0][lastReadDigitOrder + 1]]);
303
- }
304
- wordArray.push(this.cardinalTriplets[i - 1]);
305
- return this.joinWords(wordArray);
306
- }
307
- } else {
308
- if(this.cardinalTens[this.integersToRead[0][lastReadDigitOrder + 1]]) {
309
- wordArray.push(this.cardinalTens[this.integersToRead[0][lastReadDigitOrder + 1]]);
310
- }
311
- }
312
- }
313
- if (this.integersToRead[0][lastReadDigitOrder + 2] != '0') {
314
- if (this.lastZeroDigitOrder == this.integersToRead[0].length - lastReadDigitOrder - 3) {
315
- if (i == 1) {
316
- if(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]) {
317
- wordArray.push(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]);
318
- }
319
- return this.joinWords(wordArray);
320
- }
321
- if (i == 2) {
322
- if (this.integersToRead[0].slice(lastReadDigitOrder, lastReadDigitOrder + 2) != '00') {
323
- if(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]) {
324
- wordArray.push(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]);
325
- }
326
- } else if (this.integersToRead[0][lastReadDigitOrder + 2] != '1') {
327
- if(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]) {
328
- wordArray.push(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]);
329
- }
330
- }
331
- wordArray.push(this.cardinalTriplets[i - 1]);
332
- return this.joinWords(wordArray);
333
- }
334
- if (i > 2) {
335
- if(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]) {
336
- wordArray.push(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]);
337
- }
338
- wordArray.push(this.cardinalTriplets[i - 1]);
339
- return this.joinWords(wordArray);
340
- }
341
- } else {
342
- if (this.integersToRead[0].slice(lastReadDigitOrder, lastReadDigitOrder + 2) != '00') {
343
- if(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]) {
344
- wordArray.push(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]);
345
- }
346
- } else {
347
- if (i == 2) {
348
- if (this.integersToRead[0].slice(lastReadDigitOrder, lastReadDigitOrder + 2) != '00') {
349
- if(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]) {
350
- wordArray.push(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]);
351
- }
352
- } else if (this.integersToRead[0][lastReadDigitOrder + 2] != '1') {
353
- if(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]) {
354
- wordArray.push(this.cardinalOnes[this.integersToRead[0][lastReadDigitOrder + 2]]);
355
- }
356
- }
357
- }
358
- }
359
- }
360
- }
361
-
362
- wordArray.push(this.cardinalTriplets[i - 1]);
363
- }
364
- }
55
+ return { [`${lText}${this.spaceSeparator}${rText}`]: lNum + rNum };
365
56
  }
366
- return this.joinWords(wordArray);
367
57
  }
368
58
  }
369
59
 
package/lib/n2words.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable import/max-dependencies */
2
2
  import n2wordsAR from './i18n/AR.mjs';
3
+ import n2wordsAZ from './i18n/AZ.mjs';
3
4
  import n2wordsCZ from './i18n/CZ.mjs';
4
5
  import n2wordsDE from './i18n/DE.mjs';
5
6
  import n2wordsDK from './i18n/DK.mjs';
@@ -53,6 +54,7 @@ const supportedLanguages = [
53
54
  'id',
54
55
  'hr',
55
56
  'vi',
57
+ 'az',
56
58
  ];
57
59
 
58
60
  /**
@@ -131,6 +133,8 @@ export default function(n, options = {lang: 'en'}) {
131
133
  return n2wordsZH(n);
132
134
  } else if (lang === 'VI') {
133
135
  return n2wordsVI(n);
136
+ } else if (lang === 'AZ') {
137
+ return n2wordsAZ(n);
134
138
  } else {
135
139
  return n2wordsEN(n);
136
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n2words",
3
- "version": "1.12.2",
3
+ "version": "1.13.0",
4
4
  "description": "Convert numbers to words, in multiple languages",
5
5
  "main": "dist/n2words.js",
6
6
  "scripts": {
@@ -47,7 +47,8 @@
47
47
  "hungarian",
48
48
  "indonesian",
49
49
  "croatian",
50
- "vietnamese"
50
+ "vietnamese",
51
+ "azerbaijani"
51
52
  ],
52
53
  "author": "Wael TELLAT",
53
54
  "license": "MIT",