Nodejs String Trim trim()

Here you can find the source of trim()

Method Source Code

// To trim the string in JS..
// create the prototype on the String object
String.prototype.trim = function()
{
   // skip leading and trailing whitespace
   // and return everything in between
   var x=this;//from   w  ww  .  j ava 2  s  .c  o  m
   x=x.replace(/^\s*(.*)/, "$1");
   x=x.replace(/(.*?)\s*$/, "$1");
   return x;
}

Related

  1. trim()
    String.prototype.trim = function () {
      "use strict";
      return this.replace(/^\s+|\s+$/g, '');
    };
    
  2. trim()
    String.prototype.trim = function() {
      var re = /^\s+|\s+$/g;
      return this.replace(re, "");
    
  3. trim()
    String._trimRE = new RegExp().compile(/^\s+|\s+$/g);
    String.prototype.trim = function()
      return this.replace(String._trimRE, "");
    
  4. trim()
    String.prototype.trim = function() {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    };
    
  5. trim()
    console.log("'" + " a ".trim() + "'");
    String.prototype.trim = function(){
      return this.replace(/^\s+|\s+$/g, '');
    };    
    console.log("'" + " b ".trim() + "'");
    
  6. trim()
    var Firefox = (document.getElementById && !document.all);
    var MSIE = (-1 != navigator.userAgent.indexOf('MSIE'));
    String.prototype.trim=function(){
      return this.replace(/^\s+|\s+$/g,"");
    };
    function Redirect(url)
      parent.location=url;
    var Submitted = 0;
    function OnSubmit(form)
      if (Submitted) {
        return false;
      Submitted = 1;
      return true;
    
  7. trim()
    String.prototype.trim = function(){ 
      return this.rTrim(this.lTrim());
    
  8. trim()
    String.prototype.trim = String.prototype.trim || function () {
      const
        str = this.replace(/^\s\s*/, '');
      let
        i = str.length;
      for (let rgxp = /\s/; rgxp.test(str.charAt(--i));) {
      return str.substring(0, i + 1);
    };
    ...
    
  9. trim()
    'use strict';
    Array.isArray = Array.isArray || function (obj) {
      return {}.call(obj) === '[object Array]';
    };
    String.prototype.trim = String.prototype.trim || function () {
      const
        str = this.replace(/^\s\s*/, '');
      let
        i = str.length;
    ...