index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var formatDistanceLocale = {
  7. lessThanXSeconds: {
  8. standalone: {
  9. one: 'manner wéi eng Sekonn',
  10. other: 'manner wéi {{count}} Sekonnen'
  11. },
  12. withPreposition: {
  13. one: 'manner wéi enger Sekonn',
  14. other: 'manner wéi {{count}} Sekonnen'
  15. }
  16. },
  17. xSeconds: {
  18. standalone: {
  19. one: 'eng Sekonn',
  20. other: '{{count}} Sekonnen'
  21. },
  22. withPreposition: {
  23. one: 'enger Sekonn',
  24. other: '{{count}} Sekonnen'
  25. }
  26. },
  27. halfAMinute: {
  28. standalone: 'eng hallef Minutt',
  29. withPreposition: 'enger hallwer Minutt'
  30. },
  31. lessThanXMinutes: {
  32. standalone: {
  33. one: 'manner wéi eng Minutt',
  34. other: 'manner wéi {{count}} Minutten'
  35. },
  36. withPreposition: {
  37. one: 'manner wéi enger Minutt',
  38. other: 'manner wéi {{count}} Minutten'
  39. }
  40. },
  41. xMinutes: {
  42. standalone: {
  43. one: 'eng Minutt',
  44. other: '{{count}} Minutten'
  45. },
  46. withPreposition: {
  47. one: 'enger Minutt',
  48. other: '{{count}} Minutten'
  49. }
  50. },
  51. aboutXHours: {
  52. standalone: {
  53. one: 'ongeféier eng Stonn',
  54. other: 'ongeféier {{count}} Stonnen'
  55. },
  56. withPreposition: {
  57. one: 'ongeféier enger Stonn',
  58. other: 'ongeféier {{count}} Stonnen'
  59. }
  60. },
  61. xHours: {
  62. standalone: {
  63. one: 'eng Stonn',
  64. other: '{{count}} Stonnen'
  65. },
  66. withPreposition: {
  67. one: 'enger Stonn',
  68. other: '{{count}} Stonnen'
  69. }
  70. },
  71. xDays: {
  72. standalone: {
  73. one: 'een Dag',
  74. other: '{{count}} Deeg'
  75. },
  76. withPreposition: {
  77. one: 'engem Dag',
  78. other: '{{count}} Deeg'
  79. }
  80. },
  81. aboutXWeeks: {
  82. standalone: {
  83. one: 'ongeféier eng Woch',
  84. other: 'ongeféier {{count}} Wochen'
  85. },
  86. withPreposition: {
  87. one: 'ongeféier enger Woche',
  88. other: 'ongeféier {{count}} Wochen'
  89. }
  90. },
  91. xWeeks: {
  92. standalone: {
  93. one: 'eng Woch',
  94. other: '{{count}} Wochen'
  95. },
  96. withPreposition: {
  97. one: 'enger Woch',
  98. other: '{{count}} Wochen'
  99. }
  100. },
  101. aboutXMonths: {
  102. standalone: {
  103. one: 'ongeféier ee Mount',
  104. other: 'ongeféier {{count}} Méint'
  105. },
  106. withPreposition: {
  107. one: 'ongeféier engem Mount',
  108. other: 'ongeféier {{count}} Méint'
  109. }
  110. },
  111. xMonths: {
  112. standalone: {
  113. one: 'ee Mount',
  114. other: '{{count}} Méint'
  115. },
  116. withPreposition: {
  117. one: 'engem Mount',
  118. other: '{{count}} Méint'
  119. }
  120. },
  121. aboutXYears: {
  122. standalone: {
  123. one: 'ongeféier ee Joer',
  124. other: 'ongeféier {{count}} Joer'
  125. },
  126. withPreposition: {
  127. one: 'ongeféier engem Joer',
  128. other: 'ongeféier {{count}} Joer'
  129. }
  130. },
  131. xYears: {
  132. standalone: {
  133. one: 'ee Joer',
  134. other: '{{count}} Joer'
  135. },
  136. withPreposition: {
  137. one: 'engem Joer',
  138. other: '{{count}} Joer'
  139. }
  140. },
  141. overXYears: {
  142. standalone: {
  143. one: 'méi wéi ee Joer',
  144. other: 'méi wéi {{count}} Joer'
  145. },
  146. withPreposition: {
  147. one: 'méi wéi engem Joer',
  148. other: 'méi wéi {{count}} Joer'
  149. }
  150. },
  151. almostXYears: {
  152. standalone: {
  153. one: 'bal ee Joer',
  154. other: 'bal {{count}} Joer'
  155. },
  156. withPreposition: {
  157. one: 'bal engem Joer',
  158. other: 'bal {{count}} Joer'
  159. }
  160. }
  161. };
  162. var EXCEPTION_CONSONANTS = ['d', 'h', 'n', 't', 'z'];
  163. var VOWELS = ['a,', 'e', 'i', 'o', 'u'];
  164. var DIGITS_SPOKEN_N_NEEDED = [0, 1, 2, 3, 8, 9];
  165. var FIRST_TWO_DIGITS_SPOKEN_NO_N_NEEDED = [40, 50, 60, 70];
  166. // Eifeler Regel
  167. function isFinalNNeeded(nextWords) {
  168. var firstLetter = nextWords.charAt(0).toLowerCase();
  169. if (VOWELS.indexOf(firstLetter) != -1 || EXCEPTION_CONSONANTS.indexOf(firstLetter) != -1) {
  170. return true;
  171. }
  172. // Numbers would need to converted into words for checking.
  173. // Therefore, I have listed the digits that require a preceeding n with a few exceptions.
  174. var firstWord = nextWords.split(' ')[0];
  175. var number = parseInt(firstWord);
  176. if (!isNaN(number) && DIGITS_SPOKEN_N_NEEDED.indexOf(number % 10) != -1 && FIRST_TWO_DIGITS_SPOKEN_NO_N_NEEDED.indexOf(parseInt(firstWord.substring(0, 2))) == -1) {
  177. return true;
  178. }
  179. // Omit other checks as they are not expected here.
  180. return false;
  181. }
  182. var formatDistance = function formatDistance(token, count, options) {
  183. var result;
  184. var tokenValue = formatDistanceLocale[token];
  185. var usageGroup = options !== null && options !== void 0 && options.addSuffix ? tokenValue.withPreposition : tokenValue.standalone;
  186. if (typeof usageGroup === 'string') {
  187. result = usageGroup;
  188. } else if (count === 1) {
  189. result = usageGroup.one;
  190. } else {
  191. result = usageGroup.other.replace('{{count}}', String(count));
  192. }
  193. if (options !== null && options !== void 0 && options.addSuffix) {
  194. if (options.comparison && options.comparison > 0) {
  195. return 'a' + (isFinalNNeeded(result) ? 'n' : '') + ' ' + result;
  196. } else {
  197. return 'viru' + (isFinalNNeeded(result) ? 'n' : '') + ' ' + result;
  198. }
  199. }
  200. return result;
  201. };
  202. var _default = formatDistance;
  203. exports.default = _default;
  204. module.exports = exports.default;