Nodejs String Trim trim()

Here you can find the source of trim()

Method Source Code

function cutFixedNum(value,num){
   var value_str = "" + value;
   var index = value_str.indexOf('.');
   if (index!=-1){
      value_str = value_str.substring(0,index+num+1);
   }//  w  ww  .j ava 2  s. c  o  m
   return value_str;
}
//string trim
String.prototype.trim = function() 
{ 
   return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 
String.prototype.ltrim = function() 
{ 
   return this.replace(/(^\s*)/g, ""); 
} 
String.prototype.rtrim = function() 
{ 
   return this.replace(/(\s*$)/g, ""); 
} 

String.format = function(src){
    if (arguments.length == 0) return null;
    var args = Array.prototype.slice.call(arguments, 1);
    return src.replace(/\{(\d+)\}/g, function(m, i){
        return args[i];
    });
};

Related

  1. trim()
    $(document).ready(function(){
    });
    String.prototype.trim = function() {
        return this.replace(/(^\s*)|(\s*$)/g, '');
    
  2. trim()
    String.prototype.trim = function() {
      var x=this;
      x=x.replace(/^\s*(.*)/, "$1");
      x=x.replace(/(.*?)\s*$/, "$1");
      return x;
    
  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(){
      trimLeft = /^\s+/;
      trimRight = /\s+$/;
      return this.replace(trimLeft,"").replace(trimRight,"");
    };
    
  5. trim()
    String.prototype.trim = String.prototype.trim || (String.prototype.trim = function() {
      return this.replace(/^[ ]+|[ ]+$/g, "");
    });
    
  6. trim()
    var Person = function() {
        this.omdb_id
        this.name
        this.character
        this.job
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, '');
    };
    ...
    
  7. trim()
    String.prototype.trim = function() {
      return this.replace(/(^\s*)|(\s*$)/g, "");
    };
    String.prototype.trim = function() {
      var start = 0,
        end = this.length - 1,
        ws = /\s/;
      while (ws.test(this.charAt(start))) {
        start++;
    ...
    
  8. 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;
    
  9. 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;