n2words 1.16.2 → 1.16.4

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 (62) hide show
  1. package/dist/n2words.d.ts +3 -0
  2. package/dist/n2words.js +2 -1
  3. package/dist/n2words.js.map +1 -0
  4. package/lib/classes/AbstractLanguage.d.ts +53 -0
  5. package/lib/classes/BaseLanguage.d.ts +59 -0
  6. package/lib/i18n/ar.d.ts +27 -0
  7. package/lib/i18n/ar.js +29 -14
  8. package/lib/i18n/az.d.ts +15 -0
  9. package/lib/i18n/az.js +5 -4
  10. package/lib/i18n/cz.d.ts +12 -0
  11. package/lib/i18n/cz.js +3 -3
  12. package/lib/i18n/de.d.ts +17 -0
  13. package/lib/i18n/de.js +4 -4
  14. package/lib/i18n/dk.d.ts +14 -0
  15. package/lib/i18n/dk.js +4 -4
  16. package/lib/i18n/en.d.ts +22 -0
  17. package/lib/i18n/en.js +2 -2
  18. package/lib/i18n/es.d.ts +16 -0
  19. package/lib/i18n/es.js +6 -6
  20. package/lib/i18n/fa.d.ts +54 -0
  21. package/lib/i18n/fa.js +2 -2
  22. package/lib/i18n/fr.d.ts +15 -0
  23. package/lib/i18n/fr.js +7 -7
  24. package/lib/i18n/he.d.ts +28 -0
  25. package/lib/i18n/he.js +3 -3
  26. package/lib/i18n/hr.d.ts +35 -0
  27. package/lib/i18n/hr.js +3 -3
  28. package/lib/i18n/hu.d.ts +17 -0
  29. package/lib/i18n/hu.js +2 -2
  30. package/lib/i18n/id.d.ts +43 -0
  31. package/lib/i18n/id.js +8 -8
  32. package/lib/i18n/it.d.ts +29 -0
  33. package/lib/i18n/it.js +25 -15
  34. package/lib/i18n/ko.d.ts +15 -0
  35. package/lib/i18n/ko.js +4 -4
  36. package/lib/i18n/lt.d.ts +12 -0
  37. package/lib/i18n/lt.js +3 -3
  38. package/lib/i18n/lv.d.ts +12 -0
  39. package/lib/i18n/lv.js +4 -4
  40. package/lib/i18n/nl.d.ts +20 -0
  41. package/lib/i18n/nl.js +6 -6
  42. package/lib/i18n/no.d.ts +15 -0
  43. package/lib/i18n/no.js +4 -4
  44. package/lib/i18n/pl.d.ts +11 -0
  45. package/lib/i18n/pl.js +3 -3
  46. package/lib/i18n/pt.d.ts +26 -0
  47. package/lib/i18n/pt.js +2 -2
  48. package/lib/i18n/ru.d.ts +84 -0
  49. package/lib/i18n/ru.js +2 -2
  50. package/lib/i18n/sr.d.ts +35 -0
  51. package/lib/i18n/sr.js +3 -3
  52. package/lib/i18n/tr.d.ts +15 -0
  53. package/lib/i18n/tr.js +4 -4
  54. package/lib/i18n/uk.d.ts +11 -0
  55. package/lib/i18n/uk.js +3 -3
  56. package/lib/i18n/vi.d.ts +70 -0
  57. package/lib/i18n/vi.js +2 -2
  58. package/lib/i18n/zh.d.ts +18 -0
  59. package/lib/i18n/zh.js +4 -4
  60. package/lib/n2words.d.ts +7 -0
  61. package/lib/n2words.js +1 -1
  62. package/package.json +15 -7
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Converts a value to cardinal (written) form.
3
+ * @param {number|string} value Number to be convert.
4
+ * @param {object} [options] Options for class.
5
+ * @throws {Error} Value cannot be invalid.
6
+ * @returns {string} Value in cardinal (written) format.
7
+ */
8
+ export default function _default(value: number | string, options?: object): string;
9
+ export class N2WordsRU extends AbstractLanguage {
10
+ constructor(options: any);
11
+ feminine: any;
12
+ ones: {
13
+ 1: string;
14
+ 2: string;
15
+ 3: string;
16
+ 4: string;
17
+ 5: string;
18
+ 6: string;
19
+ 7: string;
20
+ 8: string;
21
+ 9: string;
22
+ };
23
+ onesFeminine: {
24
+ 1: string;
25
+ 2: string;
26
+ 3: string;
27
+ 4: string;
28
+ 5: string;
29
+ 6: string;
30
+ 7: string;
31
+ 8: string;
32
+ 9: string;
33
+ };
34
+ tens: {
35
+ 0: string;
36
+ 1: string;
37
+ 2: string;
38
+ 3: string;
39
+ 4: string;
40
+ 5: string;
41
+ 6: string;
42
+ 7: string;
43
+ 8: string;
44
+ 9: string;
45
+ };
46
+ twenties: {
47
+ 2: string;
48
+ 3: string;
49
+ 4: string;
50
+ 5: string;
51
+ 6: string;
52
+ 7: string;
53
+ 8: string;
54
+ 9: string;
55
+ };
56
+ hundreds: {
57
+ 1: string;
58
+ 2: string;
59
+ 3: string;
60
+ 4: string;
61
+ 5: string;
62
+ 6: string;
63
+ 7: string;
64
+ 8: string;
65
+ 9: string;
66
+ };
67
+ thousands: {
68
+ 1: string[];
69
+ 2: string[];
70
+ 3: string[];
71
+ 4: string[];
72
+ 5: string[];
73
+ 6: string[];
74
+ 7: string[];
75
+ 8: string[];
76
+ 9: string[];
77
+ 10: string[];
78
+ };
79
+ toCardinal(number: any): string;
80
+ splitByX(n: any, x: any, formatInt?: boolean): any[];
81
+ getDigits(value: any): bigint[];
82
+ pluralize(n: any, forms: any): any;
83
+ }
84
+ import AbstractLanguage from '../classes/AbstractLanguage.js';
package/lib/i18n/ru.js CHANGED
@@ -194,10 +194,10 @@ export class N2WordsRU extends AbstractLanguage {
194
194
  /**
195
195
  * Converts a value to cardinal (written) form.
196
196
  * @param {number|string} value Number to be convert.
197
- * @param {object} options Options for class.
197
+ * @param {object} [options] Options for class.
198
198
  * @throws {Error} Value cannot be invalid.
199
199
  * @returns {string} Value in cardinal (written) format.
200
200
  */
201
- export default function(value, options) {
201
+ export default function (value, options = {}) {
202
202
  return new N2WordsRU(options).floatToCardinal(value);
203
203
  }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Converts a value to cardinal (written) form.
3
+ * @param {number|string} value Number to be convert.
4
+ * @param {object} [options] Options for class.
5
+ * @throws {Error} Value cannot be invalid.
6
+ * @returns {string} Value in cardinal (written) format.
7
+ */
8
+ export default function _default(value: number | string, options?: object): string;
9
+ export class N2WordsSR extends N2WordsRU {
10
+ ones: {
11
+ 1: string[];
12
+ 2: string[];
13
+ 3: string[];
14
+ 4: string[];
15
+ 5: string[];
16
+ 6: string[];
17
+ 7: string[];
18
+ 8: string[];
19
+ 9: string[];
20
+ };
21
+ SCALE: {
22
+ 0: (string | boolean)[];
23
+ 1: (string | boolean)[];
24
+ 2: (string | boolean)[];
25
+ 3: (string | boolean)[];
26
+ 4: (string | boolean)[];
27
+ 5: (string | boolean)[];
28
+ 6: (string | boolean)[];
29
+ 7: (string | boolean)[];
30
+ 8: (string | boolean)[];
31
+ 9: (string | boolean)[];
32
+ 10: (string | boolean)[];
33
+ };
34
+ }
35
+ import { N2WordsRU } from './ru.js';
package/lib/i18n/sr.js CHANGED
@@ -1,4 +1,4 @@
1
- import {N2WordsRU} from './ru.js';
1
+ import { N2WordsRU } from './ru.js';
2
2
 
3
3
  export class N2WordsSR extends N2WordsRU {
4
4
  ones = {
@@ -119,10 +119,10 @@ export class N2WordsSR extends N2WordsRU {
119
119
  /**
120
120
  * Converts a value to cardinal (written) form.
121
121
  * @param {number|string} value Number to be convert.
122
- * @param {object} options Options for class.
122
+ * @param {object} [options] Options for class.
123
123
  * @throws {Error} Value cannot be invalid.
124
124
  * @returns {string} Value in cardinal (written) format.
125
125
  */
126
- export default function(value, options) {
126
+ export default function (value, options = {}) {
127
127
  return new N2WordsSR(options).floatToCardinal(value);
128
128
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Converts a value to cardinal (written) form.
3
+ * @param {number|string} value Number to be convert.
4
+ * @param {object} [options] Options for class.
5
+ * @throws {Error} Value cannot be invalid.
6
+ * @returns {string} Value in cardinal (written) format.
7
+ */
8
+ export default function _default(value: number | string, options?: object): string;
9
+ export class N2WordsTR extends BaseLanguage {
10
+ constructor(options?: {});
11
+ merge(lPair: any, rPair: any): {
12
+ [x: string]: bigint;
13
+ };
14
+ }
15
+ import BaseLanguage from '../classes/BaseLanguage.js';
package/lib/i18n/tr.js CHANGED
@@ -40,8 +40,8 @@ export class N2WordsTR extends BaseLanguage {
40
40
  merge(lPair, rPair) {
41
41
  const lText = Object.keys(lPair)[0];
42
42
  const rText = Object.keys(rPair)[0];
43
- const lNum = parseInt(Object.values(lPair)[0]);
44
- const rNum = parseInt(Object.values(rPair)[0]);
43
+ const lNum = BigInt(Object.values(lPair)[0]);
44
+ const rNum = BigInt(Object.values(rPair)[0]);
45
45
  if (lNum == 1 && (rNum <= 100 || rNum == 1000)) {
46
46
  return { [rText]: rNum };
47
47
  } else if (rNum > lNum) {
@@ -55,10 +55,10 @@ export class N2WordsTR extends BaseLanguage {
55
55
  /**
56
56
  * Converts a value to cardinal (written) form.
57
57
  * @param {number|string} value Number to be convert.
58
- * @param {object} options Options for class.
58
+ * @param {object} [options] Options for class.
59
59
  * @throws {Error} Value cannot be invalid.
60
60
  * @returns {string} Value in cardinal (written) format.
61
61
  */
62
- export default function(value, options) {
62
+ export default function (value, options = {}) {
63
63
  return new N2WordsTR(options).floatToCardinal(value);
64
64
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Converts a value to cardinal (written) form.
3
+ * @param {number|string} value Number to be convert.
4
+ * @param {object} [options] Options for class.
5
+ * @throws {Error} Value cannot be invalid.
6
+ * @returns {string} Value in cardinal (written) format.
7
+ */
8
+ export default function _default(value: number | string, options?: object): string;
9
+ export class N2WordsUK extends N2WordsRU {
10
+ }
11
+ import { N2WordsRU } from './ru.js';
package/lib/i18n/uk.js CHANGED
@@ -1,4 +1,4 @@
1
- import {N2WordsRU} from './ru.js';
1
+ import { N2WordsRU } from './ru.js';
2
2
 
3
3
  export class N2WordsUK extends N2WordsRU {
4
4
  ones = {
@@ -86,10 +86,10 @@ export class N2WordsUK extends N2WordsRU {
86
86
  /**
87
87
  * Converts a value to cardinal (written) form.
88
88
  * @param {number|string} value Number to be convert.
89
- * @param {object} options Options for class.
89
+ * @param {object} [options] Options for class.
90
90
  * @throws {Error} Value cannot be invalid.
91
91
  * @returns {string} Value in cardinal (written) format.
92
92
  */
93
- export default function(value, options) {
93
+ export default function (value, options = {}) {
94
94
  return new N2WordsUK(options).floatToCardinal(value);
95
95
  }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Converts a value to cardinal (written) form.
3
+ * @param {number|string} value Number to be convert.
4
+ * @param {object} [options] Options for class.
5
+ * @throws {Error} Value cannot be invalid.
6
+ * @returns {string} Value in cardinal (written) format.
7
+ */
8
+ export default function _default(value: number | string, options?: object): string;
9
+ export class N2WordsID extends AbstractLanguage {
10
+ constructor(options: any);
11
+ base: {
12
+ 0: string;
13
+ 1: string;
14
+ 2: string;
15
+ 3: string;
16
+ 4: string;
17
+ 5: string;
18
+ 6: string;
19
+ 7: string;
20
+ 8: string;
21
+ 9: string;
22
+ 10: string;
23
+ 11: string;
24
+ 12: string;
25
+ 13: string;
26
+ 14: string;
27
+ 15: string;
28
+ 16: string;
29
+ 17: string;
30
+ 18: string;
31
+ 19: string;
32
+ };
33
+ tens: {
34
+ 20: string;
35
+ 30: string;
36
+ 40: string;
37
+ 50: string;
38
+ 60: string;
39
+ 70: string;
40
+ 80: string;
41
+ 90: string;
42
+ };
43
+ thousands: {
44
+ 1: string;
45
+ 2: string;
46
+ 3: string;
47
+ 4: string;
48
+ 5: string;
49
+ 6: string;
50
+ 7: string;
51
+ 8: string;
52
+ 9: string;
53
+ 10: string;
54
+ 11: string;
55
+ 12: string;
56
+ 13: string;
57
+ 14: string;
58
+ 15: string;
59
+ 16: string;
60
+ 17: string;
61
+ 18: string;
62
+ 19: string;
63
+ 20: string;
64
+ };
65
+ convertLess100(number: any): any;
66
+ convertLess1000(number: any): any;
67
+ convertMore1000(number: any): any;
68
+ toCardinal(number: any): any;
69
+ }
70
+ import AbstractLanguage from '../classes/AbstractLanguage.js';
package/lib/i18n/vi.js CHANGED
@@ -146,10 +146,10 @@ export class N2WordsID extends AbstractLanguage {
146
146
  /**
147
147
  * Converts a value to cardinal (written) form.
148
148
  * @param {number|string} value Number to be convert.
149
- * @param {object} options Options for class.
149
+ * @param {object} [options] Options for class.
150
150
  * @throws {Error} Value cannot be invalid.
151
151
  * @returns {string} Value in cardinal (written) format.
152
152
  */
153
- export default function (value, options) {
153
+ export default function (value, options = {}) {
154
154
  return new N2WordsID(options).floatToCardinal(value);
155
155
  }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Converts a value to cardinal (written) form.
3
+ * @param {number|string} value Number to be convert.
4
+ * @param {object} [options] Options for class.
5
+ * @throws {Error} Value cannot be invalid.
6
+ * @returns {string} Value in cardinal (written) format.
7
+ */
8
+ export default function _default(value: number | string, options?: object): string;
9
+ export class N2WordsZH extends BaseLanguage {
10
+ constructor(options: any);
11
+ merge(lPair: any, rPair: any): {
12
+ [x: string]: bigint;
13
+ };
14
+ decimalToCardinal(decimal: any): any;
15
+ digit(num: any): any;
16
+ zeroDigit(num: any): number;
17
+ }
18
+ import BaseLanguage from '../classes/BaseLanguage.js';
package/lib/i18n/zh.js CHANGED
@@ -30,9 +30,9 @@ export class N2WordsZH extends BaseLanguage {
30
30
  merge(lPair, rPair) {
31
31
  // {'one':1}, {'hundred':100}
32
32
  const ltext = Object.keys(lPair)[0];
33
- const lnum = parseInt(Object.values(lPair)[0]);
33
+ const lnum = BigInt(Object.values(lPair)[0]);
34
34
  const rtext = Object.keys(rPair)[0];
35
- const rnum = parseInt(Object.values(rPair)[0]);
35
+ const rnum = BigInt(Object.values(rPair)[0]);
36
36
 
37
37
  let result = { [`${ltext}${rtext}`]: lnum + rnum };
38
38
 
@@ -69,10 +69,10 @@ export class N2WordsZH extends BaseLanguage {
69
69
  /**
70
70
  * Converts a value to cardinal (written) form.
71
71
  * @param {number|string} value Number to be convert.
72
- * @param {object} options Options for class.
72
+ * @param {object} [options] Options for class.
73
73
  * @throws {Error} Value cannot be invalid.
74
74
  * @returns {string} Value in cardinal (written) format.
75
75
  */
76
- export default function(value, options) {
76
+ export default function (value, options = {}) {
77
77
  return new N2WordsZH(options).floatToCardinal(value);
78
78
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Converts a number to written form.
3
+ * @param {number|string} value The number to convert.
4
+ * @param {object} [options] User options.
5
+ * @returns {string} Value in written format.
6
+ */
7
+ export default function _default(value: number | string, options?: object): string;
package/lib/n2words.js CHANGED
@@ -32,7 +32,7 @@ import n2wordsZH from './i18n/zh.js';
32
32
  * @param {object} [options] User options.
33
33
  * @returns {string} Value in written format.
34
34
  */
35
- export default function(value, options = {lang: 'en'}) {
35
+ export default function (value, options = { lang: 'en' }) {
36
36
  switch (options.lang) {
37
37
  case 'en': return n2wordsEN(value, options); // default
38
38
  case 'ar': return n2wordsAR(value, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n2words",
3
- "version": "1.16.2",
3
+ "version": "1.16.4",
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",
@@ -59,19 +59,25 @@
59
59
  "unpkg": "dist/n2words.js",
60
60
  "files": [
61
61
  "lib/*",
62
- "dist/*"
62
+ "dist/*",
63
+ "types/*"
63
64
  ],
64
65
  "scripts": {
65
66
  "bench": "node bench.js",
66
67
  "build": "webpack --config webpack.config.js --progress",
68
+ "build:types": "npx -p typescript tsc lib/n2words.js dist/n2words.js --target esnext --module nodenext --declaration --allowJs --emitDeclarationOnly",
67
69
  "coverage": "c8 ava",
68
70
  "lint": "eslint --config .eslintrc.json lib/ test/ bench.js",
69
- "test": "ava --verbose"
71
+ "test": "ava --verbose",
72
+ "test:cjs": "ava --verbose test/import.cjs",
73
+ "test:core": "ava --verbose test/core.js",
74
+ "test:i18n": "ava --verbose test/i18n.js",
75
+ "test:web": "ava --verbose test/web.js"
70
76
  },
71
77
  "ava": {
72
78
  "files": [
73
- "test/**/*",
74
- "!test/i18n"
79
+ "test/*",
80
+ "!test/web.js"
75
81
  ]
76
82
  },
77
83
  "c8": {
@@ -91,14 +97,16 @@
91
97
  "babel-loader": "^9.1.2",
92
98
  "benchmark": "^2.1.4",
93
99
  "c8": "^7.14.0",
100
+ "chromedriver": "^114.0.1",
94
101
  "core-js": "^3.30.2",
95
102
  "eslint": "^8.42.0",
96
103
  "eslint-plugin-ava": "^14.0.0",
97
104
  "eslint-plugin-import": "^2.27.5",
98
- "eslint-plugin-jsdoc": "^46.2.3",
105
+ "eslint-plugin-jsdoc": "^46.2.5",
99
106
  "eslint-plugin-node": "^11.1.0",
100
107
  "microtime": "^3.1.1",
101
- "webpack": "^5.85.0",
108
+ "selenium-webdriver": "^4.9.2",
109
+ "webpack": "^5.85.1",
102
110
  "webpack-cli": "^5.1.3"
103
111
  },
104
112
  "engines": {