n2words 1.16.4 → 1.18.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/README.md +2 -1
- package/dist/n2words.js +1 -1
- package/dist/n2words.js.map +1 -1
- package/lib/classes/AbstractLanguage.d.ts +2 -2
- package/lib/classes/AbstractLanguage.js +16 -7
- package/lib/classes/BaseLanguage.d.ts +0 -1
- package/lib/classes/BaseLanguage.js +0 -4
- package/lib/i18n/ar.d.ts +6 -5
- package/lib/i18n/ar.js +80 -42
- package/lib/i18n/az.js +4 -2
- package/lib/i18n/cz.d.ts +56 -0
- package/lib/i18n/cz.js +4 -2
- package/lib/i18n/de.js +4 -2
- package/lib/i18n/dk.js +1 -1
- package/lib/i18n/en.js +4 -2
- package/lib/i18n/fa.js +4 -2
- package/lib/i18n/fr-BE.d.ts +11 -0
- package/lib/i18n/fr-BE.js +20 -0
- package/lib/i18n/fr.js +8 -3
- package/lib/i18n/he.d.ts +33 -0
- package/lib/i18n/he.js +9 -4
- package/lib/i18n/hr.d.ts +33 -0
- package/lib/i18n/hr.js +4 -2
- package/lib/i18n/hu.js +4 -2
- package/lib/i18n/id.js +4 -2
- package/lib/i18n/it.js +4 -2
- package/lib/i18n/ko.js +4 -2
- package/lib/i18n/lt.d.ts +56 -0
- package/lib/i18n/lt.js +4 -2
- package/lib/i18n/lv.d.ts +45 -0
- package/lib/i18n/lv.js +4 -2
- package/lib/i18n/no.js +4 -2
- package/lib/i18n/pl.d.ts +56 -0
- package/lib/i18n/pl.js +4 -2
- package/lib/i18n/pt.js +4 -2
- package/lib/i18n/ru.d.ts +15 -69
- package/lib/i18n/ru.js +16 -22
- package/lib/i18n/sr.d.ts +33 -12
- package/lib/i18n/sr.js +13 -13
- package/lib/i18n/uk.d.ts +67 -0
- package/lib/n2words.js +41 -30
- package/package.json +18 -17
package/lib/n2words.js
CHANGED
|
@@ -7,6 +7,7 @@ import n2wordsEN from './i18n/en.js';
|
|
|
7
7
|
import n2wordsES from './i18n/es.js';
|
|
8
8
|
import n2wordsFA from './i18n/fa.js';
|
|
9
9
|
import n2wordsFR from './i18n/fr.js';
|
|
10
|
+
import n2wordsFRBE from './i18n/fr-BE.js';
|
|
10
11
|
import n2wordsHE from './i18n/he.js';
|
|
11
12
|
import n2wordsHR from './i18n/hr.js';
|
|
12
13
|
import n2wordsHU from './i18n/hu.js';
|
|
@@ -26,6 +27,37 @@ import n2wordsUK from './i18n/uk.js';
|
|
|
26
27
|
import n2wordsVI from './i18n/vi.js';
|
|
27
28
|
import n2wordsZH from './i18n/zh.js';
|
|
28
29
|
|
|
30
|
+
const dict = {
|
|
31
|
+
'ar': n2wordsAR,
|
|
32
|
+
'az': n2wordsAZ,
|
|
33
|
+
'cz': n2wordsCZ,
|
|
34
|
+
'de': n2wordsDE,
|
|
35
|
+
'dk': n2wordsDK,
|
|
36
|
+
'en': n2wordsEN, // default
|
|
37
|
+
'es': n2wordsES,
|
|
38
|
+
'fa': n2wordsFA,
|
|
39
|
+
'fr': n2wordsFR,
|
|
40
|
+
'fr-BE': n2wordsFRBE,
|
|
41
|
+
'he': n2wordsHE, // only for numbers <= 9999
|
|
42
|
+
'hr': n2wordsHR,
|
|
43
|
+
'hu': n2wordsHU,
|
|
44
|
+
'id': n2wordsID,
|
|
45
|
+
'it': n2wordsIT,
|
|
46
|
+
'ko': n2wordsKO,
|
|
47
|
+
'lt': n2wordsLT,
|
|
48
|
+
'lv': n2wordsLV,
|
|
49
|
+
'nl': n2wordsNL,
|
|
50
|
+
'no': n2wordsNO,
|
|
51
|
+
'pl': n2wordsPL,
|
|
52
|
+
'pt': n2wordsPT,
|
|
53
|
+
'ru': n2wordsRU,
|
|
54
|
+
'sr': n2wordsSR,
|
|
55
|
+
'tr': n2wordsTR,
|
|
56
|
+
'uk': n2wordsUK,
|
|
57
|
+
'vi': n2wordsVI,
|
|
58
|
+
'zh': n2wordsZH,
|
|
59
|
+
};
|
|
60
|
+
|
|
29
61
|
/**
|
|
30
62
|
* Converts a number to written form.
|
|
31
63
|
* @param {number|string} value The number to convert.
|
|
@@ -33,34 +65,13 @@ import n2wordsZH from './i18n/zh.js';
|
|
|
33
65
|
* @returns {string} Value in written format.
|
|
34
66
|
*/
|
|
35
67
|
export default function (value, options = { lang: 'en' }) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
case 'fr': return n2wordsFR(value, options);
|
|
46
|
-
case 'he': return n2wordsHE(value, options); // only for numbers <= 9999
|
|
47
|
-
case 'hr': return n2wordsHR(value, options);
|
|
48
|
-
case 'hu': return n2wordsHU(value, options);
|
|
49
|
-
case 'id': return n2wordsID(value, options);
|
|
50
|
-
case 'it': return n2wordsIT(value, options);
|
|
51
|
-
case 'ko': return n2wordsKO(value, options);
|
|
52
|
-
case 'lt': return n2wordsLT(value, options);
|
|
53
|
-
case 'lv': return n2wordsLV(value, options);
|
|
54
|
-
case 'nl': return n2wordsNL(value, options);
|
|
55
|
-
case 'no': return n2wordsNO(value, options);
|
|
56
|
-
case 'pl': return n2wordsPL(value, options);
|
|
57
|
-
case 'pt': return n2wordsPT(value, options);
|
|
58
|
-
case 'ru': return n2wordsRU(value, options);
|
|
59
|
-
case 'sr': return n2wordsSR(value, options);
|
|
60
|
-
case 'tr': return n2wordsTR(value, options);
|
|
61
|
-
case 'uk': return n2wordsUK(value, options);
|
|
62
|
-
case 'vi': return n2wordsVI(value, options);
|
|
63
|
-
case 'zh': return n2wordsZH(value, options);
|
|
64
|
-
default: throw Error('Unsupported language: ' + value + '.');
|
|
65
|
-
}
|
|
68
|
+
const fn = dict[options.lang];
|
|
69
|
+
if (fn != null) return fn(value, options);
|
|
70
|
+
|
|
71
|
+
const fallbackLang = options.lang.split('-') // 'en-UK' -> ['en', 'UK']
|
|
72
|
+
.map((_, i, arr) => arr.slice(0, arr.length - i).join('-')) // ['en-UK', 'en']
|
|
73
|
+
.find(l => dict[l] != null);
|
|
74
|
+
if (fallbackLang != null) return dict[fallbackLang](value, options);
|
|
75
|
+
|
|
76
|
+
throw Error('Unsupported language: ' + value + '.');
|
|
66
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n2words",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"description": "n2words converts a numerical number into a written one, supports 27 languages and has zero dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"n2words",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"scripts": {
|
|
66
66
|
"bench": "node bench.js",
|
|
67
67
|
"build": "webpack --config webpack.config.js --progress",
|
|
68
|
-
"build:types": "npx -p typescript tsc lib/n2words.js dist/n2words.js --target
|
|
68
|
+
"build:types": "npx -p typescript tsc lib/n2words.js dist/n2words.js --target es6 --module esnext --allowJs --declaration --emitDeclarationOnly",
|
|
69
69
|
"coverage": "c8 ava",
|
|
70
|
-
"lint": "eslint --config .eslintrc.json lib/ test/ bench.js",
|
|
70
|
+
"lint": "eslint --config .eslintrc.json lib/ test/ examples/ bench.js",
|
|
71
71
|
"test": "ava --verbose",
|
|
72
72
|
"test:cjs": "ava --verbose test/import.cjs",
|
|
73
73
|
"test:core": "ava --verbose test/core.js",
|
|
@@ -91,25 +91,26 @@
|
|
|
91
91
|
]
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@babel/core": "^7.22.
|
|
95
|
-
"@babel/preset-env": "^7.22.
|
|
96
|
-
"ava": "^5.3.
|
|
97
|
-
"babel-loader": "^9.1.
|
|
94
|
+
"@babel/core": "^7.22.11",
|
|
95
|
+
"@babel/preset-env": "^7.22.10",
|
|
96
|
+
"ava": "^5.3.1",
|
|
97
|
+
"babel-loader": "^9.1.3",
|
|
98
98
|
"benchmark": "^2.1.4",
|
|
99
|
-
"c8": "^
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
99
|
+
"c8": "^8.0.1",
|
|
100
|
+
"chalk": "^5.3.0",
|
|
101
|
+
"chromedriver": "^116.0.0",
|
|
102
|
+
"core-js": "^3.32.1",
|
|
103
|
+
"eslint": "^8.48.0",
|
|
103
104
|
"eslint-plugin-ava": "^14.0.0",
|
|
104
|
-
"eslint-plugin-import": "^2.
|
|
105
|
-
"eslint-plugin-jsdoc": "^46.
|
|
105
|
+
"eslint-plugin-import": "^2.28.1",
|
|
106
|
+
"eslint-plugin-jsdoc": "^46.5.0",
|
|
106
107
|
"eslint-plugin-node": "^11.1.0",
|
|
107
108
|
"microtime": "^3.1.1",
|
|
108
|
-
"selenium-webdriver": "^4.
|
|
109
|
-
"webpack": "^5.
|
|
110
|
-
"webpack-cli": "^5.1.
|
|
109
|
+
"selenium-webdriver": "^4.11.1",
|
|
110
|
+
"webpack": "^5.88.2",
|
|
111
|
+
"webpack-cli": "^5.1.4"
|
|
111
112
|
},
|
|
112
113
|
"engines": {
|
|
113
|
-
"node": "16 || >=
|
|
114
|
+
"node": "16 || 18 || >=20"
|
|
114
115
|
}
|
|
115
116
|
}
|