index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function buildLocalizeTokenFn(schema) {
  7. return function (count, options) {
  8. if (count === 1) {
  9. if (options !== null && options !== void 0 && options.addSuffix) {
  10. return schema.one[0].replace('{{time}}', schema.one[2]);
  11. } else {
  12. return schema.one[0].replace('{{time}}', schema.one[1]);
  13. }
  14. } else {
  15. var rem = count % 10 === 1 && count % 100 !== 11;
  16. if (options !== null && options !== void 0 && options.addSuffix) {
  17. return schema.other[0].replace('{{time}}', rem ? schema.other[3] : schema.other[4]).replace('{{count}}', String(count));
  18. } else {
  19. return schema.other[0].replace('{{time}}', rem ? schema.other[1] : schema.other[2]).replace('{{count}}', String(count));
  20. }
  21. }
  22. };
  23. }
  24. var formatDistanceLocale = {
  25. lessThanXSeconds: buildLocalizeTokenFn({
  26. one: ['mazāk par {{time}}', 'sekundi', 'sekundi'],
  27. other: ['mazāk nekā {{count}} {{time}}', 'sekunde', 'sekundes', 'sekundes', 'sekundēm']
  28. }),
  29. xSeconds: buildLocalizeTokenFn({
  30. one: ['1 {{time}}', 'sekunde', 'sekundes'],
  31. other: ['{{count}} {{time}}', 'sekunde', 'sekundes', 'sekundes', 'sekundēm']
  32. }),
  33. halfAMinute: function halfAMinute(_count, options) {
  34. if (options !== null && options !== void 0 && options.addSuffix) {
  35. return 'pusminūtes';
  36. } else {
  37. return 'pusminūte';
  38. }
  39. },
  40. lessThanXMinutes: buildLocalizeTokenFn({
  41. one: ['mazāk par {{time}}', 'minūti', 'minūti'],
  42. other: ['mazāk nekā {{count}} {{time}}', 'minūte', 'minūtes', 'minūtes', 'minūtēm']
  43. }),
  44. xMinutes: buildLocalizeTokenFn({
  45. one: ['1 {{time}}', 'minūte', 'minūtes'],
  46. other: ['{{count}} {{time}}', 'minūte', 'minūtes', 'minūtes', 'minūtēm']
  47. }),
  48. aboutXHours: buildLocalizeTokenFn({
  49. one: ['apmēram 1 {{time}}', 'stunda', 'stundas'],
  50. other: ['apmēram {{count}} {{time}}', 'stunda', 'stundas', 'stundas', 'stundām']
  51. }),
  52. xHours: buildLocalizeTokenFn({
  53. one: ['1 {{time}}', 'stunda', 'stundas'],
  54. other: ['{{count}} {{time}}', 'stunda', 'stundas', 'stundas', 'stundām']
  55. }),
  56. xDays: buildLocalizeTokenFn({
  57. one: ['1 {{time}}', 'diena', 'dienas'],
  58. other: ['{{count}} {{time}}', 'diena', 'dienas', 'dienas', 'dienām']
  59. }),
  60. aboutXWeeks: buildLocalizeTokenFn({
  61. one: ['apmēram 1 {{time}}', 'nedēļa', 'nedēļas'],
  62. other: ['apmēram {{count}} {{time}}', 'nedēļa', 'nedēļu', 'nedēļas', 'nedēļām']
  63. }),
  64. xWeeks: buildLocalizeTokenFn({
  65. one: ['1 {{time}}', 'nedēļa', 'nedēļas'],
  66. other: ['{{count}} {{time}}',
  67. // TODO
  68. 'nedēļa', 'nedēļu', 'nedēļas', 'nedēļām']
  69. }),
  70. aboutXMonths: buildLocalizeTokenFn({
  71. one: ['apmēram 1 {{time}}', 'mēnesis', 'mēneša'],
  72. other: ['apmēram {{count}} {{time}}', 'mēnesis', 'mēneši', 'mēneša', 'mēnešiem']
  73. }),
  74. xMonths: buildLocalizeTokenFn({
  75. one: ['1 {{time}}', 'mēnesis', 'mēneša'],
  76. other: ['{{count}} {{time}}', 'mēnesis', 'mēneši', 'mēneša', 'mēnešiem']
  77. }),
  78. aboutXYears: buildLocalizeTokenFn({
  79. one: ['apmēram 1 {{time}}', 'gads', 'gada'],
  80. other: ['apmēram {{count}} {{time}}', 'gads', 'gadi', 'gada', 'gadiem']
  81. }),
  82. xYears: buildLocalizeTokenFn({
  83. one: ['1 {{time}}', 'gads', 'gada'],
  84. other: ['{{count}} {{time}}', 'gads', 'gadi', 'gada', 'gadiem']
  85. }),
  86. overXYears: buildLocalizeTokenFn({
  87. one: ['ilgāk par 1 {{time}}', 'gadu', 'gadu'],
  88. other: ['vairāk nekā {{count}} {{time}}', 'gads', 'gadi', 'gada', 'gadiem']
  89. }),
  90. almostXYears: buildLocalizeTokenFn({
  91. one: ['gandrīz 1 {{time}}', 'gads', 'gada'],
  92. other: ['vairāk nekā {{count}} {{time}}', 'gads', 'gadi', 'gada', 'gadiem']
  93. })
  94. };
  95. var formatDistance = function formatDistance(token, count, options) {
  96. var result = formatDistanceLocale[token](count, options);
  97. if (options !== null && options !== void 0 && options.addSuffix) {
  98. if (options.comparison && options.comparison > 0) {
  99. return 'pēc ' + result;
  100. } else {
  101. return 'pirms ' + result;
  102. }
  103. }
  104. return result;
  105. };
  106. var _default = formatDistance;
  107. exports.default = _default;
  108. module.exports = exports.default;