From 551f9fcdf9c126ff5db9bb04810e9a2005ddac60 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 9 Jan 2014 23:27:32 -0800 Subject: [PATCH] Make checks for `_.map` and `_.reduce` use consistent with `indexTypes`. --- dist/lodash.compat.js | 52 +++++++++------- dist/lodash.compat.min.js | 110 +++++++++++++++++----------------- dist/lodash.js | 52 +++++++++------- dist/lodash.min.js | 101 +++++++++++++++---------------- dist/lodash.underscore.js | 38 +++++++++--- dist/lodash.underscore.min.js | 66 ++++++++++---------- lodash.js | 52 +++++++++------- 7 files changed, 258 insertions(+), 213 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 8b82358b2..25b64725d 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -157,6 +157,16 @@ ''': "'" }; + /** Used to determine if values are an indexes or keys */ + var indexTypes = { + 'boolean': false, + 'function': false, + 'object': false, + 'number': true, + 'string': true, + 'undefined': false + }; + /** Used to determine if values are of the language type Object */ var objectTypes = { 'boolean': false, @@ -2349,7 +2359,7 @@ // juggle arguments if (typeof isShallow != 'boolean' && isShallow != null) { thisArg = callback; - callback = (typeof isShallow != 'function' && thisArg && thisArg[isShallow] === array) ? null : isShallow; + callback = (indexTypes[typeof isShallow] && thisArg && thisArg[isShallow] === array) ? null : isShallow; isShallow = false; } if (callback != null) { @@ -3028,7 +3038,7 @@ // juggle arguments if (typeof isSorted != 'boolean' && isSorted != null) { thisArg = callback; - callback = (typeof isSorted != 'function' && thisArg && thisArg[isSorted] === array) ? null : isSorted; + callback = (indexTypes[typeof isSorted] && thisArg && thisArg[isSorted] === array) ? null : isSorted; isSorted = false; } if (callback != null) { @@ -3301,11 +3311,11 @@ * _.at(['fred', 'barney', 'pebbles'], 0, 2); * // => ['fred', 'pebbles'] */ - function at(collection) { + function at(collection, guard) { var args = arguments, index = -1, props = baseFlatten(args, true, false, 1), - length = (args[2] && args[2][args[1]] === collection) ? 1 : props.length, + length = (indexTypes[typeof guard] && args[2] && args[2][guard] === collection) ? 1 : props.length, result = Array(length); if (support.unindexedChars && isString(collection)) { @@ -3946,7 +3956,7 @@ // allows working with functions like `_.map` without using // their `index` argument as a callback - if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { + if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -4021,7 +4031,7 @@ // allows working with functions like `_.map` without using // their `index` argument as a callback - if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { + if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -5151,11 +5161,12 @@ * defaults(object, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function assign(object, source) { + function assign(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = args[3] && args[3][args[2]] === source ? 2 : args.length; + argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + // juggle arguments if (argsLength > 3 && typeof args[argsLength - 2] == 'function') { var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2); } else if (argsLength > 2 && typeof args[argsLength - 1] == 'function') { @@ -5218,11 +5229,10 @@ * // => 0 */ function clone(value, isDeep, callback, thisArg) { - // allows working with "Collections" methods without using their `index` - // and `collection` arguments for `isDeep` and `callback` + // juggle arguments if (typeof isDeep != 'boolean' && isDeep != null) { thisArg = callback; - callback = isDeep; + callback = (indexTypes[typeof isDeep] && thisArg && thisArg[isDeep] === value) ? null : isDeep; isDeep = false; } return baseClone(value, isDeep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1)); @@ -5320,6 +5330,8 @@ * @category Objects * @param {Object} object The destination object. * @param {...Object} [source] The source objects. + * @param- {Object} [guard] Allows working with `_.reduce` without using its + * `key` and `object` arguments as sources. * @returns {Object} Returns the destination object. * @example * @@ -5327,10 +5339,10 @@ * _.defaults(object, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function defaults(object, source) { + function defaults(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = args[3] && args[3][args[2]] === source ? 2 : args.length; + argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; while (++argsIndex < argsLength) { source = args[argsIndex]; @@ -6230,18 +6242,14 @@ * }); * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot] } */ - function merge(object) { - var args = arguments, - length = 2; - + function merge(object, source, guard) { if (!isObject(object)) { return object; } - // allows working with `_.reduce` and `_.reduceRight` without using - // their `index` and `collection` arguments - if (typeof args[2] != 'number') { - length = args.length; - } + var args = arguments, + length = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + + // juggle arguments if (length > 3 && typeof args[length - 2] == 'function') { var callback = baseCreateCallback(args[--length - 1], args[length--], 2); } else if (length > 2 && typeof args[length - 1] == 'function') { diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 841801919..ed7464177 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -5,60 +5,60 @@ */ ;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202=A&&o===t,l=[];if(i){var c=f(e);c?(o=r,e=c):i=false}for(;++uo(e,c)&&l.push(c);return i&&y(e),l}function lt(n,t,r){var e=-1,u=n,o=n?n.length:0;if(t=t&&typeof r=="undefined"?t:k(t,r,3),typeof o=="number")for(ne.unindexedChars&&rr(u)&&(u=u.split(""));++e=A&&a===t,p=u||c?s():l;for(c&&(p=f(p),a=r);++oa(p,g))&&((u||c)&&p.push(g),l.push(h))}return c?(v(p.g),y(p)):u&&v(p),l}function mt(n){return function(t,r,u){var o={}; -if(r=e.createCallback(r,u,3),le(t)){u=-1;for(var a=t.length;++uu;u++)e+="l='"+n.d[u]+"';if((!(k&&n[l])&&h.call(p,l))",n.f||(e+="||(!n[l]&&p[l]!==q[l])"),e+="){"+n.c+"}"; -e+="}"}return t("a,f,g,h,j,q,r,o,v,w,y",r+(e+"return s;")+"}")(k,Z,_r,Rr,xt,wr,ct,Zr,ut,jr,kr)}function _t(){var n=(n=e.indexOf)===kt?t:n;return n}function wt(n){return typeof n=="function"&&Or.test(Ir.call(n))}function jt(n){var t,r;return!n||kr.call(n)!=rt||!Rr.call(n,"constructor")&&(t=n.constructor,Zt(t)&&!(t instanceof t))||!ne.argsClass&&xt(n)||!ne.nodeClass&&g(n)?false:ne.ownLast?(ie(n,function(n,t,e){return r=Rr.call(e,t),false}),false!==r):(ie(n,function(n,t){r=t}),typeof r=="undefined"||Rr.call(n,r)) -}function xt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&kr.call(n)==H||false}function Ct(n,t,r){var u=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=-1;for(t=e.createCallback(t,r,3);++ae?Ur(0,u+e):e||0}else if(e)return e=St(n,r),n[e]===r?e:-1;return t(n,r,e)}function Ot(n,t,r){if(typeof t!="number"&&null!=t){var u=0,o=-1,a=n?n.length:0; -for(t=e.createCallback(t,r,3);++ot?t=Ur(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Ur(u+r,0):r>u&&(r=u),u=r-t||0,r=fr(u);++e>>1,r(n[u])r?0:r);++t=e)return false;if(typeof n=="string"||!le(n)&&rr(n))return Lr?Lr.call(n,t,r):-1r?Ur(0,e+r):r)||0,-1a&&(a=l)}}else t=null==t&&rr(n)?u:e.createCallback(t,r,3),lt(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Wt(n,t,r,u){var o=3>arguments.length; -if(t=e.createCallback(t,u,4),le(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=e.createCallback(t,u,4),$t(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Kt(n){var t=-1,r=n?n.length:0,e=fr(typeof r=="number"?r:0);return Ft(n,function(n){var r=gt(0,++t);e[t]=e[r],e[r]=n}),e}function Mt(n,t,r){var u;if(t=e.createCallback(t,r,3),le(n)){r=-1;for(var o=n.length;++r=y;m?(a&&(a=Sr(a)),s=l,i=n.apply(f,o)):a||(a=Dr(e,y))}return m&&c?c=Sr(c):c||t===h||(c=Dr(u,t)),r&&(m=true,i=n.apply(f,o)),!m||c||a||(o=f=null),i}}function Xt(n,t){var r=arguments,e=0,u=r[3]&&r[3][r[2]]===t?2:r.length;if(3--n?t.apply(this,arguments):void 0}},e.assign=Xt,e.at=function(n){var t=arguments,r=-1,e=ft(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:e.length,u=fr(t);for(ne.unindexedChars&&rr(n)&&(n=n.split(""));++r=A&&f(e?n[e]:l)))}var i=n[0],p=-1,h=i?i.length:0,g=[];n:for(;++p(m?r(m,c):a(l,c))){for(e=u,(m||l).push(c);--e;)if(m=o[e],0>(m?r(m,c):a(n[e],c)))continue n;g.push(c) -}}for(;u--;)(m=o[u])&&y(m);return v(o),v(l),g},e.invert=function(n,t){for(var r=-1,e=ce(n),u=e.length,o={};++rr?Ur(0,e+r):Vr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},e.mixin=ar,e.noConflict=function(){return n._=Cr,this},e.noop=ir,e.now=ge,e.parseInt=ve,e.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=Gr(),Vr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):gt(n,t) -},e.reduce=Wt,e.reduceRight=zt,e.result=function(n,t){if(n){var r=n[t];return Zt(r)?n[t]():r}},e.runInContext=x,e.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ce(n).length},e.some=Mt,e.sortedIndex=St,e.template=function(n,t,r){var u=e.templateSettings;n=mr(n||""),r=Gt({},r,u);var o,a=Gt({},r.imports,u.imports),u=ce(a),a=er(a),i=0,l=r.interpolate||M,f="__p+='",l=yr((r.escape||M).source+"|"+l.source+"|"+(l===L?B:M).source+"|"+(r.evaluate||M).source+"|$","g");n.replace(l,function(t,r,e,u,a,l){return e||(e=u),f+=n.slice(i,l).replace(V,p),r&&(f+="'+__e("+r+")+'"),a&&(o=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=l+t.length,t -}),f+="';",l=r=r.variable,l||(r="obj",f="with("+r+"){"+f+"}"),f=(o?f.replace(R,""):f).replace(T,"$1").replace(P,"$1;"),f="function("+r+"){"+(l?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=sr(u,"return "+f).apply(C,a)}catch(s){throw s.source=f,s}return t?c(t):(c.source=f,c)},e.trim=pe,e.trimLeft=se,e.trimRight=he,e.unescape=function(n){return null==n?"":(n=mr(n),0>n.indexOf(";")?n:n.replace(D,j)) -},e.uniqueId=function(n){var t=++E;return mr(null==n?"":n)+t},e.all=Pt,e.any=Mt,e.detect=qt,e.findWhere=qt,e.foldl=Wt,e.foldr=zt,e.include=Tt,e.inject=Wt,ar(function(){var n={};return Ht(e,function(t,r){e.prototype[r]||(n[r]=t)}),n}(),false),e.first=Ct,e.last=function(n,t,r){var u=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o;for(t=e.createCallback(t,r,3);a--&&t(n[a],a,n);)u++}else if(u=t,null==u||r)return n?n[o-1]:C;return u=o-u,Et(n,0e||13e||8202r||13r||8202=A&&o===t,l=[];if(i){var c=f(e);c?(o=r,e=c):i=false}for(;++uo(e,c)&&l.push(c);return i&&y(e),l}function lt(n,t,r){var e=-1,u=n,o=n?n.length:0;if(t=t&&typeof r=="undefined"?t:k(t,r,3),typeof o=="number")for(te.unindexedChars&&er(u)&&(u=u.split(""));++e=A&&a===t,p=u||c?s():l;for(c&&(p=f(p),a=r);++oa(p,g))&&((u||c)&&p.push(g),l.push(h))}return c?(v(p.g),y(p)):u&&v(p),l}function dt(n){return function(t,r,u){var o={}; +if(r=e.createCallback(r,u,3),fe(t)){u=-1;for(var a=t.length;++uu;u++)e+="l='"+n.d[u]+"';if((!(k&&n[l])&&h.call(p,l))",n.f||(e+="||(!n[l]&&p[l]!==q[l])"),e+="){"+n.c+"}"; +e+="}"}return t("a,f,g,h,j,q,r,o,v,w,y",r+(e+"return s;")+"}")(k,Z,wr,Tr,Ct,jr,pt,ne,ut,xr,Or)}function wt(){var n=(n=e.indexOf)===Ot?t:n;return n}function jt(n){return typeof n=="function"&&Er.test(Nr.call(n))}function xt(n){var t,r;return!n||Or.call(n)!=rt||!Tr.call(n,"constructor")&&(t=n.constructor,nr(t)&&!(t instanceof t))||!te.argsClass&&Ct(n)||!te.nodeClass&&g(n)?false:te.ownLast?(le(n,function(n,t,e){return r=Tr.call(e,t),false}),false!==r):(le(n,function(n,t){r=t}),typeof r=="undefined"||Tr.call(n,r)) +}function Ct(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Or.call(n)==H||false}function kt(n,t,r){var u=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=-1;for(t=e.createCallback(t,r,3);++ae?Vr(0,u+e):e||0}else if(e)return e=At(n,r),n[e]===r?e:-1;return t(n,r,e)}function Et(n,t,r){if(typeof t!="number"&&null!=t){var u=0,o=-1,a=n?n.length:0; +for(t=e.createCallback(t,r,3);++ot?t=Vr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Vr(u+r,0):r>u&&(r=u),u=r-t||0,r=cr(u);++e>>1,r(n[u])r?0:r);++t=e)return false;if(typeof n=="string"||!fe(n)&&er(n))return Br?Br.call(n,t,r):-1r?Vr(0,e+r):r)||0,-1a&&(a=l)}}else t=null==t&&er(n)?u:e.createCallback(t,r,3),lt(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function zt(n,t,r,u){var o=3>arguments.length;if(t=e.createCallback(t,u,4),fe(n)){var a=-1,i=n.length; +for(o&&i&&(r=n[++a]);++aarguments.length;return t=e.createCallback(t,u,4),Lt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Mt(n){var t=-1,r=n?n.length:0,e=cr(typeof r=="number"?r:0);return $t(n,function(n){var r=vt(0,++t);e[t]=e[r],e[r]=n}),e}function Ut(n,t,r){var u;if(t=e.createCallback(t,r,3),fe(n)){r=-1;for(var o=n.length;++r=y;m?(u&&(u=Ar(u)),c=a,o=n.apply(i,e)):u||(u=qr(v,y))}return m&&l?l=Ar(l):l||t===p||(l=qr(g,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o}}function Gt(n,t,r){var e=arguments,u=0,o=ct[typeof r]&&e[3]&&e[3][r]===t?2:e.length;if(3--n?t.apply(this,arguments):void 0}},e.assign=Gt,e.at=function(n,t){var r=arguments,e=-1,u=ft(r,true,false,1),r=ct[typeof t]&&r[2]&&r[2][t]===n?1:u.length,o=cr(r);for(te.unindexedChars&&er(n)&&(n=n.split(""));++e=A&&f(e?n[e]:l)))}var i=n[0],p=-1,h=i?i.length:0,g=[];n:for(;++p(m?r(m,c):a(l,c))){for(e=u,(m||l).push(c);--e;)if(m=o[e],0>(m?r(m,c):a(n[e],c)))continue n;g.push(c) +}}for(;u--;)(m=o[u])&&y(m);return v(o),v(l),g},e.invert=function(n,t){for(var r=-1,e=pe(n),u=e.length,o={};++rr?Vr(0,e+r):Xr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},e.mixin=ir,e.noConflict=function(){return n._=kr,this},e.noop=lr,e.now=ve,e.parseInt=ye,e.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=Hr(),Xr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):vt(n,t) +},e.reduce=zt,e.reduceRight=Kt,e.result=function(n,t){if(n){var r=n[t];return nr(r)?n[t]():r}},e.runInContext=x,e.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:pe(n).length},e.some=Ut,e.sortedIndex=At,e.template=function(n,t,r){var u=e.templateSettings;n=dr(n||""),r=Ht({},r,u);var o,a=Ht({},r.imports,u.imports),u=pe(a),a=ur(a),i=0,l=r.interpolate||M,f="__p+='",l=mr((r.escape||M).source+"|"+l.source+"|"+(l===L?B:M).source+"|"+(r.evaluate||M).source+"|$","g");n.replace(l,function(t,r,e,u,a,l){return e||(e=u),f+=n.slice(i,l).replace(V,p),r&&(f+="'+__e("+r+")+'"),a&&(o=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=l+t.length,t +}),f+="';",l=r=r.variable,l||(r="obj",f="with("+r+"){"+f+"}"),f=(o?f.replace(R,""):f).replace(T,"$1").replace(P,"$1;"),f="function("+r+"){"+(l?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=hr(u,"return "+f).apply(C,a)}catch(s){throw s.source=f,s}return t?c(t):(c.source=f,c)},e.trim=se,e.trimLeft=he,e.trimRight=ge,e.unescape=function(n){return null==n?"":(n=dr(n),0>n.indexOf(";")?n:n.replace(D,j)) +},e.uniqueId=function(n){var t=++E;return dr(null==n?"":n)+t},e.all=Dt,e.any=Ut,e.detect=Ft,e.findWhere=Ft,e.foldl=zt,e.foldr=Kt,e.include=Pt,e.inject=zt,ir(function(){var n={};return Jt(e,function(t,r){e.prototype[r]||(n[r]=t)}),n}(),false),e.first=kt,e.last=function(n,t,r){var u=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o;for(t=e.createCallback(t,r,3);a--&&t(n[a],a,n);)u++}else if(u=t,null==u||r)return n?n[o-1]:C;return u=o-u,St(n,0"']/g,F=/<%-([\s\S]+?)%>/g,$=/<%([\s\S]+?)%>/g,L=/<%=([\s\S]+?)%>/g,B=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,W=/\w*$/,z=/^\s*function[ \n\r\t]+\w/,K=/^0[xX]/,M=/($^)/,U=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,X="Array Boolean Date Error Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),G="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),H="[object Arguments]",J="[object Array]",Q="[object Boolean]",Y="[object Date]",Z="[object Error]",nt="[object Function]",tt="[object Number]",rt="[object Object]",et="[object RegExp]",ut="[object String]",ot={}; -ot[nt]=false,ot[H]=ot[J]=ot[Q]=ot[Y]=ot[tt]=ot[rt]=ot[et]=ot[ut]=true;var at={leading:false,maxWait:0,trailing:false},it={configurable:false,enumerable:false,value:null,writable:false},lt={"&":"&","<":"<",">":">",'"':""","'":"'"},ft={"&":"&","<":"<",">":">",""":'"',"'":"'"},ct={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},pt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},st=ct[typeof window]&&window||this,ht=ct[typeof exports]&&exports&&!exports.nodeType&&exports,gt=ct[typeof global]&&global; -!gt||gt.global!==gt&>.window!==gt||(st=gt);var vt=(gt=ct[typeof module]&&module&&!module.nodeType&&module)&>.exports===ht&&ht,yt=x();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(st._=yt, define(function(){return yt})):ht&>?vt?(gt.exports=yt)._=yt:ht._=yt:st._=yt}).call(this); \ No newline at end of file +ot[nt]=false,ot[H]=ot[J]=ot[Q]=ot[Y]=ot[tt]=ot[rt]=ot[et]=ot[ut]=true;var at={leading:false,maxWait:0,trailing:false},it={configurable:false,enumerable:false,value:null,writable:false},lt={"&":"&","<":"<",">":">",'"':""","'":"'"},ft={"&":"&","<":"<",">":">",""":'"',"'":"'"},ct={"boolean":false,"function":false,object:false,number:true,string:true,undefined:false},pt={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},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,vt=pt[typeof global]&&global; +!vt||vt.global!==vt&&vt.window!==vt||(ht=vt);var yt=(vt=pt[typeof module]&&module&&!module.nodeType&&module)&&vt.exports===gt&>,mt=x();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(ht._=mt, define(function(){return mt})):gt&&vt?yt?(vt.exports=mt)._=mt:gt._=mt:ht._=mt}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 389f5b886..e0216bcf3 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -147,6 +147,16 @@ ''': "'" }; + /** Used to determine if values are an indexes or keys */ + var indexTypes = { + 'boolean': false, + 'function': false, + 'object': false, + 'number': true, + 'string': true, + 'undefined': false + }; + /** Used to determine if values are of the language type Object */ var objectTypes = { 'boolean': false, @@ -2045,7 +2055,7 @@ // juggle arguments if (typeof isShallow != 'boolean' && isShallow != null) { thisArg = callback; - callback = (typeof isShallow != 'function' && thisArg && thisArg[isShallow] === array) ? null : isShallow; + callback = (indexTypes[typeof isShallow] && thisArg && thisArg[isShallow] === array) ? null : isShallow; isShallow = false; } if (callback != null) { @@ -2724,7 +2734,7 @@ // juggle arguments if (typeof isSorted != 'boolean' && isSorted != null) { thisArg = callback; - callback = (typeof isSorted != 'function' && thisArg && thisArg[isSorted] === array) ? null : isSorted; + callback = (indexTypes[typeof isSorted] && thisArg && thisArg[isSorted] === array) ? null : isSorted; isSorted = false; } if (callback != null) { @@ -2997,11 +3007,11 @@ * _.at(['fred', 'barney', 'pebbles'], 0, 2); * // => ['fred', 'pebbles'] */ - function at(collection) { + function at(collection, guard) { var args = arguments, index = -1, props = baseFlatten(args, true, false, 1), - length = (args[2] && args[2][args[1]] === collection) ? 1 : props.length, + length = (indexTypes[typeof guard] && args[2] && args[2][guard] === collection) ? 1 : props.length, result = Array(length); while(++index < length) { @@ -3635,7 +3645,7 @@ // allows working with functions like `_.map` without using // their `index` argument as a callback - if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { + if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -3710,7 +3720,7 @@ // allows working with functions like `_.map` without using // their `index` argument as a callback - if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { + if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -4836,11 +4846,12 @@ * defaults(object, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function assign(object, source) { + function assign(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = args[3] && args[3][args[2]] === source ? 2 : args.length; + argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + // juggle arguments if (argsLength > 3 && typeof args[argsLength - 2] == 'function') { var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2); } else if (argsLength > 2 && typeof args[argsLength - 1] == 'function') { @@ -4903,11 +4914,10 @@ * // => 0 */ function clone(value, isDeep, callback, thisArg) { - // allows working with "Collections" methods without using their `index` - // and `collection` arguments for `isDeep` and `callback` + // juggle arguments if (typeof isDeep != 'boolean' && isDeep != null) { thisArg = callback; - callback = isDeep; + callback = (indexTypes[typeof isDeep] && thisArg && thisArg[isDeep] === value) ? null : isDeep; isDeep = false; } return baseClone(value, isDeep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1)); @@ -5005,6 +5015,8 @@ * @category Objects * @param {Object} object The destination object. * @param {...Object} [source] The source objects. + * @param- {Object} [guard] Allows working with `_.reduce` without using its + * `key` and `object` arguments as sources. * @returns {Object} Returns the destination object. * @example * @@ -5012,10 +5024,10 @@ * _.defaults(object, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function defaults(object, source) { + function defaults(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = args[3] && args[3][args[2]] === source ? 2 : args.length; + argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; while (++argsIndex < argsLength) { source = args[argsIndex]; @@ -5910,18 +5922,14 @@ * }); * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot] } */ - function merge(object) { - var args = arguments, - length = 2; - + function merge(object, source, guard) { if (!isObject(object)) { return object; } - // allows working with `_.reduce` and `_.reduceRight` without using - // their `index` and `collection` arguments - if (typeof args[2] != 'number') { - length = args.length; - } + var args = arguments, + length = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + + // juggle arguments if (length > 3 && typeof args[length - 2] == 'function') { var callback = baseCreateCallback(args[--length - 1], args[length--], 2); } else if (length > 2 && typeof args[length - 1] == 'function') { diff --git a/dist/lodash.min.js b/dist/lodash.min.js index ae1428ac1..187e517ee 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -5,54 +5,55 @@ */ ;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202=E&&o===t,f=[];if(a){var c=l(e);c?(o=r,e=c):a=false}for(;++uo(e,c)&&f.push(c);return a&&g(e),f}function ft(n,t,r,e){e=(e||0)-1;for(var u=n?n.length:0,o=[];++e=E&&i===t,p=u||c?s():f;for(c&&(p=l(p),i=r);++oi(p,y))&&((u||c)&&p.push(y),f.push(h))}return c?(v(p.g),g(p)):u&&v(p),f}function gt(n){return function(t,r,e){var u={};r=i.createCallback(r,e,3),e=-1;var o=t?t.length:0;if(typeof o=="number")for(;++ee?zr(0,u+e):e||0}else if(e)return e=Ct(n,r),n[e]===r?e:-1;return t(n,r,e)}function kt(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,o=n?n.length:0;for(t=i.createCallback(t,r,3);++ut?t=zr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=zr(u+r,0):r>u&&(r=u),u=r-t||0,r=ir(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!te(n)&&Zt(n))return Dr?Dr.call(n,t,r):-1r?zr(0,e+r):r)||0,-1o&&(o=f)}}else t=null==t&&Zt(n)?u:i.createCallback(t,r,3),Dt(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function qt(n,t,r,e){var u=3>arguments.length;t=i.createCallback(t,e,4);var o=-1,a=n?n.length:0;if(typeof a=="number")for(u&&a&&(r=n[++o]);++oarguments.length;return t=i.createCallback(t,e,4),Ft(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o) -}),r}function zt(n){var t=-1,r=n?n.length:0,e=ir(typeof r=="number"?r:0);return Dt(n,function(n){var r=st(0,++t);e[t]=e[r],e[r]=n}),e}function Lt(n,t,r){var e;t=i.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++r=y;m?(i&&(i=xr(i)),s=f,a=n.apply(l,o)):i||(i=Rr(e,y))}return m&&c?c=xr(c):c||t===h||(c=Rr(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a -}}function Mt(n,t){var r=arguments,e=0,u=r[3]&&r[3][r[2]]===t?2:r.length;if(3--n?t.apply(this,arguments):void 0}},i.assign=Mt,i.at=function(n){for(var t=arguments,r=-1,e=ft(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:e.length,u=ir(t);++r=E&&l(e?n[e]:f)))}var a=n[0],p=-1,h=a?a.length:0,y=[];n:for(;++p(m?r(m,c):i(f,c))){for(e=u,(m||f).push(c);--e;)if(m=o[e],0>(m?r(m,c):i(n[e],c)))continue n;y.push(c)}}for(;u--;)(m=o[u])&&g(m);return v(o),v(f),y},i.invert=function(n,t){for(var r=-1,e=ee(n),u=e.length,o={};++rr?zr(0,e+r):Lr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},i.mixin=er,i.noConflict=function(){return n._=_r,this},i.noop=ur,i.now=ae,i.parseInt=fe,i.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=Kr(),Lr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):st(n,t) -},i.reduce=qt,i.reduceRight=Wt,i.result=function(n,t){if(n){var r=n[t];return Jt(r)?n[t]():r}},i.runInContext=j,i.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ee(n).length},i.some=Lt,i.sortedIndex=Ct,i.template=function(n,t,r){var e=i.templateSettings;n=vr(n||""),r=Ut({},r,e);var u,o=Ut({},r.imports,e.imports),e=ee(o),o=nr(o),a=0,f=r.interpolate||K,l="__p+='",f=hr((r.escape||K).source+"|"+f.source+"|"+(f===q?W:K).source+"|"+(r.evaluate||K).source+"|$","g");n.replace(f,function(t,r,e,o,i,f){return e||(e=o),l+=n.slice(a,f).replace(U,p),r&&(l+="'+__e("+r+")+'"),i&&(u=true,l+="';"+i+";\n__p+='"),e&&(l+="'+((__t=("+e+"))==null?'':__t)+'"),a=f+t.length,t -}),l+="';",f=r=r.variable,f||(r="obj",l="with("+r+"){"+l+"}"),l=(u?l.replace(I,""):l).replace(S,"$1").replace(T,"$1;"),l="function("+r+"){"+(f?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}";try{var c=lr(e,"return "+l).apply(k,o)}catch(s){throw s.source=l,s}return t?c(t):(c.source=l,c)},i.trim=ue,i.trimLeft=oe,i.trimRight=ie,i.unescape=function(n){return null==n?"":(n=vr(n),0>n.indexOf(";")?n:n.replace(D,w)) -},i.uniqueId=function(n){var t=++O;return vr(null==n?"":n)+t},i.all=It,i.any=Lt,i.detect=Tt,i.findWhere=Tt,i.foldl=qt,i.foldr=Wt,i.include=Rt,i.inject=qt,er(function(){var n={};return Vt(i,function(t,r){i.prototype[r]||(n[r]=t)}),n}(),false),i.first=wt,i.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=i.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:k;return e=u-e,xt(n,0"']/g,$=/<%-([\s\S]+?)%>/g,B=/<%([\s\S]+?)%>/g,q=/<%=([\s\S]+?)%>/g,W=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,z=/\w*$/,L=/^\s*function[ \n\r\t]+\w/,P=/^0[xX]/,K=/($^)/,M=/\bthis\b/,U=/['\n\r\t\u2028\u2029\\]/g,V="Array Boolean Date Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),X="[object Arguments]",G="[object Array]",H="[object Boolean]",J="[object Date]",Q="[object Function]",Y="[object Number]",Z="[object Object]",nt="[object RegExp]",tt="[object String]",rt={}; -rt[Q]=false,rt[X]=rt[G]=rt[H]=rt[J]=rt[Y]=rt[Z]=rt[nt]=rt[tt]=true;var et={leading:false,maxWait:0,trailing:false},ut={configurable:false,enumerable:false,value:null,writable:false},ot={"&":"&","<":"<",">":">",'"':""","'":"'"},it={"&":"&","<":"<",">":">",""":'"',"'":"'"},at={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},ft={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},lt=at[typeof window]&&window||this,ct=at[typeof exports]&&exports&&!exports.nodeType&&exports,pt=at[typeof global]&&global; -!pt||pt.global!==pt&&pt.window!==pt||(lt=pt);var st=(pt=at[typeof module]&&module&&!module.nodeType&&module)&&pt.exports===ct&&ct,ht=j();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(lt._=ht, define(function(){return ht})):ct&&pt?st?(pt.exports=ht)._=ht:ct._=ht:lt._=ht}).call(this); \ No newline at end of file +}return t}function _(n){for(var t=n.length;t--;){var r=n.charCodeAt(t);if((160r||13r||8202=E&&o===t,f=[];if(a){var c=l(e);c?(o=r,e=c):a=false}for(;++uo(e,c)&&f.push(c);return a&&g(e),f}function lt(n,t,r,e){e=(e||0)-1;for(var u=n?n.length:0,o=[];++e=E&&i===t,p=u||c?s():f;for(c&&(p=l(p),i=r);++oi(p,y))&&((u||c)&&p.push(y),f.push(h))}return c?(v(p.g),g(p)):u&&v(p),f}function yt(n){return function(t,r,e){var u={};r=i.createCallback(r,e,3),e=-1;var o=t?t.length:0;if(typeof o=="number")for(;++ee?Lr(0,u+e):e||0}else if(e)return e=Ot(n,r),n[e]===r?e:-1;return t(n,r,e)}function xt(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,o=n?n.length:0;for(t=i.createCallback(t,r,3);++ut?t=Lr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Lr(u+r,0):r>u&&(r=u),u=r-t||0,r=ar(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!re(n)&&nr(n))return Fr?Fr.call(n,t,r):-1r?Lr(0,e+r):r)||0,-1o&&(o=f)}}else t=null==t&&nr(n)?u:i.createCallback(t,r,3),Ft(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function Wt(n,t,r,e){var u=3>arguments.length;t=i.createCallback(t,e,4);var o=-1,a=n?n.length:0;if(typeof a=="number")for(u&&a&&(r=n[++o]);++oarguments.length;return t=i.createCallback(t,e,4),$t(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o) +}),r}function Lt(n){var t=-1,r=n?n.length:0,e=ar(typeof r=="number"?r:0);return Ft(n,function(n){var r=ht(0,++t);e[t]=e[r],e[r]=n}),e}function Pt(n,t,r){var e;t=i.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++r=y;m?(i&&(i=Cr(i)),s=f,a=n.apply(l,o)):i||(i=Ir(e,y))}return m&&c?c=Cr(c):c||t===h||(c=Ir(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a +}}function Ut(n,t,r){var e=arguments,u=0,o=at[typeof r]&&e[3]&&e[3][r]===t?2:e.length;if(3--n?t.apply(this,arguments):void 0}},i.assign=Ut,i.at=function(n,t){for(var r=arguments,e=-1,u=lt(r,true,false,1),r=at[typeof t]&&r[2]&&r[2][t]===n?1:u.length,o=ar(r);++e=E&&l(e?n[e]:f)))}var a=n[0],p=-1,h=a?a.length:0,y=[];n:for(;++p(m?r(m,c):i(f,c))){for(e=u,(m||f).push(c);--e;)if(m=o[e],0>(m?r(m,c):i(n[e],c)))continue n;y.push(c)}}for(;u--;)(m=o[u])&&g(m);return v(o),v(f),y},i.invert=function(n,t){for(var r=-1,e=ue(n),u=e.length,o={};++rr?Lr(0,e+r):Pr(r,e-1))+1);e--;)if(n[e]===t)return e; +return-1},i.mixin=ur,i.noConflict=function(){return n._=wr,this},i.noop=or,i.now=fe,i.parseInt=le,i.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=Mr(),Pr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):ht(n,t)},i.reduce=Wt,i.reduceRight=zt,i.result=function(n,t){if(n){var r=n[t];return Qt(r)?n[t]():r}},i.runInContext=j,i.size=function(n){var t=n?n.length:0; +return typeof t=="number"?t:ue(n).length},i.some=Pt,i.sortedIndex=Ot,i.template=function(n,t,r){var e=i.templateSettings;n=gr(n||""),r=Vt({},r,e);var u,o=Vt({},r.imports,e.imports),e=ue(o),o=tr(o),a=0,f=r.interpolate||K,l="__p+='",f=vr((r.escape||K).source+"|"+f.source+"|"+(f===q?W:K).source+"|"+(r.evaluate||K).source+"|$","g");n.replace(f,function(t,r,e,o,i,f){return e||(e=o),l+=n.slice(a,f).replace(U,p),r&&(l+="'+__e("+r+")+'"),i&&(u=true,l+="';"+i+";\n__p+='"),e&&(l+="'+((__t=("+e+"))==null?'':__t)+'"),a=f+t.length,t +}),l+="';",f=r=r.variable,f||(r="obj",l="with("+r+"){"+l+"}"),l=(u?l.replace(I,""):l).replace(S,"$1").replace(T,"$1;"),l="function("+r+"){"+(f?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}";try{var c=cr(e,"return "+l).apply(k,o)}catch(s){throw s.source=l,s}return t?c(t):(c.source=l,c)},i.trim=oe,i.trimLeft=ie,i.trimRight=ae,i.unescape=function(n){return null==n?"":(n=gr(n),0>n.indexOf(";")?n:n.replace(D,w)) +},i.uniqueId=function(n){var t=++O;return gr(null==n?"":n)+t},i.all=St,i.any=Pt,i.detect=Dt,i.findWhere=Dt,i.foldl=Wt,i.foldr=zt,i.include=It,i.inject=Wt,ur(function(){var n={};return Xt(i,function(t,r){i.prototype[r]||(n[r]=t)}),n}(),false),i.first=jt,i.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=i.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:k;return e=u-e,Ct(n,0"']/g,$=/<%-([\s\S]+?)%>/g,B=/<%([\s\S]+?)%>/g,q=/<%=([\s\S]+?)%>/g,W=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,z=/\w*$/,L=/^\s*function[ \n\r\t]+\w/,P=/^0[xX]/,K=/($^)/,M=/\bthis\b/,U=/['\n\r\t\u2028\u2029\\]/g,V="Array Boolean Date Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),X="[object Arguments]",G="[object Array]",H="[object Boolean]",J="[object Date]",Q="[object Function]",Y="[object Number]",Z="[object Object]",nt="[object RegExp]",tt="[object String]",rt={}; +rt[Q]=false,rt[X]=rt[G]=rt[H]=rt[J]=rt[Y]=rt[Z]=rt[nt]=rt[tt]=true;var et={leading:false,maxWait:0,trailing:false},ut={configurable:false,enumerable:false,value:null,writable:false},ot={"&":"&","<":"<",">":">",'"':""","'":"'"},it={"&":"&","<":"<",">":">",""":'"',"'":"'"},at={"boolean":false,"function":false,object:false,number:true,string:true,undefined:false},ft={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},lt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},ct=ft[typeof window]&&window||this,pt=ft[typeof exports]&&exports&&!exports.nodeType&&exports,st=ft[typeof global]&&global; +!st||st.global!==st&&st.window!==st||(ct=st);var ht=(st=ft[typeof module]&&module&&!module.nodeType&&module)&&st.exports===pt&&pt,vt=j();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(ct._=vt, define(function(){return vt})):pt&&st?ht?(st.exports=vt)._=vt:pt._=vt:ct._=vt}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index fd89a9c37..a663746b0 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -72,6 +72,16 @@ ''': "'" }; + /** Used to determine if values are an indexes or keys */ + var indexTypes = { + 'boolean': false, + 'function': false, + 'object': false, + 'number': true, + 'string': true, + 'undefined': false + }; + /** Used to determine if values are of the language type Object */ var objectTypes = { 'boolean': false, @@ -1679,7 +1689,7 @@ // juggle arguments if (typeof isSorted != 'boolean' && isSorted != null) { thisArg = callback; - callback = (typeof isSorted != 'function' && thisArg && thisArg[isSorted] === array) ? null : isSorted; + callback = (indexTypes[typeof isSorted] && thisArg && thisArg[isSorted] === array) ? null : isSorted; isSorted = false; } if (callback != null) { @@ -2484,7 +2494,7 @@ // allows working with functions like `_.map` without using // their `index` argument as a callback - if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { + if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { callback = null; } var index = -1, @@ -2557,7 +2567,7 @@ // allows working with functions like `_.map` without using // their `index` argument as a callback - if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { + if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { callback = null; } var index = -1, @@ -3567,12 +3577,16 @@ * defaults(object, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function assign(object) { + function assign(object, source, guard) { if (!object) { return object; } - for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { - var source = arguments[argsIndex]; + var args = arguments, + argsIndex = 0, + argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + + while (++argsIndex < argsLength) { + source = args[argsIndex]; if (source) { for (var key in source) { object[key] = source[key]; @@ -3638,6 +3652,8 @@ * @category Objects * @param {Object} object The destination object. * @param {...Object} [source] The source objects. + * @param- {Object} [guard] Allows working with `_.reduce` without using its + * `key` and `object` arguments as sources. * @returns {Object} Returns the destination object. * @example * @@ -3645,12 +3661,16 @@ * _.defaults(object, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function defaults(object) { + function defaults(object, source, guard) { if (!object) { return object; } - for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { - var source = arguments[argsIndex]; + var args = arguments, + argsIndex = 0, + argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + + while (++argsIndex < argsLength) { + source = args[argsIndex]; if (source) { for (var key in source) { if (typeof object[key] == 'undefined') { diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index b4aad262f..60b40f71a 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,37 +3,37 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE * Build: `lodash underscore exports="amd,commonjs,global,node" -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(te(r,i)&&o.push(i)}return o}function s(n,r,t,e){e=(e||0)-1; -for(var u=n?n.length:0,o=[];++eu(f,c))&&(t&&f.push(c),i.push(a))}return i}function h(n){return function(r,t,e){var u={};t=X(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++ee?Ur(0,u+e):e||0}else if(e)return e=T(r,t),r[e]===t?e:-1;return n(r,t,e)}function j(n,r,t){if(typeof r!="number"&&null!=r){var e=0,u=-1,o=n?n.length:0;for(r=X(r,t,3);++ur?r=Ur(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Ur(u+t,0):t>u&&(t=u),u=t-r||0,t=Array(u);++e>>1,t(n[e])u&&(u=t); -else r=X(r,t,3),N(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=X(r,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=X(r,e,4),q(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:0,e=Array(typeof t=="number"?t:0);return N(n,function(n){var t;t=++r,t=0+Fr(Gr()*(t-0+1)),e[r]=e[t],e[t]=n -}),e}function M(n,r,t){var e;r=X(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number")for(;++t=y;m?(u&&(u=clearTimeout(u)),l=i,o=n.apply(f,e)):u||(u=setTimeout(h,y))}return m&&a?a=clearTimeout(a):a||r===p||(a=setTimeout(v,r)),t&&(m=true,o=n.apply(f,e)),!m||a||u||(e=f=null),o -}}function C(n){if(!n)return n;for(var r=1,t=arguments.length;r"']/g,fr=/($^)/,ar=/['\n\r\t\u2028\u2029\\]/g,cr="[object Arguments]",lr="[object Array]",pr="[object Boolean]",sr="[object Date]",gr="[object Number]",vr="[object Object]",hr="[object RegExp]",yr="[object String]",mr={"&":"&","<":"<",">":">",'"':""","'":"'"},_r={"&":"&","<":"<",">":">",""":'"',"'":"'"},dr={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},br={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},wr=dr[typeof window]&&window||this,jr=dr[typeof exports]&&exports&&!exports.nodeType&&exports,xr=dr[typeof global]&&global; -!xr||xr.global!==xr&&xr.window!==xr||(wr=xr);var Tr=dr[typeof module]&&module&&!module.nodeType&&module,Ar=Tr&&Tr.exports===jr&&jr,Er=Array.prototype,Or=Object.prototype,Sr=wr._,kr=Or.toString,Nr=RegExp("^"+(kr+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),qr=Math.ceil,Fr=Math.floor,Br=Function.prototype.toString,Rr=Or.hasOwnProperty,$r=Er.push,Ir=Or.propertyIsEnumerable,Mr=Er.splice,Dr=_(Dr=Object.create)&&Dr,Wr=_(Wr=Array.isArray)&&Wr,zr=wr.isFinite,Cr=wr.isNaN,Pr=_(Pr=Object.keys)&&Pr,Ur=Math.max,Vr=Math.min,Gr=Math.random; -i.prototype=o.prototype;var Hr={};!function(){var n={0:1,length:1};Hr.spliceObjects=(Mr.call(n,0,1),!n[0])}(1),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Dr||(a=function(){function n(){}return function(r){if(J(r)){n.prototype=r;var t=new n;n.prototype=null}return t||wr.Object()}}()),d(arguments)||(d=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Rr.call(n,"callee")&&!Ir.call(n,"callee")||false});var Jr=function(n){var r=[]; -if(!n||!dr[typeof n])return r;for(var t in n)Rr.call(n,t)&&r.push(t);return r},Kr=h(function(n,r,t){Rr.call(n,t)?n[t]++:n[t]=1}),Lr=h(function(n,r,t){Rr.call(n,t)?n[t].push(r):n[t]=[r]}),Qr=h(function(n,r,t){n[t]=r}),Xr=F,Yr=function(n,r){if(!n||!dr[typeof n])return n;for(var t in n)if(r(n[t],t,n)===ur)break;return n},Zr=Wr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&kr.call(n)==lr||false};H(/x/)&&(H=function(n){return typeof n=="function"&&"[object Function]"==kr.call(n)}); -var nt=Pr?function(n){return J(n)?Pr(n):[]}:Jr,rt=_(rt=Date.now)&&rt||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=1i(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n; -a.push(e)}return a},o.invert=function(n,r){for(var t=-1,e=nt(n),u=e.length,o={};++te||typeof t=="undefined"){t=1;break n}if(te(r,i)&&o.push(i)}return o}function s(n,r,t,e){e=(e||0)-1; +for(var u=n?n.length:0,o=[];++eu(f,l))&&(t&&f.push(l),i.push(a))}return i}function v(n){return function(r,t,e){var u={};t=X(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++ee?Vr(0,u+e):e||0}else if(e)return e=T(r,t),r[e]===t?e:-1;return n(r,t,e)}function j(n,r,t){if(typeof r!="number"&&null!=r){var e=0,u=-1,o=n?n.length:0;for(r=X(r,t,3);++ur?r=Vr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Vr(u+t,0):t>u&&(t=u),u=t-r||0,t=Array(u);++e>>1,t(n[e])u&&(u=t); +else r=X(r,t,3),N(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=X(r,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=X(r,e,4),q(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:0,e=Array(typeof t=="number"?t:0);return N(n,function(n){var t;t=++r,t=0+Br(Hr()*(t-0+1)),e[r]=e[t],e[t]=n +}),e}function M(n,r,t){var e;r=X(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number")for(;++t=y;m?(u&&(u=clearTimeout(u)),c=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 C(n,r,t){if(!n)return n;for(var e=arguments,u=0,o=dr[typeof t]&&e[3]&&e[3][t]===r?2:e.length;++u"']/g,fr=/($^)/,ar=/['\n\r\t\u2028\u2029\\]/g,lr="[object Arguments]",cr="[object Array]",pr="[object Boolean]",sr="[object Date]",gr="[object Number]",hr="[object Object]",vr="[object RegExp]",yr="[object String]",mr={"&":"&","<":"<",">":">",'"':""","'":"'"},_r={"&":"&","<":"<",">":">",""":'"',"'":"'"},dr={"boolean":false,"function":false,object:false,number:true,string:true,undefined:false},br={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},wr={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},jr=br[typeof window]&&window||this,xr=br[typeof exports]&&exports&&!exports.nodeType&&exports,Tr=br[typeof global]&&global; +!Tr||Tr.global!==Tr&&Tr.window!==Tr||(jr=Tr);var Ar=br[typeof module]&&module&&!module.nodeType&&module,Er=Ar&&Ar.exports===xr&&xr,Or=Array.prototype,Sr=Object.prototype,kr=jr._,Nr=Sr.toString,qr=RegExp("^"+(Nr+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Fr=Math.ceil,Br=Math.floor,Rr=Function.prototype.toString,$r=Sr.hasOwnProperty,Ir=Or.push,Mr=Sr.propertyIsEnumerable,Dr=Or.splice,Wr=_(Wr=Object.create)&&Wr,zr=_(zr=Array.isArray)&&zr,Cr=jr.isFinite,Pr=jr.isNaN,Ur=_(Ur=Object.keys)&&Ur,Vr=Math.max,Gr=Math.min,Hr=Math.random; +i.prototype=o.prototype;var Jr={};!function(){var n={0:1,length:1};Jr.spliceObjects=(Dr.call(n,0,1),!n[0])}(1),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Wr||(a=function(){function n(){}return function(r){if(J(r)){n.prototype=r;var t=new n;n.prototype=null}return t||jr.Object()}}()),d(arguments)||(d=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&$r.call(n,"callee")&&!Mr.call(n,"callee")||false});var Kr=function(n){var r=[]; +if(!n||!br[typeof n])return r;for(var t in n)$r.call(n,t)&&r.push(t);return r},Lr=v(function(n,r,t){$r.call(n,t)?n[t]++:n[t]=1}),Qr=v(function(n,r,t){$r.call(n,t)?n[t].push(r):n[t]=[r]}),Xr=v(function(n,r,t){n[t]=r}),Yr=F,Zr=function(n,r){if(!n||!br[typeof n])return n;for(var t in n)if(r(n[t],t,n)===ur)break;return n},nt=zr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Nr.call(n)==cr||false};H(/x/)&&(H=function(n){return typeof n=="function"&&"[object Function]"==Nr.call(n)}); +var rt=Ur?function(n){return J(n)?Ur(n):[]}:Kr,tt=_(tt=Date.now)&&tt||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=1i(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n; +a.push(e)}return a},o.invert=function(n,r){for(var t=-1,e=rt(n),u=e.length,o={};++tr?0:r);++nt?Ur(0,e+t):Vr(t,e-1))+1);e--;)if(n[e]===r)return e; -return-1},o.mixin=nr,o.noConflict=function(){return wr._=Sr,this},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+Fr(Gr()*(r-n+1))},o.reduce=R,o.reduceRight=$,o.result=function(n,r){if(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"?r:nt(n).length},o.some=M,o.sortedIndex=T,o.template=function(n,r,t){var u=o,i=u.templateSettings;n=(n||"")+"",t=P({},t,i);var f=0,a="__p+='",i=t.variable;n.replace(RegExp((t.escape||fr).source+"|"+(t.interpolate||fr).source+"|"+(t.evaluate||fr).source+"|$","g"),function(r,t,u,o,i){return a+=n.slice(f,i).replace(ar,e),t&&(a+="'+_.escape("+t+")+'"),o&&(a+="';"+o+";\n__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),f=i+r.length,r -}),a+="';",i||(i="obj",a="with("+i+"||{}){"+a+"}"),a="function("+i+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var c=Function("_","return "+a)(u)}catch(l){throw l.source=a,l}return r?c(r):(c.source=a,c)},o.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(or,u))},o.uniqueId=function(n){var r=++er+"";return n?n+r:r},o.all=O,o.any=M,o.detect=k,o.findWhere=function(n,r){return D(n,r,true)},o.foldl=R,o.foldr=$,o.include=E,o.inject=R,o.first=b,o.last=function(n,r,t){var e=0,u=n?n.length:0; -if(typeof r!="number"&&null!=r){var o=u;for(r=X(r,t,3);o--&&r(n[o],o,n);)e++}else if(e=r,null==e||t)return n?n[u-1]:tr;return e=u-e,x(n,0r?0:r);++nt?Vr(0,e+t):Gr(t,e-1))+1);e--;)if(n[e]===r)return e; +return-1},o.mixin=nr,o.noConflict=function(){return jr._=kr,this},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+Br(Hr()*(r-n+1))},o.reduce=R,o.reduceRight=$,o.result=function(n,r){if(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"?r:rt(n).length},o.some=M,o.sortedIndex=T,o.template=function(n,r,t){var u=o,i=u.templateSettings;n=(n||"")+"",t=P({},t,i);var f=0,a="__p+='",i=t.variable;n.replace(RegExp((t.escape||fr).source+"|"+(t.interpolate||fr).source+"|"+(t.evaluate||fr).source+"|$","g"),function(r,t,u,o,i){return a+=n.slice(f,i).replace(ar,e),t&&(a+="'+_.escape("+t+")+'"),o&&(a+="';"+o+";\n__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),f=i+r.length,r +}),a+="';",i||(i="obj",a="with("+i+"||{}){"+a+"}"),a="function("+i+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var l=Function("_","return "+a)(u)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},o.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(or,u))},o.uniqueId=function(n){var r=++er+"";return n?n+r:r},o.all=O,o.any=M,o.detect=k,o.findWhere=function(n,r){return D(n,r,true)},o.foldl=R,o.foldr=$,o.include=E,o.inject=R,o.first=b,o.last=function(n,r,t){var e=0,u=n?n.length:0; +if(typeof r!="number"&&null!=r){var o=u;for(r=X(r,t,3);o--&&r(n[o],o,n);)e++}else if(e=r,null==e||t)return n?n[u-1]:tr;return e=u-e,x(n,0 ['fred', 'pebbles'] */ - function at(collection) { + function at(collection, guard) { var args = arguments, index = -1, props = baseFlatten(args, true, false, 1), - length = (args[2] && args[2][args[1]] === collection) ? 1 : props.length, + length = (indexTypes[typeof guard] && args[2] && args[2][guard] === collection) ? 1 : props.length, result = Array(length); if (support.unindexedChars && isString(collection)) { @@ -3964,7 +3974,7 @@ // allows working with functions like `_.map` without using // their `index` argument as a callback - if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { + if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -4039,7 +4049,7 @@ // allows working with functions like `_.map` without using // their `index` argument as a callback - if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { + if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -5170,11 +5180,12 @@ * defaults(object, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function assign(object, source) { + function assign(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = args[3] && args[3][args[2]] === source ? 2 : args.length; + argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + // juggle arguments if (argsLength > 3 && typeof args[argsLength - 2] == 'function') { var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2); } else if (argsLength > 2 && typeof args[argsLength - 1] == 'function') { @@ -5237,11 +5248,10 @@ * // => 0 */ function clone(value, isDeep, callback, thisArg) { - // allows working with "Collections" methods without using their `index` - // and `collection` arguments for `isDeep` and `callback` + // juggle arguments if (typeof isDeep != 'boolean' && isDeep != null) { thisArg = callback; - callback = isDeep; + callback = (indexTypes[typeof isDeep] && thisArg && thisArg[isDeep] === value) ? null : isDeep; isDeep = false; } return baseClone(value, isDeep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1)); @@ -5339,6 +5349,8 @@ * @category Objects * @param {Object} object The destination object. * @param {...Object} [source] The source objects. + * @param- {Object} [guard] Allows working with `_.reduce` without using its + * `key` and `object` arguments as sources. * @returns {Object} Returns the destination object. * @example * @@ -5346,10 +5358,10 @@ * _.defaults(object, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function defaults(object, source) { + function defaults(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = args[3] && args[3][args[2]] === source ? 2 : args.length; + argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; while (++argsIndex < argsLength) { source = args[argsIndex]; @@ -6249,18 +6261,14 @@ * }); * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot] } */ - function merge(object) { - var args = arguments, - length = 2; - + function merge(object, source, guard) { if (!isObject(object)) { return object; } - // allows working with `_.reduce` and `_.reduceRight` without using - // their `index` and `collection` arguments - if (typeof args[2] != 'number') { - length = args.length; - } + var args = arguments, + length = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + + // juggle arguments if (length > 3 && typeof args[length - 2] == 'function') { var callback = baseCreateCallback(args[--length - 1], args[length--], 2); } else if (length > 2 && typeof args[length - 1] == 'function') {