UNPKG

@sebgroup/frontend-tools

Version:
18 lines (16 loc) 608 B
/** * Date formatter * @param date The date object or date string * @param format The output format * @param locale The locale. Default is `sv-SE` * @returns The formattted date or the input if it fails to parse it */ function formatDate(date, format = { day: "numeric", month: "long", year: "numeric" }, locale = "sv-SE") { const parsedDate = Date.parse(date); if (isNaN(parsedDate)) { return String(date); } return Intl.DateTimeFormat(locale || "sv-SE", format || {}).format(new Date(parsedDate)); } export { formatDate }; //# sourceMappingURL=formatDate.js.map