UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

1 lines 3.87 kB
{"version":3,"file":"formatUtils.cjs","sources":["../../../components/datepicker/formatUtils.js"],"sourcesContent":["/**\n * Formats a date into a long format using the specified locale.\n *\n * @param {Date} date - The date to format.\n * @param {string} [locale='default'] - The locale to use for formatting. Defaults to 'default'.\n * @returns {string} The formatted date string.\n */\nexport function formatLong (date, locale = 'default') {\n return new Intl.DateTimeFormat(locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }).format(date);\n}\n\n/**\n * Formats the given date in medium format.\n *\n * @param {Date} date - The date to be formatted.\n * @param {string} [locale='default'] - The locale to be used for formatting. Defaults to 'default'.\n * @returns {string} The formatted date string in medium format.\n */\nexport function formatMedium (date, locale = 'default') {\n return new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'long', day: 'numeric' }).format(date);\n}\n\n/**\n * Formats a date into a short string representation.\n * @param {Date} date - The date to format.\n * @param {string} [locale='default'] - The locale to use for formatting. Defaults to 'default'.\n * @param {boolean} [showWeekday=true] - Whether to include the weekday in the formatted string. Defaults to true.\n * @returns {string} The formatted date string.\n */\nexport function formatShort (date, locale = 'default', showWeekday = true) {\n const options = showWeekday ? { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' } : { year: 'numeric', month: 'short', day: 'numeric' };\n return new Intl.DateTimeFormat(locale, options).format(date);\n}\n\n/**\n * Formats a date without the year.\n *\n * @param {Date} date - The date to format.\n * @param {string} [locale='default'] - The locale to use for formatting. Defaults to 'default'.\n * @param {boolean} [abbreviated=false] - Whether to use abbreviated month names. Defaults to false.\n * @returns {string} The formatted date without the year.\n */\nexport function formatNoYear (date, locale = 'default', abbreviated = false) {\n const monthFormat = abbreviated ? 'short' : 'long';\n return new Intl.DateTimeFormat(locale, { month: monthFormat, day: 'numeric' }).format(date);\n}\n\n/**\n * Formats a date into a numerical string representation.\n *\n * @param {Date} date - The date to format.\n * @param {string} [locale='default'] - The locale to use for formatting. Defaults to 'default'.\n * @returns {string} The formatted numerical date string.\n */\nexport function formatNumerical (date, locale = 'default') {\n return new Intl.DateTimeFormat(locale, { year: '2-digit', month: '2-digit', day: '2-digit' }).format(date);\n}\n\nexport default {\n formatLong,\n formatMedium,\n formatShort,\n formatNoYear,\n formatNumerical,\n};\n"],"names":["formatLong","date","locale","formatMedium","formatShort","showWeekday","options","formatNoYear","abbreviated","monthFormat","formatNumerical","formatUtils"],"mappings":"4GAOO,SAASA,EAAYC,EAAMC,EAAS,UAAW,CACpD,OAAO,IAAI,KAAK,eAAeA,EAAQ,CAAE,QAAS,OAAQ,KAAM,UAAW,MAAO,OAAQ,IAAK,SAAW,CAAA,EAAE,OAAOD,CAAI,CACzH,CASO,SAASE,EAAcF,EAAMC,EAAS,UAAW,CACtD,OAAO,IAAI,KAAK,eAAeA,EAAQ,CAAE,KAAM,UAAW,MAAO,OAAQ,IAAK,SAAS,CAAE,EAAE,OAAOD,CAAI,CACxG,CASO,SAASG,EAAaH,EAAMC,EAAS,UAAWG,EAAc,GAAM,CACzE,MAAMC,EAAUD,EAAc,CAAE,QAAS,QAAS,KAAM,UAAW,MAAO,QAAS,IAAK,SAAW,EAAG,CAAE,KAAM,UAAW,MAAO,QAAS,IAAK,WAC9I,OAAO,IAAI,KAAK,eAAeH,EAAQI,CAAO,EAAE,OAAOL,CAAI,CAC7D,CAUO,SAASM,EAAcN,EAAMC,EAAS,UAAWM,EAAc,GAAO,CAC3E,MAAMC,EAAcD,EAAc,QAAU,OAC5C,OAAO,IAAI,KAAK,eAAeN,EAAQ,CAAE,MAAOO,EAAa,IAAK,SAAW,CAAA,EAAE,OAAOR,CAAI,CAC5F,CASO,SAASS,EAAiBT,EAAMC,EAAS,UAAW,CACzD,OAAO,IAAI,KAAK,eAAeA,EAAQ,CAAE,KAAM,UAAW,MAAO,UAAW,IAAK,SAAS,CAAE,EAAE,OAAOD,CAAI,CAC3G,CAEA,MAAeU,EAAA,CACb,WAAAX,EACA,aAAAG,EACA,YAAAC,EACA,aAAAG,EACA,gBAAAG,CACF"}