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/lib/i18n/LT.mjs CHANGED
@@ -1,87 +1,89 @@
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 N2WordsLT extends N2WordsRU {
4
+ constructor() {
5
+ super();
5
6
 
6
- this.negative_word = 'minus';
7
- this.separator_word = 'kablelis';
8
- this.feminine = false;
9
- this.ZERO = 'nulis';
10
- this.ONES = {
11
- 1: 'vienas',
12
- 2: 'du',
13
- 3: 'trys',
14
- 4: 'keturi',
15
- 5: 'penki',
16
- 6: 'šeši',
17
- 7: 'septyni',
18
- 8: 'aštuoni',
19
- 9: 'devyni'
20
- };
21
- this.ONES_FEMININE = {
22
- 1: 'viena',
23
- 2: 'dvi',
24
- 3: 'trys',
25
- 4: 'keturios',
26
- 5: 'penkios',
27
- 6: 'šešios',
28
- 7: 'septynios',
29
- 8: 'aštuonios',
30
- 9: 'devynios'
31
- };
32
- this.TENS = {
33
- 0: 'dešimt',
34
- 1: 'vienuolika',
35
- 2: 'dvylika',
36
- 3: 'trylika',
37
- 4: 'keturiolika',
38
- 5: 'penkiolika',
39
- 6: 'šešiolika',
40
- 7: 'septyniolika',
41
- 8: 'aštuoniolika',
42
- 9: 'devyniolika'
43
- };
44
- this.TWENTIES = {
45
- 2: 'dvidešimt',
46
- 3: 'trisdešimt',
47
- 4: 'keturiasdešimt',
48
- 5: 'penkiasdešimt',
49
- 6: 'šešiasdešimt',
50
- 7: 'septyniasdešimt',
51
- 8: 'aštuoniasdešimt',
52
- 9: 'devyniasdešimt'
53
- };
54
- this.HUNDREDS = ['šimtas', 'šimtai'];
55
- this.THOUSANDS = {
56
- 1: ['tūkstantis', 'tūkstančiai', 'tūkstančių'],
57
- 2: ['milijonas', 'milijonai', 'milijonų'],
58
- 3: ['milijardas', 'milijardai', 'milijardų'],
59
- 4: ['trilijonas', 'trilijonai', 'trilijonų'],
60
- 5: ['kvadrilijonas', 'kvadrilijonai', 'kvadrilijonų'],
61
- 6: ['kvintilijonas', 'kvintilijonai', 'kvintilijonų'],
62
- 7: ['sikstilijonas', 'sikstilijonai', 'sikstilijonų'],
63
- 8: ['septilijonas', 'septilijonai', 'septilijonų'],
64
- 9: ['oktilijonas', 'oktilijonai', 'oktilijonų'],
65
- 10: ['naintilijonas', 'naintilijonai', 'naintilijonų'],
66
- };
7
+ this.negativeWord = 'minus';
8
+ this.separatorWord = 'kablelis';
9
+ this.feminine = false;
10
+ this.zero = 'nulis';
11
+ this.ones = {
12
+ 1: 'vienas',
13
+ 2: 'du',
14
+ 3: 'trys',
15
+ 4: 'keturi',
16
+ 5: 'penki',
17
+ 6: 'šeši',
18
+ 7: 'septyni',
19
+ 8: 'aštuoni',
20
+ 9: 'devyni'
21
+ };
22
+ this.onesFeminine = {
23
+ 1: 'viena',
24
+ 2: 'dvi',
25
+ 3: 'trys',
26
+ 4: 'keturios',
27
+ 5: 'penkios',
28
+ 6: 'šešios',
29
+ 7: 'septynios',
30
+ 8: 'aštuonios',
31
+ 9: 'devynios'
32
+ };
33
+ this.tens = {
34
+ 0: 'dešimt',
35
+ 1: 'vienuolika',
36
+ 2: 'dvylika',
37
+ 3: 'trylika',
38
+ 4: 'keturiolika',
39
+ 5: 'penkiolika',
40
+ 6: 'šešiolika',
41
+ 7: 'septyniolika',
42
+ 8: 'aštuoniolika',
43
+ 9: 'devyniolika'
44
+ };
45
+ this.twenties = {
46
+ 2: 'dvidešimt',
47
+ 3: 'trisdešimt',
48
+ 4: 'keturiasdešimt',
49
+ 5: 'penkiasdešimt',
50
+ 6: 'šešiasdešimt',
51
+ 7: 'septyniasdešimt',
52
+ 8: 'aštuoniasdešimt',
53
+ 9: 'devyniasdešimt'
54
+ };
55
+ this.hundreds = ['šimtas', 'šimtai'];
56
+ this.thousands = {
57
+ 1: ['tūkstantis', 'tūkstančiai', 'tūkstančių'],
58
+ 2: ['milijonas', 'milijonai', 'milijonų'],
59
+ 3: ['milijardas', 'milijardai', 'milijardų'],
60
+ 4: ['trilijonas', 'trilijonai', 'trilijonų'],
61
+ 5: ['kvadrilijonas', 'kvadrilijonai', 'kvadrilijonų'],
62
+ 6: ['kvintilijonas', 'kvintilijonai', 'kvintilijonų'],
63
+ 7: ['sikstilijonas', 'sikstilijonai', 'sikstilijonų'],
64
+ 8: ['septilijonas', 'septilijonai', 'septilijonų'],
65
+ 9: ['oktilijonas', 'oktilijonai', 'oktilijonų'],
66
+ 10: ['naintilijonas', 'naintilijonai', 'naintilijonų'],
67
+ };
68
+ }
67
69
 
68
- this.pluralize = (n, forms) => {
70
+ pluralize(n, forms) {
69
71
  let form = 1;
70
- const [n1, n2] = this.get_digits(n);
72
+ const [n1, n2] = this.getDigits(n);
71
73
  if (n2 == 1 || n1 == 0 || n == 0) {
72
74
  form = 2;
73
75
  } else if (n1 == 1) {
74
76
  form = 0;
75
77
  }
76
78
  return forms[form];
77
- };
79
+ }
78
80
 
79
- this.toCardinal = (number) => {
81
+ toCardinal(number) {
80
82
  if (parseInt(number) == 0) {
81
- return this.ZERO;
83
+ return this.zero;
82
84
  }
83
85
  const words = [];
84
- const chunks = this.splitbyx(JSON.stringify(number), 3);
86
+ const chunks = this.splitByX(JSON.stringify(number), 3);
85
87
  let i = chunks.length;
86
88
  for (let j = 0; j < chunks.length; j++) {
87
89
  const x = chunks[j];
@@ -89,31 +91,35 @@ export default function () {
89
91
  if (x == 0) {
90
92
  continue;
91
93
  }
92
- const [n1, n2, n3] = this.get_digits(x);
94
+ const [n1, n2, n3] = this.getDigits(x);
93
95
  if (n3 > 0) {
94
- words.push(this.ONES[n3]);
96
+ words.push(this.ones[n3]);
95
97
  if (n3 > 1) {
96
- words.push(this.HUNDREDS[1]);
98
+ words.push(this.hundreds[1]);
97
99
  } else {
98
- words.push(this.HUNDREDS[0]);
100
+ words.push(this.hundreds[0]);
99
101
  }
100
102
  }
101
103
  if (n2 > 1) {
102
- words.push(this.TWENTIES[n2]);
104
+ words.push(this.twenties[n2]);
103
105
  }
104
106
  if (n2 == 1) {
105
- words.push(this.TENS[n1]);
107
+ words.push(this.tens[n1]);
106
108
  } else if (n1 > 0) {
107
109
  if ((i == 1 || this.feminine && i == 0) && number < 1000) {
108
- words.push(this.ONES_FEMININE[n1]);
110
+ words.push(this.onesFeminine[n1]);
109
111
  } else {
110
- words.push(this.ONES[n1]);
112
+ words.push(this.ones[n1]);
111
113
  }
112
114
  }
113
115
  if (i > 0) {
114
- words.push(this.pluralize(x, this.THOUSANDS[i]));
116
+ words.push(this.pluralize(x, this.thousands[i]));
115
117
  }
116
118
  }
117
119
  return words.join(' ');
118
- };
120
+ }
121
+ }
122
+
123
+ export default function(n) {
124
+ return new N2WordsLT().floatToCardinal(n);
119
125
  }
package/lib/i18n/LV.mjs CHANGED
@@ -1,58 +1,61 @@
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 N2WordsLV extends N2WordsRU{
4
+ constructor() {
5
+ super();
5
6
 
6
- this.negative_word = 'mīnus';
7
- this.separator_word = 'komats';
8
- this.ZERO = 'nulle';
9
- this.ONES = {
10
- 1: 'viens',
11
- 2: 'divi',
12
- 3: 'trīs',
13
- 4: 'četri',
14
- 5: 'pieci',
15
- 6: 'seši',
16
- 7: 'septiņi',
17
- 8: 'astoņi',
18
- 9: 'deviņi'
19
- };
20
- this.TENS = {
21
- 0: 'desmit',
22
- 1: 'vienpadsmit',
23
- 2: 'divpadsmit',
24
- 3: 'trīspadsmit',
25
- 4: 'četrpadsmit',
26
- 5: 'piecpadsmit',
27
- 6: 'sešpadsmit',
28
- 7: 'septiņpadsmit',
29
- 8: 'astoņpadsmit',
30
- 9: 'deviņpadsmit'
31
- };
32
- this.TWENTIES = {
33
- 2: 'divdesmit',
34
- 3: 'trīsdesmit',
35
- 4: 'četrdesmit',
36
- 5: 'piecdesmit',
37
- 6: 'sešdesmit',
38
- 7: 'septiņdesmit',
39
- 8: 'astoņdesmit',
40
- 9: 'deviņdesmit'
41
- };
42
- this.HUNDREDS = ['simts', 'simti', 'simtu'];
43
- this.THOUSANDS = {
44
- 1: ['tūkstotis', 'tūkstoši', 'tūkstošu'],
45
- 2: ['miljons', 'miljoni', 'miljonu'],
46
- 3: ['miljards', 'miljardi', 'miljardu'],
47
- 4: ['triljons', 'triljoni', 'triljonu'],
48
- 5: ['kvadriljons', 'kvadriljoni', 'kvadriljonu'],
49
- 6: ['kvintiljons', 'kvintiljoni', 'kvintiljonu'],
50
- 7: ['sikstiljons', 'sikstiljoni', 'sikstiljonu'],
51
- 8: ['septiljons', 'septiljoni', 'septiljonu'],
52
- 9: ['oktiljons', 'oktiljoni', 'oktiljonu'],
53
- 10: ['nontiljons', 'nontiljoni', 'nontiljonu'],
54
- };
55
- this.pluralize = (n, forms) => {
7
+ this.negativeWord = 'mīnus';
8
+ this.separatorWord = 'komats';
9
+ this.zero = 'nulle';
10
+ this.ones = {
11
+ 1: 'viens',
12
+ 2: 'divi',
13
+ 3: 'trīs',
14
+ 4: 'četri',
15
+ 5: 'pieci',
16
+ 6: 'seši',
17
+ 7: 'septiņi',
18
+ 8: 'astoņi',
19
+ 9: 'deviņi'
20
+ };
21
+ this.tens = {
22
+ 0: 'desmit',
23
+ 1: 'vienpadsmit',
24
+ 2: 'divpadsmit',
25
+ 3: 'trīspadsmit',
26
+ 4: 'četrpadsmit',
27
+ 5: 'piecpadsmit',
28
+ 6: 'sešpadsmit',
29
+ 7: 'septiņpadsmit',
30
+ 8: 'astoņpadsmit',
31
+ 9: 'deviņpadsmit'
32
+ };
33
+ this.twenties = {
34
+ 2: 'divdesmit',
35
+ 3: 'trīsdesmit',
36
+ 4: 'četrdesmit',
37
+ 5: 'piecdesmit',
38
+ 6: 'sešdesmit',
39
+ 7: 'septiņdesmit',
40
+ 8: 'astoņdesmit',
41
+ 9: 'deviņdesmit'
42
+ };
43
+ this.hundreds = ['simts', 'simti', 'simtu'];
44
+ this.thousands = {
45
+ 1: ['tūkstotis', 'tūkstoši', 'tūkstošu'],
46
+ 2: ['miljons', 'miljoni', 'miljonu'],
47
+ 3: ['miljards', 'miljardi', 'miljardu'],
48
+ 4: ['triljons', 'triljoni', 'triljonu'],
49
+ 5: ['kvadriljons', 'kvadriljoni', 'kvadriljonu'],
50
+ 6: ['kvintiljons', 'kvintiljoni', 'kvintiljonu'],
51
+ 7: ['sikstiljons', 'sikstiljoni', 'sikstiljonu'],
52
+ 8: ['septiljons', 'septiljoni', 'septiljonu'],
53
+ 9: ['oktiljons', 'oktiljoni', 'oktiljonu'],
54
+ 10: ['nontiljons', 'nontiljoni', 'nontiljonu'],
55
+ };
56
+ }
57
+
58
+ pluralize(n, forms) {
56
59
  let form = 2;
57
60
  if (n != 0) {
58
61
  if (n % 10 == 1 && n % 100 != 11) {
@@ -62,14 +65,14 @@ export default function () {
62
65
  }
63
66
  }
64
67
  return forms[form];
65
- };
68
+ }
66
69
 
67
- this.toCardinal = (number) => {
70
+ toCardinal(number) {
68
71
  if (parseInt(number) == 0) {
69
- return this.ZERO;
72
+ return this.zero;
70
73
  }
71
74
  const words = [];
72
- const chunks = this.splitbyx(JSON.stringify(number), 3);
75
+ const chunks = this.splitByX(JSON.stringify(number), 3);
73
76
  let i = chunks.length;
74
77
  for (let j = 0; j < chunks.length; j++) {
75
78
  const x = chunks[j];
@@ -77,29 +80,33 @@ export default function () {
77
80
  if (x == 0) {
78
81
  continue;
79
82
  }
80
- const [n1, n2, n3] = this.get_digits(x);
83
+ const [n1, n2, n3] = this.getDigits(x);
81
84
  if (n3 > 0) {
82
85
  if (n3 == 1 && n2 == 0 && n1 > 0) {
83
- words.push(this.HUNDREDS[2]);
86
+ words.push(this.hundreds[2]);
84
87
  } else if (n3 > 1) {
85
- words.push(this.ONES[n3]);
86
- words.push(this.HUNDREDS[1]);
88
+ words.push(this.ones[n3]);
89
+ words.push(this.hundreds[1]);
87
90
  } else {
88
- words.push(this.HUNDREDS[0]);
91
+ words.push(this.hundreds[0]);
89
92
  }
90
93
  }
91
94
  if (n2 > 1) {
92
- words.push(this.TWENTIES[n2]);
95
+ words.push(this.twenties[n2]);
93
96
  }
94
97
  if (n2 == 1) {
95
- words.push(this.TENS[n1]);
98
+ words.push(this.tens[n1]);
96
99
  } else if (n1 > 0 && !(i > 0 && x == 1)) {
97
- words.push(this.ONES[n1]);
100
+ words.push(this.ones[n1]);
98
101
  }
99
102
  if (i > 0) {
100
- words.push(this.pluralize(x, this.THOUSANDS[i]));
103
+ words.push(this.pluralize(x, this.thousands[i]));
101
104
  }
102
105
  }
103
106
  return words.join(' ');
104
- };
107
+ }
108
+ }
109
+
110
+ export default function(n) {
111
+ return new N2WordsLV().floatToCardinal(n);
105
112
  }
package/lib/i18n/NL.mjs CHANGED
@@ -1,110 +1,115 @@
1
1
  import N2WordsBase from '../classes/N2WordsBase.mjs';
2
2
 
3
- export default function(options) {
4
- N2WordsBase.call(this);
3
+ export class N2WordsNL extends N2WordsBase {
4
+ constructor(options) {
5
+ super();
5
6
 
6
- this.negative_word = 'min';
7
- this.separator_word = 'komma';
8
- this.ZERO = 'nul';
7
+ this.negativeWord = 'min';
8
+ this.separatorWord = 'komma';
9
+ this.zero = 'nul';
9
10
 
10
- const defaultOptions = {
11
- includeOptionalAnd: false,
12
- noHundredPairs: false,
13
- };
11
+ this.options = Object.assign({
12
+ includeOptionalAnd: false,
13
+ noHundredPairs: false,
14
+ }, options);
14
15
 
15
- const localOptions = Object.assign({}, defaultOptions, options);
16
+ this.cards = [
17
+ {'1000000000000000000000000000': 'quadriljard'},
18
+ {'1000000000000000000000000': 'quadriljoen'},
19
+ {'1000000000000000000000': 'triljard'},
20
+ {1000000000000000000: 'triljoen'},
21
+ {1000000000000000: 'biljard'},
22
+ {1000000000000: 'biljoen'},
23
+ {1000000000: 'miljard'},
24
+ {1000000: 'miljoen'},
25
+ {1000: 'duizend'},
26
+ {100: 'honderd'},
27
+ {90: 'negentig'},
28
+ {80: 'tachtig'},
29
+ {70: 'zeventig'},
30
+ {60: 'zestig'},
31
+ {50: 'vijftig'},
32
+ {40: 'veertig'},
33
+ {30: 'dertig'},
34
+ {20: 'twintig'},
35
+ {19: 'negentien'},
36
+ {18: 'achttien'},
37
+ {17: 'zeventien'},
38
+ {16: 'zestien'},
39
+ {15: 'vijftien'},
40
+ {14: 'veertien'},
41
+ {13: 'dertien'},
42
+ {12: 'twaalf'},
43
+ {11: 'elf'},
44
+ {10: 'tien'},
45
+ {9: 'negen'},
46
+ {8: 'acht'},
47
+ {7: 'zeven'},
48
+ {6: 'zes'},
49
+ {5: 'vijf'},
50
+ {4: 'vier'},
51
+ {3: 'drie'},
52
+ {2: 'twee'},
53
+ {1: 'een'},
54
+ {0: 'nul'},
55
+ ];
56
+ }
16
57
 
17
- this.cards = [
18
- {'1000000000000000000000000000': 'quadriljard'},
19
- {'1000000000000000000000000': 'quadriljoen'},
20
- {'1000000000000000000000': 'triljard'},
21
- {1000000000000000000: 'triljoen'},
22
- {1000000000000000: 'biljard'},
23
- {1000000000000: 'biljoen'},
24
- {1000000000: 'miljard'},
25
- {1000000: 'miljoen'},
26
- {1000: 'duizend'},
27
- {100: 'honderd'},
28
- {90: 'negentig'},
29
- {80: 'tachtig'},
30
- {70: 'zeventig'},
31
- {60: 'zestig'},
32
- {50: 'vijftig'},
33
- {40: 'veertig'},
34
- {30: 'dertig'},
35
- {20: 'twintig'},
36
- {19: 'negentien'},
37
- {18: 'achtien'},
38
- {17: 'zeventien'},
39
- {16: 'zestien'},
40
- {15: 'vijftien'},
41
- {14: 'veertien'},
42
- {13: 'dertien'},
43
- {12: 'twaalf'},
44
- {11: 'elf'},
45
- {10: 'tien'},
46
- {9: 'negen'},
47
- {8: 'acht'},
48
- {7: 'zeven'},
49
- {6: 'zes'},
50
- {5: 'vijf'},
51
- {4: 'vier'},
52
- {3: 'drie'},
53
- {2: 'twee'},
54
- {1: 'een'},
55
- {0: 'nul'},
56
- ];
57
-
58
- this.merge = (curr, next) => {
59
- let ctext = Object.keys(curr)[0]; const cnum = parseInt(Object.values(curr)[0]);
60
- let ntext = Object.keys(next)[0]; const nnum = parseInt(Object.values(next)[0]);
61
- if (cnum == 1) {
62
- if (nnum < 1000000) {
63
- return {[ntext]: nnum};
58
+ merge(curr, next) {
59
+ let cText = Object.keys(curr)[0];
60
+ let nText = Object.keys(next)[0];
61
+ const cNum = parseInt(Object.values(curr)[0]);
62
+ const nNum = parseInt(Object.values(next)[0]);
63
+ if (cNum == 1) {
64
+ if (nNum < 1000000) {
65
+ return {[nText]: nNum};
64
66
  }
65
- ctext = 'een';
67
+ cText = 'een';
66
68
  }
67
69
 
68
70
  let val = 0;
69
- if (nnum > cnum) {
70
- if (nnum >= 1000000) {
71
- ctext += ' ';
72
- } else if (nnum > 100) {
73
- ntext += ' ';
71
+ if (nNum > cNum) {
72
+ if (nNum >= 1000000) {
73
+ cText += ' ';
74
+ } else if (nNum > 100) {
75
+ nText += ' ';
74
76
  }
75
- val = cnum * nnum;
77
+ val = cNum * nNum;
76
78
  } else {
77
- if (nnum < 10 && cnum > 10 && cnum < 100) {
78
- const temp = ntext;
79
- ntext = ctext;
80
- const andtxt = temp.endsWith('e') ? 'ën' : 'en';
81
- ctext = `${temp}${andtxt}`;
82
- } else if (nnum < 13 && cnum < 1000 && localOptions.includeOptionalAnd) {
83
- ctext = `${ctext}en`;
84
- } else if (nnum < 13 && cnum >= 1000 && localOptions.includeOptionalAnd) {
85
- ntext = ` en ${ntext}`;
86
- } else if (cnum >= 1000000) {
87
- ctext += ' ';
79
+ if (nNum < 10 && cNum > 10 && cNum < 100) {
80
+ const temp = nText;
81
+ nText = cText;
82
+ const andTxt = temp.endsWith('e') ? 'ën' : 'en';
83
+ cText = `${temp}${andTxt}`;
84
+ } else if (nNum < 13 && cNum < 1000 && this.options.includeOptionalAnd) {
85
+ cText = `${cText}en`;
86
+ } else if (nNum < 13 && cNum >= 1000 && this.options.includeOptionalAnd) {
87
+ nText = ` en ${nText}`;
88
+ } else if (cNum >= 1000000) {
89
+ cText += ' ';
88
90
  } else {
89
- if (cnum === 1000) {
90
- ctext += ' ';
91
+ if (cNum === 1000) {
92
+ cText += ' ';
91
93
  }
92
94
  }
93
- val = cnum + nnum;
95
+ val = cNum + nNum;
94
96
  }
95
- return {[`${ctext}${ntext}`]: val};
96
- };
97
+ return {[`${cText}${nText}`]: val};
98
+ }
97
99
 
98
- const old_toCardinal = this.toCardinal;
99
- this.toCardinal = (value) => {
100
- if (value >= 1100 && value < 10000 && !localOptions.noHundredPairs) {
100
+ toCardinal(value) {
101
+ if (value >= 1100 && value < 10000 && !this.options.noHundredPairs) {
101
102
  const high = Math.floor(value / 100);
102
103
  const low = value % 100;
103
104
  if (high % 10 !== 0) {
104
- return old_toCardinal(high) + 'honderd' +
105
- (low ? (localOptions.includeOptionalAnd ? ' en ' : ' ') + old_toCardinal(low) : '');
105
+ return super.toCardinal(high) + 'honderd' +
106
+ (low ? (this.options.includeOptionalAnd ? ' en ' : ' ') + super.toCardinal(low) : '');
106
107
  }
107
108
  }
108
- return old_toCardinal(value);
109
- };
109
+ return super.toCardinal(value);
110
+ }
111
+ }
112
+
113
+ export default function(n, options = {}) {
114
+ return new N2WordsNL(options).floatToCardinal(n);
110
115
  }