n2words 1.9.0 → 1.11.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/lib/i18n/FA.mjs CHANGED
@@ -1,54 +1,56 @@
1
1
  import N2WordsAbs from '../classes/N2WordsAbs.mjs';
2
2
 
3
- export default function () {
4
- N2WordsAbs.call(this)
3
+ export class N2WordsFA extends N2WordsAbs {
4
+ constructor() {
5
+ super();
5
6
 
6
- this.negative_word = 'منفى';
7
- this.separator_word = 'ممیّز';
8
- this.ZERO = 'صفر';
9
- this.namedNumbers = {
10
- 0: 'صفر',
11
- 1: 'یک',
12
- 2: 'دو',
13
- 3: 'سه',
14
- 4: 'چهار',
15
- 5: 'پنج',
16
- 6: 'شش',
17
- 7: 'هفت',
18
- 8: 'هشت',
19
- 9: 'نه',
20
- 10: 'ده',
21
- 11: 'یازده',
22
- 12: 'دوازده',
23
- 13: 'سیزده',
24
- 14: 'چهارده',
25
- 15: 'پانزده',
26
- 16: 'شانزده',
27
- 17: 'هفده',
28
- 18: 'هجده',
29
- 19: 'نوزده',
30
- 20: 'بیست',
31
- 30: 'سی',
32
- 40: 'چهل',
33
- 50: 'پنجاه',
34
- 60: 'شصت',
35
- 70: 'هفتاد',
36
- 80: 'هشتاد',
37
- 90: 'نود',
38
- 100: 'صد',
39
- 200: 'دویست',
40
- 300: 'سيصد',
41
- 400: 'چهار صد',
42
- 500: 'پانصد',
43
- 600: 'ششصد',
44
- 700: 'هفتصد',
45
- 800: 'هشتصد',
46
- 900: 'نهصد',
47
- 1000: 'هزار',
48
- 1000000: 'میلیون',
49
- };
7
+ this.negativeWord = 'منفى';
8
+ this.separatorWord = 'ممیّز';
9
+ this.zero = 'صفر';
10
+ this.namedNumbers = {
11
+ 0: 'صفر',
12
+ 1: 'یک',
13
+ 2: 'دو',
14
+ 3: 'سه',
15
+ 4: 'چهار',
16
+ 5: 'پنج',
17
+ 6: 'شش',
18
+ 7: 'هفت',
19
+ 8: 'هشت',
20
+ 9: 'نه',
21
+ 10: 'ده',
22
+ 11: 'یازده',
23
+ 12: 'دوازده',
24
+ 13: 'سیزده',
25
+ 14: 'چهارده',
26
+ 15: 'پانزده',
27
+ 16: 'شانزده',
28
+ 17: 'هفده',
29
+ 18: 'هجده',
30
+ 19: 'نوزده',
31
+ 20: 'بیست',
32
+ 30: 'سی',
33
+ 40: 'چهل',
34
+ 50: 'پنجاه',
35
+ 60: 'شصت',
36
+ 70: 'هفتاد',
37
+ 80: 'هشتاد',
38
+ 90: 'نود',
39
+ 100: 'صد',
40
+ 200: 'دویست',
41
+ 300: 'سيصد',
42
+ 400: 'چهار صد',
43
+ 500: 'پانصد',
44
+ 600: 'ششصد',
45
+ 700: 'هفتصد',
46
+ 800: 'هشتصد',
47
+ 900: 'نهصد',
48
+ 1000: 'هزار',
49
+ 1000000: 'میلیون',
50
+ };
51
+ }
50
52
 
51
- this.toCardinal = (number) => {
53
+ toCardinal(number) {
52
54
  if (this.namedNumbers[number]) {
53
55
  return this.namedNumbers[number];
54
56
  }
@@ -63,25 +65,28 @@ export default function () {
63
65
  return `${this.namedNumbers[xhundred]} و ${tail}`;
64
66
  }
65
67
  if (number > 1000 && number < 1000000) {
66
- let thousand_multiplier = parseInt(number / 1000);
67
- let named_thousand_multiplier =
68
- (thousand_multiplier === 1
68
+ let thousandMultiplier = parseInt(number / 1000);
69
+ let namedThousandMultiplier =
70
+ (thousandMultiplier === 1
69
71
  ? ''
70
- : this.toCardinal(thousand_multiplier)) +
72
+ : this.toCardinal(thousandMultiplier)) +
71
73
  ' ' +
72
74
  this.namedNumbers[1000];
73
- let tail_number = number - thousand_multiplier * 1000;
74
- let tail = tail_number === 0 ? '' : ' ' + this.toCardinal(tail_number);
75
- return `${named_thousand_multiplier}${tail}`;
75
+ let tailNumber = number - thousandMultiplier * 1000;
76
+ let tail = tailNumber === 0 ? '' : ' ' + this.toCardinal(tailNumber);
77
+ return `${namedThousandMultiplier}${tail}`;
76
78
  }
77
79
  if (number > 1000000) {
78
- let million_multiplier = parseInt(number / 1000000);
79
- let named_million =
80
- this.toCardinal(million_multiplier) + ' ' + this.namedNumbers[1000000];
81
- let tail_number = number - million_multiplier * 1000000;
82
- let tail = tail_number === 0 ? '' : ' و ' + this.toCardinal(tail_number);
83
- return `${named_million}${tail}`;
80
+ let millionMultiplier = parseInt(number / 1000000);
81
+ let namedMillion =
82
+ this.toCardinal(millionMultiplier) + ' ' + this.namedNumbers[1000000];
83
+ let tailNumber = number - millionMultiplier * 1000000;
84
+ let tail = tailNumber === 0 ? '' : ' و ' + this.toCardinal(tailNumber);
85
+ return `${namedMillion}${tail}`;
84
86
  }
85
- };
86
- return this.toCardinal();
87
+ }
88
+ }
89
+
90
+ export default function(n) {
91
+ return new N2WordsFA().floatToCardinal(n);
87
92
  }
package/lib/i18n/FR.mjs CHANGED
@@ -1,77 +1,86 @@
1
1
  import N2WordsBase from '../classes/N2WordsBase.mjs';
2
2
 
3
- export default function () {
4
- N2WordsBase.call(this);
3
+ export class N2WordsFR extends N2WordsBase {
4
+ constructor() {
5
+ super();
5
6
 
6
- this.negative_word = 'moins';
7
- this.separator_word = 'virgule';
8
- this.ZERO = 'zéro';
9
- this.cards = [
10
- { '1000000000000000000000000000': 'quadrilliard' },
11
- { '1000000000000000000000000': 'quadrillion' },
12
- { '1000000000000000000000': 'trilliard' },
13
- { '1000000000000000000': 'trillion' },
14
- { '1000000000000000': 'billiard' },
15
- { '1000000000000': 'billion' },
16
- { '1000000000': 'milliard' },
17
- { '1000000': 'million' },
18
- { '1000': 'mille' },
19
- { '100': 'cent' },
20
- { '80': 'quatre-vingts' },
21
- { '60': 'soixante' },
22
- { '50': 'cinquante' },
23
- { '40': 'quarante' },
24
- { '30': 'trente' },
25
- { '20': 'vingt' },
26
- { '19': 'dix-neuf' },
27
- { '18': 'dix-huit' },
28
- { '17': 'dix-sept' },
29
- { '16': 'seize' },
30
- { '15': 'quinze' },
31
- { '14': 'quatorze' },
32
- { '13': 'treize' },
33
- { '12': 'douze' },
34
- { '11': 'onze' },
35
- { '10': 'dix' },
36
- { '9': 'neuf' },
37
- { '8': 'huit' },
38
- { '7': 'sept' },
39
- { '6': 'six' },
40
- { '5': 'cinq' },
41
- { '4': 'quatre' },
42
- { '3': 'trois' },
43
- { '2': 'deux' },
44
- { '1': 'un' },
45
- { '0': 'zéro' }
46
- ];
47
- this.merge = (curr, next) => { // {'cent':100}, {'vingt-cinq':25}
48
- let ctext = Object.keys(curr)[0]; const cnum = parseInt(Object.values(curr)[0]);
49
- let ntext = Object.keys(next)[0]; const nnum = parseInt(Object.values(next)[0]);
50
- if (cnum == 1) {
51
- if (nnum < 1000000) {
52
- return { [ntext]: nnum };
7
+ this.negativeWord = 'moins';
8
+ this.separatorWord = 'virgule';
9
+ this.zero = 'zéro';
10
+ this.cards = [
11
+ { '1000000000000000000000000000': 'quadrilliard' },
12
+ { '1000000000000000000000000': 'quadrillion' },
13
+ { '1000000000000000000000': 'trilliard' },
14
+ { '1000000000000000000': 'trillion' },
15
+ { '1000000000000000': 'billiard' },
16
+ { '1000000000000': 'billion' },
17
+ { '1000000000': 'milliard' },
18
+ { '1000000': 'million' },
19
+ { '1000': 'mille' },
20
+ { '100': 'cent' },
21
+ { '80': 'quatre-vingts' },
22
+ { '60': 'soixante' },
23
+ { '50': 'cinquante' },
24
+ { '40': 'quarante' },
25
+ { '30': 'trente' },
26
+ { '20': 'vingt' },
27
+ { '19': 'dix-neuf' },
28
+ { '18': 'dix-huit' },
29
+ { '17': 'dix-sept' },
30
+ { '16': 'seize' },
31
+ { '15': 'quinze' },
32
+ { '14': 'quatorze' },
33
+ { '13': 'treize' },
34
+ { '12': 'douze' },
35
+ { '11': 'onze' },
36
+ { '10': 'dix' },
37
+ { '9': 'neuf' },
38
+ { '8': 'huit' },
39
+ { '7': 'sept' },
40
+ { '6': 'six' },
41
+ { '5': 'cinq' },
42
+ { '4': 'quatre' },
43
+ { '3': 'trois' },
44
+ { '2': 'deux' },
45
+ { '1': 'un' },
46
+ { '0': 'zéro' }
47
+ ];
48
+ }
49
+
50
+ merge(curr, next) { // {'cent':100}, {'vingt-cinq':25}
51
+ let cText = Object.keys(curr)[0];
52
+ let nText = Object.keys(next)[0];
53
+ const cNum = parseInt(Object.values(curr)[0]);
54
+ const nNum = parseInt(Object.values(next)[0]);
55
+ if (cNum == 1) {
56
+ if (nNum < 1000000) {
57
+ return { [nText]: nNum };
53
58
  }
54
59
  } else {
55
60
  if (
56
- ((cnum - 80) % 100 == 0 || (cnum % 100 == 0 && cnum < 1000)) &&
57
- nnum < 1000000 &&
58
- ctext[ctext.length - 1] == 's'
61
+ ((cNum - 80) % 100 == 0 || (cNum % 100 == 0 && cNum < 1000)) &&
62
+ nNum < 1000000 &&
63
+ cText[cText.length - 1] == 's'
59
64
  ) {
60
- ctext = ctext.slice(0, -1); // without last elem
65
+ cText = cText.slice(0, -1); // without last elem
61
66
  }
62
67
  if (
63
- cnum < 1000 && nnum != 1000 &&
64
- ntext[ntext.length - 1] != 's' &&
65
- nnum % 100 == 0
68
+ cNum < 1000 && nNum != 1000 &&
69
+ nText[nText.length - 1] != 's' &&
70
+ nNum % 100 == 0
66
71
  ) {
67
- ntext += 's';
72
+ nText += 's';
68
73
  }
69
74
  }
70
- if (nnum < cnum && cnum < 100) {
71
- if (nnum % 10 == 1 && cnum != 80) return { [`${ctext} et ${ntext}`]: cnum + nnum };
72
- return { [`${ctext}-${ntext}`]: cnum + nnum };
75
+ if (nNum < cNum && cNum < 100) {
76
+ if (nNum % 10 == 1 && cNum != 80) return { [`${cText} et ${nText}`]: cNum + nNum };
77
+ return { [`${cText}-${nText}`]: cNum + nNum };
73
78
  }
74
- if (nnum > cnum) return { [`${ctext} ${ntext}`]: cnum * nnum };
75
- return { [`${ctext} ${ntext}`]: cnum + nnum };
76
- };
79
+ if (nNum > cNum) return { [`${cText} ${nText}`]: cNum * nNum };
80
+ return { [`${cText} ${nText}`]: cNum + nNum };
81
+ }
82
+ }
83
+
84
+ export default function(n) {
85
+ return new N2WordsFR().floatToCardinal(n);
77
86
  }
package/lib/i18n/HE.mjs CHANGED
@@ -1,31 +1,34 @@
1
- import Num2Word_RU from './RU.mjs';
1
+ import {N2WordsRU} from './RU.mjs';
2
2
 
3
- export default function () {
4
- Num2Word_RU.call(this);
3
+ export class N2WordsHE extends N2WordsRU {
4
+ constructor() {
5
+ super();
5
6
 
6
- this.negative_word = 'מינוס'; //TODO: needs confirmation
7
- this.separator_word; //TODO
8
- this.ZERO = 'אפס';
9
- this.AND = 'ו';
10
- this.ONES = { 1: 'אחת', 2: 'שתים', 3: 'שלש', 4: 'ארבע', 5: 'חמש', 6: 'שש', 7: 'שבע', 8: 'שמונה', 9: 'תשע' };
11
- this.TENS = {
12
- 0: 'עשר', 1: 'אחת עשרה', 2: 'שתים עשרה', 3: 'שלש עשרה', 4: 'ארבע עשרה',
13
- 5: 'חמש עשרה', 6: 'שש עשרה', 7: 'שבע עשרה', 8: 'שמונה עשרה', 9: 'תשע עשרה'
14
- };
15
- this.TWENTIES = {
16
- 2: 'עשרים', 3: 'שלשים', 4: 'ארבעים', 5: 'חמישים', 6: 'ששים', 7: 'שבעים', 8: 'שמונים', 9: 'תשעים'
17
- };
18
- this.HUNDREDS = { 1: 'מאה', 2: 'מאתיים', 3: 'מאות' };
19
- this.THOUSANDS = {
20
- 1: 'אלף', 2: 'אלפיים', 3: 'שלשת אלפים', 4: 'ארבעת אלפים',
21
- 5: 'חמשת אלפים', 6: 'ששת אלפים', 7: 'שבעת אלפים', 8: 'שמונת אלפים', 9: 'תשעת אלפים'
22
- };
23
- this.toCardinal = (number) => {
7
+ this.negativeWord = 'מינוס'; //TODO: Needs confirmation
8
+ this.separatorWord; //TODO
9
+ this.zero = 'אפס';
10
+ this.and = 'ו';
11
+ this.ones = { 1: 'אחת', 2: 'שתים', 3: 'שלש', 4: 'ארבע', 5: 'חמש', 6: 'שש', 7: 'שבע', 8: 'שמונה', 9: 'תשע' };
12
+ this.tens = {
13
+ 0: 'עשר', 1: 'אחת עשרה', 2: 'שתים עשרה', 3: 'שלש עשרה', 4: 'ארבע עשרה',
14
+ 5: 'חמש עשרה', 6: 'שש עשרה', 7: 'שבע עשרה', 8: 'שמונה עשרה', 9: 'תשע עשרה'
15
+ };
16
+ this.twenties = {
17
+ 2: 'עשרים', 3: 'שלשים', 4: 'ארבעים', 5: 'חמישים', 6: 'ששים', 7: 'שבעים', 8: 'שמונים', 9: 'תשעים'
18
+ };
19
+ this.hundreds = { 1: 'מאה', 2: 'מאתיים', 3: 'מאות' };
20
+ this.thousands = {
21
+ 1: 'אלף', 2: 'אלפיים', 3: 'שלשת אלפים', 4: 'ארבעת אלפים',
22
+ 5: 'חמשת אלפים', 6: 'ששת אלפים', 7: 'שבעת אלפים', 8: 'שמונת אלפים', 9: 'תשעת אלפים'
23
+ };
24
+ }
25
+
26
+ toCardinal(number) {
24
27
  if (parseInt(number) == 0) {
25
- return this.ZERO;
28
+ return this.zero;
26
29
  }
27
30
  const words = [];
28
- const chunks = this.splitbyx(JSON.stringify(number), 3);
31
+ const chunks = this.splitByX(JSON.stringify(number), 3);
29
32
  let i = chunks.length;
30
33
  for (let j = 0; j < chunks.length; j++) {
31
34
  const x = chunks[j];
@@ -33,33 +36,37 @@ export default function () {
33
36
  if (x == 0) {
34
37
  continue;
35
38
  }
36
- const [n1, n2, n3] = this.get_digits(x);
39
+ const [n1, n2, n3] = this.getDigits(x);
37
40
  if (i > 0) {
38
- words.push(this.THOUSANDS[n1]);
41
+ words.push(this.thousands[n1]);
39
42
  continue;
40
43
  }
41
44
  if (n3 > 0) {
42
45
  if (n3 <= 2) {
43
- words.push(this.HUNDREDS[n3]);
46
+ words.push(this.hundreds[n3]);
44
47
  } else {
45
- words.push(this.ONES[n3] + ' ' + this.HUNDREDS[3]);
48
+ words.push(this.ones[n3] + ' ' + this.hundreds[3]);
46
49
  }
47
50
  }
48
51
  if (n2 > 1) {
49
- words.push(this.TWENTIES[n2]);
52
+ words.push(this.twenties[n2]);
50
53
  }
51
54
  if (n2 == 1) {
52
- words.push(this.TENS[n1]);
55
+ words.push(this.tens[n1]);
53
56
  } else if (n1 > 0 && !(i > 0 && x == 1)) {
54
- words.push(this.ONES[n1]);
57
+ words.push(this.ones[n1]);
55
58
  }
56
59
  if (i > 0) {
57
- words.push(this.THOUSANDS[i]);
60
+ words.push(this.thousands[i]);
58
61
  }
59
62
  }
60
63
  if (words.length > 1) {
61
- words[words.length - 1] = this.AND + words[words.length - 1];
64
+ words[words.length - 1] = this.and + words[words.length - 1];
62
65
  }
63
66
  return words.join(' ');
64
- };
67
+ }
68
+ }
69
+
70
+ export default function(n) {
71
+ return new N2WordsHE().floatToCardinal(n);
65
72
  }
@@ -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
+ }