Nodejs String Truncate trunc()

Here you can find the source of trunc()

Method Source Code

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.//from w  w  w. j  av  a2  s.c  o  m
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require_tree ../../../vendor/assets/javascripts/
//= require script-gun
//= require_tree .


// Patching String pro. for truncation of long mechanic names
String.prototype.trunc = String.prototype.trunc ||
  function(n){
      return this.length>n ? this.substr(0,n-1)+'...' : this;
  };

Related

  1. 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_;
        };
    
  2. trunc
    String.prototype.trunc = 
          function(n){
              return this.substr(0,n-1)+(this.length>n?'…':'');
          };
    
  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(len,suffix)
    String.prototype.trunc = function(len,suffix) {
        return this.length > len ? this.slice(0, len) + (suffix||'…') : this;
    };
    
  7. trunc(len,suffix)
    String.prototype.trunc = String.prototype.trunc || function(len,suffix) {
        return this.length > len ? this.slice(0, len) + (suffix||'…') : this;
    };
    
  8. trunc(length, options)
    String.prototype.trunc = function(length, options) {
        var defaults = Ext.Object.merge({omission: "..."}, options || {});
        var stop = length - defaults.omission.length;
        return (this.length > length ? this.substring(0, stop) + defaults.omission : this).toString();
    };
    
  9. trunc(n)
    String.prototype.trunc = function(n) {
      'use strict';
      return this.length > n ? this.substr(0, n-1) + '...' : this;
    };