@squirrel-forge/ui-util
Version:
A collection of utilities, classes, functions and abstracts made for the browser and babel compatible.
10 lines (9 loc) • 326 B
JavaScript
/**
* Escape html special chars
* @param {string} text - String to escape
* @return {string} - Escaped html string
*/
export function escapeHTML( text ) {
const map = { '&' : '&', '<' : '<', '>' : '>', '"' : '"', "'" : ''' };
return text.replace( /[&<>"']/g, ( m ) => { return map[ m ]; } );
}