Ensure _.truncate doesn't truncate strings if they are equal to the given length.

This commit is contained in:
John-David Dalton
2014-03-10 01:11:08 -07:00
parent 4eaf91c3dc
commit 05dce760d6
5 changed files with 5 additions and 5 deletions

2
dist/lodash.min.js vendored
View File

@@ -56,7 +56,7 @@ return u},u.toArray=function(n){return n&&typeof n.length=="number"?Wt(n):hr(n)}
var e=n.length;return e<t?(e=(t-e)/2,t=qr(e),e=zr(e),r=kt("",e,r),r.slice(0,t)+n+r):n},u.padLeft=function(n,t,r){return n=null==n?"":Rr(n),kt(n,t,r)+n},u.padRight=function(n,t,r){return n=null==n?"":Rr(n),n+kt(n,t,r)},u.parseInt=Ne,u.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=ae(),ue(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):dt(n,t)},u.reduce=Yt,u.reduceRight=Zt,u.repeat=vr,u.result=function(n,t,r){var e=null==n?b:n[t];
return typeof e=="undefined"?r:ir(e)?n[t]():e},u.runInContext=d,u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ke(n).length},u.some=Ht,u.sortedIndex=Ft,u.snakeCase=Oe,u.startsWith=function(n,t,r){return n=null==n?"":Rr(n),r=typeof r=="number"?ue(ee(r,0),n.length):0,n.lastIndexOf(t,r)==r},u.template=function(n,t,r){var e=u.templateSettings;r=rr({},r,e),n=Rr(null==n?"":n);var o,i,a=rr({},r.imports,e.imports),e=ke(a),a=hr(a),f=0,l=r.interpolate||U,c="__p+='",l=Er((r.escape||U).source+"|"+l.source+"|"+(l===$?D:U).source+"|"+(r.evaluate||U).source+"|$","g");
n.replace(l,function(t,r,e,u,a,l){return e||(e=u),c+=n.slice(f,l).replace(M,p),r&&(o=true,c+="'+__e("+r+")+'"),a&&(i=true,c+="';"+a+";\n__p+='"),e&&(c+="'+((__t=("+e+"))==null?'':__t)+'"),f=l+t.length,t}),c+="';",(r=r.variable)||(c="with(obj){"+c+"}"),c=(i?c.replace(E,""):c).replace(R,"$1").replace(N,"$1;"),c="function("+(r||"obj")+"){"+(r?"":"obj||(obj={});")+"var __t,__p=''"+(o?",__e=_.escape":"")+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var s=Cr(e,"return "+c).apply(b,a)
}catch(h){throw h.source=c,h}return t?s(t):(s.source=c,s)},u.trim=Ae,u.trimLeft=Ie,u.trimRight=Ee,u.truncate=function(n,t){var r=30,e="...";if(t&&ar(t))var u="separator"in t?t.separator:u,r="length"in t?+t.length||0:r,e="omission"in t?Rr(t.omission):e;else null!=t&&(r=+t||0);if(n=null==n?"":Rr(n),r>n.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(lr(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=Er(u.source,(L.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(f);)a=i.index;
}catch(h){throw h.source=c,h}return t?s(t):(s.source=c,s)},u.trim=Ae,u.trimLeft=Ie,u.trimRight=Ee,u.truncate=function(n,t){var r=30,e="...";if(t&&ar(t))var u="separator"in t?t.separator:u,r="length"in t?+t.length||0:r,e="omission"in t?Rr(t.omission):e;else null!=t&&(r=+t||0);if(n=null==n?"":Rr(n),r>=n.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(lr(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=Er(u.source,(L.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(f);)a=i.index;
r=r.slice(0,null==a?o:a)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1<u&&(r=r.slice(0,u)));return r+e},u.unescape=function(n){return null==n?"":(n=Rr(n),0>n.indexOf(";")?n:n.replace(S,m))},u.uniqueId=function(n){var t=++I;return Rr(null==n?"":n)+t},u.all=qt,u.any=Ht,u.detect=Pt,u.findWhere=Pt,u.foldl=Yt,u.foldr=Zt,u.include=Bt,u.inject=Yt,br(function(){var n={};return gt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Et,u.last=St,u.sample=function(n,t,r){return n&&typeof n.length!="number"&&(n=hr(n)),null==t||r?n?n[dt(0,n.length-1)]:b:(n=Gt(n),n.length=ue(ee(0,t),n.length),n)
},u.take=Et,u.takeRight=St,u.takeRightWhile=St,u.takeWhile=Et,u.head=Et,gt(u,function(n,t){var r="sample"!==t;u.prototype[t]||(u.prototype[t]=function(t,e){var u=this.__chain__,i=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new o(i,u):i})}),u.VERSION=O,u.prototype.chain=function(){return this.__chain__=true,this},u.prototype.toString=function(){return Rr(this.__wrapped__)},u.prototype.value=zt,u.prototype.valueOf=zt,ft(["join","pop","shift"],function(n){var t=Sr[n];u.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments);
return n?new o(r,n):r}}),ft(["push","reverse","sort","unshift"],function(n){var t=Sr[n];u.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),ft(["concat","splice"],function(n){var t=Sr[n];u.prototype[n]=function(){return new o(t.apply(this.__wrapped__,arguments),this.__chain__)}}),u}var b,_=1,w=2,x=4,k=8,j=16,C=32,O="2.4.1",A="__lodash@"+O+"__",I=0,E=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,S=/&(?:amp|lt|gt|quot|#39);/g,T=/[&<>"']/g,W=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,z=/^\s*function[ \n\r\t]+\w/,B=/^0[xX]/,q=/[\xC0-\xFF]/g,U=/($^)/,P=/[.*+?^${}()|[\]\\]/g,K=/\bthis\b/,M=/['\n\r\t\u2028\u2029\\]/g,V=/[a-zA-Z0-9][a-z0-9]*/g,X=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",Y="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Z="[object Arguments]",G="[object Array]",H="[object Boolean]",J="[object Date]",Q="[object Function]",nt="[object Number]",tt="[object Object]",rt="[object RegExp]",et="[object String]",ut={};