Nodejs String Truncate truncar(number,cadena)

Here you can find the source of truncar(number,cadena)

Method Source Code

String.prototype.truncar = function(number,cadena) {
   if(number < 0)
      return this;
   if(cadena){/*from w  w w  .j a  v a2s  .  c  o m*/
      return this.substr(0,number)+cadena;
   }
   return this.substr(0,number);
}

Related

  1. trunc(n,useWordBoundary)
    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(n,useWordBoundary)
    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_ + '&hellip;' : s_;
    };
    String.prototype.startsWith = function (str){
        return this.slice(0, str.length) == str;
    };
    ...
    
  3. trunc()
    String.prototype.trunc = String.prototype.trunc ||
      function(n){
        return this.length > n ? this.substr(0,n-1) + "\u2026" : this;
      };
    
  4. trunc()
    String.prototype.trunc = String.prototype.trunc ||
        function(n){
            return (this.length > n) ? this.substr(0, n-1) + '&hellip;' : this;
        };
    
  5. trunc()
    String.prototype.trunc = String.prototype.trunc ||
      function(n){
        return this.length>n ? this.substr(0,n-1)+'&hellip;' : this;
    };
    
  6. truncate( length, char )
    String.prototype.truncate = function ( length, char ) {
      var _length = length || 18;
      return this.length > _length ? this.substring( 0, _length ).replace( /\s+$/g, '' ) + ( char || '?' ) : this;
    
  7. truncate()
    String.prototype.truncate = function(){
        var re = this.match(/^.{0,50}[\S]*/);
        var l = re[0].length;
        var re = re[0].replace(/\s$/,'');
        if(l < this.length)
            re = re + "...";
        return re;
    
  8. truncate(capLength)
    String.prototype.truncate = function(capLength){
      var trunc = '..';
      var output = this;
      if(typeof capLength !== 'number'){
        console.log('Arg must be a number type. No truncation made.');
        return output;
      if(output.length > capLength){
          if(output[capLength-1] === ' '){ 
    ...
    
  9. truncate(len = 50)
    String.prototype.truncate = function(len = 50){
      var regx = new RegExp('^.{0,'+ len +'}[\S]*')
      var matches_array = this.match(regx);
      var str_length = matches_array[0].length;
      var replacement = matches_array[0].replace(/\s$/,'');
      return ((str_length > this.length) ? (replacement) : (replacement + "...") )