Nodejs String Sanitize sanitizeToId()

Here you can find the source of sanitizeToId()

Method Source Code

/**/*  w  w  w .  j a v  a 2s .c o  m*/
 * <p>From Ruby on Rails.</p>
 *
 * @see http://www.w3.org/TR/html4/types.html#type-name
 */
String.prototype.sanitizeToId = function () {
  return this.replace(/\]/g, '').replace(/[^-a-zA-Z0-9:.]/g, '_');
};

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() {
      return this
        .replace(/&/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;')
        .replace(/'/g, '&#39;')
    
  4. sanitize()
    String.prototype.sanitize = function () {
        var str = this.replace(/<[^>]*?>/g, '');
        return str;
    };
    
  5. sanitizeSpacing()
    "use strict";
    String.prototype.sanitizeSpacing = function () {
        return this
            .replace(/[\t\r\n\-]/g, ' ')  
            .replace(/  +/g, ' ')          
            .trim();                       
    };