Nodejs String Trim trim()

Here you can find the source of trim()

Method Source Code

/**/*from  w  ww. ja va2  s .c  o m*/
 * <p>Static function that is used to trim the white spaces from the beginning and end of the string.</p>
 * @static
 * @function
 * @return {<a href="http://www.w3schools.com/jsref/jsref_obj_string.asp">String</a>} The value of the string after it has been trimmed.
 * @author <a href="mailto:pouncilt.developer@gmail.com">Tont&eacute; Pouncil</a>
*/
String.prototype.trim = function () {
   "use strict";
   return this.replace(/^\s+|\s+$/g, '');
};

Related

  1. trim()
    String.prototype.trim=function()
      return this.replace(/(\s*$)|(^\s*)/g, "");
    
  2. trim()
    String.prototype.trim = function()
        return this.replace(/^\s+/g, '').replace(/\s+$/g, '');
    };
    
  3. trim()
    String.prototype.trim = function() {
      var str = this.replace(/^\s+/, '');
      for (var i = str.length - 1; i >= 0; i--) {
        if (/\S/.test(str.charAt(i))) {
          str = str.substring(0, i + 1);
          break;
      return str;
    ...
    
  4. trim()
    String.prototype.trim = function() {
        return this.replace(/(^\s+)|(\s+$)/g, "");
    
  5. trim()
    String.prototype.trim = function() {
      a = this.replace(/^\s+/, '');
      return a.replace(/\s+$/, '');
    };
    
  6. trim()
    String.prototype.trim = function() {
      var re = /^\s+|\s+$/g;
      return this.replace(re, "");
    
  7. trim()
    String._trimRE = new RegExp().compile(/^\s+|\s+$/g);
    String.prototype.trim = function()
      return this.replace(String._trimRE, "");
    
  8. trim()
    String.prototype.trim = function() {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    };
    
  9. trim()
    console.log("'" + " a ".trim() + "'");
    String.prototype.trim = function(){
      return this.replace(/^\s+|\s+$/g, '');
    };    
    console.log("'" + " b ".trim() + "'");