πŸ“„ formatDistance.js
/home/palash/git/site/node_modules/date-fns/locale/ja/_lib/formatDistance.js
Language: js β€’ Lines: 115
const formatDistanceLocale = {
  lessThanXSeconds: {
    one: "1η§’ζœͺζΊ€",
    other: "{{count}}η§’ζœͺζΊ€",
    oneWithSuffix: "η΄„1η§’",
    otherWithSuffix: "η΄„{{count}}η§’",
  },

  xSeconds: {
    one: "1η§’",
    other: "{{count}}η§’",
  },

  halfAMinute: "30η§’",

  lessThanXMinutes: {
    one: "1εˆ†ζœͺζΊ€",
    other: "{{count}}εˆ†ζœͺζΊ€",
    oneWithSuffix: "η΄„1εˆ†",
    otherWithSuffix: "η΄„{{count}}εˆ†",
  },

  xMinutes: {
    one: "1εˆ†",
    other: "{{count}}εˆ†",
  },

  aboutXHours: {
    one: "η΄„1ζ™‚ι–“",
    other: "η΄„{{count}}ζ™‚ι–“",
  },

  xHours: {
    one: "1ζ™‚ι–“",
    other: "{{count}}ζ™‚ι–“",
  },

  xDays: {
    one: "1ζ—₯",
    other: "{{count}}ζ—₯",
  },

  aboutXWeeks: {
    one: "η΄„1ι€±ι–“",
    other: "η΄„{{count}}ι€±ι–“",
  },

  xWeeks: {
    one: "1ι€±ι–“",
    other: "{{count}}ι€±ι–“",
  },

  aboutXMonths: {
    one: "η΄„1γ‹ζœˆ",
    other: "η΄„{{count}}γ‹ζœˆ",
  },

  xMonths: {
    one: "1γ‹ζœˆ",
    other: "{{count}}γ‹ζœˆ",
  },

  aboutXYears: {
    one: "η΄„1εΉ΄",
    other: "η΄„{{count}}εΉ΄",
  },

  xYears: {
    one: "1εΉ΄",
    other: "{{count}}εΉ΄",
  },

  overXYears: {
    one: "1εΉ΄δ»₯上",
    other: "{{count}}εΉ΄δ»₯上",
  },

  almostXYears: {
    one: "1年近く",
    other: "{{count}}年近く",
  },
};

export const formatDistance = (token, count, options) => {
  options = options || {};

  let result;

  const tokenValue = formatDistanceLocale[token];
  if (typeof tokenValue === "string") {
    result = tokenValue;
  } else if (count === 1) {
    if (options.addSuffix && tokenValue.oneWithSuffix) {
      result = tokenValue.oneWithSuffix;
    } else {
      result = tokenValue.one;
    }
  } else {
    if (options.addSuffix && tokenValue.otherWithSuffix) {
      result = tokenValue.otherWithSuffix.replace("{{count}}", String(count));
    } else {
      result = tokenValue.other.replace("{{count}}", String(count));
    }
  }

  if (options.addSuffix) {
    if (options.comparison && options.comparison > 0) {
      return result + "後";
    } else {
      return result + "前";
    }
  }

  return result;
};