Nodejs HTML Escape escapeHTML()

Here you can find the source of escapeHTML()

Method Source Code

/**/* w w w. j ava 2 s  . c o m*/
@Name: String.prototype.escapeHTML
@Author: Paul Visco
@Version: 1.0 11/19/07
@Description: Checks to see if a string is empty or not
@Return: Escapes < and >
@Example:
var str = '<p>hello</p>';
var newString = str.escapeHTML();
//newString = '&lt;p&gt;hello&lt;/p&gt;'
*/
String.prototype.escapeHTML = function(){
   var str = this.replace(/</g, '&lt;');
   return str.replace(/>/g, '&gt;');
};

Related

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