Nodejs String Trim trimfast()

Here you can find the source of trimfast()

Method Source Code

/*//w w  w  .j  a  v a  2  s  .  com
 * super-fast javascript trim based on http://blog.stevenlevithan.com/archives/faster-trim-javascript
 */

// prototype in our new trim method (named differently to not offend others relying on native version)
String.prototype.trimfast = function() {
   var   str = this.replace(/^\s\s*/, ''),
      ws = /\s/,
      i = this.length;
   while (ws.test(this.charAt(--i)));
   return str.slice(0, i + 1);
};

// jQuery extension to get the value, trim and return it (often useful for forms)
(function($){
  $.fn.trimval = function() {
    return this.val().trimfast();
  };
})(jQuery);

Related

  1. trimToLength(m)
    String.prototype.trimToLength = function(m) {
      return (this.length > m) 
        ? jQuery.trim(this).substring(0, m).split(" ").slice(0, -1).join(" ") + "..."
        : this;
    };
    
  2. trimToLength(m)
    String.prototype.trimToLength = function(m) {
      return (this.length > m) ? jQuery.trim(this).substring(0, m).split(' ').slice(0, -1).join(' ') : this.replace('"', '');
    };
    
  3. trimToPx(length)
    String.prototype.trimToPx = function(length)
        var tmp = this;
        var trimmed = this;
        if (tmp.visualLength() > length)
            trimmed += "...";
            while (trimmed.visualLength() > length)
                tmp = tmp.substring(0, tmp.length-1);
                trimmed = tmp + "...";
        return trimmed;
    
  4. trimTrailZeroes()
    String.prototype.trimTrailZeroes = function() {
        return this.replace(/(.\d*?)0+$/, "$1").replace(/\.$/, "");
    };
    
  5. trim_(str)
    var trim_ = function (str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    };
    
  6. trimj()
    String.prototype.trim  = jCube.String.trim  = function () {
      return this.replace( /^\s+|\s+$|^\n+|\n+$|^\t+|\t+$/g, "");
    
  7. Trim( aimStr )
    String.prototype.Trim = function( aimStr )
        var str = this;
        var re = My.RegExp.InvolvedCharsRegExp;
        var reStart, reEnd;
        if ( aimStr )
            aimStr = aimStr.replace( re, '\\$1' );
            reStart = new RegExp( '^(' + aimStr + ')+' );
    ...
    
  8. Trim()
    String.prototype.Trim = function(){
      return this.replace(/(^\s*)|(\s*$)/g, "");
    };
    
  9. Trim()
    String.prototype.Trim = function() {
      return this.lTrim().rTrim();
    };