numbers_de.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.NUMBERS = void 0;
  4. const messages_js_1 = require("../messages.js");
  5. function onePrefix_(num, mill = false) {
  6. return num === exports.NUMBERS.ones[1] ? (mill ? 'eine' : 'ein') : num;
  7. }
  8. function hundredsToWords_(num) {
  9. let n = num % 1000;
  10. let str = '';
  11. let ones = exports.NUMBERS.ones[Math.floor(n / 100)];
  12. str += ones ? onePrefix_(ones) + 'hundert' : '';
  13. n = n % 100;
  14. if (n) {
  15. str += str ? exports.NUMBERS.numSep : '';
  16. ones = exports.NUMBERS.ones[n];
  17. if (ones) {
  18. str += ones;
  19. }
  20. else {
  21. const tens = exports.NUMBERS.tens[Math.floor(n / 10)];
  22. ones = exports.NUMBERS.ones[n % 10];
  23. str += ones ? onePrefix_(ones) + 'und' + tens : tens;
  24. }
  25. }
  26. return str;
  27. }
  28. function numberToWords(num) {
  29. if (num === 0) {
  30. return exports.NUMBERS.zero;
  31. }
  32. if (num >= Math.pow(10, 36)) {
  33. return num.toString();
  34. }
  35. let pos = 0;
  36. let str = '';
  37. while (num > 0) {
  38. const hundreds = num % 1000;
  39. if (hundreds) {
  40. const hund = hundredsToWords_(num % 1000);
  41. if (pos) {
  42. const large = exports.NUMBERS.large[pos];
  43. const plural = pos > 1 && hundreds > 1 ? (large.match(/e$/) ? 'n' : 'en') : '';
  44. str = onePrefix_(hund, pos > 1) + large + plural + str;
  45. }
  46. else {
  47. str = onePrefix_(hund, pos > 1) + str;
  48. }
  49. }
  50. num = Math.floor(num / 1000);
  51. pos++;
  52. }
  53. return str.replace(/ein$/, 'eins');
  54. }
  55. function numberToOrdinal(num, plural) {
  56. if (num === 1) {
  57. return 'eintel';
  58. }
  59. if (num === 2) {
  60. return plural ? 'halbe' : 'halb';
  61. }
  62. return wordOrdinal(num) + 'l';
  63. }
  64. function wordOrdinal(num) {
  65. if (num === 1) {
  66. return 'erste';
  67. }
  68. if (num === 3) {
  69. return 'dritte';
  70. }
  71. if (num === 7) {
  72. return 'siebte';
  73. }
  74. if (num === 8) {
  75. return 'achte';
  76. }
  77. const ordinal = numberToWords(num);
  78. return ordinal + (num < 19 ? 'te' : 'ste');
  79. }
  80. function numericOrdinal(num) {
  81. return num.toString() + '.';
  82. }
  83. exports.NUMBERS = (0, messages_js_1.NUMBERS)({
  84. wordOrdinal: wordOrdinal,
  85. numericOrdinal: numericOrdinal,
  86. numberToWords: numberToWords,
  87. numberToOrdinal: numberToOrdinal
  88. });