@dialpad/dialtone
Version:
Dialpad's Dialtone design system monorepo
1 lines • 3.62 kB
Source Map (JSON)
{"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":[],"mappings":";;AAOO,SAAS,WAAY,MAAM,SAAS,WAAW;AACpD,SAAO,IAAI,KAAK,eAAe,QAAQ,EAAE,SAAS,QAAQ,MAAM,WAAW,OAAO,QAAQ,KAAK,UAAW,CAAA,EAAE,OAAO,IAAI;AACzH;AASO,SAAS,aAAc,MAAM,SAAS,WAAW;AACtD,SAAO,IAAI,KAAK,eAAe,QAAQ,EAAE,MAAM,WAAW,OAAO,QAAQ,KAAK,UAAS,CAAE,EAAE,OAAO,IAAI;AACxG;AASO,SAAS,YAAa,MAAM,SAAS,WAAW,cAAc,MAAM;AACzE,QAAM,UAAU,cAAc,EAAE,SAAS,SAAS,MAAM,WAAW,OAAO,SAAS,KAAK,UAAW,IAAG,EAAE,MAAM,WAAW,OAAO,SAAS,KAAK;AAC9I,SAAO,IAAI,KAAK,eAAe,QAAQ,OAAO,EAAE,OAAO,IAAI;AAC7D;AAUO,SAAS,aAAc,MAAM,SAAS,WAAW,cAAc,OAAO;AAC3E,QAAM,cAAc,cAAc,UAAU;AAC5C,SAAO,IAAI,KAAK,eAAe,QAAQ,EAAE,OAAO,aAAa,KAAK,UAAW,CAAA,EAAE,OAAO,IAAI;AAC5F;AASO,SAAS,gBAAiB,MAAM,SAAS,WAAW;AACzD,SAAO,IAAI,KAAK,eAAe,QAAQ,EAAE,MAAM,WAAW,OAAO,WAAW,KAAK,UAAS,CAAE,EAAE,OAAO,IAAI;AAC3G;;;;;;"}