index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var formatDistanceLocale = {
  7. lessThanXSeconds: {
  8. one: '1秒未満',
  9. other: '{{count}}秒未満',
  10. oneWithSuffix: '約1秒',
  11. otherWithSuffix: '約{{count}}秒'
  12. },
  13. xSeconds: {
  14. one: '1秒',
  15. other: '{{count}}秒'
  16. },
  17. halfAMinute: '30秒',
  18. lessThanXMinutes: {
  19. one: '1分未満',
  20. other: '{{count}}分未満',
  21. oneWithSuffix: '約1分',
  22. otherWithSuffix: '約{{count}}分'
  23. },
  24. xMinutes: {
  25. one: '1分',
  26. other: '{{count}}分'
  27. },
  28. aboutXHours: {
  29. one: '約1時間',
  30. other: '約{{count}}時間'
  31. },
  32. xHours: {
  33. one: '1時間',
  34. other: '{{count}}時間'
  35. },
  36. xDays: {
  37. one: '1日',
  38. other: '{{count}}日'
  39. },
  40. aboutXWeeks: {
  41. one: '約1週間',
  42. other: '約{{count}}週間'
  43. },
  44. xWeeks: {
  45. one: '1週間',
  46. other: '{{count}}週間'
  47. },
  48. aboutXMonths: {
  49. one: '約1か月',
  50. other: '約{{count}}か月'
  51. },
  52. xMonths: {
  53. one: '1か月',
  54. other: '{{count}}か月'
  55. },
  56. aboutXYears: {
  57. one: '約1年',
  58. other: '約{{count}}年'
  59. },
  60. xYears: {
  61. one: '1年',
  62. other: '{{count}}年'
  63. },
  64. overXYears: {
  65. one: '1年以上',
  66. other: '{{count}}年以上'
  67. },
  68. almostXYears: {
  69. one: '1年近く',
  70. other: '{{count}}年近く'
  71. }
  72. };
  73. var formatDistance = function formatDistance(token, count, options) {
  74. options = options || {};
  75. var result;
  76. var tokenValue = formatDistanceLocale[token];
  77. if (typeof tokenValue === 'string') {
  78. result = tokenValue;
  79. } else if (count === 1) {
  80. if (options.addSuffix && tokenValue.oneWithSuffix) {
  81. result = tokenValue.oneWithSuffix;
  82. } else {
  83. result = tokenValue.one;
  84. }
  85. } else {
  86. if (options.addSuffix && tokenValue.otherWithSuffix) {
  87. result = tokenValue.otherWithSuffix.replace('{{count}}', String(count));
  88. } else {
  89. result = tokenValue.other.replace('{{count}}', String(count));
  90. }
  91. }
  92. if (options.addSuffix) {
  93. if (options.comparison && options.comparison > 0) {
  94. return result + '後';
  95. } else {
  96. return result + '前';
  97. }
  98. }
  99. return result;
  100. };
  101. var _default = formatDistance;
  102. exports.default = _default;
  103. module.exports = exports.default;