UNPKG

@web3r/flowerkit

Version:

Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).

13 lines (12 loc) 778 B
Object.defineProperty(exports,"__esModule",{value:true}); /** * Unescapes HTML entities back to their characters. * Unescaped: `&amp; &lt; &gt; &quot; &#39;` * @param {string} str Source string * @returns {string} Unescaped string * @throws {TypeError} If str is not a string * @example * getStrUnescaped("&lt;b&gt;Hello &amp; world&lt;/b&gt;"); * // => "<b>Hello & world</b>" */const getStrUnescaped=str=>{if(typeof str!=="string")throw new TypeError("getStrUnescaped: str must be a string");const symbols={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"};const regExp=/&(?:amp|lt|gt|quot|#39);/g;const getUnescaped=entity=>symbols[entity];return str.replace(regExp,getUnescaped)};exports.getStrUnescaped=getStrUnescaped; //# sourceMappingURL=index.cjs.map