Nodejs String Trim trim()

Here you can find the source of trim()

Method Source Code

// add string trim function
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();
   if (substr == 'chrome:') return true;

   return false;/*from  w ww . ja v a 2s.  co m*/
}

function openList(list) {
   var strings = list.split(/\r\n|\r|\n/);

   for (var i=0; i<strings.length; i++) {
      // check empty
      strings[i] = strings[i].trim();
      if (strings[i] == '') continue;

      var url = strings[i];

      if (!isProbablyUrl(url)) {
         // if it looks like a URL we'll open it, otherwise we will do a Google search on it
         url = 'http://www.google.com/search?q=' + encodeURI(url);
      }

      //open the new tab
      chrome.tabs.create({'url':url,'selected':false});
   }
}

Related

  1. trim()
    String.prototype.trim = function()
        var res = this;
        while (res.substring(0, 1) == " ") {
            res = res.substring(1, res.length);
        while (res.substring(res.length - 1, res.length) == " ") {
            res = res.substring(0, res.length - 1);
        return res;
    
  2. trim()
    String.prototype.trim = function () {
      return this .replace(/^\s\s*/, '' ).replace(/\s\s*$/, '' );
    function isEmpty(str){
      if(str == null || str== undefined || str.trim().length == 0)
        return true;
      else
        return false;
    
  3. 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 );
    };
    
  4. 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 );
    };
    
  5. 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+$/,'');
    };
    ...
    
  6. trim()
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, "");
    
  7. trim()
    String.prototype.trim=function()
      return this.replace(/^\s+|\s+$/g, '');
    String.prototype.ltrim=function()
      return this.replace(/^\s+/,'');
    String.prototype.rtrim=function()
    ...
    
  8. trim()
    String.prototype.trim = function() {
      this.replace(/(^\s*)|(\s*$)/gi,'');
      this.replace(/[ ]{2,}/gi,' ');
      this.replace(/\n /,'\n');
      return this;
    };
    
  9. 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--;
    ...