Nodejs String Truncate trunc

Here you can find the source of trunc

Method Source Code

/**//from w ww. jav a  2  s . co m
 * Truncates string to n chars
 */
String.prototype.trunc = 
      function(n){
          return this.substr(0,n-1)+(this.length>n?'…':'');
      };

Related

  1. trunc
    String.prototype.trunc =
         function(n,useWordBoundary){
             var toLong = this.length>n,
                 s_ = toLong ? this.substr(0,n-1) : this;
             s_ = useWordBoundary && toLong ? s_.substr(0,s_.lastIndexOf(' ')) : s_;
             return  toLong ? s_ +'...' : s_;
          };
    
  2. trunc
    String.prototype.trunc =
        function( n, useWordBoundary ){
            var isTooLong = this.length > n,
                s_ = isTooLong ? this.substr(0,n-1) : this;
            s_ = (useWordBoundary && isTooLong) ? s_.substr(0,s_.lastIndexOf(' ')) : s_;
            return  isTooLong ? s_ + '…' : s_;
        };
    
  3. trunc
    String.prototype.trunc =
         function (n, useWordBoundary) {
             var toLong = this.length > n,
                 s_ = toLong ? this.substr(0, n - 1) : this;
             s_ = useWordBoundary && toLong ? s_.substr(0, s_.lastIndexOf(' ')) : s_;
             return toLong ? s_ + '...' : s_;
         };
    String.prototype.nl2br =
             function () {
    ...
    
  4. trunc()
    String.prototype.trunc = String.prototype.trunc ||
          function(n){
              return (this.length > n) ? this.substr(0,n-1)+'…' : this;
          };
    
  5. trunc()
    String.prototype.trunc = String.prototype.trunc ||
    function(n){
      return this.length>n ? this.substr(0,n-1)+'?' : this;
    };
    
  6. trunc()
    String.prototype.trunc = String.prototype.trunc ||
      function(n){
          return this.length>n ? this.substr(0,n-1)+'...' : this;
      };