Nodejs String Trim trimToLength(m)

Here you can find the source of trimToLength(m)

Method Source Code

// method to truncate text in react component
String.prototype.trimToLength = function(m) {
  return (this.length > m) 
    ? jQuery.trim(this).substring(0, m).split(" ").slice(0, -1).join(" ") + "..."
    : this;//w  w  w  .  j a  v  a  2  s .c o  m
};

Related

  1. trimStart(c)
    String.prototype.trimStart=function(c)
        c = c?c:' ';
        var i=0;
        for(;i<this.length && this.charAt(i)==c; i++);
        return this.substring(i);
    
  2. trimStart(s)
    String.prototype.trimStart = function(s) {
        return this.replace(new RegExp("^" + s + "+", "gm"), "");
    
  3. trimString_trim()
    String.prototype.trim = function String_trim()
      this.replace(/^\s+/m, '').replace(/\s+$/m, '');
    
  4. trimTailChars(c)
    String.prototype.trimTailChars = function(c){
      var idx, len = this.length;
      var tmp = this;
      while(len--){
        idx = tmp.lastIndexOf(c);
        if(idx == -1) {
          break;
        tmp = tmp.substring(0,idx);
    ...
    
  5. trimToLength(m)
    String.prototype.trimToLength = function(m) {
      return (this.length > m) 
        ? jQuery.trim(this).substring(0, m).split(" ").slice(0, -1).join(" ") + "..."
        : this;
    };
    
  6. trimToLength(m)
    String.prototype.trimToLength = function(m) {
      return (this.length > m) ? jQuery.trim(this).substring(0, m).split(' ').slice(0, -1).join(' ') : this.replace('"', '');
    };
    
  7. 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;
    
  8. trimTrailZeroes()
    String.prototype.trimTrailZeroes = function() {
        return this.replace(/(.\d*?)0+$/, "$1").replace(/\.$/, "");
    };
    
  9. trim_(str)
    var trim_ = function (str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    };