Nodejs HTML Escape htmlEscape()

Here you can find the source of htmlEscape()

Method Source Code

String.prototype.htmlEscape = function (){
    var escapedStr = String(this).replace(/&/g, '&');
    escapedStr = escapedStr.replace(/\s/g, ' ');
    return escapedStr;
}

var text = 'This is for testing';
console.log(text);// w ww.j  ava 2s .c o  m
text = text.htmlEscape(); //because string is immutable type
console.log(text);

Related

  1. 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;
    ...
    
  2. escapelHTML()
    String.prototype.escapelHTML = function(){
        return String(this)
            .replace(/&/g, "&")
            .replace(/</g, "&lt;")
            .replace(/>/g, "&gt;")
            .replace(/"/g, "&quot;")
            .replace(/'/g, "&#039;")
            .replace(/\
    };
    ...
    
  3. htmlEscape()
    String.prototype.htmlEscape = function(){
        var span = document.createElement('span');
        var txt =  document.createTextNode('');
        span.appendChild(txt);
        txt.data = this;
        return span.innerHTML;
    };
    
  4. htmlEscape()
    String.prototype.htmlEscape = function () {
        return this.replace(/&/g, '%amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39');
    console.log('<script>'.htmlEscape());
    
  5. htmlEscape()
    String.prototype.htmlEscape = function() {
         return $('<div/>').text(this.toString()).html();
    };
    (function($) {
        $.fn.hasScrollBar = function() {
            if (this.height() < 0) {
                return false;
            return this.get(0).scrollHeight > this.height();
    ...
    
  6. htmlEscape()
    String.prototype.htmlEscape = function (){
      var escapedStr = String(this).replace(/&/g, '&amp;');
      escapedStr = escapedStr.replace(/</g, '&lt;');
      escapedStr = escapedStr.replace(/>/g, '&gt;');
      escapedStr = escapedStr.replace(/"/g, '&quot;');
      escapedStr = escapedStr.replace(/'/g, "&#39");
      return escapedStr;
    
  7. htmlEscape()
    String.prototype.htmlEscape = function() {
        return this.replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    console.log('<script>'.htmlEscape()); 
    
  8. htmlEscape()
    "use strict";
    String.prototype.htmlEscape = function()
      return this.
        replace(/&/g, '&amp;').
        replace(/</g, '&lt;').
        replace(/>/g, '&gt;').
        replace(/"/g, '&quot;').
        replace(/\n/g, '<br/>');
    ...
    
  9. htmlEscape()
    String.prototype.htmlEscape = function() {
      var obj = document.createElement('div');
      if (typeof obj.textContent != 'undefined') {
        obj.textContent = this;
      } else {
        obj.innerText = this;
      return obj.innerHTML;
    };
    ...