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) 777 B
Object.defineProperty(exports,"__esModule",{value:true}); /** * Escapes special HTML characters to their corresponding entities. * Escaped: `& < > " '` * @param {string} str Source string * @returns {string} Escaped string safe for HTML text context * @throws {TypeError} If str is not a string * @example * getStrEscaped('<b>Hello & "world"</b>'); * // => "&lt;b&gt;Hello &amp; &quot;world&quot;&lt;/b&gt;" */const getStrEscaped=str=>{if(typeof str!=="string")throw new TypeError("getStrEscaped: str must be a string");const symbols={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};const regExp=/[&<>"']/g;const getEscaped=char=>symbols[char];return str.replace(regExp,getEscaped)};exports.getStrEscaped=getStrEscaped; //# sourceMappingURL=index.cjs.map