index.js 2.4 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;