Nodejs String Truncate truncate(length, truncation)

Here you can find the source of truncate(length, truncation)

Method Source Code

String.prototype.truncate = function(length, truncation) {
    length = length || 30;
    truncation = (typeof truncation == 'undefined') ? '…' : truncation;
    return this.length > length
        ? this.slice(0, length) + truncation
        : this;/*from www. j a v  a  2s .c  o m*/
};

Related

  1. truncate(length)
    String.prototype.truncate = function(length) {
      return this.substr(0, length - 1) + (this.length > length? '...' : '');
    
  2. truncate(length)
    String.prototype.truncate = function(length) {
      if (length == null) 
        length = 30;
      if (this.length > length) {
        content = this.substring(0, length);
        content += '?';
      } else {
        content = this  
      return content; 
    };
    var viewingMode;
    
  3. truncate(length)
    String.prototype.truncate = function(length) {
      length = typeof length !== 'undefined' ? length : 100;
      if (this.length > length) {
        var str = this.substring(0, length);
        str = str.substring(0, Math.min(str.length, str.lastIndexOf(" ")));
        str = str + " ...";
        return str;
      } else {
        return this;
    ...
    
  4. truncate(length, substitute)
    String.prototype.truncate = String.prototype.truncate || function (length, substitute) {
      return this.length > (length || 30) ? this.substr(0, (length || 30)).replace(/\s$/, '') + (substitute || '?') : this.toString()
    
  5. truncate(length, truncation)
    String.prototype.truncate = function(length, truncation) {
      length = length || 30;
      truncation = truncation === undefined ? '...' : truncation;
      return this.length > length ?
        this.slice(0, length - truncation.length) + truncation : String(this);
    };
    
  6. truncate(length, useWordBoundary)
    String.prototype.truncate = function(length, useWordBoundary) {
        var toLong = this.length > length,
        s_ = toLong ? this.substr(0, length - 1) : this;
        s_ = useWordBoundary && toLong ? s_.substr(0, s_.lastIndexOf(' ')) : s_;
        return toLong ? s_ + '…' : s_;
    };
    
  7. truncate(max_len, appender)
    'use strict';
    String.prototype.truncate = function(max_len, appender) {
      max_len  = max_len || 80;
      appender = appender || '...';
      if (appender.length >= max_len) {
        throw Error('appender length is greater or equal to max_len');
      if (this.length <= max_len) {
        return this;
    ...
    
  8. truncate(maxlength)
    String.prototype.truncate = function (maxlength) {
        if (!this) {
            return '';
        if (!maxlength) {
            maxlength = 20;
        return (this.length > maxlength) ? this.slice(0, maxlength - 3) + '...' : this;
    };
    ...
    
  9. truncate(n)
    String.prototype.truncate = function(n){
          return this.substr(0,n-1)+(this.length>n?'...':'');
    };