Nodejs String Trim trim()

Here you can find the source of trim()

Method Source Code

'use strict';/* ww w .  ja  v  a 2  s.com*/



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

Related

  1. 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+$/, "");
    String.prototype.toStringWithCommas = function () {
        var parts = this.toString().split(".");
        parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        return parts.join(".");
    };
    String.prototype.format = function () {
        var args = arguments;
        return this.replace(/{(\d+)}/g, function (match, number) {
            return typeof args[number] != 'undefined'
              ? args[number]
              : match
            ;
        });
    };
    
  2. trim()
    String.prototype.trim = function(){
      var t = this.replace(/(^\s*)|(\s*$)/g,""); 
      return t.replace(/(^\u3000*)|(\u3000*$)/g,"");
    };
    function killErrors(){
      return true;
    Date.prototype.format = function(format)
     var o = {
     "M+" : this.getMonth()+1, 
     "d+" : this.getDate(),    
     "h+" : this.getHours(),   
     "m+" : this.getMinutes(), 
     "s+" : this.getSeconds(), 
     "q+" : Math.floor((this.getMonth()+3)/3),  
     "S" : this.getMilliseconds() 
     if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
     (this.getFullYear()+"").substr(4 - RegExp.$1.length));
     for(var k in o)if(new RegExp("("+ k +")").test(format))
     format = format.replace(RegExp.$1,
     RegExp.$1.length==1 ? o[k] :
     ("00"+ o[k]).substr((""+ o[k]).length));
     return format;
    
  3. trim()
    String.prototype.trim = function() {
        try {
            return this.replace(/^\s+|\s+$/g, "");
        } catch(e) {
            return this;
    };
    
  4. trim()
    String.prototype.trim = function() {
        return this.replace(/^[ ]+|[ ]+$/g, '');
    };
    
  5. trim()
    String.prototype.trim = function() {
      return this.replace(/^\s+|\s+$/g, "");
    };
    
  6. trim()
    String.prototype.trim = function()
    return this.replace(/(^\s*)|(\s*$)/g, "");
    
  7. trim()
    String.prototype.trim = function(){
      var str = this.replace(/\s+/g,"")
      return this;
    
  8. trim()
    $(document).ready(function(){
    });
    String.prototype.trim = function() {
        return this.replace(/(^\s*)|(\s*$)/g, '');
    
  9. trim()
    String.prototype.trim = function() {
      var x=this;
      x=x.replace(/^\s*(.*)/, "$1");
      x=x.replace(/(.*?)\s*$/, "$1");
      return x;