n2words 1.13.0 → 1.15.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 +2 -2
- package/README.md +1 -1
- package/bench.mjs +94 -0
- package/dist/n2words.js +1 -1
- package/examples/node.mjs +10 -0
- package/lib/classes/AbstractLanguage.mjs +151 -0
- package/lib/classes/BaseLanguage.mjs +174 -0
- package/lib/i18n/AR.mjs +62 -38
- package/lib/i18n/AZ.mjs +44 -38
- package/lib/i18n/CZ.mjs +79 -69
- package/lib/i18n/DE.mjs +56 -50
- package/lib/i18n/DK.mjs +62 -50
- package/lib/i18n/EN.mjs +66 -54
- package/lib/i18n/ES.mjs +67 -55
- package/lib/i18n/FA.mjs +75 -63
- package/lib/i18n/FR.mjs +54 -48
- package/lib/i18n/HE.mjs +81 -23
- package/lib/i18n/HR.mjs +81 -70
- package/lib/i18n/HU.mjs +82 -76
- package/lib/i18n/ID.mjs +55 -46
- package/lib/i18n/IT.mjs +39 -27
- package/lib/i18n/KO.mjs +38 -32
- package/lib/i18n/LT.mjs +79 -67
- package/lib/i18n/LV.mjs +69 -57
- package/lib/i18n/NL.mjs +70 -60
- package/lib/i18n/NO.mjs +58 -52
- package/lib/i18n/PL.mjs +78 -67
- package/lib/i18n/PT.mjs +63 -56
- package/lib/i18n/RU.mjs +159 -122
- package/lib/i18n/SR.mjs +81 -70
- package/lib/i18n/TR.mjs +45 -43
- package/lib/i18n/UK.mjs +87 -75
- package/lib/i18n/VI.mjs +89 -79
- package/lib/i18n/ZH.mjs +40 -33
- package/lib/n2words.mjs +33 -107
- package/package.json +17 -11
- package/webpack.config.js +1 -1
- package/lib/classes/N2WordsAbs.mjs +0 -72
- package/lib/classes/N2WordsBase.mjs +0 -105
package/lib/i18n/NO.mjs
CHANGED
|
@@ -1,54 +1,53 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BaseLanguage from '../classes/BaseLanguage.mjs';
|
|
2
2
|
|
|
3
|
-
export class N2WordsNO extends
|
|
4
|
-
constructor() {
|
|
5
|
-
super(
|
|
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
|
-
];
|
|
3
|
+
export class N2WordsNO extends BaseLanguage {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super(Object.assign({
|
|
6
|
+
negativeWord: 'minus',
|
|
7
|
+
separatorWord: 'komma',
|
|
8
|
+
zero: 'null'
|
|
9
|
+
}, options), [
|
|
10
|
+
[1000000000000000000000000000000000n, 'quintillard'],
|
|
11
|
+
[1000000000000000000000000000000n, 'quintillion'],
|
|
12
|
+
[1000000000000000000000000000n, 'quadrillard'],
|
|
13
|
+
[1000000000000000000000000n, 'quadrillion'],
|
|
14
|
+
[1000000000000000000000n, 'trillard'],
|
|
15
|
+
[1000000000000000000n, 'trillion'],
|
|
16
|
+
[1000000000000000n, 'billard'],
|
|
17
|
+
[1000000000000n, 'billion'],
|
|
18
|
+
[1000000000n, 'millard'],
|
|
19
|
+
[1000000n, 'million'],
|
|
20
|
+
[1000n, 'tusen'],
|
|
21
|
+
[100n, 'hundre'],
|
|
22
|
+
[90n, 'nitti'],
|
|
23
|
+
[80n, 'åtti'],
|
|
24
|
+
[70n, 'sytti'],
|
|
25
|
+
[60n, 'seksti'],
|
|
26
|
+
[50n, 'femti'],
|
|
27
|
+
[40n, 'førti'],
|
|
28
|
+
[30n, 'tretti'],
|
|
29
|
+
[20n, 'tjue'],
|
|
30
|
+
[19n, 'nitten'],
|
|
31
|
+
[18n, 'atten'],
|
|
32
|
+
[17n, 'sytten'],
|
|
33
|
+
[16n, 'seksten'],
|
|
34
|
+
[15n, 'femten'],
|
|
35
|
+
[14n, 'fjorten'],
|
|
36
|
+
[13n, 'tretten'],
|
|
37
|
+
[12n, 'tolv'],
|
|
38
|
+
[11n, 'elleve'],
|
|
39
|
+
[10n, 'ti'],
|
|
40
|
+
[9n, 'ni'],
|
|
41
|
+
[8n, 'åtte'],
|
|
42
|
+
[7n, 'syv'],
|
|
43
|
+
[6n, 'seks'],
|
|
44
|
+
[5n, 'fem'],
|
|
45
|
+
[4n, 'fire'],
|
|
46
|
+
[3n, 'tre'],
|
|
47
|
+
[2n, 'to'],
|
|
48
|
+
[1n, 'en'],
|
|
49
|
+
[0n, 'null']
|
|
50
|
+
]);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
merge(lPair, rPair) { // {'one':1}, {'hundred':100}
|
|
@@ -64,6 +63,13 @@ export class N2WordsNO extends N2WordsBase {
|
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Converts a value to cardinal (written) form.
|
|
68
|
+
* @param {number|string} value Number to be convert.
|
|
69
|
+
* @param {object} options Options for class.
|
|
70
|
+
* @throws {Error} Value cannot be invalid.
|
|
71
|
+
* @returns {string} Value in cardinal (written) format.
|
|
72
|
+
*/
|
|
73
|
+
export default function(value, options) {
|
|
74
|
+
return new N2WordsNO(options).floatToCardinal(value);
|
|
69
75
|
}
|
package/lib/i18n/PL.mjs
CHANGED
|
@@ -1,87 +1,91 @@
|
|
|
1
1
|
import {N2WordsRU} from './RU.mjs';
|
|
2
2
|
|
|
3
3
|
export class N2WordsPL extends N2WordsRU {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
ones = {
|
|
5
|
+
1: 'jeden',
|
|
6
|
+
2: 'dwa',
|
|
7
|
+
3: 'trzy',
|
|
8
|
+
4: 'cztery',
|
|
9
|
+
5: 'pięć',
|
|
10
|
+
6: 'sześć',
|
|
11
|
+
7: 'siedem',
|
|
12
|
+
8: 'osiem',
|
|
13
|
+
9: 'dziewięć'
|
|
14
|
+
};
|
|
6
15
|
|
|
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
|
-
7: ['tryliard', 'tryliardy', 'tryliardów'], // 10^ 21
|
|
63
|
-
8: ['kwadrylion', 'kwadryliony', 'kwadrylionów'], // 10^ 24
|
|
64
|
-
9: ['kwaryliard', 'kwadryliardy', 'kwadryliardów'], // 10^ 27
|
|
65
|
-
10: ['kwintylion', 'kwintyliony', 'kwintylionów'], // 10^ 30
|
|
66
|
-
};
|
|
16
|
+
tens = {
|
|
17
|
+
0: 'dziesięć',
|
|
18
|
+
1: 'jedenaście',
|
|
19
|
+
2: 'dwanaście',
|
|
20
|
+
3: 'trzynaście',
|
|
21
|
+
4: 'czternaście',
|
|
22
|
+
5: 'piętnaście',
|
|
23
|
+
6: 'szesnaście',
|
|
24
|
+
7: 'siedemnaście',
|
|
25
|
+
8: 'osiemnaście',
|
|
26
|
+
9: 'dziewiętnaście'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
twenties = {
|
|
30
|
+
2: 'dwadzieścia',
|
|
31
|
+
3: 'trzydzieści',
|
|
32
|
+
4: 'czterdzieści',
|
|
33
|
+
5: 'pięćdziesiąt',
|
|
34
|
+
6: 'sześćdziesiąt',
|
|
35
|
+
7: 'siedemdziesiąt',
|
|
36
|
+
8: 'osiemdziesiąt',
|
|
37
|
+
9: 'dziewięćdzisiąt'
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
hundreds = {
|
|
41
|
+
1: 'sto',
|
|
42
|
+
2: 'dwieście',
|
|
43
|
+
3: 'trzysta',
|
|
44
|
+
4: 'czterysta',
|
|
45
|
+
5: 'pięćset',
|
|
46
|
+
6: 'sześćset',
|
|
47
|
+
7: 'siedemset',
|
|
48
|
+
8: 'osiemset',
|
|
49
|
+
9: 'dziewięćset'
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
thousands = {
|
|
53
|
+
1: ['tysiąc', 'tysiące', 'tysięcy'], // 10^ 3
|
|
54
|
+
2: ['milion', 'miliony', 'milionów'], // 10^ 6
|
|
55
|
+
3: ['miliard', 'miliardy', 'miliardów'], // 10^ 9
|
|
56
|
+
4: ['bilion', 'biliony', 'bilionów'], // 10^ 12
|
|
57
|
+
5: ['biliard', 'biliardy', 'biliardów'], // 10^ 15
|
|
58
|
+
6: ['trylion', 'tryliony', 'trylionów'], // 10^ 18
|
|
59
|
+
7: ['tryliard', 'tryliardy', 'tryliardów'], // 10^ 21
|
|
60
|
+
8: ['kwadrylion', 'kwadryliony', 'kwadrylionów'], // 10^ 24
|
|
61
|
+
9: ['kwaryliard', 'kwadryliardy', 'kwadryliardów'], // 10^ 27
|
|
62
|
+
10: ['kwintylion', 'kwintyliony', 'kwintylionów'], // 10^ 30
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
constructor(options) {
|
|
66
|
+
super(Object.assign({
|
|
67
|
+
negativeWord: 'minus',
|
|
68
|
+
separatorWord: 'przecinek',
|
|
69
|
+
zero: 'zero'
|
|
70
|
+
}, options));
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
pluralize(n, forms) {
|
|
70
74
|
let form = 2;
|
|
71
75
|
if (n == 1) {
|
|
72
76
|
form = 0;
|
|
73
|
-
} else if ((n %
|
|
77
|
+
} else if ((n % 10n < 5n) && (n % 10n > 1n) && ((n % 100n < 10n) || (n % 100n > 20n))) {
|
|
74
78
|
form = 1;
|
|
75
79
|
}
|
|
76
80
|
return forms[form];
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
toCardinal(number) {
|
|
80
|
-
if (
|
|
84
|
+
if (number == 0) {
|
|
81
85
|
return this.zero;
|
|
82
86
|
}
|
|
83
87
|
const words = [];
|
|
84
|
-
const chunks = this.splitByX(
|
|
88
|
+
const chunks = this.splitByX(number.toString(), 3);
|
|
85
89
|
let i = chunks.length;
|
|
86
90
|
for (let j = 0; j < chunks.length; j++) {
|
|
87
91
|
const x = chunks[j];
|
|
@@ -109,6 +113,13 @@ export class N2WordsPL extends N2WordsRU {
|
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Converts a value to cardinal (written) form.
|
|
118
|
+
* @param {number|string} value Number to be convert.
|
|
119
|
+
* @param {object} options Options for class.
|
|
120
|
+
* @throws {Error} Value cannot be invalid.
|
|
121
|
+
* @returns {string} Value in cardinal (written) format.
|
|
122
|
+
*/
|
|
123
|
+
export default function(value, options) {
|
|
124
|
+
return new N2WordsPL(options).floatToCardinal(value);
|
|
114
125
|
}
|
package/lib/i18n/PT.mjs
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BaseLanguage from '../classes/BaseLanguage.mjs';
|
|
2
2
|
|
|
3
|
-
export class N2WordsPT extends
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export class N2WordsPT extends BaseLanguage {
|
|
4
|
+
hundreds = {
|
|
5
|
+
1: 'cento',
|
|
6
|
+
2: 'duzentos',
|
|
7
|
+
3: 'trezentos',
|
|
8
|
+
4: 'quatrocentos',
|
|
9
|
+
5: 'quinhentos',
|
|
10
|
+
6: 'seiscentos',
|
|
11
|
+
7: 'setecentos',
|
|
12
|
+
8: 'oitocentos',
|
|
13
|
+
9: 'novecentos'
|
|
14
|
+
};
|
|
6
15
|
|
|
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
|
-
2: 'duzentos',
|
|
49
|
-
3: 'trezentos',
|
|
50
|
-
4: 'quatrocentos',
|
|
51
|
-
5: 'quinhentos',
|
|
52
|
-
6: 'seiscentos',
|
|
53
|
-
7: 'setecentos',
|
|
54
|
-
8: 'oitocentos',
|
|
55
|
-
9: 'novecentos'
|
|
56
|
-
};
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super(Object.assign({
|
|
18
|
+
negativeWord: 'menos',
|
|
19
|
+
separatorWord: 'vírgula',
|
|
20
|
+
zero: 'zero'
|
|
21
|
+
}, options), [
|
|
22
|
+
[1000000000000000000000000n, 'quatrilião'],
|
|
23
|
+
[1000000000000000000n, 'trilião'],
|
|
24
|
+
[1000000000000n, 'bilião'],
|
|
25
|
+
[1000000n, 'milião'],
|
|
26
|
+
[1000n, 'mil'],
|
|
27
|
+
[100n, 'cem'],
|
|
28
|
+
[90n, 'noventa'],
|
|
29
|
+
[80n, 'oitenta'],
|
|
30
|
+
[70n, 'setenta'],
|
|
31
|
+
[60n, 'sessenta'],
|
|
32
|
+
[50n, 'cinquenta'],
|
|
33
|
+
[40n, 'quarenta'],
|
|
34
|
+
[30n, 'trinta'],
|
|
35
|
+
[20n, 'vinte'],
|
|
36
|
+
[19n, 'dezanove'],
|
|
37
|
+
[18n, 'dezoito'],
|
|
38
|
+
[17n, 'dezassete'],
|
|
39
|
+
[16n, 'dezasseis'],
|
|
40
|
+
[15n, 'quinze'],
|
|
41
|
+
[14n, 'catorze'],
|
|
42
|
+
[13n, 'treze'],
|
|
43
|
+
[12n, 'doze'],
|
|
44
|
+
[11n, 'onze'],
|
|
45
|
+
[10n, 'dez'],
|
|
46
|
+
[9n, 'nove'],
|
|
47
|
+
[8n, 'oito'],
|
|
48
|
+
[7n, 'sete'],
|
|
49
|
+
[6n, 'seis'],
|
|
50
|
+
[5n, 'cinco'],
|
|
51
|
+
[4n, 'quatro'],
|
|
52
|
+
[3n, 'três'],
|
|
53
|
+
[2n, 'dois'],
|
|
54
|
+
[1n, 'um'],
|
|
55
|
+
[0n, 'zero']
|
|
56
|
+
]);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
postClean(words) {
|
|
@@ -102,6 +102,13 @@ export class N2WordsPT extends N2WordsBase {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Converts a value to cardinal (written) form.
|
|
107
|
+
* @param {number|string} value Number to be convert.
|
|
108
|
+
* @param {object} options Options for class.
|
|
109
|
+
* @throws {Error} Value cannot be invalid.
|
|
110
|
+
* @returns {string} Value in cardinal (written) format.
|
|
111
|
+
*/
|
|
112
|
+
export default function(value, options) {
|
|
113
|
+
return new N2WordsPT(options).floatToCardinal(value);
|
|
107
114
|
}
|