numbers_da.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 ? 'et' : 'en') : num;
  7. }
  8. function hundredsToWords_(num, ordinal = false) {
  9. let n = num % 1000;
  10. let str = '';
  11. let ones = exports.NUMBERS.ones[Math.floor(n / 100)];
  12. str += ones ? onePrefix_(ones, true) + ' hundrede' : '';
  13. n = n % 100;
  14. if (n) {
  15. str += str ? ' og ' : '';
  16. ones = ordinal ? exports.NUMBERS.special.smallOrdinals[n] : exports.NUMBERS.ones[n];
  17. if (ones) {
  18. str += ones;
  19. }
  20. else {
  21. const tens = ordinal
  22. ? exports.NUMBERS.special.tensOrdinals[Math.floor(n / 10)]
  23. : exports.NUMBERS.tens[Math.floor(n / 10)];
  24. ones = exports.NUMBERS.ones[n % 10];
  25. str += ones ? onePrefix_(ones) + 'og' + tens : tens;
  26. }
  27. }
  28. return str;
  29. }
  30. function numberToWords(num, ordinal = false) {
  31. if (num === 0) {
  32. return exports.NUMBERS.zero;
  33. }
  34. if (num >= Math.pow(10, 36)) {
  35. return num.toString();
  36. }
  37. let pos = 0;
  38. let str = '';
  39. while (num > 0) {
  40. const hundreds = num % 1000;
  41. if (hundreds) {
  42. const hund = hundredsToWords_(hundreds, ordinal && !pos);
  43. if (pos) {
  44. const large = exports.NUMBERS.large[pos];
  45. const plural = hundreds > 1 ? 'er' : '';
  46. str =
  47. onePrefix_(hund, pos <= 1) +
  48. ' ' +
  49. large +
  50. plural +
  51. (str ? ' og ' : '') +
  52. str;
  53. }
  54. else {
  55. str = onePrefix_(hund) + str;
  56. }
  57. }
  58. num = Math.floor(num / 1000);
  59. pos++;
  60. }
  61. return str;
  62. }
  63. function numberToOrdinal(num, plural) {
  64. if (num === 1) {
  65. return plural ? 'hel' : 'hele';
  66. }
  67. if (num === 2) {
  68. return plural ? 'halv' : 'halve';
  69. }
  70. return wordOrdinal(num) + (plural ? 'dele' : 'del');
  71. }
  72. function wordOrdinal(num) {
  73. if (num % 100) {
  74. return numberToWords(num, true);
  75. }
  76. const ordinal = numberToWords(num);
  77. return ordinal.match(/e$/) ? ordinal : ordinal + 'e';
  78. }
  79. function numericOrdinal(num) {
  80. return num.toString() + '.';
  81. }
  82. exports.NUMBERS = (0, messages_js_1.NUMBERS)({
  83. wordOrdinal: wordOrdinal,
  84. numericOrdinal: numericOrdinal,
  85. numberToWords: numberToWords,
  86. numberToOrdinal: numberToOrdinal
  87. });