Nodejs String Trim trim()

Here you can find the source of trim()

Method Source Code

/*!// w w w.  j a va2 s.c o  m
 * Inflector
 * Copyright(c) 2011 Vadim Demedes <sbioko@gmail.com>
 * MIT Licensed
 */

/**
 * Library version.
 */

exports.version = '0.0.1';

String.prototype.trim = function() { // not inflector, just helper for its libraries
   return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

Related

  1. trim()
    Array.isArray = Array.isArray || function (obj) {
      return toString.call(obj) === '[object Array]';
    };
    String.prototype.trim = String.prototype.trim || function () {
      var str = this.replace(/^\s\s*/, ''),
        i = str.length;
      for (let rgxp = /\s/; rgxp.test(str.charAt(--i));) {}
      return str.substring(0, i + 1);
    };
    ...
    
  2. trim()
    String.prototype.trim = function() {
      return this.replace(/^\s+|\s+$/g,"");
    
  3. trim()
    String.prototype.trim = function() {
      return this.replace(/\s/g, "");
    
  4. 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;
    
  5. trim()
    String.prototype.trim = function () {
        var start, end;
        start = 0;
        end = this.length - 1;
        while (start <= end && str.charAt(start) == ' ') {
            start++;
        while (start <= end && str.charAt(end) == ' ') {
            end--;
    ...
    
  6. trim()
    String.prototype.trim = function () {
      return this.replace(/^ +/, '').replace(/ +$/, '');
    };
    
  7. trim()
    String.prototype.trim = function() {
      return this.replace(/^\s+/, "").replace(/\s+$/, "");
    };
    
  8. trim()
    String.prototype.trim = function() {
        "use strict";
        return this.replace(/^\s+|\s+$/g,"");
    };
    
  9. 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;
    ...