index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var formatDistanceLocale = {
  7. lessThanXSeconds: {
  8. one: 'mindre än en sekund',
  9. other: 'mindre än {{count}} sekunder'
  10. },
  11. xSeconds: {
  12. one: 'en sekund',
  13. other: '{{count}} sekunder'
  14. },
  15. halfAMinute: 'en halv minut',
  16. lessThanXMinutes: {
  17. one: 'mindre än en minut',
  18. other: 'mindre än {{count}} minuter'
  19. },
  20. xMinutes: {
  21. one: 'en minut',
  22. other: '{{count}} minuter'
  23. },
  24. aboutXHours: {
  25. one: 'ungefär en timme',
  26. other: 'ungefär {{count}} timmar'
  27. },
  28. xHours: {
  29. one: 'en timme',
  30. other: '{{count}} timmar'
  31. },
  32. xDays: {
  33. one: 'en dag',
  34. other: '{{count}} dagar'
  35. },
  36. aboutXWeeks: {
  37. one: 'ungefär en vecka',
  38. other: 'ungefär {{count}} vecka'
  39. },
  40. xWeeks: {
  41. one: 'en vecka',
  42. other: '{{count}} vecka'
  43. },
  44. aboutXMonths: {
  45. one: 'ungefär en månad',
  46. other: 'ungefär {{count}} månader'
  47. },
  48. xMonths: {
  49. one: 'en månad',
  50. other: '{{count}} månader'
  51. },
  52. aboutXYears: {
  53. one: 'ungefär ett år',
  54. other: 'ungefär {{count}} år'
  55. },
  56. xYears: {
  57. one: 'ett år',
  58. other: '{{count}} år'
  59. },
  60. overXYears: {
  61. one: 'över ett år',
  62. other: 'över {{count}} år'
  63. },
  64. almostXYears: {
  65. one: 'nästan ett år',
  66. other: 'nästan {{count}} år'
  67. }
  68. };
  69. var wordMapping = ['noll', 'en', 'två', 'tre', 'fyra', 'fem', 'sex', 'sju', 'åtta', 'nio', 'tio', 'elva', 'tolv'];
  70. var formatDistance = function formatDistance(token, count, options) {
  71. var result;
  72. var tokenValue = formatDistanceLocale[token];
  73. if (typeof tokenValue === 'string') {
  74. result = tokenValue;
  75. } else if (count === 1) {
  76. result = tokenValue.one;
  77. } else {
  78. if (options && options.onlyNumeric) {
  79. result = tokenValue.other.replace('{{count}}', String(count));
  80. } else {
  81. result = tokenValue.other.replace('{{count}}', count < 13 ? wordMapping[count] : String(count));
  82. }
  83. }
  84. if (options !== null && options !== void 0 && options.addSuffix) {
  85. if (options.comparison && options.comparison > 0) {
  86. return 'om ' + result;
  87. } else {
  88. return result + ' sedan';
  89. }
  90. }
  91. return result;
  92. };
  93. var _default = formatDistance;
  94. exports.default = _default;
  95. module.exports = exports.default;