diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 5bf4849d7..7291ff07d 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -158,7 +158,7 @@ */ function basicIndexOf(array, value, fromIndex) { var index = (fromIndex || 0) - 1, - length = array.length; + length = array ? array.length : 0; while (++index < length) { if (array[index] === value) { @@ -235,7 +235,7 @@ } /** - * Used by `sortBy` to compare transformed `collection` values, stable sorting + * Used by `sortBy` to compare transformed `collection` elements, stable sorting * them in ascending order. * * @private @@ -957,24 +957,22 @@ * * @private * @param {Array} array The array to flatten. - * @param {Boolean} [isShallow=false] A flag to indicate only flattening a single level. - * @param {Function} [callback] The function called per iteration. + * @param {Boolean} [isShallow=false] A flag to restrict flattening to a single level. + * @param {Boolean} [isArgArrays=false] A flag to restrict flattening to arrays and `arguments` objects. + * @param {Number} [fromIndex=0] The index to start from. * @returns {Array} Returns a new flattened array. */ - function basicFlatten(array, isShallow, callback) { - var index = -1, + function basicFlatten(array, isShallow, isArgArrays, fromIndex) { + var index = (fromIndex || 0) - 1, length = array ? array.length : 0, result = []; while (++index < length) { var value = array[index]; - if (callback) { - value = callback(value, index, array); - } // recursively flatten arrays (susceptible to call stack limits) if (value && typeof value == 'object' && (isArray(value) || isArguments(value))) { push.apply(result, isShallow ? value : basicFlatten(value)); - } else { + } else if (!isArgArrays) { result.push(value); } } @@ -1156,7 +1154,7 @@ } // fallback for browsers without `Object.create` if (!nativeCreate) { - var createObject = function(prototype) { + createObject = function(prototype) { if (isObject(prototype)) { noop.prototype = prototype; var result = new noop; @@ -1185,34 +1183,11 @@ * @private * @returns {Function} Returns the "indexOf" function. */ - function getIndexOf(array, value, fromIndex) { + function getIndexOf() { var result = (result = lodash.indexOf) === indexOf ? basicIndexOf : result; return result; } - /** - * Creates a function that juggles arguments, allowing argument overloading - * for `_.flatten` and `_.uniq`, before passing them to the given `func`. - * - * @private - * @param {Function} func The function to wrap. - * @returns {Function} Returns the new function. - */ - function overloadWrapper(func) { - return function(array, flag, callback, thisArg) { - // juggle arguments - if (typeof flag != 'boolean' && flag != null) { - thisArg = callback; - callback = !(thisArg && thisArg[flag] === array) ? flag : undefined; - flag = false; - } - if (callback != null) { - callback = lodash.createCallback(callback, thisArg); - } - return func(array, flag, callback, thisArg); - }; - } - /** * A fallback implementation of `isPlainObject` which checks if a given `value` * is an object created by the `Object` constructor, assuming objects created @@ -1723,8 +1698,8 @@ var forOwn = createIterator(eachIteratorOptions, forOwnIteratorOptions); /** - * Creates a sorted array of all enumerable properties, own and inherited, - * of `object` that have function values. + * Creates a sorted array of property names of all enumerable properties, + * own and inherited, of `object` that have function values. * * @static * @memberOf _ @@ -2497,7 +2472,7 @@ if (isFunc) { callback = lodash.createCallback(callback, thisArg); } else { - var props = basicFlatten(nativeSlice.call(arguments, 1)); + var props = basicFlatten(arguments, true, false, 1); } forIn(object, function(value, key, object) { if (isFunc @@ -2567,7 +2542,7 @@ var result = {}; if (typeof callback != 'function') { var index = -1, - props = basicFlatten(nativeSlice.call(arguments, 1)), + props = basicFlatten(arguments, true, false, 1), length = isObject(object) ? props.length : 0; while (++index < length) { @@ -2688,7 +2663,7 @@ */ function at(collection) { var index = -1, - props = basicFlatten(nativeSlice.call(arguments, 1)), + props = basicFlatten(arguments, true, false, 1), length = props.length, result = Array(length); @@ -3693,7 +3668,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to compact. - * @returns {Array} Returns a new filtered array. + * @returns {Array} Returns a new array of filtered values. * @example * * _.compact([0, 1, false, 2, '', 3]); @@ -3714,17 +3689,15 @@ } /** - * Creates an arrat with all occurrences of the passed values removed using - * using strict equality for comparisons, i.e. `===`. Values to exclude may - * be specified as individual arguments or as arrays. + * Creates an array excluding all values of the passed-in arrays using + * strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to process. - * @param {Array} [array1, array2, ...] The values to exclude, specified as - * individual values or arrays of values. - * @returns {Array} Returns a new filtered array. + * @param {Array} [array1, array2, ...] The arrays of values to exclude. + * @returns {Array} Returns a new array of filtered values. * @example * * _.difference([1, 2, 3, 4, 5], [5, 2, 10]); @@ -3734,7 +3707,7 @@ var index = -1, indexOf = getIndexOf(), length = array ? array.length : 0, - seen = basicFlatten(nativeSlice.call(arguments, 1)), + seen = basicFlatten(arguments, true, true, 1), result = []; var isLarge = length >= largeArraySize && indexOf === basicIndexOf; @@ -3889,7 +3862,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to flatten. - * @param {Boolean} [isShallow=false] A flag to indicate only flattening a single level. + * @param {Boolean} [isShallow=false] A flag to restrict flattening to a single level. * @param {Function|Object|String} [callback=identity] The function called per * iteration. If a property name or object is passed, it will be used to create * a "_.pluck" or "_.where" style callback, respectively. @@ -3912,7 +3885,18 @@ * _.flatten(stooges, 'quotes'); * // => ['Oh, a wise guy, eh?', 'Poifect!', 'Spread out!', 'You knucklehead!'] */ - var flatten = overloadWrapper(basicFlatten); + function flatten(array, isShallow, callback, thisArg) { + // juggle arguments + if (typeof isShallow != 'boolean' && isShallow != null) { + thisArg = callback; + callback = !(thisArg && thisArg[isShallow] === array) ? isShallow : undefined; + isShallow = false; + } + if (callback != null) { + array = map(array, callback, thisArg); + } + return basicFlatten(array, isShallow); + } /** * Gets the index at which the first occurrence of `value` is found using @@ -4025,15 +4009,14 @@ } /** - * Computes the intersection of all the passed-in arrays using strict equality - * for comparisons, i.e. `===`. + * Creates an array of unique values present in all passed-in arrays using + * strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays - * @param {Array} [array1, array2, ...] Arrays to process. - * @returns {Array} Returns a new array of unique elements that are present - * in **all** of the arrays. + * @param {Array} [array1, array2, ...] The arrays to inspect. + * @returns {Array} Returns an array of composite values. * @example * * _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); @@ -4384,22 +4367,21 @@ } /** - * Computes the union of the passed-in arrays using strict equality for - * comparisons, i.e. `===`. + * Creates an array of unique values, in order, of the passed-in arrays + * using strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays - * @param {Array} [array1, array2, ...] Arrays to process. - * @returns {Array} Returns a new array of unique values, in order, that are - * present in one or more of the arrays. + * @param {Array} [array1, array2, ...] The arrays to inspect. + * @returns {Array} Returns an array of composite values. * @example * * _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); * // => [1, 2, 3, 101, 10] */ function union(array) { - return basicUniq(basicFlatten(compact(arguments), true)); + return basicUniq(basicFlatten(arguments, true, true)); } /** @@ -4445,18 +4427,29 @@ * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }, { 'x': 2 }] */ - var uniq = overloadWrapper(basicUniq); + function uniq(array, isSorted, callback, thisArg) { + // juggle arguments + if (typeof isSorted != 'boolean' && isSorted != null) { + thisArg = callback; + callback = !(thisArg && thisArg[isSorted] === array) ? isSorted : undefined; + isSorted = false; + } + if (callback != null) { + callback = lodash.createCallback(callback, thisArg); + } + return basicUniq(array, isSorted, callback); + } /** - * Creates an array excluding all occurrences of the passed values using - * strict equality for comparisons, i.e. `===`. + * Creates an array excluding all passed values using strict equality for + * comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to filter. - * @param {Mixed} [value1, value2, ...] Values to exclude. - * @returns {Array} Returns a new filtered array. + * @param {Mixed} [value1, value2, ...] The values to exclude. + * @returns {Array} Returns a new array of filtered values. * @example * * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); @@ -4598,7 +4591,7 @@ * @category Functions * @param {Object} object The object to bind and assign the bound methods to. * @param {String} [methodName1, methodName2, ...] The object method names to - * bind, specified as individual values or arrays of values. + * bind, specified as individual method names or arrays of method names. * @returns {Object} Returns `object`. * @example * @@ -4612,7 +4605,7 @@ * // => alerts 'clicked docs', when the button is clicked */ function bindAll(object) { - var funcs = arguments.length > 1 ? basicFlatten(nativeSlice.call(arguments, 1)) : functions(object), + var funcs = arguments.length > 1 ? basicFlatten(arguments, true, false, 1) : functions(object), index = -1, length = funcs.length; diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index adc01aed1..6477a81bd 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -3,48 +3,49 @@ * Lo-Dash 1.3.1 (Custom Build) lodash.com/license | Underscore.js 1.5.1 underscorejs.org/LICENSE * Build: `lodash -o ./dist/lodash.compat.js` */ -;!function(n){function t(n,t,r){r=(r||0)-1;for(var e=n.length;++rt||typeof n=="undefined")return 1;if(nr?0:r);++e=E&&i===t,v=u||p?f():l;if(p){var h=o(v);h?(i=r,v=h):(p=b,v=u?v:(s(v),l))}for(;++ai(v,m))&&((u||p)&&v.push(m),l.push(h))}return p?(s(v.b),g(v)):u&&s(v),l}function tt(n,t,r,e){function u(){var e=arguments,c=o?this:t;return a||(n=t[i]),r.length&&(e=e.length?(e=Ar.call(e),f?e.concat(r):r.concat(e)):r),this instanceof u?(c=at(n.prototype),e=n.apply(c,e),yt(e)?e:c):n.apply(c,e) -}var a=mt(n),o=!r,i=t;if(o){var f=e;r=t}else if(!a){if(!e)throw new tr;t=n}return u}function et(){var n=c(),t=x.o;n.g=W,n.b=n.c=n.f=n.h="",n.e="r",n.i=y,n.j=!!t;for(var r,e=0;r=arguments[e];e++)for(var u in r)n[u]=r[u];e=n.a,n.d=/^[^,]+/.exec(e)[0],r=Vt,e="return function("+e+"){",u="var m,r="+n.d+",C="+n.e+";if(!r)return C;"+n.h+";",n.b?(u+="var s=r.length;m=-1;if("+n.b+"){",zr.unindexedChars&&(u+="if(q(r)){r=r.split('')}"),u+="while(++mk;k++)u+="m='"+n.g[k]+"';if((!(p&&v[m])&&l.call(r,m))",n.i||(u+="||(!v[m]&&r[m]!==y[m])"),u+="){"+n.f+"}"; -u+="}"}return(n.b||zr.nonEnumArgs)&&(u+="}"),u+=n.c+";return C",r=r("i,j,l,indicatorObject,n,o,q,t,u,y,z,w,G,H,J",e+u+"}"),g(n),r(K,er,gr,w,pt,Rr,bt,t,_,ur,Z,Pr,X,ar,dr)}function at(n){return yt(n)?_r(n):{}}function ot(n){return Lr[n]}function it(){var n=(n=_.indexOf)===Ft?t:n;return n}function ft(n){return function(t,r,e,u){return typeof r!="boolean"&&r!=d&&(u=e,e=u&&u[r]===t?m:r,r=b),e!=d&&(e=_.createCallback(e,u)),n(t,r,e,u)}}function ct(n){var t,r;return!n||dr.call(n)!=V||(t=n.constructor,mt(t)&&!(t instanceof t))||!zr.argsClass&&pt(n)||!zr.nodeClass&&l(n)?b:zr.ownLast?(Ur(n,function(n,t,e){return r=gr.call(e,t),b -}),r!==false):(Ur(n,function(n,t){r=t}),r===m||gr.call(n,r))}function lt(n){return Gr[n]}function pt(n){return n&&typeof n=="object"?dr.call(n)==L:b}function st(n,t,r,e,u,a){var o=n;if(typeof t!="boolean"&&t!=d&&(e=r,r=t,t=b),typeof r=="function"){if(r=typeof e=="undefined"?r:_.createCallback(r,e,1),o=r(o),typeof o!="undefined")return o;o=n}if(e=yt(o)){var i=dr.call(o);if(!Y[i]||!zr.nodeClass&&l(o))return o;var c=Rr(o)}if(!e||!t)return e?c?v(o):Kr({},o):o;switch(e=Nr[i],i){case H:case J:return new e(+o); -case U:case X:return new e(o);case Q:return e(o.source,z.exec(o))}i=!u,u||(u=f()),a||(a=f());for(var p=u.length;p--;)if(u[p]==n)return a[p];return o=c?e(o.length):{},c&&(gr.call(n,"index")&&(o.index=n.index),gr.call(n,"input")&&(o.input=n.input)),u.push(n),a.push(o),(c?Wr:Vr)(n,function(n,e){o[e]=st(n,t,r,m,u,a)}),i&&(s(u),s(a)),o}function gt(n){var t=[];return Ur(n,function(n,r){mt(n)&&t.push(r)}),t.sort()}function vt(n){for(var t=-1,r=Tr(n),e=r.length,u={};++tr?xr(0,a+r):r)||0,a&&typeof a=="number"?o=-1<(bt(n)?n.indexOf(t,r):u(n,t,r)):Wr(n,function(n){return++ea&&(a=i)}}else t=!t&&bt(n)?u:_.createCallback(t,r),Wr(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,a=n)});return a}function At(n,t,r,e){var u=3>arguments.length;if(t=_.createCallback(t,e,4),Rr(n)){var a=-1,o=n.length;for(u&&(r=n[++a]);++aarguments.length;if(typeof a!="number")var i=Tr(n),a=i.length;else zr.unindexedChars&&bt(n)&&(u=n.split(""));return t=_.createCallback(t,e,4),Ot(n,function(n,e,f){e=i?i[--a]:--a,r=o?(o=b,u[e]):t(r,u[e],e,f) -}),r}function Bt(n,t,r){var e;if(t=_.createCallback(t,r),Rr(n)){r=-1;for(var u=n.length;++r=E&&u===t;if(c){var l=o(i);l?(u=r,i=l):c=b}for(;++eu(i,l)&&f.push(l);return c&&g(i),f}function zt(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&t!=d){var a=-1; -for(t=_.createCallback(t,r);++ae?xr(0,u+e):e||0}else if(e)return e=Dt(n,r),n[e]===r?e:-1;return n?t(n,r,e):-1}function $t(n,t,r){if(typeof t!="number"&&t!=d){var e=0,u=-1,a=n?n.length:0;for(t=_.createCallback(t,r);++u>>1,r(n[e])r?0:r);++tc&&(i=n.apply(f,o));else{var r=new Ut;!s&&!h&&(l=r);var e=p-(r-l);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:F,variable:"",imports:{_:_}};var Fr={a:"x,F,k",h:"var a=arguments,b=0,c=typeof k=='number'?2:a.length;while(++b":">",'"':""","'":"'"},Gr=vt(Lr),Hr=Zt("("+Tr(Gr).join("|")+")","g"),Jr=Zt("["+Tr(Lr).join("")+"]","g"),Kr=et(Fr,{h:Fr.h.replace(";",";if(c>3&&typeof a[c-2]=='function'){var d=u.createCallback(a[--c-1],a[c--],2)}else if(c>2&&typeof a[c-1]=='function'){d=a[--c]}"),f:"C[m]=d?d(C[m],r[m]):r[m]"}),Mr=et(Fr),Ur=et($r,Dr,{i:b}),Vr=et($r,Dr); -mt(/x/)&&(mt=function(n){return typeof n=="function"&&dr.call(n)==M});var Qr=sr?function(n){if(!n||dr.call(n)!=V||!zr.argsClass&&pt(n))return b;var t=n.valueOf,r=typeof t=="function"&&(r=sr(t))&&sr(r);return r?n==r||sr(n)==r:ct(n)}:ct,Xr=Et,Yr=ft(S),Zr=ft(nt);Br&&rt&&typeof mr=="function"&&(Lt=Tt(mr,e));var ne=8==Er(A+"08")?Er:function(n,t){return Er(bt(n)?n.replace($,""):n,t||0)};return _.after=function(n,t){return function(){return 1>--n?t.apply(this,arguments):void 0}},_.assign=Kr,_.at=function(n){var t=-1,r=S(Ar.call(arguments,1)),e=r.length,u=Kt(e); -for(zr.unindexedChars&&bt(n)&&(n=n.split(""));++t=E&&o(a?e[a]:h)}n:for(;++c(y?r(y,m):l(h,m))){for(a=u,(y||h).push(m);--a;)if(y=i[a],0>(y?r(y,m):l(e[a],m)))continue n;v.push(m)}}for(;u--;)(y=i[u])&&g(y);return s(i),s(h),v},_.invert=vt,_.invoke=function(n,t){var r=Ar.call(arguments,2),e=-1,u=typeof t=="function",a=n?n.length:0,o=Kt(typeof a=="number"?a:0);return Ot(n,function(n){o[++e]=(u?t:n[t]).apply(n,r)}),o},_.keys=Tr,_.map=Et,_.max=St,_.memoize=function(n,t){function r(){var e=r.cache,u=O+(t?t.apply(this,arguments):arguments[0]); -return gr.call(e,u)?e[u]:e[u]=n.apply(this,arguments)}return r.cache={},r},_.merge=_t,_.min=function(n,t,r){var e=1/0,a=e;if(!t&&Rr(n)){r=-1;for(var o=n.length;++re(o,r))&&(a[r]=n)}),a},_.once=function(n){var t,r; -return function(){return t?r:(t=y,r=n.apply(this,arguments),n=d,r)}},_.pairs=function(n){for(var t=-1,r=Tr(n),e=r.length,u=Kt(e);++tr?xr(0,e+r):Or(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},_.mixin=Ht,_.noConflict=function(){return e._=or,this},_.parseInt=ne,_.random=function(n,t){n==d&&t==d&&(t=1),n=+n||0,t==d?(t=n,n=0):t=+t||0;var r=Sr();return n%1||t%1?n+Or(r*(t-n+parseFloat("1e-"+((r+"").length-1))),t):n+lr(r*(t-n+1))},_.reduce=At,_.reduceRight=It,_.result=function(n,t){var r=n?n[t]:m; -return mt(r)?n[t]():r},_.runInContext=h,_.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Tr(n).length},_.some=Bt,_.sortedIndex=Dt,_.template=function(n,t,r){var e=_.templateSettings;n||(n=""),r=Mr({},r,e);var u,a=Mr({},r.imports,e.imports),e=Tr(a),a=jt(a),o=0,f=r.interpolate||D,c="__p+='",f=Zt((r.escape||D).source+"|"+f.source+"|"+(f===F?P:D).source+"|"+(r.evaluate||D).source+"|$","g");n.replace(f,function(t,r,e,a,f,l){return e||(e=a),c+=n.slice(o,l).replace(q,i),r&&(c+="'+__e("+r+")+'"),f&&(u=y,c+="';"+f+";__p+='"),e&&(c+="'+((__t=("+e+"))==null?'':__t)+'"),o=l+t.length,t -}),c+="';\n",f=r=r.variable,f||(r="obj",c="with("+r+"){"+c+"}"),c=(u?c.replace(I,""):c).replace(B,"$1").replace(N,"$1;"),c="function("+r+"){"+(f?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var l=Vt(e,"return "+c).apply(m,a)}catch(p){throw p.source=c,p}return t?l(t):(l.source=c,l)},_.unescape=function(n){return n==d?"":nr(n).replace(Hr,lt)},_.uniqueId=function(n){var t=++C;return nr(n==d?"":n)+t -},_.all=wt,_.any=Bt,_.detect=xt,_.findWhere=xt,_.foldl=At,_.foldr=It,_.include=Ct,_.inject=At,Vr(_,function(n,t){_.prototype[t]||(_.prototype[t]=function(){var t=[this.__wrapped__];return vr.apply(t,arguments),n.apply(_,t)})}),_.first=zt,_.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&t!=d){var a=u;for(t=_.createCallback(t,r);a--&&t(n[a],a,n);)e++}else if(e=t,e==d||r)return n[u-1];return v(n,xr(0,u-e))}},_.take=zt,_.head=zt,Vr(_,function(n,t){_.prototype[t]||(_.prototype[t]=function(t,r){var e=n(this.__wrapped__,t,r); -return t==d||r&&typeof t!="function"?e:new j(e)})}),_.VERSION="1.3.1",_.prototype.toString=function(){return nr(this.__wrapped__)},_.prototype.value=Jt,_.prototype.valueOf=Jt,Wr(["join","pop","shift"],function(n){var t=rr[n];_.prototype[n]=function(){return t.apply(this.__wrapped__,arguments)}}),Wr(["push","reverse","sort","unshift"],function(n){var t=rr[n];_.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Wr(["concat","slice","splice"],function(n){var t=rr[n];_.prototype[n]=function(){return new j(t.apply(this.__wrapped__,arguments)) -}}),zr.spliceObjects||Wr(["pop","shift","splice"],function(n){var t=rr[n],r="splice"==n;_.prototype[n]=function(){var n=this.__wrapped__,e=t.apply(n,arguments);return 0===n.length&&delete n[0],r?new j(e):e}}),_}var m,y=!0,d=null,b=!1,_=[],j=[],C=0,w={},x={},O=+new Date+"",E=75,S=40,A=" \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",I=/\b__p\+='';/g,B=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,P=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,z=/\w*$/,F=/<%=([\s\S]+?)%>/g,$=RegExp("^["+A+"]*0+(?=.$)"),D=/($^)/,R=(R=/\bthis\b/)&&R.test(h)&&R,q=/['\n\r\t\u2028\u2029\\]/g,T="Array Boolean Date Error Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),W="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),L="[object Arguments]",G="[object Array]",H="[object Boolean]",J="[object Date]",K="[object Error]",M="[object Function]",U="[object Number]",V="[object Object]",Q="[object RegExp]",X="[object String]",Y={}; +;!function(n){function t(n,t,r){r=(r||0)-1;for(var e=n?n.length:0;++rt||typeof n=="undefined")return 1;if(nr?0:r);++e=E&&i===t,v=u||p?f():l;if(p){var h=a(v);h?(i=r,v=h):(p=b,v=u?v:(s(v),l))}for(;++oi(v,m))&&((u||p)&&v.push(m),l.push(h))}return p?(s(v.b),g(v)):u&&s(v),l}function tt(n,t,r,e){function u(){var e=arguments,c=a?this:t;return o||(n=t[i]),r.length&&(e=e.length?(e=Sr.call(e),f?e.concat(r):r.concat(e)):r),this instanceof u?(c=ot(n.prototype),e=n.apply(c,e),mt(e)?e:c):n.apply(c,e) +}var o=ht(n),a=!r,i=t;if(a){var f=e;r=t}else if(!o){if(!e)throw new nr;t=n}return u}function et(){var n=c(),t=x.o;n.g=W,n.b=n.c=n.f=n.h="",n.e="r",n.i=y,n.j=!!t;for(var r,e=0;r=arguments[e];e++)for(var u in r)n[u]=r[u];e=n.a,n.d=/^[^,]+/.exec(e)[0],r=Ut,e="return function("+e+"){",u="var m,r="+n.d+",C="+n.e+";if(!r)return C;"+n.h+";",n.b?(u+="var s=r.length;m=-1;if("+n.b+"){",Pr.unindexedChars&&(u+="if(q(r)){r=r.split('')}"),u+="while(++mk;k++)u+="m='"+n.g[k]+"';if((!(p&&v[m])&&l.call(r,m))",n.i||(u+="||(!v[m]&&r[m]!==y[m])"),u+="){"+n.f+"}"; +u+="}"}return(n.b||Pr.nonEnumArgs)&&(u+="}"),u+=n.c+";return C",r=r("i,j,l,indicatorObject,n,o,q,t,u,y,z,w,G,H,J",e+u+"}"),g(n),r(K,rr,sr,w,lt,Dr,dt,t,_,er,Z,Nr,X,ur,yr)}function ot(n){return mt(n)?br(n):{}}function at(n){return Wr[n]}function it(){var n=(n=_.indexOf)===Pt?t:n;return n}function ft(n){var t,r;return!n||yr.call(n)!=V||(t=n.constructor,ht(t)&&!(t instanceof t))||!Pr.argsClass&<(n)||!Pr.nodeClass&&l(n)?b:Pr.ownLast?(Mr(n,function(n,t,e){return r=sr.call(e,t),b}),r!==false):(Mr(n,function(n,t){r=t +}),r===m||sr.call(n,r))}function ct(n){return Lr[n]}function lt(n){return n&&typeof n=="object"?yr.call(n)==L:b}function pt(n,t,r,e,u,o){var a=n;if(typeof t!="boolean"&&t!=d&&(e=r,r=t,t=b),typeof r=="function"){if(r=typeof e=="undefined"?r:_.createCallback(r,e,1),a=r(a),typeof a!="undefined")return a;a=n}if(e=mt(a)){var i=yr.call(a);if(!Y[i]||!Pr.nodeClass&&l(a))return a;var c=Dr(a)}if(!e||!t)return e?c?v(a):Jr({},a):a;switch(e=Br[i],i){case H:case J:return new e(+a);case U:case X:return new e(a); +case Q:return e(a.source,z.exec(a))}i=!u,u||(u=f()),o||(o=f());for(var p=u.length;p--;)if(u[p]==n)return o[p];return a=c?e(a.length):{},c&&(sr.call(n,"index")&&(a.index=n.index),sr.call(n,"input")&&(a.input=n.input)),u.push(n),o.push(a),(c?Tr:Ur)(n,function(n,e){a[e]=pt(n,t,r,m,u,o)}),i&&(s(u),s(o)),a}function st(n){var t=[];return Mr(n,function(n,r){ht(n)&&t.push(r)}),t.sort()}function gt(n){for(var t=-1,r=qr(n),e=r.length,u={};++tr?kr(0,o+r):r)||0,o&&typeof o=="number"?a=-1<(dt(n)?n.indexOf(t,r):u(n,t,r)):Tr(n,function(n){return++eo&&(o=i)}}else t=!t&&dt(n)?u:_.createCallback(t,r),Tr(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function St(n,t,r,e){var u=3>arguments.length;if(t=_.createCallback(t,e,4),Dr(n)){var o=-1,a=n.length;for(u&&(r=n[++o]);++oarguments.length;if(typeof o!="number")var i=qr(n),o=i.length;else Pr.unindexedChars&&dt(n)&&(u=n.split(""));return t=_.createCallback(t,e,4),xt(n,function(n,e,f){e=i?i[--o]:--o,r=a?(a=b,u[e]):t(r,u[e],e,f) +}),r}function It(n,t,r){var e;if(t=_.createCallback(t,r),Dr(n)){r=-1;for(var u=n.length;++r=E&&u===t;if(c){var l=a(i);l?(u=r,i=l):c=b}for(;++eu(i,l)&&f.push(l);return c&&g(i),f}function Nt(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&t!=d){var o=-1;for(t=_.createCallback(t,r);++oe?kr(0,u+e):e||0}else if(e)return e=Ft(n,r),n[e]===r?e:-1;return n?t(n,r,e):-1}function zt(n,t,r){if(typeof t!="number"&&t!=d){var e=0,u=-1,o=n?n.length:0;for(t=_.createCallback(t,r);++u>>1,r(n[e])r?0:r);++tc&&(i=n.apply(f,a));else{var r=new Mt;!s&&!h&&(l=r);var e=p-(r-l);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:F,variable:"",imports:{_:_}};var zr={a:"x,F,k",h:"var a=arguments,b=0,c=typeof k=='number'?2:a.length;while(++b":">",'"':""","'":"'"},Lr=gt(Wr),Gr=Yt("("+qr(Lr).join("|")+")","g"),Hr=Yt("["+qr(Wr).join("")+"]","g"),Jr=et(zr,{h:zr.h.replace(";",";if(c>3&&typeof a[c-2]=='function'){var d=u.createCallback(a[--c-1],a[c--],2)}else if(c>2&&typeof a[c-1]=='function'){d=a[--c]}"),f:"C[m]=d?d(C[m],r[m]):r[m]"}),Kr=et(zr),Mr=et(Fr,$r,{i:b}),Ur=et(Fr,$r); +ht(/x/)&&(ht=function(n){return typeof n=="function"&&yr.call(n)==M});var Vr=pr?function(n){if(!n||yr.call(n)!=V||!Pr.argsClass&<(n))return b;var t=n.valueOf,r=typeof t=="function"&&(r=pr(t))&&pr(r);return r?n==r||pr(n)==r:ft(n)}:ft,Qr=Ot;Ir&&rt&&typeof hr=="function"&&(Wt=qt(hr,e));var Xr=8==Or(A+"08")?Or:function(n,t){return Or(dt(n)?n.replace($,""):n,t||0)};return _.after=function(n,t){return function(){return 1>--n?t.apply(this,arguments):void 0}},_.assign=Jr,_.at=function(n){var t=-1,r=S(arguments,y,b,1),e=r.length,u=Jt(e); +for(Pr.unindexedChars&&dt(n)&&(n=n.split(""));++t=E&&a(o?e[o]:h)}n:for(;++c(y?r(y,m):l(h,m))){for(o=u,(y||h).push(m);--o;)if(y=i[o],0>(y?r(y,m):l(e[o],m)))continue n; +v.push(m)}}for(;u--;)(y=i[u])&&g(y);return s(i),s(h),v},_.invert=gt,_.invoke=function(n,t){var r=Sr.call(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,a=Jt(typeof o=="number"?o:0);return xt(n,function(n){a[++e]=(u?t:n[t]).apply(n,r)}),a},_.keys=qr,_.map=Ot,_.max=Et,_.memoize=function(n,t){function r(){var e=r.cache,u=O+(t?t.apply(this,arguments):arguments[0]);return sr.call(e,u)?e[u]:e[u]=n.apply(this,arguments)}return r.cache={},r},_.merge=bt,_.min=function(n,t,r){var e=1/0,o=e;if(!t&&Dr(n)){r=-1; +for(var a=n.length;++re(a,r))&&(o[r]=n)}),o},_.once=function(n){var t,r;return function(){return t?r:(t=y,r=n.apply(this,arguments),n=d,r)}},_.pairs=function(n){for(var t=-1,r=qr(n),e=r.length,u=Jt(e);++tr?kr(0,e+r):xr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},_.mixin=Gt,_.noConflict=function(){return e._=or,this},_.parseInt=Xr,_.random=function(n,t){n==d&&t==d&&(t=1),n=+n||0,t==d?(t=n,n=0):t=+t||0;var r=Er();return n%1||t%1?n+xr(r*(t-n+parseFloat("1e-"+((r+"").length-1))),t):n+cr(r*(t-n+1))},_.reduce=St,_.reduceRight=At,_.result=function(n,t){var r=n?n[t]:m;return ht(r)?n[t]():r},_.runInContext=h,_.size=function(n){var t=n?n.length:0; +return typeof t=="number"?t:qr(n).length},_.some=It,_.sortedIndex=Ft,_.template=function(n,t,r){var e=_.templateSettings;n||(n=""),r=Kr({},r,e);var u,o=Kr({},r.imports,e.imports),e=qr(o),o=_t(o),a=0,f=r.interpolate||D,c="__p+='",f=Yt((r.escape||D).source+"|"+f.source+"|"+(f===F?P:D).source+"|"+(r.evaluate||D).source+"|$","g");n.replace(f,function(t,r,e,o,f,l){return e||(e=o),c+=n.slice(a,l).replace(q,i),r&&(c+="'+__e("+r+")+'"),f&&(u=y,c+="';"+f+";__p+='"),e&&(c+="'+((__t=("+e+"))==null?'':__t)+'"),a=l+t.length,t +}),c+="';\n",f=r=r.variable,f||(r="obj",c="with("+r+"){"+c+"}"),c=(u?c.replace(I,""):c).replace(B,"$1").replace(N,"$1;"),c="function("+r+"){"+(f?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var l=Ut(e,"return "+c).apply(m,o)}catch(p){throw p.source=c,p}return t?l(t):(l.source=c,l)},_.unescape=function(n){return n==d?"":Zt(n).replace(Gr,ct)},_.uniqueId=function(n){var t=++C;return Zt(n==d?"":n)+t +},_.all=Ct,_.any=It,_.detect=kt,_.findWhere=kt,_.foldl=St,_.foldr=At,_.include=jt,_.inject=St,Ur(_,function(n,t){_.prototype[t]||(_.prototype[t]=function(){var t=[this.__wrapped__];return gr.apply(t,arguments),n.apply(_,t)})}),_.first=Nt,_.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&t!=d){var o=u;for(t=_.createCallback(t,r);o--&&t(n[o],o,n);)e++}else if(e=t,e==d||r)return n[u-1];return v(n,kr(0,u-e))}},_.take=Nt,_.head=Nt,Ur(_,function(n,t){_.prototype[t]||(_.prototype[t]=function(t,r){var e=n(this.__wrapped__,t,r); +return t==d||r&&typeof t!="function"?e:new j(e)})}),_.VERSION="1.3.1",_.prototype.toString=function(){return Zt(this.__wrapped__)},_.prototype.value=Ht,_.prototype.valueOf=Ht,Tr(["join","pop","shift"],function(n){var t=tr[n];_.prototype[n]=function(){return t.apply(this.__wrapped__,arguments)}}),Tr(["push","reverse","sort","unshift"],function(n){var t=tr[n];_.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Tr(["concat","slice","splice"],function(n){var t=tr[n];_.prototype[n]=function(){return new j(t.apply(this.__wrapped__,arguments)) +}}),Pr.spliceObjects||Tr(["pop","shift","splice"],function(n){var t=tr[n],r="splice"==n;_.prototype[n]=function(){var n=this.__wrapped__,e=t.apply(n,arguments);return 0===n.length&&delete n[0],r?new j(e):e}}),_}var m,y=!0,d=null,b=!1,_=[],j=[],C=0,w={},x={},O=+new Date+"",E=75,S=40,A=" \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",I=/\b__p\+='';/g,B=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,P=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,z=/\w*$/,F=/<%=([\s\S]+?)%>/g,$=RegExp("^["+A+"]*0+(?=.$)"),D=/($^)/,R=(R=/\bthis\b/)&&R.test(h)&&R,q=/['\n\r\t\u2028\u2029\\]/g,T="Array Boolean Date Error Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),W="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),L="[object Arguments]",G="[object Array]",H="[object Boolean]",J="[object Date]",K="[object Error]",M="[object Function]",U="[object Number]",V="[object Object]",Q="[object RegExp]",X="[object String]",Y={}; Y[M]=b,Y[L]=Y[G]=Y[H]=Y[J]=Y[U]=Y[V]=Y[Q]=Y[X]=y;var Z={"boolean":b,"function":y,object:y,number:b,string:b,undefined:b},nt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},tt=Z[typeof exports]&&exports,rt=Z[typeof module]&&module&&module.exports==tt&&module,et=Z[typeof global]&&global;!et||et.global!==et&&et.window!==et||(n=et);var ut=h();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=ut, define(function(){return ut})):tt&&!tt.nodeType?rt?(rt.exports=ut)._=ut:tt._=ut:n._=ut }(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 473dac71a..c4c3ad25a 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -151,7 +151,7 @@ */ function basicIndexOf(array, value, fromIndex) { var index = (fromIndex || 0) - 1, - length = array.length; + length = array ? array.length : 0; while (++index < length) { if (array[index] === value) { @@ -228,7 +228,7 @@ } /** - * Used by `sortBy` to compare transformed `collection` values, stable sorting + * Used by `sortBy` to compare transformed `collection` elements, stable sorting * them in ascending order. * * @private @@ -662,24 +662,22 @@ * * @private * @param {Array} array The array to flatten. - * @param {Boolean} [isShallow=false] A flag to indicate only flattening a single level. - * @param {Function} [callback] The function called per iteration. + * @param {Boolean} [isShallow=false] A flag to restrict flattening to a single level. + * @param {Boolean} [isArgArrays=false] A flag to restrict flattening to arrays and `arguments` objects. + * @param {Number} [fromIndex=0] The index to start from. * @returns {Array} Returns a new flattened array. */ - function basicFlatten(array, isShallow, callback) { - var index = -1, + function basicFlatten(array, isShallow, isArgArrays, fromIndex) { + var index = (fromIndex || 0) - 1, length = array ? array.length : 0, result = []; while (++index < length) { var value = array[index]; - if (callback) { - value = callback(value, index, array); - } // recursively flatten arrays (susceptible to call stack limits) if (value && typeof value == 'object' && (isArray(value) || isArguments(value))) { push.apply(result, isShallow ? value : basicFlatten(value)); - } else { + } else if (!isArgArrays) { result.push(value); } } @@ -826,34 +824,11 @@ * @private * @returns {Function} Returns the "indexOf" function. */ - function getIndexOf(array, value, fromIndex) { + function getIndexOf() { var result = (result = lodash.indexOf) === indexOf ? basicIndexOf : result; return result; } - /** - * Creates a function that juggles arguments, allowing argument overloading - * for `_.flatten` and `_.uniq`, before passing them to the given `func`. - * - * @private - * @param {Function} func The function to wrap. - * @returns {Function} Returns the new function. - */ - function overloadWrapper(func) { - return function(array, flag, callback, thisArg) { - // juggle arguments - if (typeof flag != 'boolean' && flag != null) { - thisArg = callback; - callback = !(thisArg && thisArg[flag] === array) ? flag : undefined; - flag = false; - } - if (callback != null) { - callback = lodash.createCallback(callback, thisArg); - } - return func(array, flag, callback, thisArg); - }; - } - /** * A fallback implementation of `isPlainObject` which checks if a given `value` * is an object created by the `Object` constructor, assuming objects created @@ -1384,8 +1359,8 @@ }; /** - * Creates a sorted array of all enumerable properties, own and inherited, - * of `object` that have function values. + * Creates a sorted array of property names of all enumerable properties, + * own and inherited, of `object` that have function values. * * @static * @memberOf _ @@ -2151,7 +2126,7 @@ if (isFunc) { callback = lodash.createCallback(callback, thisArg); } else { - var props = basicFlatten(nativeSlice.call(arguments, 1)); + var props = basicFlatten(arguments, true, false, 1); } forIn(object, function(value, key, object) { if (isFunc @@ -2221,7 +2196,7 @@ var result = {}; if (typeof callback != 'function') { var index = -1, - props = basicFlatten(nativeSlice.call(arguments, 1)), + props = basicFlatten(arguments, true, false, 1), length = isObject(object) ? props.length : 0; while (++index < length) { @@ -2342,7 +2317,7 @@ */ function at(collection) { var index = -1, - props = basicFlatten(nativeSlice.call(arguments, 1)), + props = basicFlatten(arguments, true, false, 1), length = props.length, result = Array(length); @@ -3354,7 +3329,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to compact. - * @returns {Array} Returns a new filtered array. + * @returns {Array} Returns a new array of filtered values. * @example * * _.compact([0, 1, false, 2, '', 3]); @@ -3375,17 +3350,15 @@ } /** - * Creates an arrat with all occurrences of the passed values removed using - * using strict equality for comparisons, i.e. `===`. Values to exclude may - * be specified as individual arguments or as arrays. + * Creates an array excluding all values of the passed-in arrays using + * strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to process. - * @param {Array} [array1, array2, ...] The values to exclude, specified as - * individual values or arrays of values. - * @returns {Array} Returns a new filtered array. + * @param {Array} [array1, array2, ...] The arrays of values to exclude. + * @returns {Array} Returns a new array of filtered values. * @example * * _.difference([1, 2, 3, 4, 5], [5, 2, 10]); @@ -3395,7 +3368,7 @@ var index = -1, indexOf = getIndexOf(), length = array ? array.length : 0, - seen = basicFlatten(nativeSlice.call(arguments, 1)), + seen = basicFlatten(arguments, true, true, 1), result = []; var isLarge = length >= largeArraySize && indexOf === basicIndexOf; @@ -3550,7 +3523,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to flatten. - * @param {Boolean} [isShallow=false] A flag to indicate only flattening a single level. + * @param {Boolean} [isShallow=false] A flag to restrict flattening to a single level. * @param {Function|Object|String} [callback=identity] The function called per * iteration. If a property name or object is passed, it will be used to create * a "_.pluck" or "_.where" style callback, respectively. @@ -3573,7 +3546,18 @@ * _.flatten(stooges, 'quotes'); * // => ['Oh, a wise guy, eh?', 'Poifect!', 'Spread out!', 'You knucklehead!'] */ - var flatten = overloadWrapper(basicFlatten); + function flatten(array, isShallow, callback, thisArg) { + // juggle arguments + if (typeof isShallow != 'boolean' && isShallow != null) { + thisArg = callback; + callback = !(thisArg && thisArg[isShallow] === array) ? isShallow : undefined; + isShallow = false; + } + if (callback != null) { + array = map(array, callback, thisArg); + } + return basicFlatten(array, isShallow); + } /** * Gets the index at which the first occurrence of `value` is found using @@ -3686,15 +3670,14 @@ } /** - * Computes the intersection of all the passed-in arrays using strict equality - * for comparisons, i.e. `===`. + * Creates an array of unique values present in all passed-in arrays using + * strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays - * @param {Array} [array1, array2, ...] Arrays to process. - * @returns {Array} Returns a new array of unique elements that are present - * in **all** of the arrays. + * @param {Array} [array1, array2, ...] The arrays to inspect. + * @returns {Array} Returns an array of composite values. * @example * * _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); @@ -4045,22 +4028,21 @@ } /** - * Computes the union of the passed-in arrays using strict equality for - * comparisons, i.e. `===`. + * Creates an array of unique values, in order, of the passed-in arrays + * using strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays - * @param {Array} [array1, array2, ...] Arrays to process. - * @returns {Array} Returns a new array of unique values, in order, that are - * present in one or more of the arrays. + * @param {Array} [array1, array2, ...] The arrays to inspect. + * @returns {Array} Returns an array of composite values. * @example * * _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); * // => [1, 2, 3, 101, 10] */ function union(array) { - return basicUniq(basicFlatten(compact(arguments), true)); + return basicUniq(basicFlatten(arguments, true, true)); } /** @@ -4106,18 +4088,29 @@ * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }, { 'x': 2 }] */ - var uniq = overloadWrapper(basicUniq); + function uniq(array, isSorted, callback, thisArg) { + // juggle arguments + if (typeof isSorted != 'boolean' && isSorted != null) { + thisArg = callback; + callback = !(thisArg && thisArg[isSorted] === array) ? isSorted : undefined; + isSorted = false; + } + if (callback != null) { + callback = lodash.createCallback(callback, thisArg); + } + return basicUniq(array, isSorted, callback); + } /** - * Creates an array excluding all occurrences of the passed values using - * strict equality for comparisons, i.e. `===`. + * Creates an array excluding all passed values using strict equality for + * comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to filter. - * @param {Mixed} [value1, value2, ...] Values to exclude. - * @returns {Array} Returns a new filtered array. + * @param {Mixed} [value1, value2, ...] The values to exclude. + * @returns {Array} Returns a new array of filtered values. * @example * * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); @@ -4259,7 +4252,7 @@ * @category Functions * @param {Object} object The object to bind and assign the bound methods to. * @param {String} [methodName1, methodName2, ...] The object method names to - * bind, specified as individual values or arrays of values. + * bind, specified as individual method names or arrays of method names. * @returns {Object} Returns `object`. * @example * @@ -4273,7 +4266,7 @@ * // => alerts 'clicked docs', when the button is clicked */ function bindAll(object) { - var funcs = arguments.length > 1 ? basicFlatten(nativeSlice.call(arguments, 1)) : functions(object), + var funcs = arguments.length > 1 ? basicFlatten(arguments, true, false, 1) : functions(object), index = -1, length = funcs.length; diff --git a/dist/lodash.min.js b/dist/lodash.min.js index d41a93d5a..94c67e24b 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -3,45 +3,45 @@ * Lo-Dash 1.3.1 (Custom Build) lodash.com/license | Underscore.js 1.5.1 underscorejs.org/LICENSE * Build: `lodash modern -o ./dist/lodash.js` */ -;!function(n){function t(n,t,e){e=(e||0)-1;for(var r=n.length;++et||typeof n=="undefined")return 1;if(ne?0:e);++r=C&&i===t,g=u||v?f():s;if(v){var h=o(g);h?(i=e,g=h):(v=b,g=u?g:(l(g),s))}for(;++ai(g,y))&&((u||v)&&g.push(y),s.push(h))}return v?(l(g.b),p(g)):u&&l(g),s}function ut(n,t,e,r){function u(){var r=arguments,c=o?this:t; -return a||(n=t[i]),e.length&&(r=r.length?(r=Oe.call(r),f?r.concat(e):e.concat(r)):e),this instanceof u?(c=yt(n.prototype)?be(n.prototype):{},r=n.apply(c,r),yt(r)?r:c):n.apply(c,r)}var a=ht(n),o=!e,i=t;if(o){var f=r;e=t}else if(!a){if(!r)throw new te;t=n}return u}function at(n){return Be[n]}function ot(){var n=(n=nt.indexOf)===Rt?t:n;return n}function it(n){return function(t,e,r,u){return typeof e!="boolean"&&e!=y&&(u=r,r=u&&u[e]===t?g:e,e=b),r!=y&&(r=nt.createCallback(r,u)),n(t,e,r,u)}}function ft(n){var t,e; -return n&&he.call(n)==U&&(t=n.constructor,!ht(t)||t instanceof t)?(x(n,function(n,t){e=t}),e===g||pe.call(n,e)):b}function ct(n){return Fe[n]}function lt(n){return n&&typeof n=="object"?he.call(n)==q:b}function pt(n,t,e,r,u,a){var o=n;if(typeof t!="boolean"&&t!=y&&(r=e,e=t,t=b),typeof e=="function"){if(e=typeof r=="undefined"?e:nt.createCallback(e,r,1),o=e(o),typeof o!="undefined")return o;o=n}if(r=yt(o)){var i=he.call(o);if(!H[i])return o;var c=Ne(o)}if(!r||!t)return r?c?s(o):Q({},o):o;switch(r=Ae[i],i){case W:case P:return new r(+o); -case M:case G:return new r(o);case V:return r(o.source,N.exec(o))}i=!u,u||(u=f()),a||(a=f());for(var p=u.length;p--;)if(u[p]==n)return a[p];return o=c?r(o.length):{},c&&(pe.call(n,"index")&&(o.index=n.index),pe.call(n,"input")&&(o.input=n.input)),u.push(n),a.push(o),(c?xt:d)(n,function(n,r){o[r]=pt(n,t,e,g,u,a)}),i&&(l(u),l(a)),o}function st(n){var t=[];return x(n,function(n,e){ht(n)&&t.push(e)}),t.sort()}function vt(n){for(var t=-1,e=$e(n),r=e.length,u={};++te?je(0,a+e):e)||0,a&&typeof a=="number"?o=-1<(mt(n)?n.indexOf(t,e):u(n,t,e)):d(n,function(n){return++ra&&(a=i) -}}else t=!t&&mt(n)?u:nt.createCallback(t,e),xt(n,function(n,e,u){e=t(n,e,u),e>r&&(r=e,a=n)});return a}function St(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Gt(r);++earguments.length;t=nt.createCallback(t,r,4);var a=-1,o=n.length;if(typeof o=="number")for(u&&(e=n[++a]);++aarguments.length; -if(typeof u!="number")var o=$e(n),u=o.length;return t=nt.createCallback(t,r,4),xt(n,function(r,i,f){i=o?o[--u]:--u,e=a?(a=b,n[i]):t(e,n[i],i,f)}),e}function Nt(n,t,e){var r;t=nt.createCallback(t,e),e=-1;var u=n?n.length:0;if(typeof u=="number")for(;++e=C&&u===t; -if(c){var l=o(i);l?(u=e,i=l):c=b}for(;++ru(i,l)&&f.push(l);return c&&p(i),f}function Ft(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&t!=y){var a=-1;for(t=nt.createCallback(t,e);++ar?je(0,u+r):r||0}else if(r)return r=Dt(n,e),n[r]===e?r:-1;return n?t(n,e,r):-1}function Tt(n,t,e){if(typeof t!="number"&&t!=y){var r=0,u=-1,a=n?n.length:0; -for(t=nt.createCallback(t,e);++u>>1,e(n[r])e?0:e);++tc&&(i=n.apply(f,o));else{var e=new Jt;!s&&!m&&(l=e);var r=p-(e-l);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:$,variable:"",imports:{_:nt}};var Ne=me,$e=j.o=ke?function(n){return yt(n)?ke(n):[]}:Y,Be={"&":"&","<":"<",">":">",'"':""","'":"'"},Fe=vt(Be),Re=Zt("("+$e(Fe).join("|")+")","g"),Te=Zt("["+$e(Be).join("")+"]","g"),De=it(et),qe=it(rt);Se&&X&&typeof ve=="function"&&(Kt=Wt(ve,r)); -var ze=8==Ce(O+"08")?Ce:function(n,t){return Ce(mt(n)?n.replace(B,""):n,t||0)};return nt.after=function(n,t){return function(){return 1>--n?t.apply(this,arguments):void 0}},nt.assign=Q,nt.at=function(n){for(var t=-1,e=et(Oe.call(arguments,1)),r=e.length,u=Gt(r);++t=C&&o(a?r[a]:h)}n:for(;++c(b?e(b,y):s(h,y))){for(a=u,(b||h).push(y);--a;)if(b=i[a],0>(b?e(b,y):s(r[a],y)))continue n; -g.push(y)}}for(;u--;)(b=i[u])&&p(b);return l(i),l(h),g},nt.invert=vt,nt.invoke=function(n,t){var e=Oe.call(arguments,2),r=-1,u=typeof t=="function",a=n?n.length:0,o=Gt(typeof a=="number"?a:0);return xt(n,function(n){o[++r]=(u?t:n[t]).apply(n,e)}),o},nt.keys=$e,nt.map=Ot,nt.max=Et,nt.memoize=function(n,t){function e(){var r=e.cache,u=w+(t?t.apply(this,arguments):arguments[0]);return pe.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}return e.cache={},e},nt.merge=dt,nt.min=function(n,t,e){var r=1/0,a=r; -if(!t&&Ne(n)){e=-1;for(var o=n.length;++er(o,e))&&(a[e]=n)}),a},nt.once=function(n){var t,e;return function(){return t?e:(t=h,e=n.apply(this,arguments),n=y,e)}},nt.pairs=function(n){for(var t=-1,e=$e(n),r=e.length,u=Gt(r);++te?je(0,r+e):we(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},nt.mixin=Ut,nt.noConflict=function(){return r._=ue,this},nt.parseInt=ze,nt.random=function(n,t){n==y&&t==y&&(t=1),n=+n||0,t==y?(t=n,n=0):t=+t||0;var e=xe();return n%1||t%1?n+we(e*(t-n+parseFloat("1e-"+((e+"").length-1))),t):n+fe(e*(t-n+1))},nt.reduce=At,nt.reduceRight=It,nt.result=function(n,t){var e=n?n[t]:g; -return ht(e)?n[t]():e},nt.runInContext=v,nt.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:$e(n).length},nt.some=Nt,nt.sortedIndex=Dt,nt.template=function(n,t,e){var r=nt.templateSettings;n||(n=""),e=L({},e,r);var u,a=L({},e.imports,r.imports),r=$e(a),a=_t(a),o=0,f=e.interpolate||F,c="__p+='",f=Zt((e.escape||F).source+"|"+f.source+"|"+(f===$?I:F).source+"|"+(e.evaluate||F).source+"|$","g");n.replace(f,function(t,e,r,a,f,l){return r||(r=a),c+=n.slice(o,l).replace(T,i),e&&(c+="'+__e("+e+")+'"),f&&(u=h,c+="';"+f+";__p+='"),r&&(c+="'+((__t=("+r+"))==null?'':__t)+'"),o=l+t.length,t -}),c+="';\n",f=e=e.variable,f||(e="obj",c="with("+e+"){"+c+"}"),c=(u?c.replace(E,""):c).replace(S,"$1").replace(A,"$1;"),c="function("+e+"){"+(f?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var l=Lt(r,"return "+c).apply(g,a)}catch(p){throw p.source=c,p}return t?l(t):(l.source=c,l)},nt.unescape=function(n){return n==y?"":ne(n).replace(Re,ct)},nt.uniqueId=function(n){var t=++_;return ne(n==y?"":n)+t -},nt.all=jt,nt.any=Nt,nt.detect=Ct,nt.findWhere=Ct,nt.foldl=At,nt.foldr=It,nt.include=kt,nt.inject=At,d(nt,function(n,t){nt.prototype[t]||(nt.prototype[t]=function(){var t=[this.__wrapped__];return se.apply(t,arguments),n.apply(nt,t)})}),nt.first=Ft,nt.last=function(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&t!=y){var a=u;for(t=nt.createCallback(t,e);a--&&t(n[a],a,n);)r++}else if(r=t,r==y||e)return n[u-1];return s(n,je(0,u-r))}},nt.take=Ft,nt.head=Ft,d(nt,function(n,t){nt.prototype[t]||(nt.prototype[t]=function(t,e){var r=n(this.__wrapped__,t,e); -return t==y||e&&typeof t!="function"?r:new tt(r)})}),nt.VERSION="1.3.1",nt.prototype.toString=function(){return ne(this.__wrapped__)},nt.prototype.value=Vt,nt.prototype.valueOf=Vt,xt(["join","pop","shift"],function(n){var t=ee[n];nt.prototype[n]=function(){return t.apply(this.__wrapped__,arguments)}}),xt(["push","reverse","sort","unshift"],function(n){var t=ee[n];nt.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),xt(["concat","slice","splice"],function(n){var t=ee[n];nt.prototype[n]=function(){return new tt(t.apply(this.__wrapped__,arguments)) -}}),nt}var g,h=!0,y=null,b=!1,m=[],d=[],_=0,k={},j={},w=+new Date+"",C=75,x=40,O=" \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",E=/\b__p\+='';/g,S=/\b(__p\+=)''\+/g,A=/(__e\(.*?\)|\b__t\))\+'';/g,I=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,N=/\w*$/,$=/<%=([\s\S]+?)%>/g,B=RegExp("^["+O+"]*0+(?=.$)"),F=/($^)/,R=(R=/\bthis\b/)&&R.test(v)&&R,T=/['\n\r\t\u2028\u2029\\]/g,D="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),q="[object Arguments]",z="[object Array]",W="[object Boolean]",P="[object Date]",K="[object Function]",M="[object Number]",U="[object Object]",V="[object RegExp]",G="[object String]",H={}; -H[K]=b,H[q]=H[z]=H[W]=H[P]=H[M]=H[U]=H[V]=H[G]=h;var J={"boolean":b,"function":h,object:h,number:b,string:b,undefined:b},L={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Q=J[typeof exports]&&exports,X=J[typeof module]&&module&&module.exports==Q&&module,Y=J[typeof global]&&global;!Y||Y.global!==Y&&Y.window!==Y||(n=Y);var Z=v();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=Z, define(function(){return Z})):Q&&!Q.nodeType?X?(X.exports=Z)._=Z:Q._=Z:n._=Z +;!function(n){function t(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++et||typeof n=="undefined")return 1;if(ne?0:e);++r=C&&i===t,g=u||v?f():s;if(v){var y=o(g);y?(i=e,g=y):(v=b,g=u?g:(l(g),s))}for(;++ai(g,h))&&((u||v)&&g.push(h),s.push(y))}return v?(l(g.b),p(g)):u&&l(g),s}function ut(n,t,e,r){function u(){var r=arguments,c=o?this:t; +return a||(n=t[i]),e.length&&(r=r.length?(r=xe.call(r),f?r.concat(e):e.concat(r)):e),this instanceof u?(c=yt(n.prototype)?he(n.prototype):{},r=n.apply(c,r),yt(r)?r:c):n.apply(c,r)}var a=gt(n),o=!e,i=t;if(o){var f=r;e=t}else if(!a){if(!r)throw new ne;t=n}return u}function at(n){return Ie[n]}function ot(){var n=(n=nt.indexOf)===Bt?t:n;return n}function it(n){var t,e;return n&&ge.call(n)==U&&(t=n.constructor,!gt(t)||t instanceof t)?(x(n,function(n,t){e=t}),e===g||le.call(n,e)):b}function ft(n){return Ne[n] +}function ct(n){return n&&typeof n=="object"?ge.call(n)==q:b}function lt(n,t,e,r,u,a){var o=n;if(typeof t!="boolean"&&t!=h&&(r=e,e=t,t=b),typeof e=="function"){if(e=typeof r=="undefined"?e:nt.createCallback(e,r,1),o=e(o),typeof o!="undefined")return o;o=n}if(r=yt(o)){var i=ge.call(o);if(!H[i])return o;var c=Se(o)}if(!r||!t)return r?c?s(o):Q({},o):o;switch(r=Oe[i],i){case W:case P:return new r(+o);case M:case G:return new r(o);case V:return r(o.source,N.exec(o))}i=!u,u||(u=f()),a||(a=f());for(var p=u.length;p--;)if(u[p]==n)return a[p]; +return o=c?r(o.length):{},c&&(le.call(n,"index")&&(o.index=n.index),le.call(n,"input")&&(o.input=n.input)),u.push(n),a.push(o),(c?Ct:d)(n,function(n,r){o[r]=lt(n,t,e,g,u,a)}),i&&(l(u),l(a)),o}function pt(n){var t=[];return x(n,function(n,e){gt(n)&&t.push(e)}),t.sort()}function st(n){for(var t=-1,e=Ae(n),r=e.length,u={};++te?ke(0,a+e):e)||0,a&&typeof a=="number"?o=-1<(bt(n)?n.indexOf(t,e):u(n,t,e)):d(n,function(n){return++ra&&(a=i) +}}else t=!t&&bt(n)?u:nt.createCallback(t,e),Ct(n,function(n,e,u){e=t(n,e,u),e>r&&(r=e,a=n)});return a}function Et(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Vt(r);++earguments.length;t=nt.createCallback(t,r,4);var a=-1,o=n.length;if(typeof o=="number")for(u&&(e=n[++a]);++aarguments.length; +if(typeof u!="number")var o=Ae(n),u=o.length;return t=nt.createCallback(t,r,4),Ct(n,function(r,i,f){i=o?o[--u]:--u,e=a?(a=b,n[i]):t(e,n[i],i,f)}),e}function It(n,t,e){var r;t=nt.createCallback(t,e),e=-1;var u=n?n.length:0;if(typeof u=="number")for(;++e=C&&u===t;if(c){var l=o(i);l?(u=e,i=l):c=b}for(;++ru(i,l)&&f.push(l);return c&&p(i),f +}function $t(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&t!=h){var a=-1;for(t=nt.createCallback(t,e);++ar?ke(0,u+r):r||0}else if(r)return r=Rt(n,e),n[r]===e?r:-1;return n?t(n,e,r):-1}function Ft(n,t,e){if(typeof t!="number"&&t!=h){var r=0,u=-1,a=n?n.length:0;for(t=nt.createCallback(t,e);++u>>1,e(n[r])e?0:e);++tc&&(i=n.apply(f,o));else{var e=new Ht;!s&&!m&&(l=e);var r=p-(e-l);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:$,variable:"",imports:{_:nt}};var Se=be,Ae=j.o=_e?function(n){return yt(n)?_e(n):[]}:Y,Ie={"&":"&","<":"<",">":">",'"':""","'":"'"},Ne=st(Ie),$e=Yt("("+Ae(Ne).join("|")+")","g"),Be=Yt("["+Ae(Ie).join("")+"]","g");return Lt&&X&&typeof se=="function"&&(Pt=zt(se,r)),Gt=8==we(O+"08")?we:function(n,t){return we(bt(n)?n.replace(B,""):n,t||0) +},nt.after=function(n,t){return function(){return 1>--n?t.apply(this,arguments):void 0}},nt.assign=Q,nt.at=function(n){for(var t=-1,e=et(arguments,y,b,1),r=e.length,u=Vt(r);++t=C&&o(a?r[a]:y)}n:for(;++c(b?e(b,h):s(y,h))){for(a=u,(b||y).push(h);--a;)if(b=i[a],0>(b?e(b,h):s(r[a],h)))continue n;g.push(h)}}for(;u--;)(b=i[u])&&p(b);return l(i),l(y),g},nt.invert=st,nt.invoke=function(n,t){var e=xe.call(arguments,2),r=-1,u=typeof t=="function",a=n?n.length:0,o=Vt(typeof a=="number"?a:0);return Ct(n,function(n){o[++r]=(u?t:n[t]).apply(n,e)}),o},nt.keys=Ae,nt.map=xt,nt.max=Ot,nt.memoize=function(n,t){function e(){var r=e.cache,u=w+(t?t.apply(this,arguments):arguments[0]); +return le.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}return e.cache={},e},nt.merge=mt,nt.min=function(n,t,e){var r=1/0,a=r;if(!t&&Se(n)){e=-1;for(var o=n.length;++er(o,e))&&(a[e]=n)}),a},nt.once=function(n){var t,e; +return function(){return t?e:(t=y,e=n.apply(this,arguments),n=h,e)}},nt.pairs=function(n){for(var t=-1,e=Ae(n),r=e.length,u=Vt(r);++te?ke(0,r+e):je(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},nt.mixin=Mt,nt.noConflict=function(){return r._=re,this},nt.parseInt=Gt,nt.random=function(n,t){n==h&&t==h&&(t=1),n=+n||0,t==h?(t=n,n=0):t=+t||0;var e=Ce();return n%1||t%1?n+je(e*(t-n+parseFloat("1e-"+((e+"").length-1))),t):n+ie(e*(t-n+1))},nt.reduce=St,nt.reduceRight=At,nt.result=function(n,t){var e=n?n[t]:g; +return gt(e)?n[t]():e},nt.runInContext=v,nt.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Ae(n).length},nt.some=It,nt.sortedIndex=Rt,nt.template=function(n,t,e){var r=nt.templateSettings;n||(n=""),e=L({},e,r);var u,a=L({},e.imports,r.imports),r=Ae(a),a=dt(a),o=0,f=e.interpolate||F,c="__p+='",f=Yt((e.escape||F).source+"|"+f.source+"|"+(f===$?I:F).source+"|"+(e.evaluate||F).source+"|$","g");n.replace(f,function(t,e,r,a,f,l){return r||(r=a),c+=n.slice(o,l).replace(T,i),e&&(c+="'+__e("+e+")+'"),f&&(u=y,c+="';"+f+";__p+='"),r&&(c+="'+((__t=("+r+"))==null?'':__t)+'"),o=l+t.length,t +}),c+="';\n",f=e=e.variable,f||(e="obj",c="with("+e+"){"+c+"}"),c=(u?c.replace(E,""):c).replace(S,"$1").replace(A,"$1;"),c="function("+e+"){"+(f?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var l=Jt(r,"return "+c).apply(g,a)}catch(p){throw p.source=c,p}return t?l(t):(l.source=c,l)},nt.unescape=function(n){return n==h?"":Zt(n).replace($e,ft)},nt.uniqueId=function(n){var t=++_;return Zt(n==h?"":n)+t +},nt.all=kt,nt.any=It,nt.detect=wt,nt.findWhere=wt,nt.foldl=St,nt.foldr=At,nt.include=_t,nt.inject=St,d(nt,function(n,t){nt.prototype[t]||(nt.prototype[t]=function(){var t=[this.__wrapped__];return pe.apply(t,arguments),n.apply(nt,t)})}),nt.first=$t,nt.last=function(n,t,e){if(n){var r=0,u=n.length;if(typeof t!="number"&&t!=h){var a=u;for(t=nt.createCallback(t,e);a--&&t(n[a],a,n);)r++}else if(r=t,r==h||e)return n[u-1];return s(n,ke(0,u-r))}},nt.take=$t,nt.head=$t,d(nt,function(n,t){nt.prototype[t]||(nt.prototype[t]=function(t,e){var r=n(this.__wrapped__,t,e); +return t==h||e&&typeof t!="function"?r:new tt(r)})}),nt.VERSION="1.3.1",nt.prototype.toString=function(){return Zt(this.__wrapped__)},nt.prototype.value=Ut,nt.prototype.valueOf=Ut,Ct(["join","pop","shift"],function(n){var t=te[n];nt.prototype[n]=function(){return t.apply(this.__wrapped__,arguments)}}),Ct(["push","reverse","sort","unshift"],function(n){var t=te[n];nt.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Ct(["concat","slice","splice"],function(n){var t=te[n];nt.prototype[n]=function(){return new tt(t.apply(this.__wrapped__,arguments)) +}}),nt}var g,y=!0,h=null,b=!1,m=[],d=[],_=0,k={},j={},w=+new Date+"",C=75,x=40,O=" \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",E=/\b__p\+='';/g,S=/\b(__p\+=)''\+/g,A=/(__e\(.*?\)|\b__t\))\+'';/g,I=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,N=/\w*$/,$=/<%=([\s\S]+?)%>/g,B=RegExp("^["+O+"]*0+(?=.$)"),F=/($^)/,R=(R=/\bthis\b/)&&R.test(v)&&R,T=/['\n\r\t\u2028\u2029\\]/g,D="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),q="[object Arguments]",z="[object Array]",W="[object Boolean]",P="[object Date]",K="[object Function]",M="[object Number]",U="[object Object]",V="[object RegExp]",G="[object String]",H={}; +H[K]=b,H[q]=H[z]=H[W]=H[P]=H[M]=H[U]=H[V]=H[G]=y;var J={"boolean":b,"function":y,object:y,number:b,string:b,undefined:b},L={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Q=J[typeof exports]&&exports,X=J[typeof module]&&module&&module.exports==Q&&module,Y=J[typeof global]&&global;!Y||Y.global!==Y&&Y.window!==Y||(n=Y);var Z=v();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=Z, define(function(){return Z})):Q&&!Q.nodeType?X?(X.exports=Z)._=Z:Q._=Z:n._=Z }(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 68ff46864..192e1f664 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -91,7 +91,7 @@ */ function basicIndexOf(array, value, fromIndex) { var index = (fromIndex || 0) - 1, - length = array.length; + length = array ? array.length : 0; while (++index < length) { if (array[index] === value) { @@ -102,7 +102,7 @@ } /** - * Used by `sortBy` to compare transformed `collection` values, stable sorting + * Used by `sortBy` to compare transformed `collection` elements, stable sorting * them in ascending order. * * @private @@ -360,6 +360,68 @@ /*--------------------------------------------------------------------------*/ + /** + * A basic implementation of `_.flatten` without support for `callback` + * shorthands or `thisArg` binding. + * + * @private + * @param {Array} array The array to flatten. + * @param {Boolean} [isShallow=false] A flag to restrict flattening to a single level. + * @param {Boolean} [isArgArrays=false] A flag to restrict flattening to arrays and `arguments` objects. + * @param {Number} [fromIndex=0] The index to start from. + * @returns {Array} Returns a new flattened array. + */ + function basicFlatten(array, isShallow, isArgArrays, fromIndex) { + var index = (fromIndex || 0) - 1, + length = array ? array.length : 0, + result = []; + + while (++index < length) { + var value = array[index]; + // recursively flatten arrays (susceptible to call stack limits) + if (value && typeof value == 'object' && (isArray(value) || isArguments(value))) { + push.apply(result, isShallow ? value : basicFlatten(value)); + } else if (!isArgArrays) { + result.push(value); + } + } + return result; + } + + /** + * A basic implementation of `_.uniq` without support for `callback` shorthands + * or `thisArg` binding. + * + * @private + * @param {Array} array The array to process. + * @param {Boolean} [isSorted=false] A flag to indicate that the `array` is already sorted. + * @param {Function} [callback] The function called per iteration. + * @returns {Array} Returns a duplicate-value-free array. + */ + function basicUniq(array, isSorted, callback) { + var index = -1, + indexOf = getIndexOf(), + length = array ? array.length : 0, + result = [], + seen = callback ? [] : result; + + while (++index < length) { + var value = array[index], + computed = callback ? callback(value, index, array) : value; + + if (isSorted + ? !index || seen[seen.length - 1] !== computed + : indexOf(seen, computed) < 0 + ) { + if (callback) { + seen.push(computed); + } + result.push(value); + } + } + return result; + } + /** * Creates a function that, when called, invokes `func` with the `this` binding * of `thisArg` and prepends any `partialArgs` to the arguments passed to the @@ -430,7 +492,7 @@ } // fallback for browsers without `Object.create` if (!nativeCreate) { - var createObject = function(prototype) { + createObject = function(prototype) { if (isObject(prototype)) { noop.prototype = prototype; var result = new noop; @@ -459,7 +521,7 @@ * @private * @returns {Function} Returns the "indexOf" function. */ - function getIndexOf(array, value, fromIndex) { + function getIndexOf() { var result = (result = lodash.indexOf) === indexOf ? basicIndexOf : result; return result; } @@ -793,8 +855,8 @@ }; /** - * Creates a sorted array of all enumerable properties, own and inherited, - * of `object` that have function values. + * Creates a sorted array of property names of all enumerable properties, + * own and inherited, of `object` that have function values. * * @static * @memberOf _ @@ -2445,7 +2507,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to compact. - * @returns {Array} Returns a new filtered array. + * @returns {Array} Returns a new array of filtered values. * @example * * _.compact([0, 1, false, 2, '', 3]); @@ -2466,17 +2528,15 @@ } /** - * Creates an arrat with all occurrences of the passed values removed using - * using strict equality for comparisons, i.e. `===`. Values to exclude may - * be specified as individual arguments or as arrays. + * Creates an array excluding all values of the passed-in arrays using + * strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to process. - * @param {Array} [array1, array2, ...] The values to exclude, specified as - * individual values or arrays of values. - * @returns {Array} Returns a new filtered array. + * @param {Array} [array1, array2, ...] The arrays of values to exclude. + * @returns {Array} Returns a new array of filtered values. * @example * * _.difference([1, 2, 3, 4, 5], [5, 2, 10]); @@ -2594,7 +2654,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to flatten. - * @param {Boolean} [isShallow=false] A flag to indicate only flattening a single level. + * @param {Boolean} [isShallow=false] A flag to restrict flattening to a single level. * @param {Function|Object|String} [callback=identity] The function called per * iteration. If a property name or object is passed, it will be used to create * a "_.pluck" or "_.where" style callback, respectively. @@ -2618,19 +2678,7 @@ * // => ['Oh, a wise guy, eh?', 'Poifect!', 'Spread out!', 'You knucklehead!'] */ function flatten(array, isShallow) { - var index = -1, - length = array ? array.length : 0, - result = []; - - while (++index < length) { - var value = array[index]; - if (value && typeof value == 'object' && (isArray(value) || isArguments(value))) { - push.apply(result, isShallow ? value : flatten(value)); - } else { - result.push(value); - } - } - return result; + return basicFlatten(array, isShallow); } /** @@ -2744,15 +2792,14 @@ } /** - * Computes the intersection of all the passed-in arrays using strict equality - * for comparisons, i.e. `===`. + * Creates an array of unique values present in all passed-in arrays using + * strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays - * @param {Array} [array1, array2, ...] Arrays to process. - * @returns {Array} Returns a new array of unique elements that are present - * in **all** of the arrays. + * @param {Array} [array1, array2, ...] The arrays to inspect. + * @returns {Array} Returns an array of composite values. * @example * * _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); @@ -3082,22 +3129,21 @@ } /** - * Computes the union of the passed-in arrays using strict equality for - * comparisons, i.e. `===`. + * Creates an array of unique values, in order, of the passed-in arrays + * using strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays - * @param {Array} [array1, array2, ...] Arrays to process. - * @returns {Array} Returns a new array of unique values, in order, that are - * present in one or more of the arrays. + * @param {Array} [array1, array2, ...] The arrays to inspect. + * @returns {Array} Returns an array of composite values. * @example * * _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); * // => [1, 2, 3, 101, 10] */ function union(array) { - return uniq(flatten(compact(arguments), true)); + return basicUniq(basicFlatten(arguments, true, true)); } /** @@ -3144,48 +3190,28 @@ * // => [{ 'x': 1 }, { 'x': 2 }] */ function uniq(array, isSorted, callback, thisArg) { - var index = -1, - indexOf = getIndexOf(), - length = array ? array.length : 0, - result = [], - seen = result; - + // juggle arguments if (typeof isSorted != 'boolean' && isSorted != null) { thisArg = callback; - callback = isSorted; + callback = !(thisArg && thisArg[isSorted] === array) ? isSorted : undefined; isSorted = false; } if (callback != null) { - seen = []; callback = createCallback(callback, thisArg); } - while (++index < length) { - var value = array[index], - computed = callback ? callback(value, index, array) : value; - - if (isSorted - ? !index || seen[seen.length - 1] !== computed - : indexOf(seen, computed) < 0 - ) { - if (callback) { - seen.push(computed); - } - result.push(value); - } - } - return result; + return basicUniq(array, isSorted, callback); } /** - * Creates an array excluding all occurrences of the passed values using - * strict equality for comparisons, i.e. `===`. + * Creates an array excluding all passed values using strict equality for + * comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to filter. - * @param {Mixed} [value1, value2, ...] Values to exclude. - * @returns {Array} Returns a new filtered array. + * @param {Mixed} [value1, value2, ...] The values to exclude. + * @returns {Array} Returns a new array of filtered values. * @example * * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); @@ -3326,7 +3352,7 @@ * @category Functions * @param {Object} object The object to bind and assign the bound methods to. * @param {String} [methodName1, methodName2, ...] The object method names to - * bind, specified as individual values or arrays of values. + * bind, specified as individual method names or arrays of method names. * @returns {Object} Returns `object`. * @example * @@ -3340,7 +3366,7 @@ * // => alerts 'clicked docs', when the button is clicked */ function bindAll(object) { - var funcs = arguments.length > 1 ? flatten(nativeSlice.call(arguments, 1)) : functions(object), + var funcs = arguments.length > 1 ? basicFlatten(arguments, true, false, 1) : functions(object), index = -1, length = funcs.length; diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index cc0376098..03ad0d792 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,34 +3,34 @@ * Lo-Dash 1.3.1 (Custom Build) lodash.com/license | Underscore.js 1.5.1 underscorejs.org/LICENSE * Build: `lodash underscore exports="amd,commonjs,global,node" -o ./dist/lodash.underscore.js` */ -;!function(n){function t(n,t,r){r=(r||0)-1;for(var e=n.length;++rt||typeof n=="undefined")return 1;if(ne&&(e=r,u=n)}); -else for(;++iu&&(u=r);return u}function R(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(var u=Array(e);++rarguments.length;t=H(t,e,4);var i=-1,o=n.length;if(typeof o=="number")for(u&&(r=n[++i]);++iarguments.length;if(typeof u!="number")var o=Mt(n),u=o.length;return t=H(t,e,4),S(n,function(e,a,f){a=o?o[--u]:--u,r=i?(i=!1,n[a]):t(r,n[a],a,f) -}),r}function D(n,t,r){var e;t=H(t,r),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++rr(u,o)&&i.push(o)}return i}function z(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&null!=t){var i=-1; -for(t=H(t,r);++ie?Ft(0,u+e):e||0}else if(e)return e=P(n,r),n[e]===r?e:-1;return n?t(n,r,e):-1}function C(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,i=n?n.length:0;for(t=H(t,r);++u>>1,r(n[e])i(f,l))&&(r&&f.push(l),a.push(e))}return a}function V(){for(var n=-1,t=N(R(arguments,"length")),r=Array(0>t?0:t);++nl&&(a=n.apply(f,o));else{var r=new Date;!s&&!h&&(c=r); -var e=p-(r-c);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},At||(f=function(n){if(b(n)){u.prototype=n;var t=new u;u.prototype=null}return t||{}}),s(arguments)||(s=function(n){return n&&typeof n=="object"?bt.call(n,"callee"):!1});var qt=Ot||function(n){return n&&typeof n=="object"?wt.call(n)==et:!1},Ot=function(n){var t,r=[]; -if(!n||!ct[typeof n])return r;for(t in n)bt.call(n,t)&&r.push(t);return r},Mt={}.o=St?function(n){return b(n)?St(n):[]}:Ot,$t={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},zt=y($t),It=RegExp("("+Mt(zt).join("|")+")","g"),Wt=RegExp("["+Mt($t).join("")+"]","g"),Ct=function(n,t){var r;if(!n||!ct[typeof n])return n;for(r in n)if(t(n[r],r,n)===Y)break;return n},Pt=function(n,t){var r;if(!n||!ct[typeof n])return n;for(r in n)if(bt.call(n,r)&&t(n[r],r,n)===Y)break;return n}; -d(/x/)&&(d=function(n){return typeof n=="function"&&"[object Function]"==wt.call(n)}),i.after=function(n,t){return function(){return 1>--n?t.apply(this,arguments):void 0}},i.bind=G,i.bindAll=function(n){for(var t=1u(o,a)){for(var f=r;--f;)if(0>u(t[f],a))continue n;o.push(a)}}return o},i.invert=y,i.invoke=function(n,t){var r=Bt.call(arguments,2),e=-1,u=typeof t=="function",i=n?n.length:0,o=Array(typeof i=="number"?i:0);return S(n,function(n){o[++e]=(u?t:n[t]).apply(n,r)}),o},i.keys=Mt,i.map=F,i.max=N,i.memoize=function(n,t){var r={}; -return function(){var e=Z+(t?t.apply(this,arguments):arguments[0]);return bt.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},i.min=function(n,t,r){var e=1/0,u=e,i=-1,o=n?n.length:0;if(t||typeof o!="number")t=H(t,r),S(n,function(n,r,i){r=t(n,r,i),rt(r,u)&&(e[u]=n)}),e},i.once=function(n){var t,r;return function(){return t?r:(t=!0,r=n.apply(this,arguments),n=null,r) -}},i.pairs=function(n){for(var t=-1,r=Mt(n),e=r.length,u=Array(e);++tr?Ft(0,e+r):Nt(r,e-1))+1);e--;)if(n[e]===t)return e; -return-1},i.mixin=L,i.noConflict=function(){return n._=yt,this},i.random=function(n,t){null==n&&null==t&&(t=1),n=+n||0,null==t?(t=n,n=0):t=+t||0;var r=Rt();return n%1||t%1?n+Nt(r*(t-n+parseFloat("1e-"+((r+"").length-1))),t):n+dt(r*(t-n+1))},i.reduce=B,i.reduceRight=k,i.result=function(n,t){var r=n?n[t]:Q;return d(r)?n[t]():r},i.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Mt(n).length},i.some=D,i.sortedIndex=P,i.template=function(n,t,r){var u=i.templateSettings;n||(n=""),r=g({},r,u); -var o=0,a="__p+='",u=r.variable;n.replace(RegExp((r.escape||nt).source+"|"+(r.interpolate||nt).source+"|"+(r.evaluate||nt).source+"|$","g"),function(t,r,u,i,f){return a+=n.slice(o,f).replace(tt,e),r&&(a+="'+_['escape']("+r+")+'"),i&&(a+="';"+i+";__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),o=f+t.length,t}),a+="';\n",u||(u="obj",a="with("+u+"||{}){"+a+"}"),a="function("+u+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var f=Function("_","return "+a)(i) -}catch(l){throw l.source=a,l}return t?f(t):(f.source=a,f)},i.unescape=function(n){return null==n?"":(n+"").replace(It,p)},i.uniqueId=function(n){var t=++X+"";return n?n+t:t},i.all=O,i.any=D,i.detect=T,i.findWhere=function(n,t){return q(n,t,!0)},i.foldl=B,i.foldr=k,i.include=A,i.inject=B,i.first=z,i.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&null!=t){var i=u;for(t=H(t,r);i--&&t(n[i],i,n);)e++}else if(e=t,null==e||r)return n[u-1];return Bt.call(n,Ft(0,u-e))}},i.take=z,i.head=z,i.VERSION="1.3.1",L(i),i.prototype.chain=function(){return this.__chain__=!0,this -},i.prototype.value=function(){return this.__wrapped__},S("pop push reverse shift sort splice unshift".split(" "),function(n){var t=ht[n];i.prototype[n]=function(){var n=this.__wrapped__;return t.apply(n,arguments),!Dt.spliceObjects&&0===n.length&&delete n[0],this}}),S(["concat","join","slice"],function(n){var t=ht[n];i.prototype[n]=function(){var n=t.apply(this.__wrapped__,arguments);return this.__chain__&&(n=new o(n),n.__chain__=!0),n}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=i, define(function(){return i -})):st&&!st.nodeType?vt?(vt.exports=i)._=i:st._=i:n._=i}(this); \ No newline at end of file +;!function(n){function t(n,t,r){r=(r||0)-1;for(var e=n?n.length:0;++rt||typeof n=="undefined")return 1;if(nu(a,l))&&(r&&a.push(l),o.push(f))}return o}function l(n,t,r,e){function u(){var e=arguments,l=o?this:t;return i||(n=t[a]),r.length&&(e=e.length?(e=Dt.call(e),f?e.concat(r):r.concat(e)):r),this instanceof u?(l=c(n.prototype),e=n.apply(l,e),w(e)?e:l):n.apply(l,e)}var i=j(n),o=!r,a=t;if(o){var f=e;r=t}else if(!i){if(!e)throw new TypeError;t=n}return u}function c(n){return w(n)?Et(n):{} +}function p(n){return Ct[n]}function s(){var n=(n=i.indexOf)===C?t:n;return n}function v(n){return Pt[n]}function g(n){return n&&typeof n=="object"?At.call(n)==et:!1}function h(n){if(!n)return n;for(var t=1,r=arguments.length;te&&(e=r,u=n)});else for(;++iu&&(u=r);return u}function k(n,t){var r=-1,e=n?n.length:0; +if(typeof e=="number")for(var u=Array(e);++rarguments.length;t=J(t,e,4);var i=-1,o=n.length;if(typeof o=="number")for(u&&(r=n[++i]);++iarguments.length;if(typeof u!="number")var o=Wt(n),u=o.length;return t=J(t,e,4),N(n,function(e,a,f){a=o?o[--u]:--u,r=i?(i=!1,n[a]):t(r,n[a],a,f)}),r}function M(n,t,r){var e; +t=J(t,r),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++rr(u,o)&&i.push(o)}return i}function I(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&null!=t){var i=-1;for(t=J(t,r);++ie?Rt(0,u+e):e||0}else if(e)return e=U(n,r),n[e]===r?e:-1;return n?t(n,r,e):-1}function P(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,i=n?n.length:0;for(t=J(t,r);++u>>1,r(n[e])t?0:t);++nl&&(a=n.apply(f,o)); +else{var r=new Date;!s&&!h&&(c=r);var e=p-(r-c);0/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Et||(c=function(n){if(w(n)){u.prototype=n;var t=new u;u.prototype=null}return t||{}}),g(arguments)||(g=function(n){return n&&typeof n=="object"?wt.call(n,"callee"):!1});var zt=Tt||function(n){return n&&typeof n=="object"?At.call(n)==ut:!1},It=function(n){var t,r=[]; +if(!n||!pt[typeof n])return r;for(t in n)wt.call(n,t)&&r.push(t);return r},Wt={}.o=Nt?function(n){return w(n)?Nt(n):[]}:It,Ct={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Pt=_(Ct),Ut=RegExp("("+Wt(Pt).join("|")+")","g"),Vt=RegExp("["+Wt(Ct).join("")+"]","g"),Gt=function(n,t){var r;if(!n||!pt[typeof n])return n;for(r in n)if(t(n[r],r,n)===true)break;return n},Ht=function(n,t){var r;if(!n||!pt[typeof n])return n;for(r in n)if(wt.call(n,r)&&t(n[r],r,n)===true)break;return n +};j(/x/)&&(j=function(n){return typeof n=="function"&&"[object Function]"==At.call(n)}),i.after=function(n,t){return function(){return 1>--n?t.apply(this,arguments):void 0}},i.bind=H,i.bindAll=function(n){for(var t=1u(o,a)){for(var f=r;--f;)if(0>u(t[f],a))continue n;o.push(a)}}return o},i.invert=_,i.invoke=function(n,t){var r=Dt.call(arguments,2),e=-1,u=typeof t=="function",i=n?n.length:0,o=Array(typeof i=="number"?i:0); +return N(n,function(n){o[++e]=(u?t:n[t]).apply(n,r)}),o},i.keys=Wt,i.map=R,i.max=B,i.memoize=function(n,t){var r={};return function(){var e=nt+(t?t.apply(this,arguments):arguments[0]);return wt.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},i.min=function(n,t,r){var e=1/0,u=e,i=-1,o=n?n.length:0;if(t||typeof o!="number")t=J(t,r),N(n,function(n,r,i){r=t(n,r,i),rt(r,u)&&(e[u]=n) +}),e},i.once=function(n){var t,r;return function(){return t?r:(t=!0,r=n.apply(this,arguments),n=null,r)}},i.pairs=function(n){for(var t=-1,r=Wt(n),e=r.length,u=Array(e);++tr?Rt(0,e+r):Bt(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},i.mixin=Q,i.noConflict=function(){return n._=_t,this},i.random=function(n,t){null==n&&null==t&&(t=1),n=+n||0,null==t?(t=n,n=0):t=+t||0;var r=kt();return n%1||t%1?n+Bt(r*(t-n+parseFloat("1e-"+((r+"").length-1))),t):n+jt(r*(t-n+1))},i.reduce=D,i.reduceRight=q,i.result=function(n,t){var r=n?n[t]:X;return j(r)?n[t]():r},i.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Wt(n).length},i.some=M,i.sortedIndex=U,i.template=function(n,t,r){var u=i.templateSettings; +n||(n=""),r=y({},r,u);var o=0,a="__p+='",u=r.variable;n.replace(RegExp((r.escape||tt).source+"|"+(r.interpolate||tt).source+"|"+(r.evaluate||tt).source+"|$","g"),function(t,r,u,i,f){return a+=n.slice(o,f).replace(rt,e),r&&(a+="'+_['escape']("+r+")+'"),i&&(a+="';"+i+";__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),o=f+t.length,t}),a+="';\n",u||(u="obj",a="with("+u+"||{}){"+a+"}"),a="function("+u+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}"; +try{var f=Function("_","return "+a)(i)}catch(l){throw l.source=a,l}return t?f(t):(f.source=a,f)},i.unescape=function(n){return null==n?"":(n+"").replace(Ut,v)},i.uniqueId=function(n){var t=++Y+"";return n?n+t:t},i.all=T,i.any=M,i.detect=F,i.findWhere=function(n,t){return $(n,t,!0)},i.foldl=D,i.foldr=q,i.include=E,i.inject=D,i.first=I,i.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&null!=t){var i=u;for(t=J(t,r);i--&&t(n[i],i,n);)e++}else if(e=t,null==e||r)return n[u-1];return Dt.call(n,Rt(0,u-e)) +}},i.take=I,i.head=I,i.VERSION="1.3.1",Q(i),i.prototype.chain=function(){return this.__chain__=!0,this},i.prototype.value=function(){return this.__wrapped__},N("pop push reverse shift sort splice unshift".split(" "),function(n){var t=yt[n];i.prototype[n]=function(){var n=this.__wrapped__;return t.apply(n,arguments),!$t.spliceObjects&&0===n.length&&delete n[0],this}}),N(["concat","join","slice"],function(n){var t=yt[n];i.prototype[n]=function(){var n=t.apply(this.__wrapped__,arguments);return this.__chain__&&(n=new o(n),n.__chain__=!0),n +}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=i, define(function(){return i})):vt&&!vt.nodeType?gt?(gt.exports=i)._=i:vt._=i:n._=i}(this); \ No newline at end of file diff --git a/lodash.js b/lodash.js index f3b190ee2..23050dc4a 100644 --- a/lodash.js +++ b/lodash.js @@ -234,7 +234,7 @@ } /** - * Used by `sortBy` to compare transformed `collection` values, stable sorting + * Used by `sortBy` to compare transformed `collection` elements, stable sorting * them in ascending order. * * @private @@ -974,24 +974,22 @@ * * @private * @param {Array} array The array to flatten. - * @param {Boolean} [isShallow=false] A flag to indicate only flattening a single level. - * @param {Function} [callback] The function called per iteration. + * @param {Boolean} [isShallow=false] A flag to restrict flattening to a single level. + * @param {Boolean} [isArgArrays=false] A flag to restrict flattening to arrays and `arguments` objects. + * @param {Number} [fromIndex=0] The index to start from. * @returns {Array} Returns a new flattened array. */ - function basicFlatten(array, isShallow, callback) { - var index = -1, + function basicFlatten(array, isShallow, isArgArrays, fromIndex) { + var index = (fromIndex || 0) - 1, length = array ? array.length : 0, result = []; while (++index < length) { var value = array[index]; - if (callback) { - value = callback(value, index, array); - } // recursively flatten arrays (susceptible to call stack limits) if (value && typeof value == 'object' && (isArray(value) || isArguments(value))) { push.apply(result, isShallow ? value : basicFlatten(value)); - } else { + } else if (!isArgArrays) { result.push(value); } } @@ -1175,7 +1173,7 @@ } // fallback for browsers without `Object.create` if (!nativeCreate) { - var createObject = function(prototype) { + createObject = function(prototype) { if (isObject(prototype)) { noop.prototype = prototype; var result = new noop; @@ -1204,34 +1202,11 @@ * @private * @returns {Function} Returns the "indexOf" function. */ - function getIndexOf(array, value, fromIndex) { + function getIndexOf() { var result = (result = lodash.indexOf) === indexOf ? basicIndexOf : result; return result; } - /** - * Creates a function that juggles arguments, allowing argument overloading - * for `_.flatten` and `_.uniq`, before passing them to the given `func`. - * - * @private - * @param {Function} func The function to wrap. - * @returns {Function} Returns the new function. - */ - function overloadWrapper(func) { - return function(array, flag, callback, thisArg) { - // juggle arguments - if (typeof flag != 'boolean' && flag != null) { - thisArg = callback; - callback = !(thisArg && thisArg[flag] === array) ? flag : undefined; - flag = false; - } - if (callback != null) { - callback = lodash.createCallback(callback, thisArg); - } - return func(array, flag, callback, thisArg); - }; - } - /** * A fallback implementation of `isPlainObject` which checks if a given `value` * is an object created by the `Object` constructor, assuming objects created @@ -1742,8 +1717,8 @@ var forOwn = createIterator(eachIteratorOptions, forOwnIteratorOptions); /** - * Creates a sorted array of all enumerable properties, own and inherited, - * of `object` that have function values. + * Creates a sorted array of property names of all enumerable properties, + * own and inherited, of `object` that have function values. * * @static * @memberOf _ @@ -2516,7 +2491,7 @@ if (isFunc) { callback = lodash.createCallback(callback, thisArg); } else { - var props = basicFlatten(nativeSlice.call(arguments, 1)); + var props = basicFlatten(arguments, true, false, 1); } forIn(object, function(value, key, object) { if (isFunc @@ -2586,7 +2561,7 @@ var result = {}; if (typeof callback != 'function') { var index = -1, - props = basicFlatten(nativeSlice.call(arguments, 1)), + props = basicFlatten(arguments, true, false, 1), length = isObject(object) ? props.length : 0; while (++index < length) { @@ -2707,7 +2682,7 @@ */ function at(collection) { var index = -1, - props = basicFlatten(nativeSlice.call(arguments, 1)), + props = basicFlatten(arguments, true, false, 1), length = props.length, result = Array(length); @@ -3712,7 +3687,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to compact. - * @returns {Array} Returns a new filtered array. + * @returns {Array} Returns a new array of filtered values. * @example * * _.compact([0, 1, false, 2, '', 3]); @@ -3733,17 +3708,15 @@ } /** - * Creates an arrat with all occurrences of the passed values removed using - * using strict equality for comparisons, i.e. `===`. Values to exclude may - * be specified as individual arguments or as arrays. + * Creates an array excluding all values of the passed-in arrays using + * strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to process. - * @param {Array} [array1, array2, ...] The values to exclude, specified as - * individual values or arrays of values. - * @returns {Array} Returns a new filtered array. + * @param {Array} [array1, array2, ...] The arrays of values to exclude. + * @returns {Array} Returns a new array of filtered values. * @example * * _.difference([1, 2, 3, 4, 5], [5, 2, 10]); @@ -3753,7 +3726,7 @@ var index = -1, indexOf = getIndexOf(), length = array ? array.length : 0, - seen = basicFlatten(nativeSlice.call(arguments, 1)), + seen = basicFlatten(arguments, true, true, 1), result = []; var isLarge = length >= largeArraySize && indexOf === basicIndexOf; @@ -3908,7 +3881,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to flatten. - * @param {Boolean} [isShallow=false] A flag to indicate only flattening a single level. + * @param {Boolean} [isShallow=false] A flag to restrict flattening to a single level. * @param {Function|Object|String} [callback=identity] The function called per * iteration. If a property name or object is passed, it will be used to create * a "_.pluck" or "_.where" style callback, respectively. @@ -3931,7 +3904,18 @@ * _.flatten(stooges, 'quotes'); * // => ['Oh, a wise guy, eh?', 'Poifect!', 'Spread out!', 'You knucklehead!'] */ - var flatten = overloadWrapper(basicFlatten); + function flatten(array, isShallow, callback, thisArg) { + // juggle arguments + if (typeof isShallow != 'boolean' && isShallow != null) { + thisArg = callback; + callback = !(thisArg && thisArg[isShallow] === array) ? isShallow : undefined; + isShallow = false; + } + if (callback != null) { + array = map(array, callback, thisArg); + } + return basicFlatten(array, isShallow); + } /** * Gets the index at which the first occurrence of `value` is found using @@ -4044,15 +4028,14 @@ } /** - * Computes the intersection of all the passed-in arrays using strict equality - * for comparisons, i.e. `===`. + * Creates an array of unique values present in all passed-in arrays using + * strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays - * @param {Array} [array1, array2, ...] Arrays to process. - * @returns {Array} Returns a new array of unique elements that are present - * in **all** of the arrays. + * @param {Array} [array1, array2, ...] The arrays to inspect. + * @returns {Array} Returns an array of composite values. * @example * * _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); @@ -4403,22 +4386,21 @@ } /** - * Computes the union of the passed-in arrays using strict equality for - * comparisons, i.e. `===`. + * Creates an array of unique values, in order, of the passed-in arrays + * using strict equality for comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays - * @param {Array} [array1, array2, ...] Arrays to process. - * @returns {Array} Returns a new array of unique values, in order, that are - * present in one or more of the arrays. + * @param {Array} [array1, array2, ...] The arrays to inspect. + * @returns {Array} Returns an array of composite values. * @example * * _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); * // => [1, 2, 3, 101, 10] */ function union(array) { - return basicUniq(basicFlatten(compact(arguments), true)); + return basicUniq(basicFlatten(arguments, true, true)); } /** @@ -4464,18 +4446,29 @@ * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }, { 'x': 2 }] */ - var uniq = overloadWrapper(basicUniq); + function uniq(array, isSorted, callback, thisArg) { + // juggle arguments + if (typeof isSorted != 'boolean' && isSorted != null) { + thisArg = callback; + callback = !(thisArg && thisArg[isSorted] === array) ? isSorted : undefined; + isSorted = false; + } + if (callback != null) { + callback = lodash.createCallback(callback, thisArg); + } + return basicUniq(array, isSorted, callback); + } /** - * Creates an array excluding all occurrences of the passed values using - * strict equality for comparisons, i.e. `===`. + * Creates an array excluding all passed values using strict equality for + * comparisons, i.e. `===`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to filter. - * @param {Mixed} [value1, value2, ...] Values to exclude. - * @returns {Array} Returns a new filtered array. + * @param {Mixed} [value1, value2, ...] The values to exclude. + * @returns {Array} Returns a new array of filtered values. * @example * * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); @@ -4617,7 +4610,7 @@ * @category Functions * @param {Object} object The object to bind and assign the bound methods to. * @param {String} [methodName1, methodName2, ...] The object method names to - * bind, specified as individual values or arrays of values. + * bind, specified as individual method names or arrays of method names. * @returns {Object} Returns `object`. * @example * @@ -4631,7 +4624,7 @@ * // => alerts 'clicked docs', when the button is clicked */ function bindAll(object) { - var funcs = arguments.length > 1 ? basicFlatten(nativeSlice.call(arguments, 1)) : functions(object), + var funcs = arguments.length > 1 ? basicFlatten(arguments, true, false, 1) : functions(object), index = -1, length = funcs.length;