Nodejs String Trim trimToPx(length)

Here you can find the source of trimToPx(length)

Method Source Code

String.prototype.trimToPx = function(length)
{
    var tmp = this;
    var trimmed = this;
    if (tmp.visualLength() > length)
    {/*  w w w .  j  av a 2 s  .  c  o  m*/
        trimmed += "...";
        while (trimmed.visualLength() > length)
        {
            tmp = tmp.substring(0, tmp.length-1);
            trimmed = tmp + "...";
        }
    }
     
    return trimmed;
}

Related

  1. trimString_trim()
    String.prototype.trim = function String_trim()
      this.replace(/^\s+/m, '').replace(/\s+$/m, '');
    
  2. 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);
    ...
    
  3. trimToLength(m)
    String.prototype.trimToLength = function(m) {
      return (this.length > m) 
        ? jQuery.trim(this).substring(0, m).split(" ").slice(0, -1).join(" ") + "..."
        : this;
    };
    
  4. trimToLength(m)
    String.prototype.trimToLength = function(m) {
      return (this.length > m) 
        ? jQuery.trim(this).substring(0, m).split(" ").slice(0, -1).join(" ") + "..."
        : this;
    };
    
  5. trimToLength(m)
    String.prototype.trimToLength = function(m) {
      return (this.length > m) ? jQuery.trim(this).substring(0, m).split(' ').slice(0, -1).join(' ') : this.replace('"', '');
    };
    
  6. trimTrailZeroes()
    String.prototype.trimTrailZeroes = function() {
        return this.replace(/(.\d*?)0+$/, "$1").replace(/\.$/, "");
    };
    
  7. trim_(str)
    var trim_ = function (str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    };
    
  8. trimfast()
    String.prototype.trimfast = function() {
      var  str = this.replace(/^\s\s*/, ''),
        ws = /\s/,
        i = this.length;
      while (ws.test(this.charAt(--i)));
      return str.slice(0, i + 1);
    };
    (function($){
      $.fn.trimval = function() {
    ...
    
  9. trimj()
    String.prototype.trim  = jCube.String.trim  = function () {
      return this.replace( /^\s+|\s+$|^\n+|\n+$|^\t+|\t+$/g, "");