📄 formatDistance.js
/home/palash/git/site/node_modules/date-fns/locale/sv/_lib/formatDistance.js
Language: js ‱ Lines: 120
const formatDistanceLocale = {
  lessThanXSeconds: {
    one: "mindre Àn en sekund",
    other: "mindre Àn {{count}} sekunder",
  },

  xSeconds: {
    one: "en sekund",
    other: "{{count}} sekunder",
  },

  halfAMinute: "en halv minut",

  lessThanXMinutes: {
    one: "mindre Àn en minut",
    other: "mindre Àn {{count}} minuter",
  },

  xMinutes: {
    one: "en minut",
    other: "{{count}} minuter",
  },

  aboutXHours: {
    one: "ungefÀr en timme",
    other: "ungefÀr {{count}} timmar",
  },

  xHours: {
    one: "en timme",
    other: "{{count}} timmar",
  },

  xDays: {
    one: "en dag",
    other: "{{count}} dagar",
  },

  aboutXWeeks: {
    one: "ungefÀr en vecka",
    other: "ungefÀr {{count}} veckor",
  },

  xWeeks: {
    one: "en vecka",
    other: "{{count}} veckor",
  },

  aboutXMonths: {
    one: "ungefÀr en mÄnad",
    other: "ungefÀr {{count}} mÄnader",
  },

  xMonths: {
    one: "en mÄnad",
    other: "{{count}} mÄnader",
  },

  aboutXYears: {
    one: "ungefÀr ett Är",
    other: "ungefÀr {{count}} Är",
  },

  xYears: {
    one: "ett Är",
    other: "{{count}} Är",
  },

  overXYears: {
    one: "över ett Är",
    other: "över {{count}} Är",
  },

  almostXYears: {
    one: "nÀstan ett Är",
    other: "nÀstan {{count}} Är",
  },
};

const wordMapping = [
  "noll",
  "en",
  "tvÄ",
  "tre",
  "fyra",
  "fem",
  "sex",
  "sju",
  "Ätta",
  "nio",
  "tio",
  "elva",
  "tolv",
];

export const formatDistance = (token, count, options) => {
  let result;

  const tokenValue = formatDistanceLocale[token];
  if (typeof tokenValue === "string") {
    result = tokenValue;
  } else if (count === 1) {
    result = tokenValue.one;
  } else {
    result = tokenValue.other.replace(
      "{{count}}",
      count < 13 ? wordMapping[count] : String(count),
    );
  }

  if (options?.addSuffix) {
    if (options.comparison && options.comparison > 0) {
      return "om " + result;
    } else {
      return result + " sedan";
    }
  }

  return result;
};