Nodejs Utililty Methods HTML Escape

List of utility methods to do HTML Escape

Description

The list of methods to do HTML Escape are organized into topic(s).

Method

escapeHTML()
String.prototype.escapeHTML = function() {
  return this.
    replace(/&/g, "&").
    replace(/</g, "&lt;").
    replace(/>/g, "&gt;").
    replace(/\"/g, "&quot;");
};
console.log("<&>".escapeHTML()); 
escapeHTML()
String.prototype.escapeHTML = function(){
  var str = this.replace(/</g, '&lt;');
  return str.replace(/>/g, '&gt;');
};
escapeHTML()
String.prototype.escapeHTML = function()
  var m = {"&": "&amp;", "<": "&lt;", ">": "&gt;", '"': '&quot;', "'": '&#39;', "/": '&#x2F;'};
  return String(this).replace(/[&<>"'\/]/g, function(s)
    return m[s];
  });
escapeHTML()
String.prototype.escapeHTML = function () {
  return(this.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;'));                                                 
};
escapeHTML()
var __entityMap = {
  "&": "&amp;",
  "<": "&lt;",
  ">": "&gt;",
  '"': '&quot;',
  "'": '&#39;',
  "/": '&#x2F;'
};
String.prototype.escapeHTML = function() {
...
escapeHTML()
String.prototype.escapeHTML = function() {
  return this.replace(/</g,'&lt;').replace(/>/g, '&gt;');
};
escapeHTML()
String.prototype.escapeHTML = function() {
  return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
};
escapeHTML()
var __entityMap = {
  "&": "&amp;",
  "<": "&lt;",
  ">": "&gt;",
  '"': '&quot;',
  "'": '&#39;',
  "/": '&#x2F;'
};
String.prototype.escapeHTML = function() {
...
escapeHTML()
String.prototype.escapeHTML = function () {
    return ('' + this).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
}; 
escapeHtml()
String.prototype.escapeHtml = function() {
        return this
          .replace(/&/g, '&amp;')
            .replace(/"/g,  '&quot;')
              .replace(/'/g,  '&#039;')
                .replace(/</g,  '&lt;')
                  .replace(/>/g,  '&gt;');
};