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

View File

@@ -7543,7 +7543,7 @@
length = +options || 0;
}
string = string == null ? '' : String(string);
if (length > string.length) {
if (length >= string.length) {
return string;
}
var end = length - omission.length;

View File

@@ -60,7 +60,7 @@ e=typeof n;var u=typeof t;if(n===n&&(null==n||null==t||"function"!=e&&"object"!=
return-1},u.mixin=xr,u.noConflict=function(){return n._=Br,this},u.noop=Cr,u.now=Fe,u.pad=function(n,t,r){n=null==n?"":Lr(n),t=+t||0;var e=n.length;return e<t?(e=(t-e)/2,t=Vr(e),e=Kr(e),r=Ot("",e,r),r.slice(0,t)+n+r):n},u.padLeft=function(n,t,r){return n=null==n?"":Lr(n),Ot(n,t,r)+n},u.padRight=function(n,t,r){return n=null==n?"":Lr(n),n+Ot(n,t,r)},u.parseInt=Pe,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=he(),ce(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):wt(n,t)
},u.reduce=Ht,u.reduceRight=Jt,u.repeat=dr,u.result=function(n,t,r){var e=null==n?_:n[t];return typeof e=="undefined"?r:fr(e)?n[t]():e},u.runInContext=b,u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Se(n).length},u.some=nr,u.sortedIndex=$t,u.snakeCase=Ne,u.startsWith=function(n,t,r){return n=null==n?"":Lr(n),r=typeof r=="number"?ce(fe(r,0),n.length):0,n.lastIndexOf(t,r)==r},u.template=function(n,t,r){var e=u.templateSettings;r=or({},r,e),n=Lr(null==n?"":n);var o,a,i=or({},r.imports,e.imports),e=Se(i),i=yr(i),l=0,f=r.interpolate||U,c="__p+='",f=Tr((r.escape||U).source+"|"+f.source+"|"+(f===P?$:U).source+"|"+(r.evaluate||U).source+"|$","g");
n.replace(f,function(t,r,e,u,i,f){return e||(e=u),c+=n.slice(l,f).replace(V,s),r&&(o=true,c+="'+__e("+r+")+'"),i&&(a=true,c+="';"+i+";\n__p+='"),e&&(c+="'+((__t=("+e+"))==null?'':__t)+'"),l=f+t.length,t}),c+="';",(r=r.variable)||(c="with(obj){"+c+"}"),c=(a?c.replace(I,""):c).replace(R,"$1").replace(N,"$1;"),c="function("+(r||"obj")+"){"+(r?"":"obj||(obj={});")+"var __t,__p=''"+(o?",__e=_.escape":"")+(a?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var p=Sr(e,"return "+c).apply(_,i)
}catch(h){throw h.source=c,h}return t?p(t):(p.source=c,p)},u.trim=Te,u.trimLeft=Le,u.trimRight=We,u.truncate=function(n,t){var r=30,e="...";if(t&&cr(t))var u="separator"in t?t.separator:u,r="length"in t?+t.length||0:r,e="omission"in t?Lr(t.omission):e;else null!=t&&(r=+t||0);if(n=null==n?"":Lr(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(pr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=Tr(u.source,(D.exec(u)||"")+"g")),u.lastIndex=0;a=u.exec(l);)i=a.index;
}catch(h){throw h.source=c,h}return t?p(t):(p.source=c,p)},u.trim=Te,u.trimLeft=Le,u.trimRight=We,u.truncate=function(n,t){var r=30,e="...";if(t&&cr(t))var u="separator"in t?t.separator:u,r="length"in t?+t.length||0:r,e="omission"in t?Lr(t.omission):e;else null!=t&&(r=+t||0);if(n=null==n?"":Lr(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(pr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=Tr(u.source,(D.exec(u)||"")+"g")),u.lastIndex=0;a=u.exec(l);)i=a.index;
r=r.slice(0,null==i?o:i)}}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=Lr(n),0>n.indexOf(";")?n:n.replace(T,d))},u.uniqueId=function(n){var t=++S;return Lr(null==n?"":n)+t},u.all=Kt,u.any=nr,u.detect=Vt,u.findWhere=Vt,u.foldl=Ht,u.foldr=Jt,u.include=Ut,u.inject=Ht,xr(function(){var n={};return mt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Nt,u.last=Wt,u.sample=function(n,t,r){return n&&typeof n.length!="number"?n=yr(n):be.unindexedChars&&hr(n)&&(n=n.split("")),null==t||r?n?n[wt(0,n.length-1)]:_:(n=Qt(n),n.length=ce(fe(0,t),n.length),n)
},u.take=Nt,u.takeRight=Wt,u.takeRightWhile=Wt,u.takeWhile=Nt,u.head=Nt,mt(u,function(n,t){var r="sample"!==t;u.prototype[t]||(u.prototype[t]=function(t,e){var u=this.__chain__,a=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new o(a,u):a})}),u.VERSION=E,u.prototype.chain=function(){return this.__chain__=true,this},u.prototype.toString=function(){return Lr(this.__wrapped__)},u.prototype.value=qt,u.prototype.valueOf=qt,st(["join","pop","shift"],function(n){var t=Fr[n];u.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments);
return n?new o(r,n):r}}),st(["push","reverse","sort","unshift"],function(n){var t=Fr[n];u.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),st(["concat","splice"],function(n){var t=Fr[n];u.prototype[n]=function(){return new o(t.apply(this.__wrapped__,arguments),this.__chain__)}}),be.spliceObjects||st(["pop","shift","splice"],function(n){var t=Fr[n],r="splice"==n;u.prototype[n]=function(){var n=this.__chain__,e=this.__wrapped__,u=t.apply(e,arguments);return 0===e.length&&delete e[0],n||r?new o(u,n):u

2
dist/lodash.js vendored
View File

@@ -7316,7 +7316,7 @@
length = +options || 0;
}
string = string == null ? '' : String(string);
if (length > string.length) {
if (length >= string.length) {
return string;
}
var end = length - omission.length;

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={};

View File

@@ -7562,7 +7562,7 @@
length = +options || 0;
}
string = string == null ? '' : String(string);
if (length > string.length) {
if (length >= string.length) {
return string;
}
var end = length - omission.length;