@sebgroup/frontend-tools
Version:
A set of frontend tools
22 lines (18 loc) • 697 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
/**
* 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));
}
exports.formatDate = formatDate;
//# sourceMappingURL=formatDate.js.map