@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
JavaScript
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>');
* // => "<b>Hello & "world"</b>"
*/const getStrEscaped=str=>{if(typeof str!=="string")throw new TypeError("getStrEscaped: str must be a string");const symbols={"&":"&","<":"<",">":">",'"':""","'":"'"};const regExp=/[&<>"']/g;const getEscaped=char=>symbols[char];return str.replace(regExp,getEscaped)};exports.getStrEscaped=getStrEscaped;
//# sourceMappingURL=index.cjs.map