everyutil
Version:
A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.
14 lines (13 loc) • 416 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.htmlEscape = void 0;
/**
* Escapes HTML entities in a string.
* @author @dailker
* @param {string} str
* @returns {string}
*/
function htmlEscape(str) {
return str.replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', '\'': ''' }[c] ?? c));
}
exports.htmlEscape = htmlEscape;