Nodejs HTML Escape escapeHTML()

Here you can find the source of escapeHTML()

Method Source Code

/**/*  ww  w.  java  2  s.c  om*/
 * Javascript String escapeHTML function add
 * @return String
 */
String.prototype.escapeHTML = function() {
   return this.replace(/</g,'&lt;').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 str = this.replace(/</g, '&lt;');
      return str.replace(/>/g, '&gt;');
    };
    
  3. escapeHTML()
    String.prototype.escapeHTML = function()
      var m = {"&": "&amp;", "<": "&lt;", ">": "&gt;", '"': '&quot;', "'": '&#39;', "/": '&#x2F;'};
      return String(this).replace(/[&<>"'\/]/g, function(s)
        return m[s];
      });
    
  4. escapeHTML()
    String.prototype.escapeHTML = function () {
      return(this.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;'));                                                 
    };
    
  5. escapeHTML()
    var __entityMap = {
      "&": "&amp;",
      "<": "&lt;",
      ">": "&gt;",
      '"': '&quot;',
      "'": '&#39;',
      "/": '&#x2F;'
    };
    String.prototype.escapeHTML = function() {
    ...
    
  6. escapeHTML()
    String.prototype.escapeHTML = function() {
      return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
    };
    
  7. escapeHTML()
    var __entityMap = {
      "&": "&amp;",
      "<": "&lt;",
      ">": "&gt;",
      '"': '&quot;',
      "'": '&#39;',
      "/": '&#x2F;'
    };
    String.prototype.escapeHTML = function() {
    ...
    
  8. escapeHTML()
    String.prototype.escapeHTML = function () {
        return ('' + this).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
    }; 
    
  9. escapeHtml()
    String.prototype.escapeHtml = function() {
            return this
              .replace(/&/g, '&amp;')
                .replace(/"/g,  '&quot;')
                  .replace(/'/g,  '&#039;')
                    .replace(/</g,  '&lt;')
                      .replace(/>/g,  '&gt;');
    };