package.cjs.initializers.utils.customFormatters.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neeto-commons-frontend Show documentation
Show all versions of neeto-commons-frontend Show documentation
A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.lowerCaseDynamicTextFormatter = exports.listFormatter = void 0;
var _dompurify = _interopRequireDefault(require("dompurify"));
var _constants = require("../constants");
var sanitizer = function sanitizer(array) {
return _dompurify["default"].sanitize(array, {
USE_PROFILES: {
html: true
}
});
};
var cacheStore = new Map();
var fetchCachedOrInvoke = function fetchCachedOrInvoke(func, lng, options) {
var _cacheStore$get;
var cache = (_cacheStore$get = cacheStore.get(lng)) === null || _cacheStore$get === void 0 ? void 0 : _cacheStore$get.get(options);
if (cache) return cache;
cache = func(lng, options);
var lngCache = cacheStore.get(lng);
if (lngCache) lngCache.set(options, cache);else cacheStore.set(lng, new Map([[options, cache]]));
return cache;
};
var lowerCaseDynamicTextFormatter = exports.lowerCaseDynamicTextFormatter = function lowerCaseDynamicTextFormatter(value, format) {
if (!value || format === _constants.FORMATS.anyCase || typeof value !== "string") {
return value;
}
return _constants.LOWERCASED + value.toLocaleLowerCase();
};
var listFormatter = exports.listFormatter = function listFormatter(_ref) {
var value = _ref.value,
format = _ref.format,
lng = _ref.lng,
options = _ref.options;
var formatter = fetchCachedOrInvoke(function (lng, options) {
return new Intl.ListFormat(lng, options);
}, lng, options);
var newValue = value;
if (format === _constants.FORMATS.boldList) {
newValue = value.map(function (item) {
return "".concat(item, "");
});
}
var sanitizedItems = sanitizer(newValue).split(",");
return formatter.format(sanitizedItems);
};
//# sourceMappingURL=customFormatters.js.map