'use strict';

var DOMPurify = require('dompurify');
var v2_initializers_constants = require('../constants.js');

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;
};
var lowerCaseDynamicTextFormatter = function lowerCaseDynamicTextFormatter(value, format) {
  if (!value || format === v2_initializers_constants.FORMATS.anyCase || typeof value !== "string") {
    return value;
  }
  return v2_initializers_constants.LOWERCASED + value.toLocaleLowerCase();
};
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 === v2_initializers_constants.FORMATS.boldList) {
    newValue = value.map(function (item) {
      return "<strong>".concat(item, "</strong>");
    });
  }
  var sanitizedItems = sanitizer(newValue).split(",");
  return formatter.format(sanitizedItems);
};

exports.listFormatter = listFormatter;
exports.lowerCaseDynamicTextFormatter = lowerCaseDynamicTextFormatter;
//# sourceMappingURL=customFormatters.js.map
