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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy