Nodejs HTML Escape escapeHtml()

Here you can find the source of escapeHtml()

Method Source Code

var entityMap = {
    '&': '&',
    '<': '&lt;',
    '>': '&gt;',
    '"': '&quot;',
    "'": '&#39;',
    '/': '&#x2F;'
};
String.prototype.escapeHtml = function() {
    return this.replace(/[&<>"'\/]/g, function (s) {
        return entityMap[s];
    });/* w ww  .j  a v  a 2s. c o  m*/
};

function getCookie(name) {
    var cookieStr = document.cookie;
    var cookieList = cookieStr.split('; ');
    for (var i = 0; i < cookieList.length; i++) {
        var cookie = cookieList[i].split('=');
        if (cookie[0] == name) {
            return decodeURI(cookie[1]);
        }
    }
    return '';
}

Related

  1. escapeHTML()
    String.prototype.escapeHTML = function() {
      return this.replace(/</g,'&lt;').replace(/>/g, '&gt;');
    };
    
  2. escapeHTML()
    String.prototype.escapeHTML = function() {
      return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
    };
    
  3. escapeHTML()
    var __entityMap = {
      "&": "&amp;",
      "<": "&lt;",
      ">": "&gt;",
      '"': '&quot;',
      "'": '&#39;',
      "/": '&#x2F;'
    };
    String.prototype.escapeHTML = function() {
    ...
    
  4. escapeHTML()
    String.prototype.escapeHTML = function () {
        return ('' + this).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
    }; 
    
  5. escapeHtml()
    String.prototype.escapeHtml = function() {
            return this
              .replace(/&/g, '&amp;')
                .replace(/"/g,  '&quot;')
                  .replace(/'/g,  '&#039;')
                    .replace(/</g,  '&lt;')
                      .replace(/>/g,  '&gt;');
    };
    
  6. escapeHtml()
    String.prototype.escapeHtml = String.prototype.escapeHtml || (String.prototype.escapeHtml = function() {
      return this.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
    });
    
  7. escape_html()
    String.prototype.escape_html = function() {
        return this.replace(/&/g, "&amp;")
                   .replace(/</g, "&lt;")
                   .replace(/>/g, "&gt;")
                   .replace(/"/g, "&quot;");
    
  8. escape_html()
    String.prototype.escape_html = function(){
      var span = document.createElement('span');
      var txt =  document.createTextNode('');
      span.appendChild(txt);
      txt.data = this;
      return span.innerHTML;
    };
    
  9. escape_html()
    String.prototype.escape_html = function(){
      var span = document.createElement('span');
      var txt =  document.createTextNode('');
      span.appendChild(txt);
      txt.data = this;
      return span.innerHTML;
    };
    var Notifer = new function(){
      var self = this;
    ...