numbers_nn.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.NUMBERS = void 0;
  4. const engine_js_1 = require("../../common/engine.js");
  5. const messages_js_1 = require("../messages.js");
  6. function hundredsToWordsRo_(num, ordinal = false) {
  7. let n = num % 1000;
  8. let str = '';
  9. const count = Math.floor(n / 100);
  10. const ones = exports.NUMBERS.ones[count];
  11. str += ones ? (count === 1 ? '' : ones) + 'hundre' : '';
  12. n = n % 100;
  13. if (n) {
  14. str += str ? 'og' : '';
  15. if (ordinal) {
  16. const ord = exports.NUMBERS.special.smallOrdinals[n];
  17. if (ord) {
  18. return str + ord;
  19. }
  20. if (n % 10) {
  21. return (str +
  22. exports.NUMBERS.tens[Math.floor(n / 10)] +
  23. exports.NUMBERS.special.smallOrdinals[n % 10]);
  24. }
  25. }
  26. str +=
  27. exports.NUMBERS.ones[n] ||
  28. exports.NUMBERS.tens[Math.floor(n / 10)] + (n % 10 ? exports.NUMBERS.ones[n % 10] : '');
  29. }
  30. return ordinal ? replaceOrdinal(str) : str;
  31. }
  32. function numberToWordsRo(num, ordinal = false) {
  33. if (num === 0) {
  34. return ordinal ? exports.NUMBERS.special.smallOrdinals[0] : exports.NUMBERS.zero;
  35. }
  36. if (num >= Math.pow(10, 36)) {
  37. return num.toString();
  38. }
  39. let pos = 0;
  40. let str = '';
  41. while (num > 0) {
  42. const hundreds = num % 1000;
  43. if (hundreds) {
  44. const hund = hundredsToWordsRo_(num % 1000, pos ? false : ordinal);
  45. if (!pos && ordinal) {
  46. ordinal = !ordinal;
  47. }
  48. str =
  49. hund +
  50. (pos
  51. ? ' ' +
  52. (exports.NUMBERS.large[pos] + (pos > 1 && hundreds > 1 ? 'er' : '')) +
  53. (str ? ' ' : '')
  54. : '') +
  55. str;
  56. }
  57. num = Math.floor(num / 1000);
  58. pos++;
  59. }
  60. return ordinal ? str + (str.match(/tusen$/) ? 'de' : 'te') : str;
  61. }
  62. function numberToOrdinal(num, _plural) {
  63. return wordOrdinal(num);
  64. }
  65. function replaceOrdinal(str) {
  66. const letOne = exports.NUMBERS.special.endOrdinal[0];
  67. if (letOne === 'a' && str.match(/en$/)) {
  68. return str.slice(0, -2) + exports.NUMBERS.special.endOrdinal;
  69. }
  70. if (str.match(/(d|n)$/) || str.match(/hundre$/)) {
  71. return str + 'de';
  72. }
  73. if (str.match(/i$/)) {
  74. return str + exports.NUMBERS.special.endOrdinal;
  75. }
  76. if (letOne === 'a' && str.match(/e$/)) {
  77. return str.slice(0, -1) + exports.NUMBERS.special.endOrdinal;
  78. }
  79. if (str.match(/e$/)) {
  80. return str + 'nde';
  81. }
  82. return str + 'nde';
  83. }
  84. function wordOrdinal(num) {
  85. const ordinal = numberToWords(num, true);
  86. return ordinal;
  87. }
  88. function numericOrdinal(num) {
  89. return num.toString() + '.';
  90. }
  91. exports.NUMBERS = (0, messages_js_1.NUMBERS)({
  92. wordOrdinal: wordOrdinal,
  93. numericOrdinal: numericOrdinal,
  94. numberToWords: numberToWords,
  95. numberToOrdinal: numberToOrdinal
  96. });
  97. function onePrefix_(num, thd = false) {
  98. const numOne = exports.NUMBERS.ones[1];
  99. return num === numOne ? (num === 'ein' ? 'eitt ' : thd ? 'et' : 'ett') : num;
  100. }
  101. function hundredsToWordsGe_(num, ordinal = false) {
  102. let n = num % 1000;
  103. let str = '';
  104. let ones = exports.NUMBERS.ones[Math.floor(n / 100)];
  105. str += ones ? onePrefix_(ones) + 'hundre' : '';
  106. n = n % 100;
  107. if (n) {
  108. str += str ? 'og' : '';
  109. if (ordinal) {
  110. const ord = exports.NUMBERS.special.smallOrdinals[n];
  111. if (ord) {
  112. return (str += ord);
  113. }
  114. }
  115. ones = exports.NUMBERS.ones[n];
  116. if (ones) {
  117. str += ones;
  118. }
  119. else {
  120. const tens = exports.NUMBERS.tens[Math.floor(n / 10)];
  121. ones = exports.NUMBERS.ones[n % 10];
  122. str += ones ? ones + 'og' + tens : tens;
  123. }
  124. }
  125. return ordinal ? replaceOrdinal(str) : str;
  126. }
  127. function numberToWordsGe(num, ordinal = false) {
  128. if (num === 0) {
  129. return ordinal ? exports.NUMBERS.special.smallOrdinals[0] : exports.NUMBERS.zero;
  130. }
  131. if (num >= Math.pow(10, 36)) {
  132. return num.toString();
  133. }
  134. let pos = 0;
  135. let str = '';
  136. while (num > 0) {
  137. const hundreds = num % 1000;
  138. if (hundreds) {
  139. const hund = hundredsToWordsGe_(num % 1000, pos ? false : ordinal);
  140. if (!pos && ordinal) {
  141. ordinal = !ordinal;
  142. }
  143. str =
  144. (pos === 1 ? onePrefix_(hund, true) : hund) +
  145. (pos > 1 ? exports.NUMBERS.numSep : '') +
  146. (pos
  147. ?
  148. exports.NUMBERS.large[pos] + (pos > 1 && hundreds > 1 ? 'er' : '')
  149. : '') +
  150. (pos > 1 && str ? exports.NUMBERS.numSep : '') +
  151. str;
  152. }
  153. num = Math.floor(num / 1000);
  154. pos++;
  155. }
  156. return ordinal ? str + (str.match(/tusen$/) ? 'de' : 'te') : str;
  157. }
  158. function numberToWords(num, ordinal = false) {
  159. const word = engine_js_1.Engine.getInstance().subiso === 'alt'
  160. ? numberToWordsGe(num, ordinal)
  161. : numberToWordsRo(num, ordinal);
  162. return word;
  163. }