Nodejs String Sanitize sanitize()

Here you can find the source of sanitize()

Method Source Code

String.prototype.sanitize = function() {
  return this/* w  ww.  j  av a2s .c o  m*/
    .replace(/&/g, '&')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#39;')
}

Related

  1. sanitize()
    String.prototype.sanitize = function() {
        return $('<div/>').text(this).html();
    };
    
  2. sanitize()
    String.prototype.sanitize = function(){
        return this.replace(/</g, '&lt;').replace(/>/g, '&gt;');
    
  3. sanitize()
    String.prototype.sanitize = function () {
        var str = this.replace(/<[^>]*?>/g, '');
        return str;
    };
    
  4. sanitizeSpacing()
    "use strict";
    String.prototype.sanitizeSpacing = function () {
        return this
            .replace(/[\t\r\n\-]/g, ' ')  
            .replace(/  +/g, ' ')          
            .trim();                       
    };
    
  5. sanitizeToId()
    String.prototype.sanitizeToId = function () {
      return this.replace(/\]/g, '').replace(/[^-a-zA-Z0-9:.]/g, '_');
    };