Nodejs String Trim trim(ch)

Here you can find the source of trim(ch)

Method Source Code

String.prototype.trim = function(ch) {
    var r = new RegExp("^{0}+|{0}+$".format(ch || "\\s"), "g");
    return this.replace(r, "");
};

Related

  1. trim()
    String.prototype.trim = function(){
      var whitespace  = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
      var l      = 0;
      var i      = 0;
      var str      = this + '';
      l = str.length;
      for(i = 0; i < l; i++){
        if(whitespace.indexOf(str.charAt(i)) === -1){
          str = str.substring(i);
    ...
    
  2. trim()
    String.prototype.trim = function() {
        return this.replace(/^\s+/g,"").replace(/\s+$/g,"");
    };
    
  3. trim(c)
    String.prototype.trim = function (c) {
        if (c) {
            var r = new RegExp('(^' + c + ')|(' + c + '$)', 'g');
            return this.replace(r, '');
        } else {
            return this.replace(/^\s+|\s+$/g,'');
    };
    String.prototype.capitalize = function() {
    ...
    
  4. trim(c, t)
    String.prototype.trim = function(c, t){
      return c = "[" + (c == undefined ? " " : c.replace(/([\^\]\\-])/g, "\\\$1")) + "]+",
      this.replace(new RegExp((t != 2 ? "^" : "") + c + (t != 1 ? "|" + c + "$" : ""), "g"), "");
    };
    
  5. trim(c, t)
    String.prototype.trim = function(c, t){
      return c = "[" + (c == undefined ? " " : c.replace(/([\^\]\\-])/g, "\\\$1")) + "]+",
      this.replace(new RegExp((t != 2 ? "^" : "") + c + (t != 1 ? "|" + c + "$" : ""), "g"), "");
    };
    
  6. trim(character)
    String.prototype.trim = function (character) {
      return this.trimLeft(character).trimRight(character);
    };
    
  7. trim(charlist)
    'use strict';
    String.prototype.trim = function (charlist) {
      return this.ltrim(charlist).rtrim(charlist);
    };
    
  8. trim(chars)
    String.prototype.trim = function(chars) {
      return this.replace(new RegExp('^[' + (chars || '\\s') + ']+|[' + (chars || '\\s') + ']+$', 'g'), '');
    };
    
  9. trim(fag='default')
    String.prototype.trim = function (fag='default'){
      const preg_arr = {'default':/(^\s*)|(\s*$)/,'left':/(^\s*)/,'right':/(\s*$)/};
      switch(fag){
        case 'left':
          return this.replace(preg_arr.left,'');
        break;
        case 'right':
          return this.replace(preg_arr.right,'');
        break;
    ...