Nodejs String Escape escapeSelector( find )

Here you can find the source of escapeSelector( find )

Method Source Code

/**/* www .  j ava  2 s .com*/
 * Utilities
 * ==========================================================================
 * @group  Chimplet
 * @author Locomotive
 */

// Escape a string for use in a CSS selector
String.prototype.escapeSelector = function( find )
{
   find = new RegExp( '([' + (find || '\[\]:') + '])' );
   return this.replace(find, '\\$1');
};

Array.prototype.powerSet = function()
{
   var i = 1,
       j = 0,
       sets = [],
       size = this.length,
       combination,
       combinationsCount = ( 1 << size );

   for ( i = 1; i < combinationsCount; i++ ) {
      combination = [];

      for ( j = 0; j < size; j++ ) {
         if ( ( i & ( 1 << j ) ) ){
            combination.push( this[ j ] );
         }
      }

      sets.push( combination );
   }

   return sets;
};

Related

  1. escapeCharacters(chars)
    String.prototype.escapeCharacters = function(chars) {
        var foundChar = false;
        var length = chars.length;
        for (var i = 0; i < length; ++i) {
            if (this.indexOf(chars.charAt(i)) !== -1) {
                foundChar = true;
                break;
        if (!foundChar)
            return this;
        var result = "";
        for (var j = 0; j < this.length; ++j) {
            if (chars.indexOf(this.charAt(j)) !== -1)
                result += "\\";
            result += this.charAt(j);
        return result;
    };
    
  2. escapeForRegExp()
    String.prototype.escapeForRegExp = function() {
        return this.escapeCharacters("^[]{}()\\.$*+?|");
    };
    
  3. escapeOnce()
    String.prototype.escapeOnce = function () {
      return this.replace(/"/g, '&quot;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/&(?!([a-zA-Z]+|#\d+);)/g, '&amp;');
    };
    
  4. escapeQuotes()
    String.prototype.escapeQuotes = function()
      var m = {"\"": "\\\"", "'": "\\'"};
      return String(this.replace("\\", "\\\\")).replace(/["']/g, function(s)
        return m[s];
      });
    
  5. escapeSecure()
    String.prototype.escapeSecure = function () {
      var returnStr, tmpStr;
      tmpStr = $(this);
      tmpStr.find("script").remove();
      returnStr = tmpStr.html();
      return returnStr;
    };
    
  6. escapeURL()
    String.prototype.escapeURL = function() {
      return escape(this)
    
  7. escaped()
    String.prototype.escaped = function () {
      return this.replace(/&/gim, "&amp;").replace(/</gim, "&lt;").replace(/>/gim, "&gt;").replace(/"/gim, "&quot;").replace(/'/gim, "&#39;");