UNPKG

stringiful

Version:

Easy to use stringify function with built-in configurable formatters

30 lines 1.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDateFormatter = void 0; const lodash_1 = __importDefault(require("lodash")); const config_1 = __importDefault(require("../../../config")); const getCurrTimezone = () => { return Intl.DateTimeFormat().resolvedOptions().timeZone; }; const getDateFormatter = (formatterConfig) => { var _a; const { formattersDefaultParams: { date: { timezone, locale }, }, } = config_1.default; const dateFormatter = { matches: (obj) => { return lodash_1.default.isDate(obj); }, }; const defaultFormatFunction = (date) => { var _a, _b, _c, _d, _e; const selectedTimezone = (_c = (_b = (_a = formatterConfig.params) === null || _a === void 0 ? void 0 : _a.timezone) !== null && _b !== void 0 ? _b : getCurrTimezone()) !== null && _c !== void 0 ? _c : timezone; const selectedLocale = (_e = (_d = formatterConfig.params) === null || _d === void 0 ? void 0 : _d.locale) !== null && _e !== void 0 ? _e : locale; return new Date(date.toLocaleString(selectedLocale, { timeZone: selectedTimezone })); }; dateFormatter.format = (_a = formatterConfig.format) !== null && _a !== void 0 ? _a : defaultFormatFunction; return dateFormatter; }; exports.getDateFormatter = getDateFormatter; //# sourceMappingURL=index.js.map