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.
@@ -1,50 +1,71 @@
1
1
  /**
2
- * This is an abstract class.
3
- * Must be inherited by all languages.
2
+ * Abstract class that must be inherited by all languages.
4
3
  */
5
- export default function () {
6
- this.negative_word = '';
7
- this.separator_word;
8
- this.ZERO;
9
- this.space_separator = ' '; // space
10
- this.toCardinal = () => {}; // Must take an integer and return a string.
4
+ export default class {
5
+ constructor() {
6
+ this.negativeWord = '';
7
+ this.separatorWord;
8
+ this.zero;
9
+ this.spaceSeparator = ' ';
10
+ }
11
11
 
12
- this.toDecimal = (decimalPart) => {
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.ZERO);
33
+ decimalPartWordsArray.push(this.zero);
19
34
  }
20
35
  decimalPartWordsArray.push(this.toCardinal(parseInt(decimalPart, 10)));
21
36
 
22
- return decimalPartWordsArray.join(this.space_separator);
23
- };
37
+ return decimalPartWordsArray.join(this.spaceSeparator);
38
+ }
24
39
 
25
- this.floatToCardinal = (value) => {
26
- if (Number(value) === value) {
27
- let words = [];
28
- let positiveValue = Math.abs(value);
29
- if (value % 1 === 0 || typeof this.separator_word === 'undefined') {
30
- // if value is integer or if separator_word is not defined
31
- words = [this.toCardinal(positiveValue)];
32
- } else {
33
- const splittedValue = positiveValue.toString().split('.');
34
- const wholeNumberStr = this.toCardinal(parseInt(splittedValue[0], 10));
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
- let decimalPart = splittedValue[1];
60
+ let decimalPart = splittedValue[1];
37
61
 
38
- const decimalPartStr = this.toDecimal(decimalPart);
39
- words = [wholeNumberStr, this.separator_word, decimalPartStr];
40
- }
41
- if (value < 0) {
42
- // negative numbers
43
- words = [this.negative_word].concat(words);
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 funtions used by multiple languages (mostly european).
4
+ * This class has common functions used by multiple languages (mostly european).
5
5
  */
6
- export default function() {
7
- N2WordsAbs.call(this);
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
- this.splitnum = (value) => {
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.splitnum(div));
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.splitnum(mod));
50
+ out.push(this.splitNum(mod));
53
51
  }
54
52
  return out;
55
53
  }
56
- };
54
+ }
57
55
 
58
- this.scannum = (value) => {
59
- return value.split('').map((v) => this.getValueFromCards(parseInt(v, 10)));
60
- };
56
+ scanNum(value) {
57
+ return value.split('').map(v => this.getValueFromCards(parseInt(v, 10)));
58
+ }
61
59
 
62
- this.clean = (val) => {
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
- this.postClean = (out0) => out0.trimRight();
89
+ postClean(out0) {
90
+ return out0.trimRight();
91
+ }
92
92
 
93
- this.toCardinal = (value) => {
94
- const val = this.splitnum(value);
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 default function() {
4
- N2WordsAbs.call(this);
3
+ export class N2WordsAR extends N2WordsAbs {
4
+ constructor() {
5
+ super();
5
6
 
6
- this.integer_value = 0;
7
- this._decimalValue = 0;
8
- this.negative_word = "ناقص";
9
- this.separator_word = "فاصلة";
10
- this.number = 0;
11
- this.ZERO = 'صفر';
12
- // this.isCurrencyPartNameFeminine = true
13
- // this.isCurrencyNameFeminine = false
14
- this.arabicOnes = [
15
- '', 'واحد', 'اثنان', 'ثلاثة', 'أربعة', 'خمسة', 'ستة', 'سبعة', 'ثمانية',
16
- 'تسعة',
17
- 'عشرة', 'أحد عشر', 'اثنا عشر', 'ثلاثة عشر', 'أربعة عشر', 'خمسة عشر',
18
- 'ستة عشر', 'سبعة عشر', 'ثمانية عشر',
19
- 'تسعة عشر',
20
- ];
21
- this.arabicFeminineOnes = [
22
- '', 'إحدى', 'اثنتان', 'ثلاث', 'أربع', 'خمس', 'ست', 'سبع', 'ثمان',
23
- 'تسع',
24
- 'عشر', 'إحدى عشرة', 'اثنتا عشرة', 'ثلاث عشرة', 'أربع عشرة',
25
- 'خمس عشرة', 'ست عشرة', 'سبع عشرة', 'ثماني عشرة',
26
- 'تسع عشرة',
27
- ];
28
- this.arabicTens = ['عشرون', 'ثلاثون', 'أربعون', 'خمسون', 'ستون', 'سبعون', 'ثمانون', 'تسعون'];
29
- this.arabicHundreds = ['', 'مائة', 'مئتان', 'ثلاثمائة', 'أربعمائة', 'خمسمائة', 'ستمائة', 'سبعمائة', 'ثمانمائة', 'تسعمائة'];
30
- this.arabicAppendedTwos = ['مئتا', 'ألفا', 'مليونا', 'مليارا', 'تريليونا', 'كوادريليونا', 'كوينتليونا', 'سكستيليونا'];
31
- this.arabicTwos = ['مئتان', 'ألفان', 'مليونان', 'ملياران', 'تريليونان', 'كوادريليونان', 'كوينتليونان', 'سكستيليونان'];
32
- this.arabicGroup = ['مائة', 'ألف', 'مليون', 'مليار', 'تريليون', 'كوادريليون', 'كوينتليون', 'سكستيليون'];
33
- this.arabicAppendedGroup = ['', 'ألفاً', 'مليوناً', 'ملياراً', 'تريليوناً', 'كوادريليوناً', 'كوينتليوناً', 'سكستيليوناً'];
34
- this.arabicPluralGroups = ['', 'آلاف', 'ملايين', 'مليارات', 'تريليونات', 'كوادريليونات', 'كوينتليونات', 'سكستيليونات'];
35
- this.digit_feminine_status = (digit/* , group_level */) => {
36
- // if ((group_level == -1 && this.isCurrencyPartNameFeminine) || (group_level == 0 && this.isCurrencyNameFeminine)) {
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
- this.process_arabic_group = (group_number, group_level, remaining_number) => {
42
- let tens = group_number % 100;
43
- const hundreds = group_number / 100;
44
- let ret_val = '';
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
- ret_val = (
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 && group_level > 0) {
53
- ret_val = ([
56
+ if (tens == 2 && parseInt(hundreds) == 0 && groupLevel > 0) {
57
+ retVal = ([
54
58
  2000, 2000000, 2000000000, 2000000000000, 2000000000000000, 2000000000000000000
55
- ].indexOf(this.integer_value) != -1) ? this.arabicAppendedTwos[
56
- parseInt(group_level)] : this.arabicTwos[parseInt(group_level)
57
- ];
59
+ ].indexOf(this.integerValue) != -1) ? this.arabicAppendedTwos[
60
+ parseInt(groupLevel)] : this.arabicTwos[parseInt(groupLevel)
61
+ ];
58
62
  } else {
59
- if (ret_val != '') {
60
- ret_val += ' و ';
63
+ if (retVal != '') {
64
+ retVal += ' و ';
61
65
  }
62
- if (tens == 1 && group_level > 0 && hundreds == 0) {
63
- ret_val += '';
66
+ if (tens == 1 && groupLevel > 0 && hundreds == 0) {
67
+ retVal += '';
64
68
  } else if (
65
- (tens == 1 || tens == 2) && (group_level == 0 || group_level == -1) &&
66
- (hundreds == 0 && remaining_number == 0)
69
+ (tens == 1 || tens == 2) && (groupLevel == 0 || groupLevel == -1) &&
70
+ (hundreds == 0 && remainingNumber == 0)
67
71
  ) {
68
- ret_val += '';
72
+ retVal += '';
69
73
  } else {
70
- ret_val += this.digit_feminine_status(parseInt(tens), group_level);
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 (ret_val != '' && tens < 4) {
78
- ret_val += ' و ';
81
+ if (retVal != '' && tens < 4) {
82
+ retVal += ' و ';
79
83
  }
80
- ret_val += this.digit_feminine_status(ones, group_level);
84
+ retVal += this.digitFeminineStatus(ones, groupLevel);
81
85
  }
82
- if (ret_val != '' && ones != 0) {
83
- ret_val += ' و ';
86
+ if (retVal != '' && ones != 0) {
87
+ retVal += ' و ';
84
88
  }
85
- ret_val += this.arabicTens[parseInt(tens)];
89
+ retVal += this.arabicTens[parseInt(tens)];
86
90
  }
87
91
  }
88
- return ret_val;
89
- };
92
+ return retVal;
93
+ }
90
94
 
91
- this.toCardinal = (number) => {
95
+ toCardinal(number) {
92
96
  if (parseInt(number) == 0) {
93
- return this.ZERO;
97
+ return this.zero;
94
98
  }
95
- let temp_number = number;
96
- this.integer_value = number;
97
- let ret_val = '';
99
+ let tempNumber = number;
100
+ this.integerValue = number;
101
+ let retVal = '';
98
102
  let group = 0;
99
- while (temp_number > 0) {
100
- const number_to_process = parseInt(temp_number % 1000);
101
- temp_number = parseInt(temp_number / 1000);
102
- const group_description = this.process_arabic_group(number_to_process, group, Math.floor(temp_number));
103
- if (group_description != '') {
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 (ret_val != '') {
106
- ret_val = ' و ' + ret_val;
109
+ if (retVal != '') {
110
+ retVal = ' و ' + retVal;
107
111
  }
108
- if (number_to_process != 2) {
109
- if (number_to_process % 100 != 1) {
110
- if (number_to_process >= 3 && number_to_process <= 10) {
111
- ret_val = this.arabicPluralGroups[group] + ' ' + ret_val;
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 (ret_val != '') {
114
- ret_val = this.arabicAppendedGroup[group] + ' ' + ret_val;
117
+ if (retVal != '') {
118
+ retVal = this.arabicAppendedGroup[group] + ' ' + retVal;
115
119
  } else {
116
- ret_val = this.arabicGroup[group] + ' ' + ret_val;
120
+ retVal = this.arabicGroup[group] + ' ' + retVal;
117
121
  }
118
122
  }
119
123
  } else {
120
- ret_val = this.arabicGroup[group] + ' ' + ret_val;
124
+ retVal = this.arabicGroup[group] + ' ' + retVal;
121
125
  }
122
126
  }
123
127
  }
124
- ret_val = group_description + ' ' + ret_val;
128
+ retVal = groupDescription + ' ' + retVal;
125
129
  }
126
130
  group += 1;
127
131
  }
128
- return ret_val.trim();
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 Num2Word_RU from './RU.mjs';
1
+ import {N2WordsRU} from './RU.mjs';
2
2
 
3
- export default function () {
4
- Num2Word_RU.call(this);
3
+ export class N2WordsCZ extends N2WordsRU {
4
+ constructor() {
5
+ super();
5
6
 
6
- this.negative_word = "mínus";
7
- this.separator_word = "celá";
8
- this.ZERO = 'nula';
9
- this.ONES = {
10
- 1: 'jedna',
11
- 2: 'dva',
12
- 3: 'tři',
13
- 4: 'čtyři',
14
- 5: 'pět',
15
- 6: 'šest',
16
- 7: 'sedm',
17
- 8: 'osm',
18
- 9: 'devět'
19
- };
20
- this.TENS = {
21
- 0: 'deset',
22
- 1: 'jedenáct',
23
- 2: 'dvanáct',
24
- 3: 'třináct',
25
- 4: 'čtrnáct',
26
- 5: 'patnáct',
27
- 6: 'šestnáct',
28
- 7: 'sedmnáct',
29
- 8: 'osmnáct',
30
- 9: 'devatenáct'
31
- };
32
- this.TWENTIES = {
33
- 2: 'dvacet',
34
- 3: 'třicet',
35
- 4: 'čtyřicet',
36
- 5: 'padesát',
37
- 6: 'šedesát',
38
- 7: 'sedmdesát',
39
- 8: 'osmdesát',
40
- 9: 'devadesát'
41
- };
42
- this.HUNDREDS = {
43
- 1: 'sto',
44
- 2: 'dvěstě',
45
- 3: 'třista',
46
- 4: 'čtyřista',
47
- 5: 'pětset',
48
- 6: 'šestset',
49
- 7: 'sedmset',
50
- 8: 'osmset',
51
- 9: 'devětset'
52
- };
53
- this.THOUSANDS = {
54
- 1: ['tisíc', 'tisíce', 'tisíc'], // 10^ 3
55
- 2: ['milion', 'miliony', 'milionů'], // 10^ 6
56
- 3: ['miliarda', 'miliardy', 'miliard'], // 10^ 9
57
- 4: ['bilion', 'biliony', 'bilionů'], // 10^ 12
58
- 5: ['biliarda', 'biliardy', 'biliard'], // 10^ 15
59
- 6: ['trilion', 'triliony', 'trilionů'], // 10^ 18
60
- 7: ['triliarda', 'triliardy', 'triliard'], // 10^ 21
61
- 8: ['kvadrilion', 'kvadriliony', 'kvadrilionů'], // 10^ 24
62
- 9: ['kvadriliarda', 'kvadriliardy', 'kvadriliard'], // 10^ 27
63
- 10: ['quintillion', 'quintilliony', 'quintillionů'], // 10^ 30
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
- this.pluralize = (n, forms) => {
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
- this.toCardinal = (number) => {
78
+ toCardinal(number) {
77
79
  if (parseInt(number) == 0) {
78
- return this.ZERO;
80
+ return this.zero;
79
81
  }
80
82
  const words = [];
81
- const chunks = this.splitbyx(JSON.stringify(number), 3);
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.get_digits(x);
91
+ const [n1, n2, n3] = this.getDigits(x);
90
92
  if (n3 > 0) {
91
- words.push(this.HUNDREDS[n3]);
93
+ words.push(this.hundreds[n3]);
92
94
  }
93
95
  if (n2 > 1) {
94
- words.push(this.TWENTIES[n2]);
96
+ words.push(this.twenties[n2]);
95
97
  }
96
98
  if (n2 == 1) {
97
- words.push(this.TENS[n1]);
99
+ words.push(this.tens[n1]);
98
100
  } else if (n1 > 0 && !(i > 0 && x == 1)) {
99
- words.push(this.ONES[n1]);
101
+ words.push(this.ones[n1]);
100
102
  }
101
103
  if (i > 0) {
102
- words.push(this.pluralize(x, this.THOUSANDS[i]));
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
  }