All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.initializers.utils.customFormatters.js Maven / Gradle / Ivy

Go to download

A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.

There is a newer version: 4.12.3
Show newest version
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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy