@web3r/flowerkit
Version:
A collection of more than 60 often used utility JS functions that simplify frontend development.
13 lines (12 loc) • 659 B
JavaScript
import ow from"ow";
/**
* Gets a string with replaced special chars on their HTML entities.
* @param str{String} - source string
* @return {string}
* @example
* // How to escape special HTML characters?
* const str = "<b>Hello world & underworld!</b>";
* const escaped = getStrEscaped(str);
* console.log(escaped); // => "<b>Hello world & underworld!</b>"
*/const getStrEscaped=str=>{ow(str,ow.string);const symbols={"&":"&","<":"<",">":">",'"':""","'":"'"};const regExp=/[&<>"']/g;const getEscaped=char=>symbols[char];return str.replace(regExp,getEscaped)};export{getStrEscaped};
//# sourceMappingURL=index.js.map