package.initializers.utils.customFormatters.js.map 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.
{"version":3,"file":"customFormatters.js","names":["DOMPurify","LOWERCASED","FORMATS","sanitizer","array","sanitize","USE_PROFILES","html","cacheStore","Map","fetchCachedOrInvoke","func","lng","options","_cacheStore$get","cache","get","lngCache","set","lowerCaseDynamicTextFormatter","value","format","anyCase","toLocaleLowerCase","listFormatter","_ref","formatter","Intl","ListFormat","newValue","boldList","map","item","concat","sanitizedItems","split"],"sources":["../../../src/initializers/utils/customFormatters.js"],"sourcesContent":["import DOMPurify from \"dompurify\";\n\nimport { LOWERCASED, FORMATS } from \"../constants\";\n\nconst sanitizer = array =>\n DOMPurify.sanitize(array, { USE_PROFILES: { html: true } });\n\nconst cacheStore = new Map();\n\nconst fetchCachedOrInvoke = (func, lng, options) => {\n let cache = cacheStore.get(lng)?.get(options);\n if (cache) return cache;\n\n cache = func(lng, options);\n const lngCache = cacheStore.get(lng);\n if (lngCache) lngCache.set(options, cache);\n else cacheStore.set(lng, new Map([[options, cache]]));\n\n return cache;\n};\n\nexport const lowerCaseDynamicTextFormatter = (value, format) => {\n if (!value || format === FORMATS.anyCase || typeof value !== \"string\") {\n return value;\n }\n\n return LOWERCASED + value.toLocaleLowerCase();\n};\n\nexport const listFormatter = ({ value, format, lng, options }) => {\n const formatter = fetchCachedOrInvoke(\n (lng, options) => new Intl.ListFormat(lng, options),\n lng,\n options\n );\n\n let newValue = value;\n if (format === FORMATS.boldList) {\n newValue = value.map(item => `${item}`);\n }\n const sanitizedItems = sanitizer(newValue).split(\",\");\n\n return formatter.format(sanitizedItems);\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,WAAW;AAEjC,SAASC,UAAU,EAAEC,OAAO;AAE5B,IAAMC,SAAS,GAAG,SAAZA,SAASA,CAAGC,KAAK;E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