package.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.
import DOMPurify from "dompurify";
import { LOWERCASED, FORMATS } from "../constants";
var sanitizer = function sanitizer(array) {
return DOMPurify.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;
};
export var lowerCaseDynamicTextFormatter = function lowerCaseDynamicTextFormatter(value, format) {
if (!value || format === FORMATS.anyCase || typeof value !== "string") {
return value;
}
return LOWERCASED + value.toLocaleLowerCase();
};
export var 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 === FORMATS.boldList) {
newValue = value.map(function (item) {
return "".concat(item, "");
});
}
var sanitizedItems = sanitizer(newValue).split(",");
return formatter.format(sanitizedItems);
};
//# sourceMappingURL=customFormatters.js.map