n2words 1.20.0 → 1.22.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/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/ar.js +2 -0
- package/dist/ar.js.map +1 -0
- package/dist/az.js +2 -0
- package/dist/az.js.map +1 -0
- package/dist/cz.js +2 -0
- package/dist/cz.js.map +1 -0
- package/dist/de.js +2 -0
- package/dist/de.js.map +1 -0
- package/dist/dk.js +2 -0
- package/dist/dk.js.map +1 -0
- package/dist/en.js +2 -0
- package/dist/en.js.map +1 -0
- package/dist/es.js +2 -0
- package/dist/es.js.map +1 -0
- package/dist/fa.js +2 -0
- package/dist/fa.js.map +1 -0
- package/dist/fr-BE.js +2 -0
- package/dist/fr-BE.js.map +1 -0
- package/dist/fr.js +2 -0
- package/dist/fr.js.map +1 -0
- package/dist/he.js +2 -0
- package/dist/he.js.map +1 -0
- package/dist/hr.js +2 -0
- package/dist/hr.js.map +1 -0
- package/dist/hu.js +2 -0
- package/dist/hu.js.map +1 -0
- package/dist/id.js +2 -0
- package/dist/id.js.map +1 -0
- package/dist/it.js +2 -0
- package/dist/it.js.map +1 -0
- package/dist/ko.js +2 -0
- package/dist/ko.js.map +1 -0
- package/dist/lt.js +2 -0
- package/dist/lt.js.map +1 -0
- package/dist/lv.js +2 -0
- package/dist/lv.js.map +1 -0
- package/dist/n2words.js +1 -1
- package/dist/n2words.js.map +1 -1
- package/dist/nl.js +2 -0
- package/dist/nl.js.map +1 -0
- package/dist/no.js +2 -0
- package/dist/no.js.map +1 -0
- package/dist/pl.js +2 -0
- package/dist/pl.js.map +1 -0
- package/dist/pt.js +2 -0
- package/dist/pt.js.map +1 -0
- package/dist/ro.js +2 -0
- package/dist/ro.js.map +1 -0
- package/dist/ru.js +2 -0
- package/dist/ru.js.map +1 -0
- package/dist/sr.js +2 -0
- package/dist/sr.js.map +1 -0
- package/dist/tr.js +2 -0
- package/dist/tr.js.map +1 -0
- package/dist/uk.js +2 -0
- package/dist/uk.js.map +1 -0
- package/dist/vi.js +2 -0
- package/dist/vi.js.map +1 -0
- package/dist/zh.js +2 -0
- package/dist/zh.js.map +1 -0
- package/lib/classes/{AbstractLanguage.d.ts → abstract-language.d.ts} +4 -3
- package/lib/classes/{AbstractLanguage.js → abstract-language.js} +14 -12
- package/lib/classes/{BaseLanguage.d.ts → base-language.d.ts} +6 -10
- package/lib/classes/{BaseLanguage.js → base-language.js} +23 -28
- package/lib/i18n/ar.d.ts +6 -6
- package/lib/i18n/ar.js +37 -45
- package/lib/i18n/az.d.ts +3 -3
- package/lib/i18n/az.js +15 -15
- package/lib/i18n/cz.d.ts +2 -2
- package/lib/i18n/cz.js +8 -9
- package/lib/i18n/de.d.ts +4 -4
- package/lib/i18n/de.js +33 -37
- package/lib/i18n/dk.d.ts +4 -4
- package/lib/i18n/dk.js +32 -32
- package/lib/i18n/en.d.ts +3 -3
- package/lib/i18n/en.js +18 -18
- package/lib/i18n/es.d.ts +4 -4
- package/lib/i18n/es.js +24 -24
- package/lib/i18n/fa.d.ts +3 -3
- package/lib/i18n/fa.js +9 -9
- package/lib/i18n/fr-BE.d.ts +2 -2
- package/lib/i18n/fr-BE.js +2 -2
- package/lib/i18n/fr.d.ts +4 -4
- package/lib/i18n/fr.js +29 -29
- package/lib/i18n/he.d.ts +2 -2
- package/lib/i18n/he.js +9 -12
- package/lib/i18n/hr.d.ts +2 -2
- package/lib/i18n/hr.js +10 -11
- package/lib/i18n/hu.d.ts +3 -3
- package/lib/i18n/hu.js +14 -14
- package/lib/i18n/id.d.ts +4 -4
- package/lib/i18n/id.js +25 -35
- package/lib/i18n/it.d.ts +3 -3
- package/lib/i18n/it.js +18 -38
- package/lib/i18n/ko.d.ts +3 -3
- package/lib/i18n/ko.js +16 -16
- package/lib/i18n/lt.d.ts +2 -2
- package/lib/i18n/lt.js +8 -9
- package/lib/i18n/lv.d.ts +2 -2
- package/lib/i18n/lv.js +10 -16
- package/lib/i18n/nl.d.ts +4 -4
- package/lib/i18n/nl.js +34 -34
- package/lib/i18n/no.d.ts +3 -3
- package/lib/i18n/no.js +20 -20
- package/lib/i18n/pl.d.ts +2 -2
- package/lib/i18n/pl.js +8 -9
- package/lib/i18n/pt.d.ts +4 -4
- package/lib/i18n/pt.js +25 -25
- package/lib/i18n/ro.d.ts +109 -0
- package/lib/i18n/ro.js +360 -0
- package/lib/i18n/ru.d.ts +4 -4
- package/lib/i18n/ru.js +15 -14
- package/lib/i18n/sr.d.ts +2 -2
- package/lib/i18n/sr.js +10 -11
- package/lib/i18n/tr.d.ts +3 -3
- package/lib/i18n/tr.js +15 -15
- package/lib/i18n/uk.d.ts +2 -2
- package/lib/i18n/uk.js +2 -2
- package/lib/i18n/vi.d.ts +3 -3
- package/lib/i18n/vi.js +4 -8
- package/lib/i18n/zh.d.ts +6 -6
- package/lib/i18n/zh.js +11 -11
- package/lib/n2words.d.ts +3 -1
- package/lib/n2words.js +17 -7
- package/package.json +32 -23
package/lib/i18n/zh.d.ts
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* Converts a value to cardinal (written) form.
|
|
3
3
|
* @param {number|string|bigint} value Number to be convert.
|
|
4
4
|
* @param {object} [options] Options for class.
|
|
5
|
-
* @throws {Error} Value cannot be invalid.
|
|
6
5
|
* @returns {string} Value in cardinal (written) format.
|
|
6
|
+
* @throws {Error} Value cannot be invalid.
|
|
7
7
|
*/
|
|
8
|
-
export default function
|
|
8
|
+
export default function floatToCardinal(value: number | string | bigint, options?: object): string;
|
|
9
9
|
export class N2WordsZH extends BaseLanguage {
|
|
10
10
|
constructor(options: any);
|
|
11
11
|
merge(lPair: any, rPair: any): {
|
|
12
12
|
[x: string]: bigint;
|
|
13
13
|
};
|
|
14
|
-
decimalToCardinal(decimal: any):
|
|
15
|
-
digit(
|
|
16
|
-
zeroDigit(
|
|
14
|
+
decimalToCardinal(decimal: any): string;
|
|
15
|
+
digit(number_: any): any;
|
|
16
|
+
zeroDigit(number_: any): number;
|
|
17
17
|
}
|
|
18
|
-
import BaseLanguage from '../classes/
|
|
18
|
+
import BaseLanguage from '../classes/base-language.js';
|
package/lib/i18n/zh.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import BaseLanguage from '../classes/
|
|
1
|
+
import BaseLanguage from '../classes/base-language.js';
|
|
2
2
|
|
|
3
3
|
export class N2WordsZH extends BaseLanguage {
|
|
4
4
|
constructor(options) {
|
|
@@ -8,9 +8,9 @@ export class N2WordsZH extends BaseLanguage {
|
|
|
8
8
|
zero: '零',
|
|
9
9
|
spaceSeparator: ''
|
|
10
10
|
}, options), [
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
11
|
+
[1_000_000_000_000n, '万'],
|
|
12
|
+
[100_000_000n, '亿'],
|
|
13
|
+
[10_000n, '万'],
|
|
14
14
|
[1000n, '仟'],
|
|
15
15
|
[100n, '佰'],
|
|
16
16
|
[10n, '拾'],
|
|
@@ -48,7 +48,7 @@ export class N2WordsZH extends BaseLanguage {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
decimalToCardinal(decimal) {
|
|
51
|
-
const decimalPartArray = decimal
|
|
51
|
+
const decimalPartArray = [...decimal];
|
|
52
52
|
|
|
53
53
|
const decimalPartWordsArray = decimalPartArray.map(decimal =>
|
|
54
54
|
this.getCardWord(decimal)
|
|
@@ -57,12 +57,12 @@ export class N2WordsZH extends BaseLanguage {
|
|
|
57
57
|
return decimalPartWordsArray.join(this.spaceSeparator);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
digit(
|
|
61
|
-
return
|
|
60
|
+
digit(number_) {
|
|
61
|
+
return number_.toString().length;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
zeroDigit(
|
|
65
|
-
return
|
|
64
|
+
zeroDigit(number_) {
|
|
65
|
+
return [...number_.toString()].filter(c => c == '0').length;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -70,9 +70,9 @@ export class N2WordsZH extends BaseLanguage {
|
|
|
70
70
|
* Converts a value to cardinal (written) form.
|
|
71
71
|
* @param {number|string|bigint} value Number to be convert.
|
|
72
72
|
* @param {object} [options] Options for class.
|
|
73
|
-
* @throws {Error} Value cannot be invalid.
|
|
74
73
|
* @returns {string} Value in cardinal (written) format.
|
|
74
|
+
* @throws {Error} Value cannot be invalid.
|
|
75
75
|
*/
|
|
76
|
-
export default function (value, options = {}) {
|
|
76
|
+
export default function floatToCardinal (value, options = {}) {
|
|
77
77
|
return new N2WordsZH(options).floatToCardinal(value);
|
|
78
78
|
}
|
package/lib/n2words.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
export default floatToCardinal;
|
|
1
2
|
/**
|
|
2
3
|
* Converts a number to written form.
|
|
3
4
|
* @param {number|string|bigint} value The number to convert.
|
|
4
5
|
* @param {object} [options] User options.
|
|
5
6
|
* @returns {string} Value in written format.
|
|
7
|
+
* TODO [2024-06] Migrate to object destructing for parameters
|
|
6
8
|
*/
|
|
7
|
-
|
|
9
|
+
declare function floatToCardinal(value: number | string | bigint, options?: object): string;
|
package/lib/n2words.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module n2words
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import n2wordsAR from './i18n/ar.js';
|
|
2
6
|
import n2wordsAZ from './i18n/az.js';
|
|
3
7
|
import n2wordsCZ from './i18n/cz.js';
|
|
@@ -20,6 +24,7 @@ import n2wordsNL from './i18n/nl.js';
|
|
|
20
24
|
import n2wordsNO from './i18n/no.js';
|
|
21
25
|
import n2wordsPL from './i18n/pl.js';
|
|
22
26
|
import n2wordsPT from './i18n/pt.js';
|
|
27
|
+
import n2wordsRO from './i18n/ro.js';
|
|
23
28
|
import n2wordsRU from './i18n/ru.js';
|
|
24
29
|
import n2wordsSR from './i18n/sr.js';
|
|
25
30
|
import n2wordsTR from './i18n/tr.js';
|
|
@@ -50,6 +55,7 @@ const dict = {
|
|
|
50
55
|
'no': n2wordsNO,
|
|
51
56
|
'pl': n2wordsPL,
|
|
52
57
|
'pt': n2wordsPT,
|
|
58
|
+
'ro': n2wordsRO,
|
|
53
59
|
'ru': n2wordsRU,
|
|
54
60
|
'sr': n2wordsSR,
|
|
55
61
|
'tr': n2wordsTR,
|
|
@@ -63,15 +69,19 @@ const dict = {
|
|
|
63
69
|
* @param {number|string|bigint} value The number to convert.
|
|
64
70
|
* @param {object} [options] User options.
|
|
65
71
|
* @returns {string} Value in written format.
|
|
72
|
+
* TODO [2024-06] Migrate to object destructing for parameters
|
|
66
73
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
// eslint-disable-next-line unicorn/no-object-as-default-parameter
|
|
75
|
+
function floatToCardinal(value, options = { lang: 'en' }) {
|
|
76
|
+
const function_ = dict[options.lang];
|
|
77
|
+
if (function_ != undefined) return function_(value, options);
|
|
70
78
|
|
|
71
79
|
const fallbackLang = options.lang.split('-') // 'en-UK' -> ['en', 'UK']
|
|
72
|
-
.map((_,
|
|
73
|
-
.find(l => dict[l] !=
|
|
74
|
-
if (fallbackLang !=
|
|
80
|
+
.map((_, index, array) => array.slice(0, array.length - index).join('-')) // ['en-UK', 'en']
|
|
81
|
+
.find(l => dict[l] != undefined);
|
|
82
|
+
if (fallbackLang != undefined) return dict[fallbackLang](value, options);
|
|
75
83
|
|
|
76
|
-
throw Error('Unsupported language: ' + value + '.');
|
|
84
|
+
throw new Error('Unsupported language: ' + value + '.');
|
|
77
85
|
}
|
|
86
|
+
|
|
87
|
+
export default floatToCardinal;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n2words",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "n2words converts a numerical number into a written one, supports
|
|
3
|
+
"version": "1.22.0",
|
|
4
|
+
"description": "n2words converts a numerical number into a written one, supports 28 languages and has zero dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"n2words",
|
|
7
7
|
"convert",
|
|
@@ -43,7 +43,10 @@
|
|
|
43
43
|
"bugs": {
|
|
44
44
|
"url": "https://github.com/forzagreen/n2words/issues"
|
|
45
45
|
},
|
|
46
|
-
"repository":
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/forzagreen/n2words.git"
|
|
49
|
+
},
|
|
47
50
|
"license": "MIT",
|
|
48
51
|
"author": "Wael TELLAT",
|
|
49
52
|
"contributors": [
|
|
@@ -59,15 +62,17 @@
|
|
|
59
62
|
"unpkg": "dist/n2words.js",
|
|
60
63
|
"files": [
|
|
61
64
|
"lib/*",
|
|
62
|
-
"dist/*"
|
|
63
|
-
"types/*"
|
|
65
|
+
"dist/*"
|
|
64
66
|
],
|
|
65
67
|
"scripts": {
|
|
66
68
|
"bench": "node bench.js",
|
|
67
|
-
"build": "webpack --
|
|
69
|
+
"build": "webpack --progress",
|
|
68
70
|
"build:types": "npx -p typescript tsc lib/n2words.js dist/n2words.js --target es6 --module nodenext --allowJs --declaration --emitDeclarationOnly",
|
|
69
71
|
"coverage": "c8 ava",
|
|
70
|
-
"
|
|
72
|
+
"docs": "jsdoc -c ./conf.json",
|
|
73
|
+
"lint": "npm run lint:js && npm run lint:md",
|
|
74
|
+
"lint:js": "eslint lib/ test/ examples/ *.js",
|
|
75
|
+
"lint:md": "markdownlint-cli2 *.md",
|
|
71
76
|
"test": "ava --verbose",
|
|
72
77
|
"test:cjs": "ava --verbose test/import.cjs",
|
|
73
78
|
"test:core": "ava --verbose test/core.js",
|
|
@@ -91,26 +96,30 @@
|
|
|
91
96
|
]
|
|
92
97
|
},
|
|
93
98
|
"devDependencies": {
|
|
94
|
-
"@babel/core": "^7.
|
|
95
|
-
"@babel/preset-env": "^7.
|
|
96
|
-
"
|
|
97
|
-
"
|
|
99
|
+
"@babel/core": "^7.28.0",
|
|
100
|
+
"@babel/preset-env": "^7.28.0",
|
|
101
|
+
"@eslint/js": "^9.32.0",
|
|
102
|
+
"@stylistic/eslint-plugin-js": "^2.13.0",
|
|
103
|
+
"ava": "^6.4.1",
|
|
104
|
+
"babel-loader": "^9.2.1",
|
|
98
105
|
"benchmark": "^2.1.4",
|
|
99
|
-
"c8": "^
|
|
100
|
-
"chalk": "^5.
|
|
101
|
-
"chromedriver": "^
|
|
102
|
-
"core-js": "^3.
|
|
103
|
-
"eslint": "^
|
|
104
|
-
"eslint-plugin-ava": "^
|
|
105
|
-
"eslint-plugin-
|
|
106
|
-
"eslint-plugin-
|
|
107
|
-
"eslint-plugin-
|
|
106
|
+
"c8": "^10.1.3",
|
|
107
|
+
"chalk": "^5.5.0",
|
|
108
|
+
"chromedriver": "^138.0.5",
|
|
109
|
+
"core-js": "^3.45.0",
|
|
110
|
+
"eslint": "^9.32.0",
|
|
111
|
+
"eslint-plugin-ava": "^15.1.0",
|
|
112
|
+
"eslint-plugin-jsdoc": "^52.0.3",
|
|
113
|
+
"eslint-plugin-n": "^17.21.3",
|
|
114
|
+
"eslint-plugin-unicorn": "^60.0.0",
|
|
115
|
+
"jsdoc": "^4.0.4",
|
|
116
|
+
"markdownlint-cli2": "^0.18.1",
|
|
108
117
|
"microtime": "^3.1.1",
|
|
109
|
-
"selenium-webdriver": "^4.
|
|
110
|
-
"webpack": "^5.
|
|
118
|
+
"selenium-webdriver": "^4.34.0",
|
|
119
|
+
"webpack": "^5.101.0",
|
|
111
120
|
"webpack-cli": "^5.1.4"
|
|
112
121
|
},
|
|
113
122
|
"engines": {
|
|
114
|
-
"node": "
|
|
123
|
+
"node": "^20 || ^22 || >=24"
|
|
115
124
|
}
|
|
116
125
|
}
|