@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) • 705 B
JavaScript
/**
* Unescapes HTML entities back to their characters.
* Unescaped: `& < > " '`
* @param {string} str Source string
* @returns {string} Unescaped string
* @throws {TypeError} If str is not a string
* @example
* getStrUnescaped("<b>Hello & world</b>");
* // => "<b>Hello & world</b>"
*/
const getStrUnescaped=str=>{if(typeof str!=="string")throw new TypeError("getStrUnescaped: str must be a string");const symbols={"&":"&","<":"<",">":">",""":'"',"'":"'"};const regExp=/&(?:amp|lt|gt|quot|#39);/g;const getUnescaped=entity=>symbols[entity];return str.replace(regExp,getUnescaped)};export{getStrUnescaped};
//# sourceMappingURL=index.mjs.map