n2words 1.19.1 → 1.20.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.
- package/dist/n2words.d.ts +0 -1
- package/dist/n2words.js +1 -1
- package/dist/n2words.js.map +1 -1
- package/lib/i18n/ar.d.ts +15 -2
- package/lib/i18n/ar.js +59 -57
- package/package.json +1 -1
package/lib/i18n/ar.d.ts
CHANGED
|
@@ -22,7 +22,20 @@ export class Arabic extends AbstractLanguage {
|
|
|
22
22
|
arabicAppendedGroup: string[];
|
|
23
23
|
arabicPluralGroups: string[];
|
|
24
24
|
digitFeminineStatus(digit: any): string;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Processes the Arabic group number and returns the corresponding Arabic representation.
|
|
27
|
+
* @param {number} groupNumber - The number to process. From 1 to 999.
|
|
28
|
+
* @param {number} groupLevel - The level of the group.
|
|
29
|
+
* Example: 12345678 is processed in blocks: '678' (group 0), '345' (group 1), '12' (group 2)
|
|
30
|
+
* @returns {string} The Arabic representation of the group number.
|
|
31
|
+
*/
|
|
32
|
+
processArabicGroup(groupNumber: number, groupLevel: number): string;
|
|
33
|
+
/**
|
|
34
|
+
* Converts a number to its cardinal representation in Arabic.
|
|
35
|
+
* It process by blocks of 3 digits.
|
|
36
|
+
* @param {number} number - The number to convert.
|
|
37
|
+
* @returns {string} The cardinal representation of the number in Arabic.
|
|
38
|
+
*/
|
|
39
|
+
toCardinal(number: number): string;
|
|
27
40
|
}
|
|
28
41
|
import AbstractLanguage from '../classes/AbstractLanguage.js';
|
package/lib/i18n/ar.js
CHANGED
|
@@ -28,7 +28,7 @@ export class Arabic extends AbstractLanguage {
|
|
|
28
28
|
'تسعة عشر',
|
|
29
29
|
],
|
|
30
30
|
feminine: [
|
|
31
|
-
'
|
|
31
|
+
'واحدة',
|
|
32
32
|
'اثنتان',
|
|
33
33
|
'ثلاث',
|
|
34
34
|
'أربع',
|
|
@@ -64,10 +64,6 @@ export class Arabic extends AbstractLanguage {
|
|
|
64
64
|
|
|
65
65
|
arabicPluralGroups = ['', 'آلاف', 'ملايين', 'مليارات', 'تريليونات', 'كوادريليونات', 'كوينتليونات', 'سكستيليونات'];
|
|
66
66
|
|
|
67
|
-
// isCurrencyPartNameFeminine = true
|
|
68
|
-
|
|
69
|
-
// isCurrencyNameFeminine = false
|
|
70
|
-
|
|
71
67
|
constructor(options) {
|
|
72
68
|
options = Object.assign({
|
|
73
69
|
negativeWord: 'ناقص',
|
|
@@ -82,67 +78,70 @@ export class Arabic extends AbstractLanguage {
|
|
|
82
78
|
}
|
|
83
79
|
|
|
84
80
|
digitFeminineStatus(digit) {
|
|
85
|
-
// if ((groupLevel == -1 && this.isCurrencyPartNameFeminine) || (groupLevel == 0 && this.isCurrencyNameFeminine)) {
|
|
86
|
-
// return this.arabicFeminineOnes[digit]
|
|
87
|
-
// }
|
|
88
81
|
return this.ones[this.feminine ? 'feminine' : 'masculine'][digit - 1];
|
|
89
82
|
}
|
|
90
83
|
|
|
91
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Processes the Arabic group number and returns the corresponding Arabic representation.
|
|
86
|
+
* @param {number} groupNumber - The number to process. From 1 to 999.
|
|
87
|
+
* @param {number} groupLevel - The level of the group.
|
|
88
|
+
* Example: 12345678 is processed in blocks: '678' (group 0), '345' (group 1), '12' (group 2)
|
|
89
|
+
* @returns {string} The Arabic representation of the group number.
|
|
90
|
+
*/
|
|
91
|
+
processArabicGroup(groupNumber, groupLevel) {
|
|
92
92
|
let tens = groupNumber % 100;
|
|
93
93
|
const hundreds = groupNumber / 100;
|
|
94
94
|
let retVal = '';
|
|
95
95
|
|
|
96
|
-
if (hundreds > 0) {
|
|
97
|
-
|
|
96
|
+
if (Math.trunc(hundreds) > 0) {
|
|
97
|
+
if (tens == 0 && Math.trunc(hundreds) == 2) {
|
|
98
|
+
retVal = this.arabicTwos[0];
|
|
99
|
+
} else {
|
|
100
|
+
retVal = this.arabicHundreds[Math.trunc(hundreds)];
|
|
101
|
+
if (retVal != '' && tens != 0) {
|
|
102
|
+
retVal += ' و';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
98
105
|
}
|
|
99
106
|
|
|
100
|
-
if (tens > 0) {
|
|
101
|
-
if (tens
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
} else {
|
|
107
|
-
// Add divider
|
|
108
|
-
if (retVal != '') {
|
|
109
|
-
retVal += ' و ';
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (tens == 1 && groupLevel > 0 && hundreds == 0) {
|
|
113
|
-
retVal += '';
|
|
114
|
-
} else if (
|
|
115
|
-
(tens == 1 || tens == 2) &&
|
|
116
|
-
(groupLevel == 0 || groupLevel == -1) &&
|
|
117
|
-
(hundreds == 0 && remainingNumber == 0)
|
|
118
|
-
) {
|
|
119
|
-
retVal += '';
|
|
107
|
+
if (tens > 0 && tens < 20) { // 1 -> 19
|
|
108
|
+
if (tens === 2 && Math.trunc(hundreds) === 0 && groupLevel > 0) {
|
|
109
|
+
const pow = Math.trunc(Math.log10(Number(this.number)));
|
|
110
|
+
if (pow % 3 === 0 && this.number === 2 * Math.pow(10, pow)) {
|
|
111
|
+
if (groupNumber === 2) {
|
|
112
|
+
retVal = this.arabicTwos[Math.trunc(groupLevel)];
|
|
120
113
|
} else {
|
|
121
|
-
retVal
|
|
114
|
+
retVal = this.arabicAppendedTwos[Math.trunc(groupLevel)];
|
|
122
115
|
}
|
|
116
|
+
} else {
|
|
117
|
+
retVal = this.arabicTwos[Math.trunc(groupLevel)];
|
|
123
118
|
}
|
|
119
|
+
} else if (tens === 1 && groupLevel > 0) {
|
|
120
|
+
retVal += this.arabicGroup[Math.trunc(groupLevel)];
|
|
124
121
|
} else {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
retVal += this.digitFeminineStatus(ones, groupLevel);
|
|
134
|
-
}
|
|
135
|
-
if (retVal != '' && ones != 0) {
|
|
136
|
-
retVal += ' و ';
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
retVal += this.arabicTens[Math.trunc(tens)];
|
|
122
|
+
retVal += this.digitFeminineStatus(Math.trunc(tens), groupLevel);
|
|
123
|
+
}
|
|
124
|
+
} else if (tens >= 20) { // 20 -> 99
|
|
125
|
+
const ones = tens % 10;
|
|
126
|
+
const tensIndex = (tens / 10) - 2;
|
|
127
|
+
if (ones > 0) {
|
|
128
|
+
retVal += this.digitFeminineStatus(ones, groupLevel);
|
|
140
129
|
}
|
|
130
|
+
if (retVal != '' && ones != 0) {
|
|
131
|
+
retVal += ' و';
|
|
132
|
+
}
|
|
133
|
+
retVal += this.arabicTens[Math.trunc(tensIndex)];
|
|
141
134
|
}
|
|
142
135
|
|
|
143
136
|
return retVal;
|
|
144
137
|
}
|
|
145
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Converts a number to its cardinal representation in Arabic.
|
|
141
|
+
* It process by blocks of 3 digits.
|
|
142
|
+
* @param {number} number - The number to convert.
|
|
143
|
+
* @returns {string} The cardinal representation of the number in Arabic.
|
|
144
|
+
*/
|
|
146
145
|
toCardinal(number) {
|
|
147
146
|
if (number == 0) {
|
|
148
147
|
return this.zero;
|
|
@@ -150,30 +149,30 @@ export class Arabic extends AbstractLanguage {
|
|
|
150
149
|
|
|
151
150
|
this.number = number;
|
|
152
151
|
let tempNumber = number;
|
|
152
|
+
let tempNumberDec;
|
|
153
153
|
let group = 0;
|
|
154
154
|
let retVal = '';
|
|
155
155
|
|
|
156
156
|
// Loop until number has been reduced to zero or less
|
|
157
157
|
while (tempNumber > 0) {
|
|
158
|
+
tempNumberDec = tempNumber;
|
|
158
159
|
// Get the remaining value after dividing by 1000
|
|
159
|
-
const numberToProcess = Number(
|
|
160
|
-
|
|
161
|
-
tempNumber = tempNumber / 1000n;
|
|
160
|
+
const numberToProcess = Number(tempNumberDec % 1000n); // Maximum: 999
|
|
161
|
+
tempNumber = tempNumberDec / 1000n;
|
|
162
162
|
|
|
163
163
|
// Process "group"
|
|
164
|
-
const groupDescription = this.processArabicGroup(numberToProcess, group
|
|
164
|
+
const groupDescription = this.processArabicGroup(numberToProcess, group);
|
|
165
165
|
|
|
166
166
|
// Did the group return anything?
|
|
167
167
|
if (groupDescription != '') {
|
|
168
|
-
// Is this after the first "group"?
|
|
169
|
-
if (group > 0) {
|
|
170
|
-
// Is the return value still empty?
|
|
168
|
+
// Is this after the first "group" ? Because nothing is appeded after group 0.
|
|
169
|
+
if (group > 0) { // hundreds, thousands, etc...
|
|
170
|
+
// Is the return value still empty ?
|
|
171
171
|
if (retVal != '') {
|
|
172
|
-
retVal = ' و
|
|
172
|
+
retVal = ' و' + retVal;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
if (numberToProcess != 2) {
|
|
175
|
+
if (numberToProcess > 2) {
|
|
177
176
|
if (numberToProcess % 100 != 1) {
|
|
178
177
|
if (numberToProcess >= 3 && numberToProcess <= 10) {
|
|
179
178
|
retVal = this.arabicPluralGroups[group] + ' ' + retVal;
|
|
@@ -199,6 +198,9 @@ export class Arabic extends AbstractLanguage {
|
|
|
199
198
|
group++;
|
|
200
199
|
}
|
|
201
200
|
|
|
201
|
+
// Replace multiple spaces with one space
|
|
202
|
+
retVal = retVal.replace(/ +/g, ' ');
|
|
203
|
+
|
|
202
204
|
return retVal.trim();
|
|
203
205
|
}
|
|
204
206
|
}
|