diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index e80f177ea..0d59296f4 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -617,7 +617,11 @@ /** Used to restore the original `_` reference in `noConflict` */ var oldDash = context._; - /** Used as the maximum value returned by `toLength` */ + /** + * Used as the maximum length an array-like object. + * See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) + * for more details. + */ var maxSafeInteger = Math.pow(2, 53) - 1; /** Used to resolve the internal [[Class]] of values */ @@ -1344,8 +1348,7 @@ iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { - length = toLength(length); + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { if (support.unindexedChars && isString(iterable)) { iterable = iterable.split(''); } @@ -1373,8 +1376,7 @@ var iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { - length = toLength(length); + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { if (support.unindexedChars && isString(iterable)) { iterable = iterable.split(''); } @@ -2186,20 +2188,6 @@ return result; } - /** - * Converts `value` to an integer suitable for use as the length of an array-like - * object. See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) - * for more details. - * - * @private - * @param {*} value The value to convert. - * @returns {number} Returns the converted integer. - */ - function toLength(value) { - var result = +value || 0; - return result < 0 ? 0 : (result < maxSafeInteger ? result : maxSafeInteger); - } - /*--------------------------------------------------------------------------*/ /** @@ -3554,10 +3542,10 @@ * // => true */ function contains(collection, target, fromIndex) { - var length = toLength(collection && collection.length); + var length = collection ? collection.length : 0; fromIndex = (typeof fromIndex == 'number' && +fromIndex) || 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { if (typeof collection == 'string' || !isArray(collection) && isString(collection)) { if (fromIndex >= length) { return false; @@ -3790,12 +3778,27 @@ * // => { 'name': 'fred', 'age': 40, 'blocked': true } */ function find(collection, predicate, thisArg) { + predicate = lodash.createCallback(predicate, thisArg, 3); if (isArray(collection)) { - var index = findIndex(collection, predicate, thisArg); - return index > -1 ? collection[index] : undefined; + var index = -1, + length = collection.length; + + while (++index < length) { + var value = collection[index]; + if (predicate(value, index, collection)) { + return value; + } + } + } else { + var result; + baseEach(collection, function(value, index, collection) { + if (predicate(value, index, collection)) { + result = value; + return false; + } + }); + return result; } - var key = findKey(collection, predicate, thisArg); - return typeof key == 'string' ? collection[key] : undefined; } /** @@ -3819,12 +3822,16 @@ * // => 3 */ function findLast(collection, predicate, thisArg) { - if (isArray(collection)) { - var index = findLastIndex(collection, predicate, thisArg); - return index > -1 ? collection[index] : undefined; - } - var key = findLastKey(collection, predicate, thisArg); - return typeof key == 'string' ? collection[key] : undefined; + var result; + + predicate = lodash.createCallback(predicate, thisArg, 3); + baseEachRight(collection, function(value, index, collection) { + if (predicate(value, index, collection)) { + result = value; + return false; + } + }); + return result; } /** @@ -4016,7 +4023,8 @@ result = Array(length < 0 ? 0 : length >>> 0); baseEach(collection, function(value) { - result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); + var func = isFunc ? methodName : (value != null && value[methodName]); + result[++index] = func ? func.apply(value, args) : undefined; }); return result; } @@ -4451,7 +4459,7 @@ collection = collection.split(''); } if (n == null || guard) { - var length = toLength(collection && collection.length); + var length = collection ? collection.length : 0; return length > 0 ? collection[baseRandom(0, length - 1)] : undefined; } var result = shuffle(collection); @@ -4510,7 +4518,9 @@ */ function size(collection) { var length = collection ? collection.length : 0; - return typeof length == 'number' && length > -1 ? length : keys(collection).length; + return (typeof length == 'number' && length > -1 && length <= maxSafeInteger) + ? length + : keys(collection).length; } /** @@ -4671,7 +4681,7 @@ */ function toArray(collection) { var length = collection && collection.length; - if (typeof length == 'number' && length > -1) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { return (support.unindexedChars && isString(collection)) ? collection.split('') : slice(collection); @@ -5430,11 +5440,11 @@ * // => { 'name': 'barney', 'employer': 'slate' } */ function assign(object, source, guard) { - if (!object) { + var args = arguments; + if (!object || args.length < 2) { return object; } - var args = arguments, - argsIndex = 0, + var argsIndex = 0, argsLength = args.length, type = typeof guard; @@ -5626,7 +5636,10 @@ * _.defaults({ 'name': 'barney' }, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function defaults() { + function defaults(object) { + if (!object || arguments.length < 2) { + return object; + } var args = slice(arguments); args.push(assignDefaults); return assign.apply(null, args); @@ -7895,7 +7908,7 @@ */ function property(key) { return function(object) { - return object[key]; + return object == null ? undefined : object[key]; }; } diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 58af1eee5..d8be01c76 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -6,63 +6,63 @@ ;(function(){function n(n,t){return typeof n=="undefined"?t:n}function t(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202a(t,l)&&f.push(l);return f}function pt(n,t){var r=-1,e=n,u=n?n.length:0;if(typeof u=="number")for(u=Tt(u),Oe.unindexedChars&&br(e)&&(e=e.split(""));++ri(s,h)&&((u||f)&&s.push(h),c.push(p))}return c}function jt(n,t){for(var r=-1,e=t(n),u=e.length,o=Rr(u);++rr&&(r=0),s&&(a=[]),p&&(i=[]),h=[n,t,r,e,u,o,a,i],t==x||t==(x|O)?c(h):X(h)) -}function St(){var n=(n=o.indexOf)===Pt?r:n;return n}function It(n){return typeof n=="function"&&Gr.test(ne.call(n))}function Rt(n){var t,r;return!n||Yr.call(n)!=ot||!re.call(n,"constructor")&&(t=n.constructor,vr(t)&&!(t instanceof t))||!Oe.argsClass&&hr(n)||!Oe.nodeClass&&h(n)?false:Oe.ownLast?(vt(n,function(n,t,e){return r=re.call(e,t),false},_r),false!==r):(vt(n,function(n,t){r=t},_r),typeof r=="undefined"||re.call(n,r))}function Nt(n){for(var t=-1,r=_r(n),e=r.length,u=[];++tn?0:na?0:a)}function Pt(n,t,e){var u=n?n.length:0; -if(typeof e=="number")e=0>e?ye(0,u+e):e||0;else if(e)return e=qt(n,t),u&&n[e]===t?e:-1;return r(n,t,e)}function $t(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,a=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)a++}else a=null==t||r?1:t;return a=e-a,Bt(n,0,0>a?0:a)}function Dt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,a=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)a++}else if(a=t,null==a||r)return n?n[e-1]:w;return a=e-a,Bt(n,0>a?0:a)}function zt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,u=n?n.length:0,a=0; -for(t=o.createCallback(t,r,3);++et?0:t;return Bt(n,a)}function Bt(n,t,r){var e=-1,u=n?n.length:0;for(t=+t||0,0>t?t=ye(u+t,0):t>u&&(t=u),r=typeof r=="undefined"?u:+r||0,0>r?r=ye(u+r,0):r>u&&(r=u),u=t>r?0:r-t,r=Rr(u);++e>>1,r(n[e])r?0:r);++tr?ye(0,e+r):r,-1u?0:u>>>0);if(t=o.createCallback(t,r,3),Le(n))for(;++ea&&(a=l)}else t=null==t&&br(n)?u:o.createCallback(t,r,3),pt(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,a=n)});return a}function tr(n,t,r,e){var u=3>arguments.length;if(t=o.createCallback(t,e,4),Le(n)){var a=-1,i=n.length;for(u&&i&&(r=n[++a]);++aarguments.length;return t=o.createCallback(t,e,4),ht(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function er(n){var t=-1,r=n&&n.length,e=Rr(0>r?0:r>>>0); -return pt(n,function(n){var r=xt(0,++t);e[t]=e[r],e[r]=n}),e}function ur(n,t,r){var e;if(t=o.createCallback(t,r,3),Le(n)){r=-1;for(var u=n.length;++rarguments.length)return At(n,x,null,t);if(n)var r=n[S]?n[S][2]:n.length,e=Bt(arguments,2),r=r-e.length;return At(n,x|O,r,t,e)}function ar(n,t,r){var e,u,o,a,i,l,f,c=0,s=false,p=true;if(!vr(n))throw new Br;if(t=0>t?0:t,true===r)var h=true,p=false;else yr(r)&&(h=r.leading,s="maxWait"in r&&(ye(t,r.maxWait)||0),p="trailing"in r?r.trailing:p); -var g=function(){var r=t-(Ue()-a);0>=r||r>t?(u&&Jr(u),r=f,u=l=f=w,r&&(c=Ue(),o=n.apply(i,e),l||u||(e=i=null))):l=ae(g,r)},v=function(){l&&Jr(l),u=l=f=w,(p||s!==t)&&(c=Ue(),o=n.apply(i,e),l||u||(e=i=null))};return function(){if(e=arguments,a=Ue(),i=this,f=p&&(l||!h),false===s)var r=h&&!l;else{u||h||(c=a);var y=s-(a-c),m=0>=y||y>s;m?(u&&(u=Jr(u)),c=a,o=n.apply(i,e)):u||(u=ae(v,y))}return m&&l?l=Jr(l):l||t===s||(l=ae(g,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o}}function ir(n){if(!vr(n))throw new Br; -return function(){return!n.apply(this,arguments)}}function lr(n,t,r){if(!n)return n;var e=arguments,u=0,o=e.length,a=typeof r;if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;n=zr(n);do t%2&&(r+=n),t=Qr(t/2),n+=n;while(t);return r}function kr(n,t,r){var e=typeof n;return"function"==e||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||U(n,t,r):"object"!=e?Ir(n):Er(n)}function Or(n){return n}function Er(n){n||(n={});var t=Fe(n),r=t.length,e=t[0],u=n[e];return 1!=r||u!==u||yr(u)?function(e){for(var u=r,o=false;u--&&(o=t[u],o=re.call(e,o)&&_t(e[o],n[o],null,true)););return o}:function(n){return re.call(n,e)?(n=n[e],u===n&&(0!==u||1/u==1/n)):false -}}function Ar(n,t,r){var e=true,u=t&&pr(t);t&&(r||u.length)||(null==r&&(r=t),t=n,n=o,u=pr(t)),false===r?e=false:yr(r)&&"chain"in r&&(e=r.chain),r=-1;for(var a=vr(n),i=u?u.length:0;++r--n?t.apply(this,arguments):void 0}},o.assign=lr,o.at=function(n,t){var r=arguments,e=-1,u=gt(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),Oe.unindexedChars&&br(n)&&(n=n.split("")),r=Rr(o);++earguments.length?At(t,x|C,null,n):At(t,x|C|O,null,n,Bt(arguments,2))},o.chain=function(n){return n=new a(n),n.__chain__=true,n},o.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?e(h,c):i(f,c))){for(u=o,(h||f).push(c);--u;)if(h=a[u],0>(h?e(h,c):i(t[u],c)))continue n; -p.push(c)}}return p},o.invert=function(n,t){for(var r=-1,e=Fe(n),u=e.length,o={};++ro?0:o>>>0);return pt(n,function(n){a[++e]=(u?t:n[t]).apply(n,r)}),a},o.keys=Fe,o.keysIn=_r,o.map=Qt,o.mapValues=function(n,t,r){var e={};return t=o.createCallback(t,r,3),dt(n,function(n,r,u){e[r]=t(n,r,u)}),e},o.matches=Er,o.max=nr,o.memoize=function(n,t){if(!vr(n))throw new Br; -var r=function(){var e=r.cache,u=t?t.apply(this,arguments):"_"+arguments[0];return re.call(e,u)?e[u]:e[u]=n.apply(this,arguments)};return r.cache={},r},o.merge=function(n,t,r){if(!n)return n;var e=arguments,u=e.length,o=typeof r;if("number"!=o&&"string"!=o||!e[3]||e[3][r]!==t||(u=2),3u?0:u>>>0);for(a||(t=o.createCallback(t,r,3)),pt(n,function(n,r,u){if(a)for(r=t.length,u=Rr(r);r--;)u[r]=n[t[r]]; -else u=t(n,r,u);f[++e]={a:u,b:e,c:n}}),u=f.length,f.sort(a?l:i);u--;)f[u]=f[u].c;return f},o.tap=function(n,t,r){return t.call(r,n),n},o.throttle=function(n,t,r){var e=true,u=true;if(!vr(n))throw new Br;return false===r?e=false:yr(r)&&(e="leading"in r?!!r.leading:e,u="trailing"in r?!!r.trailing:u),ft.leading=e,ft.maxWait=+t,ft.trailing=u,ar(n,t,ft)},o.times=function(n,t,r){n=-1<(n=+n)?n:0;var e=-1,u=Rr(n);for(t=U(t,r,1);++er?ye(0,e+r):me(r,e-1))+1);e--;)if(n[e]===t)return e; -return-1},o.mixin=Ar,o.noConflict=function(){return t._=Zr,this},o.noop=Sr,o.now=Ue,o.pad=function(n,t,r){n=null==n?"":zr(n),t|=0;var e=n.length;return e=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(dr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=Dr(u.source,(z.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),-1n.indexOf(";")?n:n.replace(L,b))},o.uniqueId=function(n){var t=++I;return zr(null==n?"":n)+t},o.all=Xt,o.any=ur,o.detect=Gt,o.findWhere=Gt,o.foldl=tr,o.foldr=rr,o.include=Zt,o.inject=tr,Ar(function(){var n={};return dt(o,function(t,r){o.prototype[r]||(n[r]=t)}),n}(),false),o.first=Ft,o.last=Dt,o.sample=function(n,t,r){return n&&typeof n.length!="number"?n=xr(n):Oe.unindexedChars&&br(n)&&(n=n.split("")),null==t||r?(t=Tt(n&&n.length),0a(t,l)&&f.push(l);return f}function pt(n,t){var r=-1,e=n,u=n?n.length:0;if(typeof u=="number"&&-1i(s,h)&&((u||f)&&s.push(h),c.push(p))}return c}function Ot(n,t){for(var r=-1,e=t(n),u=e.length,o=Ar(u);++rr&&(r=0),s&&(a=[]),p&&(i=[]),h=[n,t,r,e,u,o,a,i],t==x||t==(x|O)?c(h):X(h)) +}function Rt(){var n=(n=o.indexOf)===Ft?r:n;return n}function Nt(n){return typeof n=="function"&&Zr.test(Hr.call(n))}function Tt(n){var t,r;return!n||Vr.call(n)!=ot||!Qr.call(n,"constructor")&&(t=n.constructor,pr(t)&&!(t instanceof t))||!Ce.argsClass&&cr(n)||!Ce.nodeClass&&h(n)?false:Ce.ownLast?(dt(n,function(n,t,e){return r=Qr.call(e,t),false}),false!==r):(dt(n,function(n,t){r=t}),typeof r=="undefined"||Qr.call(n,r))}function Lt(n){for(var t=-1,r=mr(n),e=r.length,u=[];++ta?0:a)}function Ft(n,t,e){var u=n?n.length:0;if(typeof e=="number")e=0>e?he(0,u+e):e||0;else if(e)return e=Bt(n,t),u&&n[e]===t?e:-1;return r(n,t,e)}function Pt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,a=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)a++}else a=null==t||r?1:t; +return a=e-a,zt(n,0,0>a?0:a)}function $t(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,a=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)a++}else if(a=t,null==a||r)return n?n[e-1]:w;return a=e-a,zt(n,0>a?0:a)}function Dt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,u=n?n.length:0,a=0;for(t=o.createCallback(t,r,3);++et?0:t;return zt(n,a)}function zt(n,t,r){var e=-1,u=n?n.length:0;for(t=+t||0,0>t?t=he(u+t,0):t>u&&(t=u),r=typeof r=="undefined"?u:+r||0,0>r?r=he(u+r,0):r>u&&(r=u),u=t>r?0:r-t,r=Ar(u);++e>>1,r(n[e])r?0:r);++tr?he(0,e+r):r,-1u?0:u>>>0);if(t=o.createCallback(t,r,3),Re(n))for(;++ea&&(a=l)}else t=null==t&&yr(n)?u:o.createCallback(t,r,3),pt(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,a=n)});return a}function nr(n,t,r,e){var u=3>arguments.length;if(t=o.createCallback(t,e,4),Re(n)){var a=-1,i=n.length;for(u&&i&&(r=n[++a]);++aarguments.length;return t=o.createCallback(t,e,4),ht(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function rr(n){var t=-1,r=n&&n.length,e=Ar(0>r?0:r>>>0); +return pt(n,function(n){var r=jt(0,++t);e[t]=e[r],e[r]=n}),e}function er(n,t,r){var e;if(t=o.createCallback(t,r,3),Re(n)){r=-1;for(var u=n.length;++rarguments.length)return It(n,x,null,t);if(n)var r=n[S]?n[S][2]:n.length,e=zt(arguments,2),r=r-e.length;return It(n,x|O,r,t,e)}function or(n,t,r){function e(){c&&Yr(c),a=c=s=w,(g||h!==t)&&(p=ze(),i=n.apply(f,o),c||a||(o=f=null))}function u(){var r=t-(ze()-l); +0>=r||r>t?(a&&Yr(a),r=s,a=c=s=w,r&&(p=ze(),i=n.apply(f,o),c||a||(o=f=null))):c=ee(u,r)}var o,a,i,l,f,c,s,p=0,h=false,g=true;if(!pr(n))throw new $r;if(t=0>t?0:t,true===r)var v=true,g=false;else hr(r)&&(v=r.leading,h="maxWait"in r&&(he(t,r.maxWait)||0),g="trailing"in r?r.trailing:g);return function(){if(o=arguments,l=ze(),f=this,s=g&&(c||!v),false===h)var r=v&&!c;else{a||v||(p=l);var y=h-(l-p),m=0>=y||y>h;m?(a&&(a=Yr(a)),p=l,i=n.apply(f,o)):a||(a=ee(e,y))}return m&&c?c=Yr(c):c||t===h||(c=ee(u,t)),r&&(m=true,i=n.apply(f,o)),!m||c||a||(o=f=null),i +}}function ar(n){if(!pr(n))throw new $r;return function(){return!n.apply(this,arguments)}}function ir(n,t,r){var e=arguments;if(!n||2>e.length)return n;var u=0,o=e.length,a=typeof r;if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3arguments.length)return t;var r=zt(arguments); +return r.push(n),ir.apply(null,r)}function fr(n){var t=[];return dt(n,function(n,r){pr(n)&&t.push(r)}),t.sort()}function cr(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Vr.call(n)==J||false}function sr(n){return n&&typeof n=="object"&&1===n.nodeType&&(Ce.nodeClass?-1t||null==n)return r;n=Pr(n);do t%2&&(r+=n),t=Gr(t/2),n+=n;while(t);return r}function xr(n,t,r){var e=typeof n; +return"function"==e||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||U(n,t,r):"object"!=e?Er(n):jr(n)}function Cr(n){return n}function jr(n){n||(n={});var t=Te(n),r=t.length,e=t[0],u=n[e];return 1!=r||u!==u||hr(u)?function(e){for(var u=r,o=false;u--&&(o=t[u],o=Qr.call(e,o)&&xt(e[o],n[o],null,true)););return o}:function(n){return Qr.call(n,e)?(n=n[e],u===n&&(0!==u||1/u==1/n)):false}}function kr(n,t,r){var e=true,u=t&&fr(t);t&&(r||u.length)||(null==r&&(r=t),t=n,n=o,u=fr(t)),false===r?e=false:hr(r)&&"chain"in r&&(e=r.chain),r=-1; +for(var a=pr(n),i=u?u.length:0;++r--n?t.apply(this,arguments):void 0}},o.assign=ir,o.at=function(n,t){var r=arguments,e=-1,u=gt(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),Ce.unindexedChars&&yr(n)&&(n=n.split("")),r=Ar(o);++earguments.length?It(t,x|C,null,n):It(t,x|C|O,null,n,zt(arguments,2))},o.chain=function(n){return n=new a(n),n.__chain__=true,n},o.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?e(h,c):i(f,c))){for(u=o,(h||f).push(c);--u;)if(h=a[u],0>(h?e(h,c):i(t[u],c)))continue n; +p.push(c)}}return p},o.invert=function(n,t){for(var r=-1,e=Te(n),u=e.length,o={};++ro?0:o>>>0);return pt(n,function(n){var o=u?t:null!=n&&n[t];a[++e]=o?o.apply(n,r):w}),a},o.keys=Te,o.keysIn=mr,o.map=Jt,o.mapValues=function(n,t,r){var e={};return t=o.createCallback(t,r,3),_t(n,function(n,r,u){e[r]=t(n,r,u)}),e},o.matches=jr,o.max=Qt,o.memoize=function(n,t){function r(){var e=r.cache,u=t?t.apply(this,arguments):"_"+arguments[0]; +return Qr.call(e,u)?e[u]:e[u]=n.apply(this,arguments)}if(!pr(n))throw new $r;return r.cache={},r},o.merge=function(n,t,r){if(!n)return n;var e=arguments,u=e.length,o=typeof r;if("number"!=o&&"string"!=o||!e[3]||e[3][r]!==t||(u=2),3u?0:u>>>0);for(a||(t=o.createCallback(t,r,3)),pt(n,function(n,r,u){if(a)for(r=t.length,u=Ar(r);r--;)u[r]=n[t[r]]; +else u=t(n,r,u);f[++e]={a:u,b:e,c:n}}),u=f.length,f.sort(a?l:i);u--;)f[u]=f[u].c;return f},o.tap=function(n,t,r){return t.call(r,n),n},o.throttle=function(n,t,r){var e=true,u=true;if(!pr(n))throw new $r;return false===r?e=false:hr(r)&&(e="leading"in r?!!r.leading:e,u="trailing"in r?!!r.trailing:u),ft.leading=e,ft.maxWait=+t,ft.trailing=u,or(n,t,ft)},o.times=function(n,t,r){n=-1<(n=+n)?n:0;var e=-1,u=Ar(n);for(t=U(t,r,1);++er?he(0,e+r):ge(r,e-1))+1);e--;)if(n[e]===t)return e; +return-1},o.mixin=kr,o.noConflict=function(){return t._=Kr,this},o.noop=Or,o.now=ze,o.pad=function(n,t,r){n=null==n?"":Pr(n),t|=0;var e=n.length;return e=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(vr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=Fr(u.source,(z.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),-1n.indexOf(";")?n:n.replace(L,b))},o.uniqueId=function(n){var t=++I;return Pr(null==n?"":n)+t},o.all=Zt,o.any=er,o.detect=Yt,o.findWhere=Yt,o.foldl=nr,o.foldr=tr,o.include=Vt,o.inject=nr,kr(function(){var n={};return _t(o,function(t,r){o.prototype[r]||(n[r]=t)}),n}(),false),o.first=Wt,o.last=$t,o.sample=function(n,t,r){return n&&typeof n.length!="number"?n=br(n):Ce.unindexedChars&&yr(n)&&(n=n.split("")),null==t||r?(t=n?n.length:0,0"']/g,F=/<%-([\s\S]+?)%>/g,P=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,z=/\w*$/,B=/^\s*function[ \n\r\t]+\w/,q=/^0[xX]/,U=/[\xC0-\xFF]/g,K=/($^)/,M=/[.*+?^${}()|[\]\\]/g,V=/\bthis\b/,Z=/['\n\r\t\u2028\u2029\\]/g,X=/[A-Z]{2,}|[a-zA-Z0-9][a-z0-9]*/g,Y=" \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",G="Array Boolean Date Error Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),H="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),J="[object Arguments]",Q="[object Array]",nt="[object Boolean]",tt="[object Date]",rt="[object Error]",et="[object Function]",ut="[object Number]",ot="[object Object]",at="[object RegExp]",it="[object String]",lt={}; lt[et]=false,lt[J]=lt[Q]=lt[nt]=lt[tt]=lt[ut]=lt[ot]=lt[at]=lt[it]=true;var ft={leading:false,maxWait:0,trailing:false},ct={configurable:false,enumerable:false,value:null,writable:false},st={"&":"&","<":"<",">":">",'"':""","'":"'"},pt={"&":"&","<":"<",">":">",""":'"',"'":"'"},ht={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":" ","\xf7":" "},gt={"function":true,object:true},vt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},yt=gt[typeof window]&&window||this,mt=gt[typeof exports]&&exports&&!exports.nodeType&&exports,gt=gt[typeof module]&&module&&!module.nodeType&&module,dt=mt&>&&typeof global=="object"&&global; !dt||dt.global!==dt&&dt.window!==dt&&dt.self!==dt||(yt=dt);var dt=gt&>.exports===mt&&mt,bt=_();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(yt._=bt, define(function(){return bt})):mt&>?dt?(gt.exports=bt)._=bt:mt._=bt:yt._=bt}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index d368e9c9e..dd98160a7 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -595,7 +595,11 @@ /** Used to restore the original `_` reference in `noConflict` */ var oldDash = context._; - /** Used as the maximum value returned by `toLength` */ + /** + * Used as the maximum length an array-like object. + * See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) + * for more details. + */ var maxSafeInteger = Math.pow(2, 53) - 1; /** Used to resolve the internal [[Class]] of values */ @@ -1187,8 +1191,7 @@ iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { - length = toLength(length); + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { if (callback(iterable[index], index, collection) === false) { break; @@ -1213,8 +1216,7 @@ var iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { - length = toLength(length); + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (length--) { if (callback(iterable[length], length, collection) === false) { break; @@ -1761,9 +1763,9 @@ callback = lodash.createCallback(callback, thisArg, 3); var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { var value = collection[index]; setter(result, value, callback(value, index, collection), collection); @@ -2011,20 +2013,6 @@ return result; } - /** - * Converts `value` to an integer suitable for use as the length of an array-like - * object. See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) - * for more details. - * - * @private - * @param {*} value The value to convert. - * @returns {number} Returns the converted integer. - */ - function toLength(value) { - var result = +value || 0; - return result < 0 ? 0 : (result < maxSafeInteger ? result : maxSafeInteger); - } - /*--------------------------------------------------------------------------*/ /** @@ -3376,10 +3364,10 @@ * // => true */ function contains(collection, target, fromIndex) { - var length = toLength(collection && collection.length); + var length = collection ? collection.length : 0; fromIndex = (typeof fromIndex == 'number' && +fromIndex) || 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { if (typeof collection == 'string' || !isArray(collection) && isString(collection)) { if (fromIndex >= length) { return false; @@ -3488,9 +3476,9 @@ predicate = lodash.createCallback(predicate, thisArg, 3); var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { if (!predicate(collection[index], index, collection)) { return false; @@ -3549,9 +3537,9 @@ predicate = lodash.createCallback(predicate, thisArg, 3); var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { var value = collection[index]; if (predicate(value, index, collection)) { @@ -3612,13 +3600,27 @@ * // => { 'name': 'fred', 'age': 40, 'blocked': true } */ function find(collection, predicate, thisArg) { - var length = toLength(collection && collection.length); - if (length) { - var index = findIndex(collection, predicate, thisArg); - return index > -1 ? collection[index] : undefined; + predicate = lodash.createCallback(predicate, thisArg, 3); + var index = -1, + length = collection ? collection.length : 0; + + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { + while (++index < length) { + var value = collection[index]; + if (predicate(value, index, collection)) { + return value; + } + } + } else { + var result; + baseEach(collection, function(value, index, collection) { + if (predicate(value, index, collection)) { + result = value; + return false; + } + }); + return result; } - var key = findKey(collection, predicate, thisArg); - return typeof key == 'string' ? collection[key] : undefined; } /** @@ -3642,13 +3644,16 @@ * // => 3 */ function findLast(collection, predicate, thisArg) { - var length = toLength(collection && collection.length); - if (length) { - var index = findLastIndex(collection, predicate, thisArg); - return index > -1 ? collection[index] : undefined; - } - var key = findLastKey(collection, predicate, thisArg); - return typeof key == 'string' ? collection[key] : undefined; + var result; + + predicate = lodash.createCallback(predicate, thisArg, 3); + baseEachRight(collection, function(value, index, collection) { + if (predicate(value, index, collection)) { + result = value; + return false; + } + }); + return result; } /** @@ -3679,10 +3684,10 @@ */ function forEach(collection, callback, thisArg) { var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { if (callback(collection[index], index, collection) === false) { break; @@ -3712,10 +3717,10 @@ * // => logs each number from right to left and returns '3,2,1' */ function forEachRight(collection, callback, thisArg) { - var length = toLength(collection && collection.length); + var length = collection ? collection.length : 0; callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (length--) { if (callback(collection[length], length, collection) === false) { break; @@ -3843,7 +3848,8 @@ result = Array(length < 0 ? 0 : length >>> 0); baseEach(collection, function(value) { - result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); + var func = isFunc ? methodName : (value != null && value[methodName]); + result[++index] = func ? func.apply(value, args) : undefined; }); return result; } @@ -3889,10 +3895,10 @@ */ function map(collection, callback, thisArg) { var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; callback = lodash.createCallback(callback, thisArg, 3); - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { var result = Array(length); while (++index < length) { result[index] = callback(collection[index], index, collection); @@ -4161,9 +4167,9 @@ callback = lodash.createCallback(callback, thisArg, 4); var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { if (noaccum && length) { accumulator = collection[++index]; } @@ -4277,7 +4283,7 @@ collection = values(collection); } if (n == null || guard) { - var length = toLength(collection && collection.length); + var length = collection ? collection.length : 0; return length > 0 ? collection[baseRandom(0, length - 1)] : undefined; } var result = shuffle(collection); @@ -4336,7 +4342,9 @@ */ function size(collection) { var length = collection ? collection.length : 0; - return typeof length == 'number' && length > -1 ? length : keys(collection).length; + return (typeof length == 'number' && length > -1 && length <= maxSafeInteger) + ? length + : keys(collection).length; } /** @@ -4386,9 +4394,9 @@ predicate = lodash.createCallback(predicate, thisArg, 3); var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { if (predicate(collection[index], index, collection)) { return true; @@ -4497,7 +4505,7 @@ */ function toArray(collection) { var length = collection && collection.length; - if (typeof length == 'number' && length > -1) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { return slice(collection); } return values(collection); @@ -5254,11 +5262,11 @@ * // => { 'name': 'barney', 'employer': 'slate' } */ function assign(object, source, guard) { - if (!object) { + var args = arguments; + if (!object || args.length < 2) { return object; } - var args = arguments, - argsIndex = 0, + var argsIndex = 0, argsLength = args.length, type = typeof guard; @@ -5450,7 +5458,10 @@ * _.defaults({ 'name': 'barney' }, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function defaults() { + function defaults(object) { + if (!object || arguments.length < 2) { + return object; + } var args = slice(arguments); args.push(assignDefaults); return assign.apply(null, args); @@ -7670,7 +7681,7 @@ */ function property(key) { return function(object) { - return object[key]; + return object == null ? undefined : object[key]; }; } diff --git a/dist/lodash.min.js b/dist/lodash.min.js index d9ea9819a..3d2d1a4fc 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -4,61 +4,61 @@ * Build: `lodash modern -o ./dist/lodash.js` */ ;(function(){function n(n,t){return typeof n=="undefined"?t:n}function t(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202i(t,l)&&f.push(l);return f}function ft(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(e=St(e);++ra(p,h)&&((u||f)&&p.push(h),c.push(s))}return c}function jt(n,t){for(var r=-1,e=t(n),u=e.length,o=Rr(u);++rr&&(r=0),p&&(i=[]),s&&(a=[]),h=[n,t,r,e,u,o,i,a],t==w||t==(w|C)?c(h):Z(h))}function It(){var n=(n=o.indexOf)===$t?r:n;return n}function Et(n){return typeof n=="function"&&Zr.test(Hr.call(n))}function Rt(n){var t,r;return n&&Vr.call(n)==rt&&(Qr.call(n,"constructor")||(t=n.constructor,!gr(t)||t instanceof t))?(vt(n,function(n,t){r=t -}),typeof r=="undefined"||Qr.call(n,r)):false}function Nt(n){for(var t=-1,r=br(n),e=r.length,u=[];++tn?0:ni?0:i)}function $t(n,t,e){var u=n?n.length:0;if(typeof e=="number")e=0>e?se(0,u+e):e||0;else if(e)return e=qt(n,t),u&&n[e]===t?e:-1;return r(n,t,e)}function Dt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,i=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)i++}else i=null==t||r?1:t;return i=e-i,Bt(n,0,0>i?0:i)}function Lt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,i=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)i++ -}else if(i=t,null==i||r)return n?n[e-1]:_;return i=e-i,Bt(n,0>i?0:i)}function zt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,u=n?n.length:0,i=0;for(t=o.createCallback(t,r,3);++et?0:t;return Bt(n,i)}function Bt(n,t,r){var e=-1,u=n?n.length:0;for(t=+t||0,0>t?t=se(u+t,0):t>u&&(t=u),r=typeof r=="undefined"?u:+r||0,0>r?r=se(u+r,0):r>u&&(r=u),u=t>r?0:r-t,r=Rr(u);++e>>1,r(n[e])r?0:r);++tr?se(0,e+r):r,-1i&&(i=l)}else t=null==t&&dr(n)?u:o.createCallback(t,r,3),ft(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,i=n)});return i}function nr(n,t,r,e){var u=3>arguments.length;t=o.createCallback(t,e,4); -var i=-1,a=St(n&&n.length);if(a)for(u&&a&&(r=n[++i]);++iarguments.length;return t=o.createCallback(t,e,4),ct(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function rr(n){var t=-1,r=n&&n.length,e=Rr(0>r?0:r>>>0);return ft(n,function(n){var r=wt(0,++t);e[t]=e[r],e[r]=n}),e}function er(n,t,r){var e;t=o.createCallback(t,r,3),r=-1;var u=St(n&&n.length);if(u){for(;++rarguments.length)return At(n,w,null,t);if(n)var r=n[I]?n[I][2]:n.length,e=Bt(arguments,2),r=r-e.length;return At(n,w|C,r,t,e)}function or(n,t,r){function e(){c&&Yr(c),i=c=p=_,(g||h!==t)&&(s=ze(),a=n.apply(f,o),c||i||(o=f=null))}function u(){var r=t-(ze()-l);0>=r||r>t?(i&&Yr(i),r=p,i=c=p=_,r&&(s=ze(),a=n.apply(f,o),c||i||(o=f=null))):c=re(u,r)}var o,i,a,l,f,c,p,s=0,h=false,g=true;if(!gr(n))throw new zr;if(t=0>t?0:t,true===r)var v=true,g=false; -else vr(r)&&(v=r.leading,h="maxWait"in r&&(se(t,r.maxWait)||0),g="trailing"in r?r.trailing:g);return function(){if(o=arguments,l=ze(),f=this,p=g&&(c||!v),false===h)var r=v&&!c;else{i||v||(s=l);var y=h-(l-s),m=0>=y||y>h;m?(i&&(i=Yr(i)),s=l,a=n.apply(f,o)):i||(i=re(e,y))}return m&&c?c=Yr(c):c||t===h||(c=re(u,t)),r&&(m=true,a=n.apply(f,o)),!m||c||i||(o=f=null),a}}function ir(n){if(!gr(n))throw new zr;return function(){return!n.apply(this,arguments)}}function ar(n,t,r){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof r; -if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;n=Lr(n);do t%2&&(r+=n),t=Gr(t/2),n+=n;while(t);return r}function kr(n,t,r){var e=typeof n;return"function"==e||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||U(n,t,r):"object"!=e?Er(n):Or(n)}function Cr(n){return n}function Or(n){n||(n={});var t=Se(n),r=t.length,e=t[0],u=n[e];return 1!=r||u!==u||vr(u)?function(e){for(var u=r,o=false;u--&&(o=t[u],o=Qr.call(e,o)&&bt(e[o],n[o],null,true)););return o}:function(n){return Qr.call(n,e)?(n=n[e],u===n&&(0!==u||1/u==1/n)):false -}}function Ar(n,t,r){var e=true,u=t&&pr(t);t&&(r||u.length)||(null==r&&(r=t),t=n,n=o,u=pr(t)),false===r?e=false:vr(r)&&"chain"in r&&(e=r.chain),r=-1;for(var i=gr(n),a=u?u.length:0;++r--n?t.apply(this,arguments):void 0 -}},o.assign=ar,o.at=function(n,t){var r=arguments,e=-1,u=pt(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=Rr(o);++earguments.length?At(t,w|x,null,n):At(t,w|x|C,null,n,Bt(arguments,2))},o.chain=function(n){return n=new i(n),n.__chain__=true,n -},o.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?e(h,c):a(f,c))){for(u=o,(h||f).push(c);--u;)if(h=i[u],0>(h?e(h,c):a(t[u],c)))continue n;s.push(c)}}return s},o.invert=function(n,t){for(var r=-1,e=Se(n),u=e.length,o={};++ro?0:o>>>0); -return ft(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},o.keys=Se,o.keysIn=br,o.map=Jt,o.mapValues=function(n,t,r){var e={};return t=o.createCallback(t,r,3),mt(n,function(n,r,u){e[r]=t(n,r,u)}),e},o.matches=Or,o.max=Qt,o.memoize=function(n,t){function r(){var e=r.cache,u=t?t.apply(this,arguments):"_"+arguments[0];return Qr.call(e,u)?e[u]:e[u]=n.apply(this,arguments)}if(!gr(n))throw new zr;return r.cache={},r},o.merge=function(n,t,r){if(!n)return n;var e=arguments,u=e.length,o=typeof r;if("number"!=o&&"string"!=o||!e[3]||e[3][r]!==t||(u=2),3u?0:u>>>0);for(i||(t=o.createCallback(t,r,3)),ft(n,function(n,r,u){if(i)for(r=t.length,u=Rr(r);r--;)u[r]=n[t[r]]; -else u=t(n,r,u);f[++e]={a:u,b:e,c:n}}),u=f.length,f.sort(i?l:a);u--;)f[u]=f[u].c;return f},o.tap=function(n,t,r){return t.call(r,n),n},o.throttle=function(n,t,r){var e=true,u=true;if(!gr(n))throw new zr;return false===r?e=false:vr(r)&&(e="leading"in r?!!r.leading:e,u="trailing"in r?!!r.trailing:u),it.leading=e,it.maxWait=+t,it.trailing=u,or(n,t,it)},o.times=function(n,t,r){n=-1<(n=+n)?n:0;var e=-1,u=Rr(n);for(t=U(t,r,1);++er?se(0,e+r):he(r,e-1))+1);e--;)if(n[e]===t)return e; -return-1},o.mixin=Ar,o.noConflict=function(){return t._=Kr,this},o.noop=Ir,o.now=ze,o.pad=function(n,t,r){n=null==n?"":Lr(n),t|=0;var e=n.length;return e=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(mr(u)){if(n.slice(o).search(u)){var i,a,l=n.slice(0,o);for(u.global||(u=Dr(u.source,(z.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(l);)a=i.index; -r=r.slice(0,null==a?o:a)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(T,d))},o.uniqueId=function(n){var t=++E;return Lr(null==n?"":n)+t},o.all=Zt,o.any=er,o.detect=Yt,o.findWhere=Yt,o.foldl=nr,o.foldr=tr,o.include=Vt,o.inject=nr,Ar(function(){var n={};return mt(o,function(t,r){o.prototype[r]||(n[r]=t)}),n}(),false),o.first=Ft,o.last=Lt,o.sample=function(n,t,r){return n&&typeof n.length!="number"&&(n=wr(n)),null==t||r?(t=St(n&&n.length),0"']/g,F=/<%-([\s\S]+?)%>/g,$=/<%([\s\S]+?)%>/g,D=/<%=([\s\S]+?)%>/g,L=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,z=/\w*$/,B=/^\s*function[ \n\r\t]+\w/,q=/^0[xX]/,U=/[\xC0-\xFF]/g,P=/($^)/,K=/[.*+?^${}()|[\]\\]/g,M=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,Z=/[A-Z]{2,}|[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(" "),G="[object Arguments]",H="[object Array]",J="[object Boolean]",Q="[object Date]",nt="[object Function]",tt="[object Number]",rt="[object Object]",et="[object RegExp]",ut="[object String]",ot={}; -ot[nt]=false,ot[G]=ot[H]=ot[J]=ot[Q]=ot[tt]=ot[rt]=ot[et]=ot[ut]=true;var it={leading:false,maxWait:0,trailing:false},at={configurable:false,enumerable:false,value:null,writable:false},lt={"&":"&","<":"<",">":">",'"':""","'":"'"},ft={"&":"&","<":"<",">":">",""":'"',"'":"'"},ct={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":" ","\xf7":" "},pt={"function":true,object:true},st={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},ht=pt[typeof window]&&window||this,gt=pt[typeof exports]&&exports&&!exports.nodeType&&exports,pt=pt[typeof module]&&module&&!module.nodeType&&module,vt=gt&&pt&&typeof global=="object"&&global; +}return t}function d(n){return lt[n]}function b(t){function o(n){return n&&typeof n=="object"&&!ke(n)&&Vr.call(n,"__wrapped__")?n:new i(n)}function i(n,t){this.__chain__=!!t,this.__wrapped__=n}function c(n){function t(){if(u){for(var n=-1,i=arguments.length,a=kr(i);++ni(t,f)&&l.push(f);return l}function lt(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number"&&-1a(p,h)&&((u||l)&&p.push(h),c.push(s))}return c}function wt(n,t){for(var r=-1,e=t(n),u=e.length,o=kr(u);++rr&&(r=0),p&&(i=[]),s&&(a=[]),h=[n,t,r,e,u,o,i,a],t==w||t==(w|C)?c(h):Z(h))}function Ot(){var n=(n=o.indexOf)===Nt?r:n;return n}function At(n){return typeof n=="function"&&Br.test(Kr.call(n))}function It(n){var t,r;return n&&zr.call(n)==rt&&(Vr.call(n,"constructor")||(t=n.constructor,!ar(t)||t instanceof t))?(st(n,function(n,t){r=t +},sr),typeof r=="undefined"||Vr.call(n,r)):false}function Et(n){for(var t=-1,r=sr(n),e=r.length,u=[];++ti?0:i)}function Nt(n,t,e){var u=n?n.length:0;if(typeof e=="number")e=0>e?oe(0,u+e):e||0;else if(e)return e=$t(n,t),u&&n[e]===t?e:-1;return r(n,t,e)}function St(n,t,r){var e=n?n.length:0; +if(typeof t!="number"&&null!=t){var u=e,i=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)i++}else i=null==t||r?1:t;return i=e-i,Ft(n,0,0>i?0:i)}function Tt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,i=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)i++}else if(i=t,null==i||r)return n?n[e-1]:_;return i=e-i,Ft(n,0>i?0:i)}function Wt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,u=n?n.length:0,i=0;for(t=o.createCallback(t,r,3);++et?0:t; +return Ft(n,i)}function Ft(n,t,r){var e=-1,u=n?n.length:0;for(t=+t||0,0>t?t=oe(u+t,0):t>u&&(t=u),r=typeof r=="undefined"?u:+r||0,0>r?r=oe(u+r,0):r>u&&(r=u),u=t>r?0:r-t,r=kr(u);++e>>1,r(n[e])r?0:r);++tr?oe(0,e+r):r,-1=e||e>Lr){var u;return lt(n,function(n,r,e){return t(n,r,e)?(u=n,false):void 0}),u}for(;++ri&&(i=f)}else t=null==t&&pr(n)?u:o.createCallback(t,r,3),lt(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,i=n)});return i}function Yt(n,t,r,e){var u=3>arguments.length; +t=o.createCallback(t,e,4);var i=-1,a=n?n.length:0;if(typeof a=="number"&&-1arguments.length;return t=o.createCallback(t,e,4),ct(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Ht(n){var t=-1,r=n&&n.length,e=kr(0>r?0:r>>>0);return lt(n,function(n){var r=bt(0,++t);e[t]=e[r],e[r]=n}),e}function Jt(n,t,r){var e;t=o.createCallback(t,r,3),r=-1;var u=n?n.length:0; +if(typeof u=="number"&&-1arguments.length)return Ct(n,w,null,t);if(n)var r=n[I]?n[I][2]:n.length,e=Ft(arguments,2),r=r-e.length;return Ct(n,w|C,r,t,e)}function nr(n,t,r){var e,u,o,i,a,f,l,c=0,p=false,s=true;if(!ar(n))throw new Sr;if(t=0>t?0:t,true===r)var h=true,s=false;else fr(r)&&(h=r.leading,p="maxWait"in r&&(oe(t,r.maxWait)||0),s="trailing"in r?r.trailing:s);var g=function(){var r=t-(Se()-i); +0>=r||r>t?(u&&Ur(u),r=l,u=f=l=_,r&&(c=Se(),o=n.apply(a,e),f||u||(e=a=null))):f=Yr(g,r)},v=function(){f&&Ur(f),u=f=l=_,(s||p!==t)&&(c=Se(),o=n.apply(a,e),f||u||(e=a=null))};return function(){if(e=arguments,i=Se(),a=this,l=s&&(f||!h),false===p)var r=h&&!f;else{u||h||(c=i);var y=p-(i-c),m=0>=y||y>p;m?(u&&(u=Ur(u)),c=i,o=n.apply(a,e)):u||(u=Yr(v,y))}return m&&f?f=Ur(f):f||t===p||(f=Yr(g,t)),r&&(m=true,o=n.apply(a,e)),!m||f||u||(e=a=null),o}}function tr(n){if(!ar(n))throw new Sr;return function(){return!n.apply(this,arguments) +}}function rr(n,t,r){var e=arguments;if(!n||2>e.length)return n;var u=0,o=e.length,i=typeof r;if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3arguments.length)return t;var r=Ft(arguments);return r.push(n),rr.apply(null,r)}function ur(n){var t=[];return st(n,function(n,r){ar(n)&&t.push(r) +},sr),t.sort()}function or(n){return n&&typeof n=="object"&&typeof n.length=="number"&&zr.call(n)==G||false}function ir(n){return n&&typeof n=="object"&&1===n.nodeType&&-1t||null==n)return r;n=Nr(n);do t%2&&(r+=n),t=Pr(t/2),n+=n;while(t); +return r}function mr(n,t,r){var e=typeof n;return"function"==e||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||U(n,t,r):"object"!=e?xr(n):br(n)}function dr(n){return n}function br(n){n||(n={});var t=Ce(n),r=t.length,e=t[0],u=n[e];return 1!=r||u!==u||fr(u)?function(e){for(var u=r,o=false;u--&&(o=t[u],o=Vr.call(e,o)&&mt(e[o],n[o],null,true)););return o}:function(n){return Vr.call(n,e)?(n=n[e],u===n&&(0!==u||1/u==1/n)):false}}function _r(n,t,r){var e=true,u=t&&ur(t);t&&(r||u.length)||(null==r&&(r=t),t=n,n=o,u=ur(t)),false===r?e=false:fr(r)&&"chain"in r&&(e=r.chain),r=-1; +for(var i=ar(n),a=u?u.length:0;++r--n?t.apply(this,arguments):void 0 +}},o.assign=rr,o.at=function(n,t){var r=arguments,e=-1,u=pt(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=kr(o);++earguments.length?Ct(t,w|x,null,n):Ct(t,w|x|C,null,n,Ft(arguments,2))},o.chain=function(n){return n=new i(n),n.__chain__=true,n +},o.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?e(h,c):a(l,c))){for(u=o,(h||l).push(c);--u;)if(h=i[u],0>(h?e(h,c):a(t[u],c)))continue n;s.push(c)}}return s},o.invert=function(n,t){for(var r=-1,e=Ce(n),u=e.length,o={};++ro?0:o>>>0); +return lt(n,function(n){var o=u?t:null!=n&&n[t];i[++e]=o?o.apply(n,r):_}),i},o.keys=Ce,o.keysIn=sr,o.map=Zt,o.mapValues=function(n,t,r){var e={};return t=o.createCallback(t,r,3),vt(n,function(n,r,u){e[r]=t(n,r,u)}),e},o.matches=br,o.max=Xt,o.memoize=function(n,t){if(!ar(n))throw new Sr;var r=function(){var e=r.cache,u=t?t.apply(this,arguments):"_"+arguments[0];return Vr.call(e,u)?e[u]:e[u]=n.apply(this,arguments)};return r.cache={},r},o.merge=function(n,t,r){if(!n)return n;var e=arguments,u=e.length,o=typeof r; +if("number"!=o&&"string"!=o||!e[3]||e[3][r]!==t||(u=2),3u?0:u>>>0);for(i||(t=o.createCallback(t,r,3)),lt(n,function(n,r,u){if(i)for(r=t.length,u=kr(r);r--;)u[r]=n[t[r]];else u=t(n,r,u);l[++e]={a:u,b:e,c:n}}),u=l.length,l.sort(i?f:a);u--;)l[u]=l[u].c;return l},o.tap=function(n,t,r){return t.call(r,n),n},o.throttle=function(n,t,r){var e=true,u=true;if(!ar(n))throw new Sr; +return false===r?e=false:fr(r)&&(e="leading"in r?!!r.leading:e,u="trailing"in r?!!r.trailing:u),it.leading=e,it.maxWait=+t,it.trailing=u,nr(n,t,it)},o.times=function(n,t,r){n=-1<(n=+n)?n:0;var e=-1,u=kr(n);for(t=U(t,r,1);++er?oe(0,e+r):ie(r,e-1))+1);e--;)if(n[e]===t)return e; +return-1},o.mixin=_r,o.noConflict=function(){return t._=Dr,this},o.noop=wr,o.now=Se,o.pad=function(n,t,r){n=null==n?"":Nr(n),t|=0;var e=n.length;return e=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(cr(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=Rr(u.source,(z.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),-1n.indexOf(";")?n:n.replace(T,d))},o.uniqueId=function(n){var t=++E;return Nr(null==n?"":n)+t},o.all=Ut,o.any=Jt,o.detect=Kt,o.findWhere=Kt,o.foldl=Yt,o.foldr=Gt,o.include=qt,o.inject=Yt,_r(function(){var n={};return vt(o,function(t,r){o.prototype[r]||(n[r]=t)}),n}(),false),o.first=Rt,o.last=Tt,o.sample=function(n,t,r){return n&&typeof n.length!="number"&&(n=gr(n)),null==t||r?(t=n?n.length:0,0"']/g,F=/<%-([\s\S]+?)%>/g,$=/<%([\s\S]+?)%>/g,D=/<%=([\s\S]+?)%>/g,L=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,z=/\w*$/,B=/^\s*function[ \n\r\t]+\w/,q=/^0[xX]/,U=/[\xC0-\xFF]/g,P=/($^)/,K=/[.*+?^${}()|[\]\\]/g,M=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,Z=/[A-Z]{2,}|[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(" "),G="[object Arguments]",H="[object Array]",J="[object Boolean]",Q="[object Date]",nt="[object Function]",tt="[object Number]",rt="[object Object]",et="[object RegExp]",ut="[object String]",ot={}; +ot[nt]=false,ot[G]=ot[H]=ot[J]=ot[Q]=ot[tt]=ot[rt]=ot[et]=ot[ut]=true;var it={leading:false,maxWait:0,trailing:false},at={configurable:false,enumerable:false,value:null,writable:false},ft={"&":"&","<":"<",">":">",'"':""","'":"'"},lt={"&":"&","<":"<",">":">",""":'"',"'":"'"},ct={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":" ","\xf7":" "},pt={"function":true,object:true},st={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},ht=pt[typeof window]&&window||this,gt=pt[typeof exports]&&exports&&!exports.nodeType&&exports,pt=pt[typeof module]&&module&&!module.nodeType&&module,vt=gt&&pt&&typeof global=="object"&&global; !vt||vt.global!==vt&&vt.window!==vt&&vt.self!==vt||(ht=vt);var vt=pt&&pt.exports===gt&>,yt=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(ht._=yt, define(function(){return yt})):gt&&pt?vt?(pt.exports=yt)._=yt:gt._=yt:ht._=yt}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 8c8e848eb..c12b9bf53 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -226,7 +226,11 @@ /** Used to restore the original `_` reference in `noConflict` */ var oldDash = root._; - /** Used as the maximum value returned by `toLength` */ + /** + * Used as the maximum length an array-like object. + * See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) + * for more details. + */ var maxSafeInteger = Math.pow(2, 53) - 1; /** Used to resolve the internal [[Class]] of values */ @@ -569,8 +573,7 @@ iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { - length = toLength(length); + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { if (callback(iterable[index], index, collection) === breakIndicator) { break; @@ -595,8 +598,7 @@ var iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { - length = toLength(length); + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (length--) { if (callback(iterable[length], length, collection) === breakIndicator) { break; @@ -981,9 +983,9 @@ callback = createCallback(callback, thisArg, 3); var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { var value = collection[index]; setter(result, value, callback(value, index, collection), collection); @@ -1109,20 +1111,6 @@ return result; } - /** - * Converts `value` to an integer suitable for use as the length of an array-like - * object. See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) - * for more details. - * - * @private - * @param {*} value The value to convert. - * @returns {number} Returns the converted integer. - */ - function toLength(value) { - var result = +value || 0; - return result < 0 ? 0 : (result < maxSafeInteger ? result : maxSafeInteger); - } - /*--------------------------------------------------------------------------*/ /** @@ -1199,60 +1187,6 @@ */ var drop = rest; - /** - * This method is like `_.find` except that it returns the index of the first - * element the predicate returns truthy for, instead of the element itself. - * - * If a property name is provided for `predicate` the created "_.pluck" style - * callback will return the property value of the given element. - * - * If an object is provided for `predicate` the created "_.where" style callback - * will return `true` for elements that have the properties of the given object, - * else `false`. - * - * @static - * @memberOf _ - * @category Arrays - * @param {Array} array The array to search. - * @param {Function|Object|string} [predicate=identity] The function called - * per iteration. If a property name or object is provided it will be used - * to create a "_.pluck" or "_.where" style callback, respectively. - * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {number} Returns the index of the found element, else `-1`. - * @example - * - * var characters = [ - * { 'name': 'barney', 'age': 36 }, - * { 'name': 'fred', 'age': 40, 'blocked': true }, - * { 'name': 'pebbles', 'age': 1 } - * ]; - * - * _.findIndex(characters, function(chr) { - * return chr.age < 20; - * }); - * // => 2 - * - * // using "_.where" callback shorthand - * _.findIndex(characters, { 'age': 36 }); - * // => 0 - * - * // using "_.pluck" callback shorthand - * _.findIndex(characters, 'blocked'); - * // => 1 - */ - function findIndex(array, predicate, thisArg) { - var index = -1, - length = array ? array.length : 0; - - predicate = createCallback(predicate, thisArg, 3); - while (++index < length) { - if (predicate(array[index], index, array)) { - return index; - } - } - return -1; - } - /** * Gets the first element of `array`. * @@ -1957,10 +1891,10 @@ */ function contains(collection, target) { var indexOf = getIndexOf(), - length = toLength(collection && collection.length), + length = collection ? collection.length : 0, result = false; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { return indexOf(collection, target) > -1; } baseEach(collection, function(value) { @@ -2053,9 +1987,9 @@ predicate = createCallback(predicate, thisArg, 3); var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { if (!predicate(collection[index], index, collection)) { return false; @@ -2114,9 +2048,9 @@ predicate = createCallback(predicate, thisArg, 3); var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { var value = collection[index]; if (predicate(value, index, collection)) { @@ -2177,13 +2111,27 @@ * // => { 'name': 'fred', 'age': 40, 'blocked': true } */ function find(collection, predicate, thisArg) { - var length = toLength(collection && collection.length); - if (length) { - var index = findIndex(collection, predicate, thisArg); - return index > -1 ? collection[index] : undefined; + predicate = createCallback(predicate, thisArg, 3); + var index = -1, + length = collection ? collection.length : 0; + + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { + while (++index < length) { + var value = collection[index]; + if (predicate(value, index, collection)) { + return value; + } + } + } else { + var result; + baseEach(collection, function(value, index, collection) { + if (predicate(value, index, collection)) { + result = value; + return breakIndicator; + } + }); + return result; } - var key = findKey(collection, predicate, thisArg); - return typeof key == 'string' ? collection[key] : undefined; } /** @@ -2214,10 +2162,10 @@ */ function forEach(collection, callback, thisArg) { var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { if (callback(collection[index], index, collection) === breakIndicator) { break; @@ -2345,7 +2293,8 @@ result = Array(length < 0 ? 0 : length >>> 0); baseEach(collection, function(value) { - result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); + var func = isFunc ? methodName : (value != null && value[methodName]); + result[++index] = func ? func.apply(value, args) : undefined; }); return result; } @@ -2391,10 +2340,10 @@ */ function map(collection, callback, thisArg) { var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; callback = createCallback(callback, thisArg, 3); - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { var result = Array(length); while (++index < length) { result[index] = callback(collection[index], index, collection); @@ -2458,9 +2407,9 @@ callback = null; } var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (callback == null && length) { + if (callback == null && typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { var value = collection[index]; if (value > result) { @@ -2531,9 +2480,9 @@ callback = null; } var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (callback == null && length) { + if (callback == null && typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { var value = collection[index]; if (value < result) { @@ -2659,9 +2608,9 @@ callback = createCallback(callback, thisArg, 4); var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { if (noaccum && length) { accumulator = collection[++index]; } @@ -2775,7 +2724,7 @@ collection = values(collection); } if (n == null || guard) { - var length = toLength(collection && collection.length); + var length = collection ? collection.length : 0; return length > 0 ? collection[baseRandom(0, length - 1)] : undefined; } var result = shuffle(collection); @@ -2834,7 +2783,9 @@ */ function size(collection) { var length = collection ? collection.length : 0; - return typeof length == 'number' && length > -1 ? length : keys(collection).length; + return (typeof length == 'number' && length > -1 && length <= maxSafeInteger) + ? length + : keys(collection).length; } /** @@ -2884,9 +2835,9 @@ predicate = createCallback(predicate, thisArg, 3); var index = -1, - length = toLength(collection && collection.length); + length = collection ? collection.length : 0; - if (length) { + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { while (++index < length) { if (predicate(collection[index], index, collection)) { return true; @@ -3720,60 +3671,6 @@ return object; } - /** - * This method is like `_.findIndex` except that it returns the key of the - * first element the predicate returns truthy for, instead of the element itself. - * - * If a property name is provided for `predicate` the created "_.pluck" style - * callback will return the property value of the given element. - * - * If an object is provided for `predicate` the created "_.where" style callback - * will return `true` for elements that have the properties of the given object, - * else `false`. - * - * @static - * @memberOf _ - * @category Objects - * @param {Object} object The object to search. - * @param {Function|Object|string} [predicate=identity] The function called - * per iteration. If a property name or object is provided it will be used - * to create a "_.pluck" or "_.where" style callback, respectively. - * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {string|undefined} Returns the key of the found element, else `undefined`. - * @example - * - * var characters = { - * 'barney': { 'age': 36 }, - * 'fred': { 'age': 40, 'blocked': true }, - * 'pebbles': { 'age': 1 } - * }; - * - * _.findKey(characters, function(chr) { - * return chr.age < 40; - * }); - * // => 'barney' (property order is not guaranteed across environments) - * - * // using "_.where" callback shorthand - * _.findKey(characters, { 'age': 1 }); - * // => 'pebbles' - * - * // using "_.pluck" callback shorthand - * _.findKey(characters, 'blocked'); - * // => 'fred' - */ - function findKey(object, predicate, thisArg) { - var result; - - predicate = createCallback(predicate, thisArg, 3); - baseForOwn(object, function(value, key, object) { - if (predicate(value, key, object)) { - result = key; - return breakIndicator; - } - }); - return result; - } - /** * Creates a sorted array of property names of all enumerable properties, * own and inherited, of `object` that have function values. @@ -4939,7 +4836,7 @@ */ function property(key) { return function(object) { - return object[key]; + return object == null ? undefined : object[key]; }; } @@ -5018,7 +4915,7 @@ */ function range(start, end, step) { start = +start || 0; - step = step == null ? 1 : (+step || 0); + step = +step || 1; if (end == null) { end = start; @@ -5029,7 +4926,7 @@ // use `Array(length)` so engines like Chakra and V8 avoid slower modes // http://youtu.be/XAqIpGU8ZZk#t=17m25s var index = -1, - length = nativeMax(0, ceil((end - start) / step)), + length = nativeMax(0, ceil((end - start) / (step || 1))), result = Array(length); while (++index < length) { diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index a822ea7d8..3f01e0bb1 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,38 +3,38 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.6.0 underscorejs.org/LICENSE * Build: `lodash underscore -o ./dist/lodash.underscore.js` */ -;(function(){function n(n,r,t){t=(+t||0)-1;for(var e=n?n.length:0;++te||typeof t=="undefined"){t=1;break n}if(tu(r,i)&&o.push(i)}return o}function p(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(e=j(e);++to(f,c)&&(t&&f.push(c),i.push(a))}return i}function m(n,r){return function(t,e,u){var o=r?[[],[]]:{}; -e=rr(e,u,3),u=-1;var i=j(t&&t.length);if(i)for(;++un?0:n<$r?n:$r}function x(n,r,t){return null==r||t?n?n[0]:ir:E(n,0,0>r?0:r)}function A(r,t,e){var u=r?r.length:0;if(typeof e=="number")e=0>e?Xr(0,u+e):e||0;else if(e)return e=O(r,t),u&&r[e]===t?e:-1;return n(r,t,e)}function T(n,r,t){return E(n,null==r||t?1:0>r?0:r)}function E(n,r,t){var e=-1,u=n?n.length:0;for(r=+r||0,0>r?r=Xr(u+r,0):r>u&&(r=u),t=typeof t=="undefined"?u:+t||0,0>t?t=Xr(u+t,0):t>u&&(t=u),u=r>t?0:t-r,t=Array(u);++e>>1,t(n[e])u&&(u=t);else r=rr(r,t,3),p(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function $(n,r,t,e){var u=3>arguments.length;r=rr(r,e,4);var o=-1,i=j(n&&n.length);if(i)for(u&&i&&(t=n[++o]);++oarguments.length;return r=rr(r,e,4),s(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function D(n){var r=-1,t=n&&n.length,e=Array(0>t?0:t>>>0);return p(n,function(n){var t;t=++r,t=0+zr(nt()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function W(n,r,t){var e;r=rr(r,t,3),t=-1;var u=j(n&&n.length);if(u){for(;++targuments.length?_(n,fr,null,r):_(n,fr|ar,null,r,E(arguments,2)) -}function C(n,r,t){var e,u,o,i,f,a,c,l=0,p=false,s=true;if(!K(n))throw new TypeError;if(r=0>r?0:r,true===t)var g=true,s=false;else L(t)&&(g=t.leading,p="maxWait"in t&&(Xr(r,t.maxWait)||0),s="trailing"in t?t.trailing:s);var h=function(){var t=r-(pt()-i);0>=t||t>r?(u&&clearTimeout(u),t=c,u=a=c=ir,t&&(l=pt(),o=n.apply(f,e),a||u||(e=f=null))):a=setTimeout(h,t)},v=function(){a&&clearTimeout(a),u=a=c=ir,(s||p!==r)&&(l=pt(),o=n.apply(f,e),a||u||(e=f=null))};return function(){if(e=arguments,i=pt(),f=this,c=s&&(a||!g),false===p)var t=g&&!a; -else{u||g||(l=i);var y=p-(i-l),m=0>=y||y>p;m?(u&&(u=clearTimeout(u)),l=i,o=n.apply(f,e)):u||(u=setTimeout(v,y))}return m&&a?a=clearTimeout(a):a||r===p||(a=setTimeout(h,r)),t&&(m=true,o=n.apply(f,e)),!m||a||u||(e=f=null),o}}function P(n){if(!K(n))throw new TypeError;return function(){return!n.apply(this,arguments)}}function U(n,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t;for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,gr=/($^)/,hr=/[.*+?^${}()|[\]\\]/g,vr=/['\n\r\t\u2028\u2029\\]/g,yr="[object Arguments]",mr="[object Array]",_r="[object Boolean]",dr="[object Date]",br="[object Number]",wr="[object Object]",jr="[object RegExp]",xr="[object String]",Ar={"&":"&","<":"<",">":">",'"':""","'":"'"},Tr={"&":"&","<":"<",">":">",""":'"',"'":"'"},Er={"function":true,object:true},Or={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Sr=Er[typeof window]&&window||this,kr=Er[typeof exports]&&exports&&!exports.nodeType&&exports,Nr=Er[typeof module]&&module&&!module.nodeType&&module,qr=kr&&Nr&&typeof global=="object"&&global; -!qr||qr.global!==qr&&qr.window!==qr&&qr.self!==qr||(Sr=qr);var Fr=Nr&&Nr.exports===kr&&kr,Br=Array.prototype,Mr=Object.prototype,Rr=Sr._,$r=Math.pow(2,53)-1,Ir=Mr.toString,Dr=RegExp("^"+(null==Ir?"":(Ir+"").replace(hr,"\\$&")).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Wr=Math.ceil,zr=Math.floor,Cr=Function.prototype.toString,Pr=Mr.hasOwnProperty,Ur=Br.push,Vr=Mr.propertyIsEnumerable,Gr=Br.splice,Hr=b(Hr=Object.create)&&Hr,Jr=b(Jr=Array.isArray)&&Jr,Kr=Sr.isFinite,Lr=Sr.isNaN,Qr=b(Qr=Object.keys)&&Qr,Xr=Math.max,Yr=Math.min,Zr=b(Zr=Date.now)&&Zr,nt=Math.random; -i.prototype=o.prototype;var rt={};!function(){var n={0:1,length:1};rt.spliceObjects=(Gr.call(n,0,1),!n[0])}(1),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Hr||(f=function(){function n(){}return function(r){if(L(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Sr.Object()}}());var tt=T,et=m(function(n,r,t){Pr.call(n,t)?n[t]++:n[t]=1}),ut=m(function(n,r,t){Pr.call(n,t)?n[t].push(r):n[t]=[r]}),ot=m(function(n,r,t){n[t]=r -}),it=m(function(n,r,t){n[t?0:1].push(r)},true),ft=M,at=q;J(arguments)||(J=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Pr.call(n,"callee")&&!Vr.call(n,"callee")||false});var ct=Jr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ir.call(n)==mr||false};K(/x/)&&(K=function(n){return typeof n=="function"&&"[object Function]"==Ir.call(n)});var lt=Qr?function(n){return L(n)?Qr(n):[]}:w,pt=Zr||function(){return(new Date).getTime()};o.after=function(n,r){if(!K(r))throw new TypeError; -return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=z,o.bindAll=function(n){for(var r=1r?0:r)},o.intersection=function(){for(var n=[],r=-1,t=arguments.length;++ri(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},o.invert=function(n){for(var r=-1,t=lt(n),e=t.length,u={};++ro?0:o>>>0); -return p(n,function(n){i[++e]=(u?r:n[r]).apply(n,t)}),i},o.keys=lt,o.map=M,o.matches=er,o.max=R,o.memoize=function(n,r){var t={};return function(){var e=r?r.apply(this,arguments):"_"+arguments[0];return Pr.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},o.min=function(n,r,t){var e=1/0,u=e,o=typeof r;"number"!=o&&"string"!=o||!t||t[r]!==n||(r=null);var o=-1,i=j(n&&n.length);if(null==r&&i)for(;++oo?0:o>>>0);for(t=rr(t,e,3),p(n,function(n,r,e){i[++u]={a:t(n,r,e),b:u,c:n}}),o=i.length,i.sort(r);o--;)i[o]=i[o].c;return i},o.tap=function(n,r){return r(n),n},o.throttle=function(n,r,t){var e=true,u=true;if(!K(n))throw new TypeError;return false===t?e=false:L(t)&&(e="leading"in t?t.leading:e,u="trailing"in t?t.trailing:u),C(n,r,{leading:e,maxWait:r,trailing:u})},o.times=function(n,r,t){n=-1<(n=+n)?n:0; -var e=-1,u=Array(n);for(r=a(r,t,1);++er?0:r);++nt?Xr(0,e+t):Yr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=ur,o.noConflict=function(){return Sr._=Rr,this},o.now=pt,o.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+zr(nt()*(r-n+1))},o.reduce=$,o.reduceRight=I,o.result=function(n,r){if(null!=n){var t=n[r];return K(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0;return typeof r=="number"&&-1n.indexOf(";")?n:n.replace(pr,u))},o.uniqueId=function(n){var r=++lr+"";return n?n+r:r},o.all=N,o.any=W,o.detect=F,o.findWhere=F,o.foldl=$,o.foldr=I,o.include=k,o.inject=$,o.first=x,o.last=function(n,r,t){var e=n?n.length:0;return null==r||t?n?n[e-1]:ir:(r=e-r,E(n,0>r?0:r))},o.sample=function(n,r,t){return n&&typeof n.length!="number"&&(n=nr(n)),null==r||t?(r=j(n&&n.length),0e||typeof t=="undefined"){t=1;break n}if(tu(r,i)&&o.push(i)}return o}function p(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number"&&-1o(f,c)&&(t&&f.push(c),i.push(a))}return i}function m(n,r){return function(t,e,u){var o=r?[[],[]]:{}; +e=Z(e,u,3),u=-1;var i=t?t.length:0;if(typeof i=="number"&&-1r?0:r)}function x(r,t,e){var u=r?r.length:0;if(typeof e=="number")e=0>e?Lr(0,u+e):e||0;else if(e)return e=E(r,t),u&&r[e]===t?e:-1;return n(r,t,e)}function A(n,r,t){return T(n,null==r||t?1:0>r?0:r)}function T(n,r,t){var e=-1,u=n?n.length:0;for(r=+r||0,0>r?r=Lr(u+r,0):r>u&&(r=u),t=typeof t=="undefined"?u:+t||0,0>t?t=Lr(u+t,0):t>u&&(t=u),u=r>t?0:t-r,t=Array(u);++e>>1,t(n[e])=e||e>Mr){var u;return p(n,function(n,t,e){return r(n,t,e)?(u=n,fr):void 0}),u}for(;++tu&&(u=t); +else r=Z(r,t,3),p(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function R(n,r,t,e){var u=3>arguments.length;r=Z(r,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number"&&-1arguments.length;return r=Z(r,e,4),s(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function I(n){var r=-1,t=n&&n.length,e=Array(0>t?0:t>>>0);return p(n,function(n){var t;t=++r,t=0+Dr(Yr()*(t-0+1)),e[r]=e[t],e[t]=n +}),e}function D(n,r,t){var e;r=Z(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number"&&-1arguments.length?_(n,or,null,r):_(n,or|ir,null,r,T(arguments,2))}function z(n,r,t){var e,u,o,i,f,a,c,l=0,p=false,s=true;if(!H(n))throw new TypeError;if(r=0>r?0:r,true===t)var h=true,s=false;else J(t)&&(h=t.leading,p="maxWait"in t&&(Lr(r,t.maxWait)||0),s="trailing"in t?t.trailing:s);var g=function(){var t=r-(ct()-i); +0>=t||t>r?(u&&clearTimeout(u),t=c,u=a=c=ur,t&&(l=ct(),o=n.apply(f,e),a||u||(e=f=null))):a=setTimeout(g,t)},v=function(){a&&clearTimeout(a),u=a=c=ur,(s||p!==r)&&(l=ct(),o=n.apply(f,e),a||u||(e=f=null))};return function(){if(e=arguments,i=ct(),f=this,c=s&&(a||!h),false===p)var t=h&&!a;else{u||h||(l=i);var y=p-(i-l),m=0>=y||y>p;m?(u&&(u=clearTimeout(u)),l=i,o=n.apply(f,e)):u||(u=setTimeout(v,y))}return m&&a?a=clearTimeout(a):a||r===p||(a=setTimeout(g,r)),t&&(m=true,o=n.apply(f,e)),!m||a||u||(e=f=null),o} +}function C(n){if(!H(n))throw new TypeError;return function(){return!n.apply(this,arguments)}}function P(n,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t;for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,pr=/($^)/,sr=/[.*+?^${}()|[\]\\]/g,hr=/['\n\r\t\u2028\u2029\\]/g,gr="[object Arguments]",vr="[object Array]",yr="[object Boolean]",mr="[object Date]",_r="[object Number]",br="[object Object]",dr="[object RegExp]",wr="[object String]",jr={"&":"&","<":"<",">":">",'"':""","'":"'"},xr={"&":"&","<":"<",">":">",""":'"',"'":"'"},Ar={"function":true,object:true},Tr={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Er=Ar[typeof window]&&window||this,Or=Ar[typeof exports]&&exports&&!exports.nodeType&&exports,Sr=Ar[typeof module]&&module&&!module.nodeType&&module,kr=Or&&Sr&&typeof global=="object"&&global; +!kr||kr.global!==kr&&kr.window!==kr&&kr.self!==kr||(Er=kr);var Nr=Sr&&Sr.exports===Or&&Or,qr=Array.prototype,Fr=Object.prototype,Br=Er._,Mr=Math.pow(2,53)-1,Rr=Fr.toString,$r=RegExp("^"+(null==Rr?"":(Rr+"").replace(sr,"\\$&")).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ir=Math.ceil,Dr=Math.floor,Wr=Function.prototype.toString,zr=Fr.hasOwnProperty,Cr=qr.push,Pr=Fr.propertyIsEnumerable,Ur=qr.splice,Vr=d(Vr=Object.create)&&Vr,Gr=d(Gr=Array.isArray)&&Gr,Hr=Er.isFinite,Jr=Er.isNaN,Kr=d(Kr=Object.keys)&&Kr,Lr=Math.max,Qr=Math.min,Xr=d(Xr=Date.now)&&Xr,Yr=Math.random; +i.prototype=o.prototype;var Zr={};!function(){var n={0:1,length:1};Zr.spliceObjects=(Ur.call(n,0,1),!n[0])}(1),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Vr||(f=function(){function n(){}return function(r){if(J(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Er.Object()}}());var nt=A,rt=m(function(n,r,t){zr.call(n,t)?n[t]++:n[t]=1}),tt=m(function(n,r,t){zr.call(n,t)?n[t].push(r):n[t]=[r]}),et=m(function(n,r,t){n[t]=r +}),ut=m(function(n,r,t){n[t?0:1].push(r)},true),ot=B,it=N;G(arguments)||(G=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&zr.call(n,"callee")&&!Pr.call(n,"callee")||false});var ft=Gr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Rr.call(n)==vr||false};H(/x/)&&(H=function(n){return typeof n=="function"&&"[object Function]"==Rr.call(n)});var at=Kr?function(n){return J(n)?Kr(n):[]}:w,ct=Xr||function(){return(new Date).getTime()};o.after=function(n,r){if(!H(r))throw new TypeError; +return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=W,o.bindAll=function(n){for(var r=1r?0:r)},o.intersection=function(){for(var n=[],r=-1,t=arguments.length;++ri(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},o.invert=function(n){for(var r=-1,t=at(n),e=t.length,u={};++ro?0:o>>>0); +return p(n,function(n){var o=u?r:null!=n&&n[r];i[++e]=o?o.apply(n,t):ur}),i},o.keys=at,o.map=B,o.matches=rr,o.max=M,o.memoize=function(n,r){var t={};return function(){var e=r?r.apply(this,arguments):"_"+arguments[0];return zr.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},o.min=function(n,r,t){var e=1/0,u=e,o=typeof r;"number"!=o&&"string"!=o||!t||t[r]!==n||(r=null);var o=-1,i=n?n.length:0;if(null==r&&typeof i=="number"&&-1o?0:o>>>0);for(t=Z(t,e,3),p(n,function(n,r,e){i[++u]={a:t(n,r,e),b:u,c:n}}),o=i.length,i.sort(r);o--;)i[o]=i[o].c;return i},o.tap=function(n,r){return r(n),n},o.throttle=function(n,r,t){var e=true,u=true;if(!H(n))throw new TypeError;return false===t?e=false:J(t)&&(e="leading"in t?t.leading:e,u="trailing"in t?t.trailing:u),z(n,r,{leading:e,maxWait:r,trailing:u}) +},o.times=function(n,r,t){n=-1<(n=+n)?n:0;var e=-1,u=Array(n);for(r=a(r,t,1);++er?0:r);++nt?Lr(0,e+t):Qr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=tr,o.noConflict=function(){return Er._=Br,this},o.now=ct,o.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Dr(Yr()*(r-n+1))},o.reduce=R,o.reduceRight=$,o.result=function(n,r){if(null!=n){var t=n[r];return H(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0;return typeof r=="number"&&-1n.indexOf(";")?n:n.replace(cr,u))},o.uniqueId=function(n){var r=++ar+"";return n?n+r:r},o.all=k,o.any=D,o.detect=q,o.findWhere=q,o.foldl=R,o.foldr=$,o.include=S,o.inject=R,o.first=j,o.last=function(n,r,t){var e=n?n.length:0;return null==r||t?n?n[e-1]:ur:(r=e-r,T(n,0>r?0:r))},o.sample=function(n,r,t){return n&&typeof n.length!="number"&&(n=Y(n)),null==r||t?(r=n?n.length:0,0