n2words 1.11.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,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
@@ -23,6 +23,7 @@ import n2wordsRU from './i18n/RU.mjs';
23
23
  import n2wordsSR from './i18n/SR.mjs';
24
24
  import n2wordsTR from './i18n/TR.mjs';
25
25
  import n2wordsUK from './i18n/UK.mjs';
26
+ import n2wordsVI from './i18n/VI.mjs';
26
27
  import n2wordsZH from './i18n/ZH.mjs';
27
28
 
28
29
  const supportedLanguages = [
@@ -51,6 +52,7 @@ const supportedLanguages = [
51
52
  'hu',
52
53
  'id',
53
54
  'hr',
55
+ 'vi',
54
56
  ];
55
57
 
56
58
  /**
@@ -127,5 +129,7 @@ export default function(n, options = {lang: 'en'}) {
127
129
  return n2wordsFA(n);
128
130
  } else if (lang === 'ZH') {
129
131
  return n2wordsZH(n);
132
+ } else if (lang === 'VI') {
133
+ return n2wordsVI(n);
130
134
  }
131
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n2words",
3
- "version": "1.11.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": {
@@ -46,7 +46,8 @@
46
46
  "chinese",
47
47
  "hungarian",
48
48
  "indonesian",
49
- "croatian"
49
+ "croatian",
50
+ "vietnamese"
50
51
  ],
51
52
  "author": "Wael TELLAT",
52
53
  "license": "MIT",
@@ -55,19 +56,19 @@
55
56
  },
56
57
  "homepage": "https://github.com/forzagreen/n2words#readme",
57
58
  "devDependencies": {
58
- "@babel/core": "^7.17.7",
59
- "@babel/preset-env": "^7.16.11",
60
- "ava": "^4.1.0",
61
- "babel-loader": "^8.2.3",
62
- "c8": "^7.11.0",
63
- "core-js": "^3.21.1",
64
- "eslint": "^8.11.0",
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",
65
66
  "eslint-plugin-ava": "^13.2.0",
66
- "eslint-plugin-import": "^2.25.4",
67
- "eslint-plugin-jsdoc": "^38.0.4",
67
+ "eslint-plugin-import": "^2.26.0",
68
+ "eslint-plugin-jsdoc": "^39.3.3",
68
69
  "eslint-plugin-node": "^11.1.0",
69
- "webpack": "^5.70.0",
70
- "webpack-cli": "^4.9.2"
70
+ "webpack": "^5.73.0",
71
+ "webpack-cli": "^4.10.0"
71
72
  },
72
73
  "ava": {
73
74
  "files": [
package/webpack.config.js CHANGED
@@ -20,7 +20,7 @@ module.exports = {
20
20
  '@babel/preset-env',
21
21
  {
22
22
  useBuiltIns: 'usage',
23
- corejs: '3.21.1',
23
+ corejs: '3.23.2',
24
24
  },
25
25
  ],
26
26
  ],