numbers_af.js 2.3 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 hundredsToWords_(num) {
  6. let n = num % 1000;
  7. let str = '';
  8. let ones = exports.NUMBERS.ones[Math.floor(n / 100)];
  9. str += ones ? ones + exports.NUMBERS.numSep + 'honderd' : '';
  10. n = n % 100;
  11. if (n) {
  12. str += str ? exports.NUMBERS.numSep : '';
  13. ones = exports.NUMBERS.ones[n];
  14. if (ones) {
  15. str += ones;
  16. }
  17. else {
  18. const tens = exports.NUMBERS.tens[Math.floor(n / 10)];
  19. ones = exports.NUMBERS.ones[n % 10];
  20. str += ones ? ones + '-en-' + tens : tens;
  21. }
  22. }
  23. return str;
  24. }
  25. function numberToWords(num) {
  26. if (num === 0) {
  27. return exports.NUMBERS.zero;
  28. }
  29. if (num >= Math.pow(10, 36)) {
  30. return num.toString();
  31. }
  32. let pos = 0;
  33. let str = '';
  34. while (num > 0) {
  35. const hundreds = num % 1000;
  36. if (hundreds) {
  37. const hund = hundredsToWords_(num % 1000);
  38. if (pos) {
  39. const large = exports.NUMBERS.large[pos];
  40. str = hund + exports.NUMBERS.numSep + large + (str ? exports.NUMBERS.numSep + str : '');
  41. }
  42. else {
  43. str = hund + (str ? exports.NUMBERS.numSep + str : '');
  44. }
  45. }
  46. num = Math.floor(num / 1000);
  47. pos++;
  48. }
  49. return str;
  50. }
  51. function numberToOrdinal(num, plural) {
  52. if (num === 1) {
  53. return 'enkel';
  54. }
  55. if (num === 2) {
  56. return plural ? 'helftes' : 'helfte';
  57. }
  58. if (num === 4) {
  59. return plural ? 'kwarte' : 'kwart';
  60. }
  61. return wordOrdinal(num) + (plural ? 's' : '');
  62. }
  63. function wordOrdinal(num) {
  64. if (num === 1) {
  65. return 'eerste';
  66. }
  67. if (num === 3) {
  68. return 'derde';
  69. }
  70. if (num === 8) {
  71. return 'agste';
  72. }
  73. if (num === 9) {
  74. return 'negende';
  75. }
  76. const ordinal = numberToWords(num);
  77. return ordinal + (num < 19 ? 'de' : 'ste');
  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. });