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.lpad = function(padString, length) {
    var str = this;
    while (str.length < length)
        str = padString + str;/* w ww.j a  v  a2 s  .  c  o  m*/
    return str;
};

String.prototype.rpad = function(padString, length) {
   var str = this;
    while (str.length < length)
        str = str + padString;
    return str;
};

String.prototype.readLines = function(){
    return this.split(/\r\n|\r|\n/);
};

String.prototype.eachLine = function(fn){
    var arr = this.readLines();
    var result = "";
    for(var i = 0; i < arr.length; i++){
        result += fn(arr[i]);
    }
    return result;
};

String.prototype.wordWrap = function(length){
  return this;  
};

Related

  1. trim()
    'use strict';
    String.prototype.trim = function(){
        return this.replace(/(^\s*)|(\s*$)/g, "");
    
  2. trim()
    String.prototype.trim = function()
    return this.replace(/(^\s*)|(\s*$)/g, "");
    
  3. trim()
    String.prototype.trim = function(){
      var str = this.replace(/\s+/g,"")
      return this;
    
  4. trim()
    $(document).ready(function(){
    });
    String.prototype.trim = function() {
        return this.replace(/(^\s*)|(\s*$)/g, '');
    
  5. trim()
    String.prototype.trim = function() {
      var x=this;
      x=x.replace(/^\s*(.*)/, "$1");
      x=x.replace(/(.*?)\s*$/, "$1");
      return x;
    
  6. trim()
    String.prototype.trim=function(){
      trimLeft = /^\s+/;
      trimRight = /\s+$/;
      return this.replace(trimLeft,"").replace(trimRight,"");
    };
    
  7. trim()
    String.prototype.trim = String.prototype.trim || (String.prototype.trim = function() {
      return this.replace(/^[ ]+|[ ]+$/g, "");
    });
    
  8. trim()
    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);
      return value_str;
    String.prototype.trim = function() 
    ...
    
  9. trim()
    var Person = function() {
        this.omdb_id
        this.name
        this.character
        this.job
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, '');
    };
    ...