n2words 1.9.0 → 1.11.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/.eslintrc.json +64 -5
- package/CHANGELOG.md +34 -0
- package/README.md +33 -14
- package/dist/n2words.js +1 -1
- package/lib/classes/N2WordsAbs.mjs +55 -34
- package/lib/classes/N2WordsBase.mjs +25 -19
- package/lib/i18n/AR.mjs +91 -83
- package/lib/i18n/CZ.mjs +80 -74
- package/lib/i18n/DE.mjs +82 -73
- package/lib/i18n/DK.mjs +82 -73
- package/lib/i18n/EN.mjs +68 -54
- package/lib/i18n/ES.mjs +86 -77
- package/lib/i18n/FA.mjs +67 -62
- package/lib/i18n/FR.mjs +72 -63
- package/lib/i18n/HE.mjs +40 -33
- package/lib/i18n/HR.mjs +117 -0
- package/lib/i18n/HU.mjs +70 -64
- package/lib/i18n/ID.mjs +155 -0
- package/lib/i18n/IT.mjs +46 -40
- package/lib/i18n/KO.mjs +44 -35
- package/lib/i18n/LT.mjs +86 -80
- package/lib/i18n/LV.mjs +74 -67
- package/lib/i18n/NL.mjs +92 -87
- package/lib/i18n/NO.mjs +65 -56
- package/lib/i18n/PL.mjs +81 -75
- package/lib/i18n/PT.mjs +85 -77
- package/lib/i18n/RU.mjs +99 -93
- package/lib/i18n/SR.mjs +83 -77
- package/lib/i18n/TR.mjs +227 -218
- package/lib/i18n/UK.mjs +80 -74
- package/lib/i18n/ZH.mjs +52 -41
- package/lib/n2words.mjs +60 -54
- package/package.json +17 -20
- package/webpack.config.js +2 -5
- package/lib/n2words_EN.mjs +0 -11
|
@@ -1,50 +1,71 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Must be inherited by all languages.
|
|
2
|
+
* Abstract class that must be inherited by all languages.
|
|
4
3
|
*/
|
|
5
|
-
export default
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export default class {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.negativeWord = '';
|
|
7
|
+
this.separatorWord;
|
|
8
|
+
this.zero;
|
|
9
|
+
this.spaceSeparator = ' ';
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Convert a number to cardinal (written) format.
|
|
14
|
+
*
|
|
15
|
+
* @param {number} value The number value to convert to cardinal form.
|
|
16
|
+
* @returns {string} Cardinal representation of number value.
|
|
17
|
+
*/
|
|
18
|
+
toCardinal(value) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {number} decimalPart Decimal part of the number to convert.
|
|
25
|
+
* @returns {string} Decimal part in written format.
|
|
26
|
+
*/
|
|
27
|
+
toDecimal(decimalPart) {
|
|
13
28
|
let decimalPartArray = Array.from(decimalPart);
|
|
14
29
|
let decimalPartWordsArray = [];
|
|
15
30
|
while (decimalPartArray[0] === '0') {
|
|
16
31
|
// Leading zeros
|
|
17
32
|
decimalPartArray.shift();
|
|
18
|
-
decimalPartWordsArray.push(this.
|
|
33
|
+
decimalPartWordsArray.push(this.zero);
|
|
19
34
|
}
|
|
20
35
|
decimalPartWordsArray.push(this.toCardinal(parseInt(decimalPart, 10)));
|
|
21
36
|
|
|
22
|
-
return decimalPartWordsArray.join(this.
|
|
23
|
-
}
|
|
37
|
+
return decimalPartWordsArray.join(this.spaceSeparator);
|
|
38
|
+
}
|
|
24
39
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param {number} value Float number.
|
|
43
|
+
* @throws {TypeError} Value must be a valid number.
|
|
44
|
+
* @returns {string|undefined} Cardinal number in written format.
|
|
45
|
+
*/
|
|
46
|
+
floatToCardinal(value) {
|
|
47
|
+
if (isNaN(Number(value))) {
|
|
48
|
+
throw new TypeError(`Invalid number: ${value}, of type: ${typeof value}`);
|
|
49
|
+
}
|
|
50
|
+
value = Number(value);
|
|
51
|
+
let words = [];
|
|
52
|
+
let positiveValue = Math.abs(value);
|
|
53
|
+
if (value % 1 === 0 || typeof this.separatorWord === 'undefined') {
|
|
54
|
+
// if value is integer or if separatorWord is not defined
|
|
55
|
+
words = [this.toCardinal(positiveValue)];
|
|
56
|
+
} else {
|
|
57
|
+
const splittedValue = positiveValue.toString().split('.');
|
|
58
|
+
const wholeNumberStr = this.toCardinal(parseInt(splittedValue[0], 10));
|
|
35
59
|
|
|
36
|
-
|
|
60
|
+
let decimalPart = splittedValue[1];
|
|
37
61
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
return words.join(this.space_separator);
|
|
46
|
-
} else {
|
|
47
|
-
return undefined;
|
|
62
|
+
const decimalPartStr = this.toDecimal(decimalPart);
|
|
63
|
+
words = [wholeNumberStr, this.separatorWord, decimalPartStr];
|
|
64
|
+
}
|
|
65
|
+
if (value < 0) {
|
|
66
|
+
// negative numbers
|
|
67
|
+
words = [this.negativeWord].concat(words);
|
|
48
68
|
}
|
|
49
|
-
|
|
69
|
+
return words.join(this.spaceSeparator);
|
|
70
|
+
}
|
|
50
71
|
}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import N2WordsAbs from './N2WordsAbs.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* This class has common
|
|
4
|
+
* This class has common functions used by multiple languages (mostly european).
|
|
5
5
|
*/
|
|
6
|
-
export default
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.getValueFromCards = (elem) => {
|
|
6
|
+
export default class extends N2WordsAbs {
|
|
7
|
+
getValueFromCards(elem) {
|
|
10
8
|
// 100
|
|
11
9
|
for (let i = 0; i < this.cards.length; i++) {
|
|
12
10
|
if (Object.prototype.hasOwnProperty.call(this.cards[i], elem)) {
|
|
13
11
|
return this.cards[i][elem];
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
|
-
}
|
|
14
|
+
}
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
splitNum(value) {
|
|
19
17
|
for (let i = 0; i < this.cards.length; i++) {
|
|
20
18
|
if (this.cards[i][0] == '.') {
|
|
21
19
|
continue;
|
|
@@ -42,24 +40,24 @@ export default function() {
|
|
|
42
40
|
if (div == value) {
|
|
43
41
|
return [(div * this.getValueFromCards(elem), div * elem)];
|
|
44
42
|
}
|
|
45
|
-
out.push(this.
|
|
43
|
+
out.push(this.splitNum(div));
|
|
46
44
|
}
|
|
47
45
|
out.push({
|
|
48
46
|
[this.getValueFromCards(elem)]: elem,
|
|
49
47
|
});
|
|
50
48
|
|
|
51
49
|
if (mod) {
|
|
52
|
-
out.push(this.
|
|
50
|
+
out.push(this.splitNum(mod));
|
|
53
51
|
}
|
|
54
52
|
return out;
|
|
55
53
|
}
|
|
56
|
-
}
|
|
54
|
+
}
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
return value.split('').map(
|
|
60
|
-
}
|
|
56
|
+
scanNum(value) {
|
|
57
|
+
return value.split('').map(v => this.getValueFromCards(parseInt(v, 10)));
|
|
58
|
+
}
|
|
61
59
|
|
|
62
|
-
|
|
60
|
+
clean(val) {
|
|
63
61
|
let out = val;
|
|
64
62
|
while (val.length != 1) {
|
|
65
63
|
out = [];
|
|
@@ -86,14 +84,22 @@ export default function() {
|
|
|
86
84
|
val = out;
|
|
87
85
|
}
|
|
88
86
|
return out[0];
|
|
89
|
-
}
|
|
87
|
+
}
|
|
90
88
|
|
|
91
|
-
|
|
89
|
+
postClean(out0) {
|
|
90
|
+
return out0.trimRight();
|
|
91
|
+
}
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Convert a number to cardinal (written) format.
|
|
95
|
+
*
|
|
96
|
+
* @param {number} value The number value to convert to cardinal form.
|
|
97
|
+
* @returns {string} Cardinal representation of number value.
|
|
98
|
+
*/
|
|
99
|
+
toCardinal(value) {
|
|
100
|
+
const val = this.splitNum(value);
|
|
95
101
|
const preWords = Object.keys(this.clean(val))[0];
|
|
96
102
|
const words = this.postClean(preWords);
|
|
97
103
|
return words;
|
|
98
|
-
}
|
|
104
|
+
}
|
|
99
105
|
}
|
package/lib/i18n/AR.mjs
CHANGED
|
@@ -1,130 +1,138 @@
|
|
|
1
1
|
import N2WordsAbs from '../classes/N2WordsAbs.mjs';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export class N2WordsAR extends N2WordsAbs {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
7
|
+
this.integerValue = 0;
|
|
8
|
+
this.decimalValue = 0;
|
|
9
|
+
this.negativeWord = 'ناقص';
|
|
10
|
+
this.separatorWord = 'فاصلة';
|
|
11
|
+
this.number = 0;
|
|
12
|
+
this.zero = 'صفر';
|
|
13
|
+
// this.isCurrencyPartNameFeminine = true
|
|
14
|
+
// this.isCurrencyNameFeminine = false
|
|
15
|
+
this.arabicOnes = [
|
|
16
|
+
'', 'واحد', 'اثنان', 'ثلاثة', 'أربعة', 'خمسة', 'ستة', 'سبعة', 'ثمانية',
|
|
17
|
+
'تسعة',
|
|
18
|
+
'عشرة', 'أحد عشر', 'اثنا عشر', 'ثلاثة عشر', 'أربعة عشر', 'خمسة عشر',
|
|
19
|
+
'ستة عشر', 'سبعة عشر', 'ثمانية عشر',
|
|
20
|
+
'تسعة عشر',
|
|
21
|
+
];
|
|
22
|
+
this.arabicFeminineOnes = [
|
|
23
|
+
'', 'إحدى', 'اثنتان', 'ثلاث', 'أربع', 'خمس', 'ست', 'سبع', 'ثمان',
|
|
24
|
+
'تسع',
|
|
25
|
+
'عشر', 'إحدى عشرة', 'اثنتا عشرة', 'ثلاث عشرة', 'أربع عشرة',
|
|
26
|
+
'خمس عشرة', 'ست عشرة', 'سبع عشرة', 'ثماني عشرة',
|
|
27
|
+
'تسع عشرة',
|
|
28
|
+
];
|
|
29
|
+
this.arabicTens = ['عشرون', 'ثلاثون', 'أربعون', 'خمسون', 'ستون', 'سبعون', 'ثمانون', 'تسعون'];
|
|
30
|
+
this.arabicHundreds = ['', 'مائة', 'مئتان', 'ثلاثمائة', 'أربعمائة', 'خمسمائة', 'ستمائة', 'سبعمائة', 'ثمانمائة', 'تسعمائة'];
|
|
31
|
+
this.arabicAppendedTwos = ['مئتا', 'ألفا', 'مليونا', 'مليارا', 'تريليونا', 'كوادريليونا', 'كوينتليونا', 'سكستيليونا'];
|
|
32
|
+
this.arabicTwos = ['مئتان', 'ألفان', 'مليونان', 'ملياران', 'تريليونان', 'كوادريليونان', 'كوينتليونان', 'سكستيليونان'];
|
|
33
|
+
this.arabicGroup = ['مائة', 'ألف', 'مليون', 'مليار', 'تريليون', 'كوادريليون', 'كوينتليون', 'سكستيليون'];
|
|
34
|
+
this.arabicAppendedGroup = ['', 'ألفاً', 'مليوناً', 'ملياراً', 'تريليوناً', 'كوادريليوناً', 'كوينتليوناً', 'سكستيليوناً'];
|
|
35
|
+
this.arabicPluralGroups = ['', 'آلاف', 'ملايين', 'مليارات', 'تريليونات', 'كوادريليونات', 'كوينتليونات', 'سكستيليونات'];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
digitFeminineStatus(digit/* , groupLevel */) {
|
|
39
|
+
// if ((groupLevel == -1 && this.isCurrencyPartNameFeminine) || (groupLevel == 0 && this.isCurrencyNameFeminine)) {
|
|
37
40
|
// return this.arabicFeminineOnes[parseInt(digit)]
|
|
38
41
|
// }
|
|
39
42
|
return this.arabicOnes[parseInt(digit)];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
processArabicGroup(groupNumber, groupLevel, remainingNumber) {
|
|
46
|
+
let tens = groupNumber % 100;
|
|
47
|
+
const hundreds = groupNumber / 100;
|
|
48
|
+
let retVal = '';
|
|
45
49
|
if (parseInt(hundreds) > 0) {
|
|
46
|
-
|
|
50
|
+
retVal = (
|
|
47
51
|
tens == 0 && parseInt(hundreds) == 2
|
|
48
52
|
) ? this.arabicAppendedTwos[0] : this.arabicHundreds[parseInt(hundreds)];
|
|
49
53
|
}
|
|
50
54
|
if (tens > 0) {
|
|
51
55
|
if (tens < 20) {
|
|
52
|
-
if (tens == 2 && parseInt(hundreds) == 0 &&
|
|
53
|
-
|
|
56
|
+
if (tens == 2 && parseInt(hundreds) == 0 && groupLevel > 0) {
|
|
57
|
+
retVal = ([
|
|
54
58
|
2000, 2000000, 2000000000, 2000000000000, 2000000000000000, 2000000000000000000
|
|
55
|
-
].indexOf(this.
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
].indexOf(this.integerValue) != -1) ? this.arabicAppendedTwos[
|
|
60
|
+
parseInt(groupLevel)] : this.arabicTwos[parseInt(groupLevel)
|
|
61
|
+
];
|
|
58
62
|
} else {
|
|
59
|
-
if (
|
|
60
|
-
|
|
63
|
+
if (retVal != '') {
|
|
64
|
+
retVal += ' و ';
|
|
61
65
|
}
|
|
62
|
-
if (tens == 1 &&
|
|
63
|
-
|
|
66
|
+
if (tens == 1 && groupLevel > 0 && hundreds == 0) {
|
|
67
|
+
retVal += '';
|
|
64
68
|
} else if (
|
|
65
|
-
(tens == 1 || tens == 2) && (
|
|
66
|
-
(hundreds == 0 &&
|
|
69
|
+
(tens == 1 || tens == 2) && (groupLevel == 0 || groupLevel == -1) &&
|
|
70
|
+
(hundreds == 0 && remainingNumber == 0)
|
|
67
71
|
) {
|
|
68
|
-
|
|
72
|
+
retVal += '';
|
|
69
73
|
} else {
|
|
70
|
-
|
|
74
|
+
retVal += this.digitFeminineStatus(parseInt(tens), groupLevel);
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
} else {
|
|
74
78
|
const ones = tens % 10;
|
|
75
79
|
tens = (tens / 10) - 2;
|
|
76
80
|
if (ones > 0) {
|
|
77
|
-
if (
|
|
78
|
-
|
|
81
|
+
if (retVal != '' && tens < 4) {
|
|
82
|
+
retVal += ' و ';
|
|
79
83
|
}
|
|
80
|
-
|
|
84
|
+
retVal += this.digitFeminineStatus(ones, groupLevel);
|
|
81
85
|
}
|
|
82
|
-
if (
|
|
83
|
-
|
|
86
|
+
if (retVal != '' && ones != 0) {
|
|
87
|
+
retVal += ' و ';
|
|
84
88
|
}
|
|
85
|
-
|
|
89
|
+
retVal += this.arabicTens[parseInt(tens)];
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
|
-
return
|
|
89
|
-
}
|
|
92
|
+
return retVal;
|
|
93
|
+
}
|
|
90
94
|
|
|
91
|
-
|
|
95
|
+
toCardinal(number) {
|
|
92
96
|
if (parseInt(number) == 0) {
|
|
93
|
-
return this.
|
|
97
|
+
return this.zero;
|
|
94
98
|
}
|
|
95
|
-
let
|
|
96
|
-
this.
|
|
97
|
-
let
|
|
99
|
+
let tempNumber = number;
|
|
100
|
+
this.integerValue = number;
|
|
101
|
+
let retVal = '';
|
|
98
102
|
let group = 0;
|
|
99
|
-
while (
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
103
|
+
while (tempNumber > 0) {
|
|
104
|
+
const numberToProcess = parseInt(tempNumber % 1000);
|
|
105
|
+
tempNumber = parseInt(tempNumber / 1000);
|
|
106
|
+
const groupDescription = this.processArabicGroup(numberToProcess, group, Math.floor(tempNumber));
|
|
107
|
+
if (groupDescription != '') {
|
|
104
108
|
if (group > 0) {
|
|
105
|
-
if (
|
|
106
|
-
|
|
109
|
+
if (retVal != '') {
|
|
110
|
+
retVal = ' و ' + retVal;
|
|
107
111
|
}
|
|
108
|
-
if (
|
|
109
|
-
if (
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
+
if (numberToProcess != 2) {
|
|
113
|
+
if (numberToProcess % 100 != 1) {
|
|
114
|
+
if (numberToProcess >= 3 && numberToProcess <= 10) {
|
|
115
|
+
retVal = this.arabicPluralGroups[group] + ' ' + retVal;
|
|
112
116
|
} else {
|
|
113
|
-
if (
|
|
114
|
-
|
|
117
|
+
if (retVal != '') {
|
|
118
|
+
retVal = this.arabicAppendedGroup[group] + ' ' + retVal;
|
|
115
119
|
} else {
|
|
116
|
-
|
|
120
|
+
retVal = this.arabicGroup[group] + ' ' + retVal;
|
|
117
121
|
}
|
|
118
122
|
}
|
|
119
123
|
} else {
|
|
120
|
-
|
|
124
|
+
retVal = this.arabicGroup[group] + ' ' + retVal;
|
|
121
125
|
}
|
|
122
126
|
}
|
|
123
127
|
}
|
|
124
|
-
|
|
128
|
+
retVal = groupDescription + ' ' + retVal;
|
|
125
129
|
}
|
|
126
130
|
group += 1;
|
|
127
131
|
}
|
|
128
|
-
return
|
|
129
|
-
}
|
|
132
|
+
return retVal.trim();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export default function(n) {
|
|
137
|
+
return new N2WordsAR().floatToCardinal(n);
|
|
130
138
|
}
|
package/lib/i18n/CZ.mjs
CHANGED
|
@@ -1,69 +1,71 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {N2WordsRU} from './RU.mjs';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export class N2WordsCZ extends N2WordsRU {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
7
|
+
this.negativeWord = 'mínus';
|
|
8
|
+
this.separatorWord = 'celá';
|
|
9
|
+
this.zero = 'nula';
|
|
10
|
+
this.ones = {
|
|
11
|
+
1: 'jedna',
|
|
12
|
+
2: 'dva',
|
|
13
|
+
3: 'tři',
|
|
14
|
+
4: 'čtyři',
|
|
15
|
+
5: 'pět',
|
|
16
|
+
6: 'šest',
|
|
17
|
+
7: 'sedm',
|
|
18
|
+
8: 'osm',
|
|
19
|
+
9: 'devět'
|
|
20
|
+
};
|
|
21
|
+
this.tens = {
|
|
22
|
+
0: 'deset',
|
|
23
|
+
1: 'jedenáct',
|
|
24
|
+
2: 'dvanáct',
|
|
25
|
+
3: 'třináct',
|
|
26
|
+
4: 'čtrnáct',
|
|
27
|
+
5: 'patnáct',
|
|
28
|
+
6: 'šestnáct',
|
|
29
|
+
7: 'sedmnáct',
|
|
30
|
+
8: 'osmnáct',
|
|
31
|
+
9: 'devatenáct'
|
|
32
|
+
};
|
|
33
|
+
this.twenties = {
|
|
34
|
+
2: 'dvacet',
|
|
35
|
+
3: 'třicet',
|
|
36
|
+
4: 'čtyřicet',
|
|
37
|
+
5: 'padesát',
|
|
38
|
+
6: 'šedesát',
|
|
39
|
+
7: 'sedmdesát',
|
|
40
|
+
8: 'osmdesát',
|
|
41
|
+
9: 'devadesát'
|
|
42
|
+
};
|
|
43
|
+
this.hundreds = {
|
|
44
|
+
1: 'sto',
|
|
45
|
+
2: 'dvěstě',
|
|
46
|
+
3: 'třista',
|
|
47
|
+
4: 'čtyřista',
|
|
48
|
+
5: 'pětset',
|
|
49
|
+
6: 'šestset',
|
|
50
|
+
7: 'sedmset',
|
|
51
|
+
8: 'osmset',
|
|
52
|
+
9: 'devětset'
|
|
53
|
+
};
|
|
54
|
+
this.thousands = {
|
|
55
|
+
1: ['tisíc', 'tisíce', 'tisíc'], // 10^ 3
|
|
56
|
+
2: ['milion', 'miliony', 'milionů'], // 10^ 6
|
|
57
|
+
3: ['miliarda', 'miliardy', 'miliard'], // 10^ 9
|
|
58
|
+
4: ['bilion', 'biliony', 'bilionů'], // 10^ 12
|
|
59
|
+
5: ['biliarda', 'biliardy', 'biliard'], // 10^ 15
|
|
60
|
+
6: ['trilion', 'triliony', 'trilionů'], // 10^ 18
|
|
61
|
+
7: ['triliarda', 'triliardy', 'triliard'], // 10^ 21
|
|
62
|
+
8: ['kvadrilion', 'kvadriliony', 'kvadrilionů'], // 10^ 24
|
|
63
|
+
9: ['kvadriliarda', 'kvadriliardy', 'kvadriliard'], // 10^ 27
|
|
64
|
+
10: ['quintillion', 'quintilliony', 'quintillionů'], // 10^ 30
|
|
65
|
+
};
|
|
66
|
+
}
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
pluralize(n, forms) {
|
|
67
69
|
let form = 2;
|
|
68
70
|
if (n == 1) {
|
|
69
71
|
form = 0;
|
|
@@ -71,14 +73,14 @@ export default function () {
|
|
|
71
73
|
form = 1;
|
|
72
74
|
}
|
|
73
75
|
return forms[form];
|
|
74
|
-
}
|
|
76
|
+
}
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
toCardinal(number) {
|
|
77
79
|
if (parseInt(number) == 0) {
|
|
78
|
-
return this.
|
|
80
|
+
return this.zero;
|
|
79
81
|
}
|
|
80
82
|
const words = [];
|
|
81
|
-
const chunks = this.
|
|
83
|
+
const chunks = this.splitByX(JSON.stringify(number), 3);
|
|
82
84
|
let i = chunks.length;
|
|
83
85
|
for (let j = 0; j < chunks.length; j++) {
|
|
84
86
|
const x = chunks[j];
|
|
@@ -86,22 +88,26 @@ export default function () {
|
|
|
86
88
|
if (x == 0) {
|
|
87
89
|
continue;
|
|
88
90
|
}
|
|
89
|
-
const [n1, n2, n3] = this.
|
|
91
|
+
const [n1, n2, n3] = this.getDigits(x);
|
|
90
92
|
if (n3 > 0) {
|
|
91
|
-
words.push(this.
|
|
93
|
+
words.push(this.hundreds[n3]);
|
|
92
94
|
}
|
|
93
95
|
if (n2 > 1) {
|
|
94
|
-
words.push(this.
|
|
96
|
+
words.push(this.twenties[n2]);
|
|
95
97
|
}
|
|
96
98
|
if (n2 == 1) {
|
|
97
|
-
words.push(this.
|
|
99
|
+
words.push(this.tens[n1]);
|
|
98
100
|
} else if (n1 > 0 && !(i > 0 && x == 1)) {
|
|
99
|
-
words.push(this.
|
|
101
|
+
words.push(this.ones[n1]);
|
|
100
102
|
}
|
|
101
103
|
if (i > 0) {
|
|
102
|
-
words.push(this.pluralize(x, this.
|
|
104
|
+
words.push(this.pluralize(x, this.thousands[i]));
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
return words.join(' ');
|
|
106
|
-
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export default function(n) {
|
|
112
|
+
return new N2WordsCZ().floatToCardinal(n);
|
|
107
113
|
}
|