n2words 1.10.1 → 1.12.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.
@@ -0,0 +1,117 @@
1
+ import {N2WordsRU} from './RU.mjs';
2
+
3
+ export class N2WordsHR extends N2WordsRU {
4
+ constructor() {
5
+ super();
6
+
7
+ this.negativeWord = 'minus';
8
+ this.separatorWord = 'zarez';
9
+ this.zero = 'nula';
10
+ this.ones = {
11
+ 1: ['jedan', 'jedna'],
12
+ 2: ['dva', 'dvije'],
13
+ 3: ['tri', 'tri'],
14
+ 4: ['četiri', 'četiri'],
15
+ 5: ['pet', 'pet'],
16
+ 6: ['šest', 'šest'],
17
+ 7: ['sedam', 'sedam'],
18
+ 8: ['osam', 'osam'],
19
+ 9: ['devet', 'devet']
20
+ };
21
+ this.tens = {
22
+ 0: 'deset',
23
+ 1: 'jedanaest',
24
+ 2: 'dvanaest',
25
+ 3: 'trinaest',
26
+ 4: 'četrnaest',
27
+ 5: 'petnaest',
28
+ 6: 'šesnaest',
29
+ 7: 'sedamnaest',
30
+ 8: 'osamnaest',
31
+ 9: 'devetnaest'
32
+ };
33
+ this.twenties = {
34
+ 2: 'dvadeset',
35
+ 3: 'trideset',
36
+ 4: 'četrdeset',
37
+ 5: 'pedeset',
38
+ 6: 'šezdeset',
39
+ 7: 'sedamdeset',
40
+ 8: 'osamdeset',
41
+ 9: 'devedeset'
42
+ };
43
+ this.hundreds = {
44
+ 1: 'sto',
45
+ 2: 'dvjesto',
46
+ 3: 'tristo',
47
+ 4: 'četiristo',
48
+ 5: 'petsto',
49
+ 6: 'šesto',
50
+ 7: 'sedamsto',
51
+ 8: 'osamsto',
52
+ 9: 'devetsto'
53
+ };
54
+ this.SCALE = {
55
+ 0: ['', '', '', false],
56
+ 1: ['tisuća', 'tisuće', 'tisuća', true], // 10 ^ 3
57
+ 2: ['milijun', 'milijuna', 'milijuna', false], // 10 ^ 6
58
+ 3: ['milijarda', 'milijarde', 'milijarda', false], // 10 ^ 9
59
+ 4: ['bilijun', 'bilijuna', 'bilijuna', false], // 10 ^ 12
60
+ 5: ['bilijarda', 'bilijarde', 'bilijarda', false], // 10 ^ 15
61
+ 6: ['trilijun', 'trilijuna', 'trilijuna', false], // 10 ^ 18
62
+ 7: ['trilijarda', 'trilijarde', 'trilijarda', false], // 10 ^ 21
63
+ 8: ['kvadrilijun', 'kvadrilijuna', 'kvadrilijuna', false], // 10 ^ 24
64
+ 9: ['kvadrilijarda', 'kvadrilijarde', 'kvadrilijarda', false], // 10 ^ 27
65
+ 10: ['kvintilijun', 'kvintilijuna', 'kvintilijuna', false], // 10 ^ 30
66
+ };
67
+ this.feminine = false;
68
+ }
69
+
70
+ pluralize(n, forms) {
71
+ let form = 2;
72
+ if ((n % 100 < 10) || (n % 100 > 20)) {
73
+ if (n % 10 == 1) {
74
+ form = 0;
75
+ } else if ((n % 10 > 1) && (n % 10 < 5)) {
76
+ form = 1;
77
+ }
78
+ }
79
+ return forms[form];
80
+ }
81
+
82
+ toCardinal(number) {
83
+ if (parseInt(number) == 0) {
84
+ return this.zero;
85
+ }
86
+ const words = [];
87
+ const chunks = this.splitByX(JSON.stringify(number), 3);
88
+ let i = chunks.length;
89
+ for (let j = 0; j < chunks.length; j++) {
90
+ const x = chunks[j];
91
+ i = i - 1;
92
+ // if (x == 0) { continue; }
93
+ const [n1, n2, n3] = this.getDigits(x);
94
+ if (n3 > 0) {
95
+ words.push(this.hundreds[n3]);
96
+ }
97
+ if (n2 > 1) {
98
+ words.push(this.twenties[n2]);
99
+ }
100
+ if (n2 == 1) {
101
+ words.push(this.tens[n1]);
102
+ } else if (n1 > 0) {
103
+ const isFeminine = (this.feminine || this.SCALE[i][3]);
104
+ const genderIdx = isFeminine ? 1 : 0;
105
+ words.push(this.ones[n1][genderIdx]);
106
+ }
107
+ if ((i > 0) && (x != 0)) {
108
+ words.push(this.pluralize(x, this.SCALE[i]));
109
+ }
110
+ }
111
+ return words.join(' ');
112
+ }
113
+ }
114
+
115
+ export default function(n) {
116
+ return new N2WordsHR().floatToCardinal(n);
117
+ }
package/lib/i18n/SR.mjs CHANGED
@@ -44,7 +44,7 @@ export class N2WordsSR extends N2WordsRU {
44
44
  1: 'sto',
45
45
  2: 'dvesta',
46
46
  3: 'trista',
47
- 4: 'četristo',
47
+ 4: 'četiristo',
48
48
  5: 'petsto',
49
49
  6: 'šesto',
50
50
  7: 'sedamsto',
@@ -55,14 +55,14 @@ export class N2WordsSR extends N2WordsRU {
55
55
  0: ['', '', '', false],
56
56
  1: ['hiljada', 'hiljade', 'hiljada', true], // 10 ^ 3
57
57
  2: ['milion', 'miliona', 'miliona', false], // 10 ^ 6
58
- 3: ['bilion', 'biliona', 'biliona', false], // 10 ^ 9
59
- 4: ['trilion', 'triliona', 'triliona', false], // 10 ^ 12
60
- 5: ['kvadrilion', 'kvadriliona', 'kvadriliona', false], // 10 ^ 15
61
- 6: ['kvintilion', 'kvintiliona', 'kvintiliona', false], // 10 ^ 18
62
- 7: ['sekstilion', 'sekstiliona', 'sekstiliona', false], // 10 ^ 21
63
- 8: ['septilion', 'septiliona', 'septiliona', false], // 10 ^ 24
64
- 9: ['oktilion', 'oktiliona', 'oktiliona', false], // 10 ^ 27
65
- 10: ['nonilion', 'noniliona', 'noniliona', false], // 10 ^ 30
58
+ 3: ['milijarda', 'milijarde', 'milijarda', false], // 10 ^ 9
59
+ 4: ['bilion', 'biliona', 'biliona', false], // 10 ^ 12
60
+ 5: ['bilijarda', 'bilijarde', 'bilijarda', false], // 10 ^ 15
61
+ 6: ['trilion', 'triliona', 'triliona', false], // 10 ^ 18
62
+ 7: ['trilijarda', 'trilijarde', 'trilijarda', false], // 10 ^ 21
63
+ 8: ['kvadrilion', 'kvadriliona', 'kvadriliona', false], // 10 ^ 24
64
+ 9: ['kvadrilijarda', 'kvadrilijarde', 'kvadrilijarda', false], // 10 ^ 27
65
+ 10: ['kvintilion', 'kvintiliona', 'kvintiliona', false], // 10 ^ 30
66
66
  };
67
67
  this.feminine = false;
68
68
  }
@@ -0,0 +1,145 @@
1
+ import N2WordsAbs from '../classes/N2WordsAbs.mjs';
2
+
3
+ export class N2WordsID extends N2WordsAbs {
4
+ constructor() {
5
+ super();
6
+
7
+ this.negativeWord = 'âm';
8
+ this.separatorWord = 'phẩy';
9
+ this.zero = 'không';
10
+ this.base = {
11
+ 0: 'không',
12
+ 1: 'một',
13
+ 2: 'hai',
14
+ 3: 'ba',
15
+ 4: 'bốn',
16
+ 5: 'năm',
17
+ 6: 'sáu',
18
+ 7: 'bảy',
19
+ 8: 'tám',
20
+ 9: 'chín',
21
+ 10: 'mười',
22
+ 11: 'mười một',
23
+ 12: 'mười hai',
24
+ 13: 'mười ba',
25
+ 14: 'mười bốn',
26
+ 15: 'mười lăm',
27
+ 16: 'mười sáu',
28
+ 17: 'mười bảy',
29
+ 18: 'mười tám',
30
+ 19: 'mười chín',
31
+ };
32
+ this.tens = {
33
+ 20: 'hai mươi',
34
+ 30: 'ba mươi',
35
+ 40: 'bốn mươi',
36
+ 50: 'năm mươi',
37
+ 60: 'sáu mươi',
38
+ 70: 'bảy mươi',
39
+ 80: 'tám mươi',
40
+ 90: 'chín mươi',
41
+ };
42
+ this.thousands = {
43
+ 1: 'nghìn', // 10^1
44
+ 2: 'triệu', // 10^2
45
+ 3: 'tỷ', // 10^3
46
+ 4: 'nghìn tỷ',
47
+ 5: 'trăm nghìn tỷ',
48
+ 6: 'Quintillion',
49
+ 7: 'Sextillion',
50
+ 8: 'Septillion',
51
+ 9: 'Octillion',
52
+ 10: 'Nonillion',
53
+ 11: 'Decillion',
54
+ 12: 'Undecillion',
55
+ 13: 'Duodecillion',
56
+ 14: 'Tredecillion',
57
+ 15: 'Quattuordecillion',
58
+ 16: 'Sexdecillion',
59
+ 17: 'Septendecillion',
60
+ 18: 'Octodecillion',
61
+ 19: 'Novemdecillion',
62
+ 20: 'Vigintillion',
63
+ };
64
+ }
65
+
66
+ convertLess100(number) {
67
+ let unitsPart = number % 10;
68
+ let tensPart = number - unitsPart;
69
+ let tensPartText = this.tens[tensPart];
70
+ if (unitsPart === 0) {
71
+ return tensPartText;
72
+ }
73
+ let unitsPartText = this.base[unitsPart];
74
+ let suffix = unitsPartText;
75
+ if (unitsPart === 1) {
76
+ suffix = 'mốt';
77
+ }
78
+ if (unitsPart === 5) {
79
+ suffix = 'lăm';
80
+ }
81
+ return tensPartText + ' ' + suffix;
82
+ }
83
+
84
+ convertLess1000(number) {
85
+ let words = [];
86
+ let tensUnitsPart = number % 100;
87
+ let hundredsPart = number - tensUnitsPart;
88
+ if (hundredsPart > 0) {
89
+ words.push(this.base[hundredsPart / 100], 'trăm');
90
+ }
91
+ if (0 < tensUnitsPart && tensUnitsPart < 10) {
92
+ if (words.length > 0) {
93
+ words.push('lẻ');
94
+ }
95
+ if (tensUnitsPart === 5) {
96
+ words.push('năm');
97
+ } else {
98
+ words.push(this.base[tensUnitsPart]);
99
+ }
100
+ }
101
+ if (tensUnitsPart >= 10) {
102
+ words.push(this.toCardinal(tensUnitsPart));
103
+ }
104
+ return words.join(' ');
105
+ }
106
+
107
+ convertMore1000(number) {
108
+ let words = [];
109
+ let division = Math.floor(number / 1000);
110
+ let power = 1;
111
+ while (division >= 1000) {
112
+ division = Math.floor(division / 1000);
113
+ power = power + 1;
114
+ }
115
+ let r = number - (division * Math.pow(1000, power));
116
+ words.push(this.toCardinal(division), this.thousands[power]);
117
+ if (r > 0) {
118
+ if (r <= 99) {
119
+ words.push('lẻ');
120
+ }
121
+ words.push(this.toCardinal(r));
122
+ }
123
+ return words.join(' ');
124
+ }
125
+
126
+ toCardinal(number) {
127
+ if (number < 20) {
128
+ return this.base[number];
129
+ } else {
130
+ if (number < 100) {
131
+ return this.convertLess100(number);
132
+ } else {
133
+ if (number < 1000) {
134
+ return this.convertLess1000(number);
135
+ } else { // number >= 1000
136
+ return this.convertMore1000(number);
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+
143
+ export default function (n) {
144
+ return new N2WordsID().floatToCardinal(n);
145
+ }
package/lib/n2words.mjs CHANGED
@@ -8,6 +8,7 @@ import n2wordsES from './i18n/ES.mjs';
8
8
  import n2wordsFA from './i18n/FA.mjs';
9
9
  import n2wordsFR from './i18n/FR.mjs';
10
10
  import n2wordsHE from './i18n/HE.mjs';
11
+ import n2wordsHR from './i18n/HR.mjs';
11
12
  import n2wordsHU from './i18n/HU.mjs';
12
13
  import n2wordsID from './i18n/ID.mjs';
13
14
  import n2wordsIT from './i18n/IT.mjs';
@@ -22,6 +23,7 @@ import n2wordsRU from './i18n/RU.mjs';
22
23
  import n2wordsSR from './i18n/SR.mjs';
23
24
  import n2wordsTR from './i18n/TR.mjs';
24
25
  import n2wordsUK from './i18n/UK.mjs';
26
+ import n2wordsVI from './i18n/VI.mjs';
25
27
  import n2wordsZH from './i18n/ZH.mjs';
26
28
 
27
29
  const supportedLanguages = [
@@ -49,6 +51,8 @@ const supportedLanguages = [
49
51
  'zh',
50
52
  'hu',
51
53
  'id',
54
+ 'hr',
55
+ 'vi',
52
56
  ];
53
57
 
54
58
  /**
@@ -111,6 +115,8 @@ export default function(n, options = {lang: 'en'}) {
111
115
  } else if (lang === 'HE') {
112
116
  // only for numbers <= 9999
113
117
  return n2wordsHE(n);
118
+ } else if (lang === 'HR') {
119
+ return n2wordsHR(n);
114
120
  } else if (lang === 'HU') {
115
121
  return n2wordsHU(n);
116
122
  } else if (lang === 'KO') {
@@ -123,5 +129,7 @@ export default function(n, options = {lang: 'en'}) {
123
129
  return n2wordsFA(n);
124
130
  } else if (lang === 'ZH') {
125
131
  return n2wordsZH(n);
132
+ } else if (lang === 'VI') {
133
+ return n2wordsVI(n);
126
134
  }
127
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n2words",
3
- "version": "1.10.1",
3
+ "version": "1.12.0",
4
4
  "description": "Convert numbers to words, in multiple languages",
5
5
  "main": "dist/n2words.js",
6
6
  "scripts": {
@@ -45,7 +45,9 @@
45
45
  "persian",
46
46
  "chinese",
47
47
  "hungarian",
48
- "indonesian"
48
+ "indonesian",
49
+ "croatian",
50
+ "vietnamese"
49
51
  ],
50
52
  "author": "Wael TELLAT",
51
53
  "license": "MIT",
@@ -54,19 +56,19 @@
54
56
  },
55
57
  "homepage": "https://github.com/forzagreen/n2words#readme",
56
58
  "devDependencies": {
57
- "@babel/core": "^7.16.0",
58
- "@babel/preset-env": "^7.16.0",
59
- "ava": "^3.15.0",
60
- "babel-loader": "^8.2.3",
61
- "c8": "^7.10.0",
62
- "core-js": "^3.19.0",
63
- "eslint": "^8.1.0",
64
- "eslint-plugin-ava": "^13.1.0",
65
- "eslint-plugin-import": "^2.25.2",
66
- "eslint-plugin-jsdoc": "^37.0.3",
59
+ "@babel/core": "^7.18.5",
60
+ "@babel/preset-env": "^7.18.2",
61
+ "ava": "^4.3.3",
62
+ "babel-loader": "^8.2.5",
63
+ "c8": "^7.11.3",
64
+ "core-js": "^3.23.2",
65
+ "eslint": "^8.18.0",
66
+ "eslint-plugin-ava": "^13.2.0",
67
+ "eslint-plugin-import": "^2.26.0",
68
+ "eslint-plugin-jsdoc": "^39.3.3",
67
69
  "eslint-plugin-node": "^11.1.0",
68
- "webpack": "^5.61.0",
69
- "webpack-cli": "^4.9.1"
70
+ "webpack": "^5.73.0",
71
+ "webpack-cli": "^4.10.0"
70
72
  },
71
73
  "ava": {
72
74
  "files": [
package/webpack.config.js CHANGED
@@ -12,9 +12,6 @@ module.exports = {
12
12
  rules: [{
13
13
  test: /\.m?js$/,
14
14
  exclude: /node_modules/,
15
- resolve: {
16
- fullySpecified: false,
17
- },
18
15
  use: {
19
16
  loader: 'babel-loader',
20
17
  options: {
@@ -23,7 +20,7 @@ module.exports = {
23
20
  '@babel/preset-env',
24
21
  {
25
22
  useBuiltIns: 'usage',
26
- corejs: '3.16',
23
+ corejs: '3.23.2',
27
24
  },
28
25
  ],
29
26
  ],