Nodejs String Trim trim()

Here you can find the source of trim()

Method Source Code

String.prototype.trim=function()
{
  return this.replace(/^\s+|\s+$/g, '');
}

String.prototype.ltrim=function()
{
  return this.replace(/^\s+/,'');
}

String.prototype.rtrim=function()
{
  return this.replace(/\s+$/,'');
}

String.prototype.fulltrim=function()
{
  return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');
}

String.prototype.startwith=function(str)
{ 
  return this.substring(0, str.length) == str;
}

String.prototype.endswith=function(str)
{
  return this.substring(this.length - str.length, this.length) == str;
}

// ===========================================================================
Array.prototype.contains = function (item) 
{
  for (var i=0; i<this.length; ++i)
    if (this[i] == item)
      return true;
  return false;/*w  w w .  ja v  a2  s  . c om*/
};

Related

  1. trim()
    String.prototype.trim = function () {
        var str = this.replace( /^\s\s*/, '' ),
            ws = /\s/,
            i = str.length;
        while ( ws.test( str.charAt( i -= 1 ) ) ) {}
        return str.slice( 0, i + 1 );
    };
    
  2. trim()
    String.prototype.trim = function () {
        var str = this.replace( /^\s\s*/, '' ),
            ws = /\s/,
            i = str.length;
        while ( ws.test( str.charAt( i -= 1 ) ) ) {}
        return str.slice( 0, i + 1 );
    };
    
  3. trim()
    String.prototype.trim = function () {
        return this.replace(/^\s+|\s+$/g,'');
    };
    String.prototype.ltrim = function() {
        return this.replace(/^\s+/,'');
    };
    String.prototype.rtrim = function() {
        return this.replace(/\s+$/,'');
    };
    ...
    
  4. trim()
    String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
    function isProbablyUrl(string) {
      var substr = string.substring(0,4).toLowerCase();
      if (substr == 'ftp:' || substr == 'www.') return true;
      var substr = string.substring(0,5).toLowerCase();
      if (substr == 'http:') return true;
      var substr = string.substring(0,6).toLowerCase();
      if (substr == 'https:') return true;
      var substr = string.substring(0,7).toLowerCase();
    ...
    
  5. trim()
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, "");
    
  6. trim()
    String.prototype.trim = function() {
      this.replace(/(^\s*)|(\s*$)/gi,'');
      this.replace(/[ ]{2,}/gi,' ');
      this.replace(/\n /,'\n');
      return this;
    };
    
  7. trim()
    String.prototype.trim = function(){
      var start,end;
      start=0;
      end=this.length-1;
      while(start<=end && this.charAt(start)==' '){
        start++;
      while(start<=end && this.charAt(end)==" "){
        end--;
    ...
    
  8. trim()
    Array.isArray = Array.isArray || function (obj) {
      return toString.call(obj) === '[object Array]';
    };
    String.prototype.trim = String.prototype.trim || function () {
      var str = this.replace(/^\s\s*/, ''),
        i = str.length;
      for (let rgxp = /\s/; rgxp.test(str.charAt(--i));) {}
      return str.substring(0, i + 1);
    };
    ...
    
  9. trim()
    String.prototype.trim = function() {
      return this.replace(/^\s+|\s+$/g,"");