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.
Files changed (127) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/ar.js +2 -0
  4. package/dist/ar.js.map +1 -0
  5. package/dist/az.js +2 -0
  6. package/dist/az.js.map +1 -0
  7. package/dist/cz.js +2 -0
  8. package/dist/cz.js.map +1 -0
  9. package/dist/de.js +2 -0
  10. package/dist/de.js.map +1 -0
  11. package/dist/dk.js +2 -0
  12. package/dist/dk.js.map +1 -0
  13. package/dist/en.js +2 -0
  14. package/dist/en.js.map +1 -0
  15. package/dist/es.js +2 -0
  16. package/dist/es.js.map +1 -0
  17. package/dist/fa.js +2 -0
  18. package/dist/fa.js.map +1 -0
  19. package/dist/fr-BE.js +2 -0
  20. package/dist/fr-BE.js.map +1 -0
  21. package/dist/fr.js +2 -0
  22. package/dist/fr.js.map +1 -0
  23. package/dist/he.js +2 -0
  24. package/dist/he.js.map +1 -0
  25. package/dist/hr.js +2 -0
  26. package/dist/hr.js.map +1 -0
  27. package/dist/hu.js +2 -0
  28. package/dist/hu.js.map +1 -0
  29. package/dist/id.js +2 -0
  30. package/dist/id.js.map +1 -0
  31. package/dist/it.js +2 -0
  32. package/dist/it.js.map +1 -0
  33. package/dist/ko.js +2 -0
  34. package/dist/ko.js.map +1 -0
  35. package/dist/lt.js +2 -0
  36. package/dist/lt.js.map +1 -0
  37. package/dist/lv.js +2 -0
  38. package/dist/lv.js.map +1 -0
  39. package/dist/n2words.js +1 -1
  40. package/dist/n2words.js.map +1 -1
  41. package/dist/nl.js +2 -0
  42. package/dist/nl.js.map +1 -0
  43. package/dist/no.js +2 -0
  44. package/dist/no.js.map +1 -0
  45. package/dist/pl.js +2 -0
  46. package/dist/pl.js.map +1 -0
  47. package/dist/pt.js +2 -0
  48. package/dist/pt.js.map +1 -0
  49. package/dist/ro.js +2 -0
  50. package/dist/ro.js.map +1 -0
  51. package/dist/ru.js +2 -0
  52. package/dist/ru.js.map +1 -0
  53. package/dist/sr.js +2 -0
  54. package/dist/sr.js.map +1 -0
  55. package/dist/tr.js +2 -0
  56. package/dist/tr.js.map +1 -0
  57. package/dist/uk.js +2 -0
  58. package/dist/uk.js.map +1 -0
  59. package/dist/vi.js +2 -0
  60. package/dist/vi.js.map +1 -0
  61. package/dist/zh.js +2 -0
  62. package/dist/zh.js.map +1 -0
  63. package/lib/classes/{AbstractLanguage.d.ts → abstract-language.d.ts} +4 -3
  64. package/lib/classes/{AbstractLanguage.js → abstract-language.js} +14 -12
  65. package/lib/classes/{BaseLanguage.d.ts → base-language.d.ts} +6 -10
  66. package/lib/classes/{BaseLanguage.js → base-language.js} +23 -28
  67. package/lib/i18n/ar.d.ts +6 -6
  68. package/lib/i18n/ar.js +37 -45
  69. package/lib/i18n/az.d.ts +3 -3
  70. package/lib/i18n/az.js +15 -15
  71. package/lib/i18n/cz.d.ts +2 -2
  72. package/lib/i18n/cz.js +8 -9
  73. package/lib/i18n/de.d.ts +4 -4
  74. package/lib/i18n/de.js +33 -37
  75. package/lib/i18n/dk.d.ts +4 -4
  76. package/lib/i18n/dk.js +32 -32
  77. package/lib/i18n/en.d.ts +3 -3
  78. package/lib/i18n/en.js +18 -18
  79. package/lib/i18n/es.d.ts +4 -4
  80. package/lib/i18n/es.js +24 -24
  81. package/lib/i18n/fa.d.ts +3 -3
  82. package/lib/i18n/fa.js +9 -9
  83. package/lib/i18n/fr-BE.d.ts +2 -2
  84. package/lib/i18n/fr-BE.js +2 -2
  85. package/lib/i18n/fr.d.ts +4 -4
  86. package/lib/i18n/fr.js +29 -29
  87. package/lib/i18n/he.d.ts +2 -2
  88. package/lib/i18n/he.js +9 -12
  89. package/lib/i18n/hr.d.ts +2 -2
  90. package/lib/i18n/hr.js +10 -11
  91. package/lib/i18n/hu.d.ts +3 -3
  92. package/lib/i18n/hu.js +14 -14
  93. package/lib/i18n/id.d.ts +4 -4
  94. package/lib/i18n/id.js +25 -35
  95. package/lib/i18n/it.d.ts +3 -3
  96. package/lib/i18n/it.js +18 -38
  97. package/lib/i18n/ko.d.ts +3 -3
  98. package/lib/i18n/ko.js +16 -16
  99. package/lib/i18n/lt.d.ts +2 -2
  100. package/lib/i18n/lt.js +8 -9
  101. package/lib/i18n/lv.d.ts +2 -2
  102. package/lib/i18n/lv.js +10 -16
  103. package/lib/i18n/nl.d.ts +4 -4
  104. package/lib/i18n/nl.js +34 -34
  105. package/lib/i18n/no.d.ts +3 -3
  106. package/lib/i18n/no.js +20 -20
  107. package/lib/i18n/pl.d.ts +2 -2
  108. package/lib/i18n/pl.js +8 -9
  109. package/lib/i18n/pt.d.ts +4 -4
  110. package/lib/i18n/pt.js +25 -25
  111. package/lib/i18n/ro.d.ts +109 -0
  112. package/lib/i18n/ro.js +360 -0
  113. package/lib/i18n/ru.d.ts +4 -4
  114. package/lib/i18n/ru.js +15 -14
  115. package/lib/i18n/sr.d.ts +2 -2
  116. package/lib/i18n/sr.js +10 -11
  117. package/lib/i18n/tr.d.ts +3 -3
  118. package/lib/i18n/tr.js +15 -15
  119. package/lib/i18n/uk.d.ts +2 -2
  120. package/lib/i18n/uk.js +2 -2
  121. package/lib/i18n/vi.d.ts +3 -3
  122. package/lib/i18n/vi.js +4 -8
  123. package/lib/i18n/zh.d.ts +6 -6
  124. package/lib/i18n/zh.js +11 -11
  125. package/lib/n2words.d.ts +3 -1
  126. package/lib/n2words.js +17 -7
  127. 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 _default(value: number | string | bigint, options?: object): string;
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): any;
15
- digit(num: any): any;
16
- zeroDigit(num: any): number;
14
+ decimalToCardinal(decimal: any): string;
15
+ digit(number_: any): any;
16
+ zeroDigit(number_: any): number;
17
17
  }
18
- import BaseLanguage from '../classes/BaseLanguage.js';
18
+ import BaseLanguage from '../classes/base-language.js';
package/lib/i18n/zh.js CHANGED
@@ -1,4 +1,4 @@
1
- import BaseLanguage from '../classes/BaseLanguage.js';
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
- [1000000000000n, '万'],
12
- [100000000n, '亿'],
13
- [10000n, '万'],
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.split('');
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(num) {
61
- return num.toString().length;
60
+ digit(number_) {
61
+ return number_.toString().length;
62
62
  }
63
63
 
64
- zeroDigit(num) {
65
- return Array.from(num.toString()).filter(c => c == '0').length;
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
- export default function _default(value: number | string | bigint, options?: object): string;
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
- export default function (value, options = { lang: 'en' }) {
68
- const fn = dict[options.lang];
69
- if (fn != null) return fn(value, options);
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((_, 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);
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.20.0",
4
- "description": "n2words converts a numerical number into a written one, supports 27 languages and has zero dependencies.",
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": "github:forzagreen/n2words",
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 --config webpack.config.js --progress",
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
- "lint": "eslint --config .eslintrc.json lib/ test/ examples/ bench.js",
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.23.9",
95
- "@babel/preset-env": "^7.23.9",
96
- "ava": "^6.1.1",
97
- "babel-loader": "^9.1.3",
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": "^9.1.0",
100
- "chalk": "^5.3.0",
101
- "chromedriver": "^121.0.2",
102
- "core-js": "^3.36.0",
103
- "eslint": "^8.56.0",
104
- "eslint-plugin-ava": "^14.0.0",
105
- "eslint-plugin-import": "^2.29.1",
106
- "eslint-plugin-jsdoc": "^48.1.0",
107
- "eslint-plugin-node": "^11.1.0",
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.17.0",
110
- "webpack": "^5.90.2",
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": "18 || >=20"
123
+ "node": "^20 || ^22 || >=24"
115
124
  }
116
125
  }