index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var translations = {
  7. xseconds_other: 'sekundė_sekundžių_sekundes',
  8. xminutes_one: 'minutė_minutės_minutę',
  9. xminutes_other: 'minutės_minučių_minutes',
  10. xhours_one: 'valanda_valandos_valandą',
  11. xhours_other: 'valandos_valandų_valandas',
  12. xdays_one: 'diena_dienos_dieną',
  13. xdays_other: 'dienos_dienų_dienas',
  14. xweeks_one: 'savaitė_savaitės_savaitę',
  15. xweeks_other: 'savaitės_savaičių_savaites',
  16. xmonths_one: 'mėnuo_mėnesio_mėnesį',
  17. xmonths_other: 'mėnesiai_mėnesių_mėnesius',
  18. xyears_one: 'metai_metų_metus',
  19. xyears_other: 'metai_metų_metus',
  20. about: 'apie',
  21. over: 'daugiau nei',
  22. almost: 'beveik',
  23. lessthan: 'mažiau nei'
  24. };
  25. var translateSeconds = function translateSeconds(_number, addSuffix, _key, isFuture) {
  26. if (!addSuffix) {
  27. return 'kelios sekundės';
  28. } else {
  29. return isFuture ? 'kelių sekundžių' : 'kelias sekundes';
  30. }
  31. };
  32. var translateSingular = function translateSingular(_number, addSuffix, key, isFuture) {
  33. return !addSuffix ? forms(key)[0] : isFuture ? forms(key)[1] : forms(key)[2];
  34. };
  35. var translate = function translate(number, addSuffix, key, isFuture) {
  36. var result = number + ' ';
  37. if (number === 1) {
  38. return result + translateSingular(number, addSuffix, key, isFuture);
  39. } else if (!addSuffix) {
  40. return result + (special(number) ? forms(key)[1] : forms(key)[0]);
  41. } else {
  42. if (isFuture) {
  43. return result + forms(key)[1];
  44. } else {
  45. return result + (special(number) ? forms(key)[1] : forms(key)[2]);
  46. }
  47. }
  48. };
  49. function special(number) {
  50. return number % 10 === 0 || number > 10 && number < 20;
  51. }
  52. function forms(key) {
  53. return translations[key].split('_');
  54. }
  55. var formatDistanceLocale = {
  56. lessThanXSeconds: {
  57. one: translateSeconds,
  58. other: translate
  59. },
  60. xSeconds: {
  61. one: translateSeconds,
  62. other: translate
  63. },
  64. halfAMinute: 'pusė minutės',
  65. lessThanXMinutes: {
  66. one: translateSingular,
  67. other: translate
  68. },
  69. xMinutes: {
  70. one: translateSingular,
  71. other: translate
  72. },
  73. aboutXHours: {
  74. one: translateSingular,
  75. other: translate
  76. },
  77. xHours: {
  78. one: translateSingular,
  79. other: translate
  80. },
  81. xDays: {
  82. one: translateSingular,
  83. other: translate
  84. },
  85. aboutXWeeks: {
  86. one: translateSingular,
  87. other: translate
  88. },
  89. xWeeks: {
  90. one: translateSingular,
  91. other: translate
  92. },
  93. aboutXMonths: {
  94. one: translateSingular,
  95. other: translate
  96. },
  97. xMonths: {
  98. one: translateSingular,
  99. other: translate
  100. },
  101. aboutXYears: {
  102. one: translateSingular,
  103. other: translate
  104. },
  105. xYears: {
  106. one: translateSingular,
  107. other: translate
  108. },
  109. overXYears: {
  110. one: translateSingular,
  111. other: translate
  112. },
  113. almostXYears: {
  114. one: translateSingular,
  115. other: translate
  116. }
  117. };
  118. var formatDistance = function formatDistance(token, count, options) {
  119. var adverb = token.match(/about|over|almost|lessthan/i);
  120. var unit = adverb ? token.replace(adverb[0], '') : token;
  121. var isFuture = (options === null || options === void 0 ? void 0 : options.comparison) !== undefined && options.comparison > 0;
  122. var result;
  123. var tokenValue = formatDistanceLocale[token];
  124. if (typeof tokenValue === 'string') {
  125. result = tokenValue;
  126. } else if (count === 1) {
  127. result = tokenValue.one(count, (options === null || options === void 0 ? void 0 : options.addSuffix) === true, unit.toLowerCase() + '_one', isFuture);
  128. } else {
  129. result = tokenValue.other(count, (options === null || options === void 0 ? void 0 : options.addSuffix) === true, unit.toLowerCase() + '_other', isFuture);
  130. }
  131. if (adverb) {
  132. var _key2 = adverb[0].toLowerCase();
  133. result = translations[_key2] + ' ' + result;
  134. }
  135. if (options !== null && options !== void 0 && options.addSuffix) {
  136. if (options.comparison && options.comparison > 0) {
  137. return 'po ' + result;
  138. } else {
  139. return 'prieš ' + result;
  140. }
  141. }
  142. return result;
  143. };
  144. var _default = formatDistance;
  145. exports.default = _default;
  146. module.exports = exports.default;