From a499fdbb13ec1503555a950aeccb26d4b8f901aa Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 12 Jan 2014 11:54:27 -0800 Subject: [PATCH] Reduce `objectTypes` and `indexTypes` deps. --- dist/lodash.compat.js | 122 ++++++++++++++++++++++------------ dist/lodash.compat.min.js | 114 +++++++++++++++---------------- dist/lodash.js | 116 +++++++++++++++++++++----------- dist/lodash.min.js | 104 ++++++++++++++--------------- dist/lodash.underscore.js | 74 ++++++++++++--------- dist/lodash.underscore.min.js | 69 +++++++++---------- lodash.js | 122 ++++++++++++++++++++++------------ 7 files changed, 424 insertions(+), 297 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index f1fab5939..176bc690b 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -151,24 +151,10 @@ ''': "'" }; - /** 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, 'function': true, - 'object': true, - 'number': false, - 'string': false, - 'undefined': false + 'object': true }; /** Used to escape characters for inclusion in compiled string literals */ @@ -1080,7 +1066,7 @@ var __p = 'var result = ' + (obj.init) + - ';\nif (!(object && objectTypes[typeof object])) {\n return result;\n}\n' + + ';\nif (!isObject(object)) {\n return result;\n}\n' + (obj.top) + ';'; if (support.nonEnumArgs) { @@ -1543,8 +1529,8 @@ // exit early for unlike primitive values if (a === a && - !(a && objectTypes[type]) && - !(b && objectTypes[otherType])) { + !(a && (type == 'function' || type == 'object')) && + !(b && (otherType == 'function' || otherType == 'object'))) { return false; } // exit early for `null` and `undefined` avoiding ES3's Function#call behavior @@ -1943,14 +1929,14 @@ // create the function factory var factory = Function( 'baseCreateCallback, errorClass, errorProto, hasOwnProperty, isArguments, ' + - 'objectProto, objectTypes, nonEnumProps, stringClass, stringProto, toString', + 'isObject, objectProto, nonEnumProps, stringClass, stringProto, toString', 'return function(' + options.args + ') {\n' + iteratorTemplate(options) + '\n}' ); // return the compiled function return factory( baseCreateCallback, errorClass, errorProto, hasOwnProperty, isArguments, - objectProto, objectTypes, nonEnumProps, stringClass, stringProto, toString + isObject, objectProto, nonEnumProps, stringClass, stringProto, toString ); } @@ -2349,11 +2335,19 @@ * // => ['hoppy', 'baby puss', 'dino'] */ function flatten(array, isShallow, callback, thisArg) { + var type = typeof isShallow; + // juggle arguments - if (typeof isShallow != 'boolean' && isShallow != null) { + if (type != 'boolean' && isShallow != null) { thisArg = callback; - callback = (indexTypes[typeof isShallow] && thisArg && thisArg[isShallow] === array) ? null : isShallow; + callback = isShallow; isShallow = false; + + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === array) { + callback = null; + } } if (callback != null) { array = map(array, callback, thisArg); @@ -3028,11 +3022,19 @@ * // => [{ 'x': 1 }, { 'x': 2 }] */ function uniq(array, isSorted, callback, thisArg) { + var type = typeof isSorted; + // juggle arguments - if (typeof isSorted != 'boolean' && isSorted != null) { + if (type != 'boolean' && isSorted != null) { thisArg = callback; - callback = (indexTypes[typeof isSorted] && thisArg && thisArg[isSorted] === array) ? null : isSorted; + callback = isSorted; isSorted = false; + + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === array) { + callback = null; + } } if (callback != null) { callback = lodash.createCallback(callback, thisArg, 3); @@ -3308,12 +3310,18 @@ var args = arguments, index = -1, props = baseFlatten(args, true, false, 1), - length = (indexTypes[typeof guard] && args[2] && args[2][guard] === collection) ? 1 : props.length, - result = Array(length); + length = props.length, + type = typeof guard; + // allows working with functions like `_.map` without using + // their `index` arguments + if ((type == 'number' || type == 'string') && args[2] && args[2][guard] === collection) { + length = 1; + } if (support.unindexedChars && isString(collection)) { collection = collection.split(''); } + var result = Array(length); while(++index < length) { result[index] = collection[props[index]]; } @@ -3945,11 +3953,12 @@ */ function max(collection, callback, thisArg) { var computed = -Infinity, - result = computed; + result = computed, + type = typeof callback; // allows working with functions like `_.map` without using // their `index` argument as a callback - if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -4020,11 +4029,12 @@ */ function min(collection, callback, thisArg) { var computed = Infinity, - result = computed; + result = computed, + type = typeof callback; // allows working with functions like `_.map` without using // their `index` argument as a callback - if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -5157,8 +5167,14 @@ function assign(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + argsLength = args.length, + type = typeof guard; + // allows working with functions like `_.reduce` without using their + // `key` and `object` arguments as sources + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + argsLength = 2; + } // juggle arguments if (argsLength > 3 && typeof args[argsLength - 2] == 'function') { var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2); @@ -5222,11 +5238,19 @@ * // => 0 */ function clone(value, isDeep, callback, thisArg) { + var type = typeof isDeep; + // juggle arguments - if (typeof isDeep != 'boolean' && isDeep != null) { + if (type != 'boolean' && isDeep != null) { thisArg = callback; - callback = (indexTypes[typeof isDeep] && thisArg && thisArg[isDeep] === value) ? null : isDeep; + callback = isDeep; isDeep = false; + + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === value) { + callback = null; + } } return baseClone(value, isDeep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1)); } @@ -5323,8 +5347,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. + * @param- {Object} [guard] Allows working with functions like `_.reduce` + * without using their `key` and `object` arguments as sources. * @returns {Object} Returns the destination object. * @example * @@ -5335,8 +5359,14 @@ function defaults(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + argsLength = args.length, + type = typeof guard; + // allows working with functions like `_.reduce` without using their + // `key` and `object` arguments as sources + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + argsLength = 2; + } while (++argsIndex < argsLength) { source = args[argsIndex]; if (isObject(source)) { @@ -5950,7 +5980,8 @@ // http://es5.github.io/#x8 // and avoid a V8 bug // http://code.google.com/p/v8/issues/detail?id=2291 - return !!(value && objectTypes[typeof value]); + var type = typeof value; + return value && (type == 'function' || type == 'object') || false; } /** @@ -6022,8 +6053,9 @@ * // => true */ function isNumber(value) { - return typeof value == 'number' || - value && typeof value == 'object' && toString.call(value) == numberClass || false; + var type = typeof value; + return type == 'number' || + value && type == 'object' && toString.call(value) == numberClass || false; } /** @@ -6076,7 +6108,9 @@ * // => true */ function isRegExp(value) { - return value && objectTypes[typeof value] && toString.call(value) == regexpClass || false; + var type = typeof value; + return value && (type == 'function' || type == 'object') && + toString.call(value) == regexpClass || false; } /** @@ -6240,8 +6274,14 @@ return object; } var args = arguments, - length = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + length = args.length, + type = typeof guard; + // allows working with functions like `_.reduce` without using their + // `key` and `object` arguments as sources + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + length = 2; + } // juggle arguments if (length > 3 && typeof args[length - 2] == 'function') { var callback = baseCreateCallback(args[--length - 1], args[length--], 2); diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 30d9b5a4f..2a0d0dd69 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=S&&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 it(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=S&&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,Y,_r,Rr,xt,wr,ct,Zr,et,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)!=tt||!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)==G||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),it(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,r){var e=arguments,u=0,o=ft[typeof r]&&e[3]&&e[3][r]===t?2:e.length;if(3--n?t.apply(this,arguments):void 0}},e.assign=Xt,e.at=function(n,t){var r=arguments,e=-1,u=lt(r,true,false,1),r=ft[typeof t]&&r[2]&&r[2][t]===n?1:u.length,o=fr(r);for(ne.unindexedChars&&rr(n)&&(n=n.split(""));++e=S&&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||K,f="__p+='",l=yr((r.escape||K).source+"|"+l.source+"|"+(l===$?L:K).source+"|"+(r.evaluate||K).source+"|$","g");n.replace(l,function(t,r,e,u,a,l){return e||(e=u),f+=n.slice(i,l).replace(U,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(N,""):f).replace(R,"$1").replace(T,"$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(P,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,0"']/g,q=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,L=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,B=/\w*$/,W=/^\s*function[ \n\r\t]+\w/,z=/^0[xX]/,K=/($^)/,M=/\bthis\b/,U=/['\n\r\t\u2028\u2029\\]/g,V="Array Boolean Date Error Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),X="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),G="[object Arguments]",H="[object Array]",J="[object Boolean]",Q="[object Date]",Y="[object Error]",Z="[object Function]",nt="[object Number]",tt="[object Object]",rt="[object RegExp]",et="[object String]",ut={}; -ut[Z]=false,ut[G]=ut[H]=ut[J]=ut[Q]=ut[nt]=ut[tt]=ut[rt]=ut[et]=true;var ot={leading:false,maxWait:0,trailing:false},at={configurable:false,enumerable:false,value:null,writable:false},it={"&":"&","<":"<",">":">",'"':""","'":"'"},lt={"&":"&","<":"<",">":">",""":'"',"'":"'"},ft={"boolean":false,"function":false,object:false,number:true,string:true,undefined:false},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 +if(u&&typeof u=="object"&&o&&typeof o=="object"&&a&&typeof a=="object")return false;for(u=g(),u["false"]=u["null"]=u["true"]=u.undefined=false,o=g(),o.g=n,o.h=u,o.push=e;++te||13e||8202r||13r||8202=q&&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 it(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(Yr.unindexedChars&&nr(u)&&(u=u.split(""));++e=q&&a===t,s=u||c?p():l;for(c&&(s=f(s),a=r);++oa(s,h))&&((u||c)&&s.push(h),l.push(g)) +}return c?(v(s.g),y(s)):u&&v(s),l}function vt(n){return function(t,r,u){var o={};if(r=e.createCallback(r,u,3),ae(t)){u=-1;for(var a=t.length;++uu;u++)e+="m='"+n.d[u]+"';if((!(l&&o[m])&&h.call(q,m))",n.f||(e+="||(!o[m]&&q[m]!==r[m])"),e+="){"+n.c+"}"; +e+="}"}return t("a,f,g,h,j,k,r,p,v,w,y",r+(e+"return s;")+"}")(k,Y,dr,Ar,wt,Yt,br,Qr,et,_r,xr)}function dt(){var n=(n=e.indexOf)===xt?t:n;return n}function bt(n){return typeof n=="function"&&Cr.test(qr.call(n))}function _t(n){var t,r;return!n||xr.call(n)!=tt||!Ar.call(n,"constructor")&&(t=n.constructor,Qt(t)&&!(t instanceof t))||!Yr.argsClass&&wt(n)||!Yr.nodeClass&&h(n)?false:Yr.ownLast?(oe(n,function(n,t,e){return r=Ar.call(e,t),false}),false!==r):(oe(n,function(n,t){r=t}),typeof r=="undefined"||Ar.call(n,r)) +}function wt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&xr.call(n)==G||false}function jt(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?Kr(0,u+e):e||0}else if(e)return e=Ot(n,r),n[e]===r?e:-1;return t(n,r,e)}function Ct(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=Kr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Kr(u+r,0):r>u&&(r=u),u=r-t||0,r=ir(u);++e>>1,r(n[u])r?0:r);++t=e)return false;if(typeof n=="string"||!ae(n)&&nr(n))return Fr?Fr.call(n,t,r):-1r?Kr(0,e+r):r)||0,-1a&&(a=l)}else t=null==t&&nr(n)?u:e.createCallback(t,r,3),it(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Lt(n,t,r,u){var o=3>arguments.length; +if(t=e.createCallback(t,u,4),ae(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=e.createCallback(t,u,4),Dt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Wt(n){var t=-1,r=n?n.length:0,e=ir(typeof r=="number"?r:0);return Pt(n,function(n){var r=pt(0,++t);e[t]=e[r],e[r]=n}),e}function zt(n,t,r){var u;if(t=e.createCallback(t,r,3),ae(n)){r=-1;for(var o=n.length;++r=y;m?(a&&(a=Or(a)),p=l,i=n.apply(f,o)):a||(a=Rr(e,y))}return m&&c?c=Or(c):c||t===g||(c=Rr(u,t)),r&&(m=true,i=n.apply(f,o)),!m||c||a||(o=f=null),i}}function Ut(n,t,r){var e=arguments,u=0,o=e.length,a=typeof r;if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3--n?t.apply(this,arguments):void 0}},e.assign=Ut,e.at=function(n,t){var r=arguments,e=-1,u=lt(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),Yr.unindexedChars&&nr(n)&&(n=n.split("")),r=ir(o);++e=q&&f(e?n[e]:l)))}var i=n[0],s=-1,g=i?i.length:0,h=[];n:for(;++s(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;h.push(c) +}}for(;u--;)(m=o[u])&&y(m);return v(o),v(l),h},e.invert=function(n,t){for(var r=-1,e=le(n),u=e.length,o={};++rr?Kr(0,e+r):Mr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},e.mixin=ur,e.noConflict=function(){return n._=jr,this},e.noop=or,e.now=pe,e.parseInt=ge,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=Vr(),Mr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):pt(n,t) +},e.reduce=Lt,e.reduceRight=Bt,e.result=function(n,t){if(n){var r=n[t];return Qt(r)?n[t]():r}},e.runInContext=x,e.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:le(n).length},e.some=zt,e.sortedIndex=Ot,e.template=function(n,t,r){var u=e.templateSettings;n=vr(n||""),r=Vt({},r,u);var o,a=Vt({},r.imports,u.imports),u=le(a),a=tr(a),i=0,l=r.interpolate||K,f="__p+='",l=hr((r.escape||K).source+"|"+l.source+"|"+(l===$?L:K).source+"|"+(r.evaluate||K).source+"|$","g");n.replace(l,function(t,r,e,u,a,l){return e||(e=u),f+=n.slice(i,l).replace(U,s),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(I,""):f).replace(N,"$1").replace(R,"$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=cr(u,"return "+f).apply(C,a)}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},e.trim=fe,e.trimLeft=ce,e.trimRight=se,e.unescape=function(n){return null==n?"":(n=vr(n),0>n.indexOf(";")?n:n.replace(T,j)) +},e.uniqueId=function(n){var t=++E;return vr(null==n?"":n)+t},e.all=Nt,e.any=zt,e.detect=Tt,e.findWhere=Tt,e.foldl=Lt,e.foldr=Bt,e.include=It,e.inject=Lt,ur(function(){var n={};return Xt(e,function(t,r){e.prototype[r]||(n[r]=t)}),n}(),false),e.first=jt,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,kt(n,0"']/g,D=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,L=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,B=/\w*$/,W=/^\s*function[ \n\r\t]+\w/,z=/^0[xX]/,K=/($^)/,M=/\bthis\b/,U=/['\n\r\t\u2028\u2029\\]/g,V="Array Boolean Date Error Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),X="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),G="[object Arguments]",H="[object Array]",J="[object Boolean]",Q="[object Date]",Y="[object Error]",Z="[object Function]",nt="[object Number]",tt="[object Object]",rt="[object RegExp]",et="[object String]",ut={}; +ut[Z]=false,ut[G]=ut[H]=ut[J]=ut[Q]=ut[nt]=ut[tt]=ut[rt]=ut[et]=true;var ot={leading:false,maxWait:0,trailing:false},at={configurable:false,enumerable:false,value:null,writable:false},it={"&":"&","<":"<",">":">",'"':""","'":"'"},lt={"&":"&","<":"<",">":">",""":'"',"'":"'"},ft={"function":true,object:true},ct={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},st=ft[typeof window]&&window||this,pt=ft[typeof exports]&&exports&&!exports.nodeType&&exports,gt=ft[typeof global]&&global; +!gt||gt.global!==gt&>.window!==gt||(st=gt);var gt=(ft=ft[typeof module]&&module&&!module.nodeType&&module)&&ft.exports===pt&&pt,ht=x();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(st._=ht, define(function(){return ht})):pt&&ft?gt?(ft.exports=ht)._=ht:pt._=ht:st._=ht}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 72cf1d311..902755772 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -144,24 +144,10 @@ ''': "'" }; - /** 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, 'function': true, - 'object': true, - 'number': false, - 'string': false, - 'undefined': false + 'object': true }; /** Used to escape characters for inclusion in compiled string literals */ @@ -1285,8 +1271,8 @@ // exit early for unlike primitive values if (a === a && - !(a && objectTypes[type]) && - !(b && objectTypes[otherType])) { + !(a && (type == 'function' || type == 'object')) && + !(b && (otherType == 'function' || otherType == 'object'))) { return false; } // exit early for `null` and `undefined` avoiding ES3's Function#call behavior @@ -1766,7 +1752,7 @@ */ var shimKeys = function(object) { var result = []; - if (!(object && objectTypes[typeof object])) { + if (!isObject(object)) { return result; } for (var key in object) { @@ -2048,11 +2034,19 @@ * // => ['hoppy', 'baby puss', 'dino'] */ function flatten(array, isShallow, callback, thisArg) { + var type = typeof isShallow; + // juggle arguments - if (typeof isShallow != 'boolean' && isShallow != null) { + if (type != 'boolean' && isShallow != null) { thisArg = callback; - callback = (indexTypes[typeof isShallow] && thisArg && thisArg[isShallow] === array) ? null : isShallow; + callback = isShallow; isShallow = false; + + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === array) { + callback = null; + } } if (callback != null) { array = map(array, callback, thisArg); @@ -2727,11 +2721,19 @@ * // => [{ 'x': 1 }, { 'x': 2 }] */ function uniq(array, isSorted, callback, thisArg) { + var type = typeof isSorted; + // juggle arguments - if (typeof isSorted != 'boolean' && isSorted != null) { + if (type != 'boolean' && isSorted != null) { thisArg = callback; - callback = (indexTypes[typeof isSorted] && thisArg && thisArg[isSorted] === array) ? null : isSorted; + callback = isSorted; isSorted = false; + + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === array) { + callback = null; + } } if (callback != null) { callback = lodash.createCallback(callback, thisArg, 3); @@ -3007,9 +3009,15 @@ var args = arguments, index = -1, props = baseFlatten(args, true, false, 1), - length = (indexTypes[typeof guard] && args[2] && args[2][guard] === collection) ? 1 : props.length, - result = Array(length); + length = props.length, + type = typeof guard; + // allows working with functions like `_.map` without using + // their `index` arguments + if ((type == 'number' || type == 'string') && args[2] && args[2][guard] === collection) { + length = 1; + } + var result = Array(length); while(++index < length) { result[index] = collection[props[index]]; } @@ -3637,11 +3645,12 @@ */ function max(collection, callback, thisArg) { var computed = -Infinity, - result = computed; + result = computed, + type = typeof callback; // allows working with functions like `_.map` without using // their `index` argument as a callback - if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -3712,11 +3721,12 @@ */ function min(collection, callback, thisArg) { var computed = Infinity, - result = computed; + result = computed, + type = typeof callback; // allows working with functions like `_.map` without using // their `index` argument as a callback - if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -4845,8 +4855,14 @@ function assign(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + argsLength = args.length, + type = typeof guard; + // allows working with functions like `_.reduce` without using their + // `key` and `object` arguments as sources + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + argsLength = 2; + } // juggle arguments if (argsLength > 3 && typeof args[argsLength - 2] == 'function') { var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2); @@ -4910,11 +4926,19 @@ * // => 0 */ function clone(value, isDeep, callback, thisArg) { + var type = typeof isDeep; + // juggle arguments - if (typeof isDeep != 'boolean' && isDeep != null) { + if (type != 'boolean' && isDeep != null) { thisArg = callback; - callback = (indexTypes[typeof isDeep] && thisArg && thisArg[isDeep] === value) ? null : isDeep; + callback = isDeep; isDeep = false; + + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === value) { + callback = null; + } } return baseClone(value, isDeep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1)); } @@ -5011,8 +5035,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. + * @param- {Object} [guard] Allows working with functions like `_.reduce` + * without using their `key` and `object` arguments as sources. * @returns {Object} Returns the destination object. * @example * @@ -5023,8 +5047,14 @@ function defaults(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + argsLength = args.length, + type = typeof guard; + // allows working with functions like `_.reduce` without using their + // `key` and `object` arguments as sources + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + argsLength = 2; + } while (++argsIndex < argsLength) { source = args[argsIndex]; if (isObject(source)) { @@ -5182,7 +5212,7 @@ */ var forIn = function(object, callback, thisArg) { var result = object; - if (!(object && objectTypes[typeof object])) { + if (!isObject(object)) { return result; } callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); @@ -5637,7 +5667,8 @@ // http://es5.github.io/#x8 // and avoid a V8 bug // http://code.google.com/p/v8/issues/detail?id=2291 - return !!(value && objectTypes[typeof value]); + var type = typeof value; + return value && (type == 'function' || type == 'object') || false; } /** @@ -5709,8 +5740,9 @@ * // => true */ function isNumber(value) { - return typeof value == 'number' || - value && typeof value == 'object' && toString.call(value) == numberClass || false; + var type = typeof value; + return type == 'number' || + value && type == 'object' && toString.call(value) == numberClass || false; } /** @@ -5923,8 +5955,14 @@ return object; } var args = arguments, - length = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + length = args.length, + type = typeof guard; + // allows working with functions like `_.reduce` without using their + // `key` and `object` arguments as sources + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + length = 2; + } // juggle arguments if (length > 3 && typeof args[length - 2] == 'function') { var callback = baseCreateCallback(args[--length - 1], args[length--], 2); diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 87fba26db..7737b11b0 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -5,55 +5,55 @@ */ ;(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,f=[];if(a){var c=l(e);c?(o=r,e=c):a=false}for(;++uo(e,c)&&f.push(c);return a&&v(e),f}function ft(n,t,r,e){e=(e||0)-1;for(var u=n?n.length:0,o=[];++e=A&&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?(g(p.g),v(p)):u&&g(p),f}function vt(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,r){var e=arguments,u=0,o=it[typeof r]&&e[3]&&e[3][r]===t?2:e.length;if(3--n?t.apply(this,arguments):void 0}},i.assign=Mt,i.at=function(n,t){for(var r=arguments,e=-1,u=ft(r,true,false,1),r=it[typeof t]&&r[2]&&r[2][t]===n?1:u.length,o=ir(r);++e=A&&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])&&v(m);return g(o),g(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=gr(n||""),r=Ut({},r,e);var u,o=Ut({},r.imports,e.imports),e=ee(o),o=nr(o),a=0,f=r.interpolate||P,l="__p+='",f=hr((r.escape||P).source+"|"+f.source+"|"+(f===B?q:P).source+"|"+(r.evaluate||P).source+"|$","g");n.replace(f,function(t,r,e,o,i,f){return e||(e=o),l+=n.slice(a,f).replace(M,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(R,""):l).replace(I,"$1").replace(S,"$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=gr(n),0>n.indexOf(";")?n:n.replace(T,w)) -},i.uniqueId=function(n){var t=++O;return gr(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,F=/<%-([\s\S]+?)%>/g,$=/<%([\s\S]+?)%>/g,B=/<%=([\s\S]+?)%>/g,q=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,W=/\w*$/,z=/^\s*function[ \n\r\t]+\w/,L=/^0[xX]/,P=/($^)/,K=/\bthis\b/,M=/['\n\r\t\u2028\u2029\\]/g,U="Array Boolean Date Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),V="[object Arguments]",X="[object Array]",G="[object Boolean]",H="[object Date]",J="[object Function]",Q="[object Number]",Y="[object Object]",Z="[object RegExp]",nt="[object String]",tt={}; -tt[J]=false,tt[V]=tt[X]=tt[G]=tt[H]=tt[Q]=tt[Y]=tt[Z]=tt[nt]=true;var rt={leading:false,maxWait:0,trailing:false},et={configurable:false,enumerable:false,value:null,writable:false},ut={"&":"&","<":"<",">":">",'"':""","'":"'"},ot={"&":"&","<":"<",">":">",""":'"',"'":"'"},it={"boolean":false,"function":false,object:false,number:true,string:true,undefined:false},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 +if(u&&typeof u=="object"&&o&&typeof o=="object"&&i&&typeof i=="object")return false;for(u=g(),u["false"]=u["null"]=u["true"]=u.undefined=false,o=g(),o.g=n,o.h=u,o.push=e;++te||13e||8202r||13r||8202=A&&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&&v(e),f}function it(n,t,r,e){e=(e||0)-1;for(var u=n?n.length:0,o=[];++e=A&&i===t,p=u||c?s():f;for(c&&(p=l(p),i=r);++oi(p,y))&&((u||c)&&p.push(y),f.push(g))}return c?(h(p.g),v(p)):u&&h(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?qr(0,u+e):e||0}else if(e)return e=kt(n,r),n[e]===r?e:-1;return t(n,r,e)}function wt(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=qr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=qr(u+r,0):r>u&&(r=u),u=r-t||0,r=ur(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!Zr(n)&&Qt(n))return Sr?Sr.call(n,t,r):-1r?qr(0,e+r):r)||0,-1o&&(o=f)}else t=null==t&&Qt(n)?u:i.createCallback(t,r,3),St(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function $t(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),Tt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function qt(n){var t=-1,r=n?n.length:0,e=ur(typeof r=="number"?r:0); +return St(n,function(n){var r=ct(0,++t);e[t]=e[r],e[r]=n}),e}function Wt(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=jr(i)),s=f,a=n.apply(l,o)):i||(i=Er(e,y))}return m&&c?c=jr(c):c||t===g||(c=Er(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a}}function Pt(n,t,r){var e=arguments,u=0,o=e.length,i=typeof r; +if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3--n?t.apply(this,arguments):void 0}},i.assign=Pt,i.at=function(n,t){var r=arguments,e=-1,u=it(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=ur(o);++e=A&&l(e?n[e]:f)))}var a=n[0],p=-1,g=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])&&v(m);return h(o),h(f),y},i.invert=function(n,t){for(var r=-1,e=te(n),u=e.length,o={};++rr?qr(0,e+r):Wr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},i.mixin=tr,i.noConflict=function(){return n._=br,this},i.noop=rr,i.now=oe,i.parseInt=ie,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=Lr(),Wr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):ct(n,t)},i.reduce=$t,i.reduceRight=Bt,i.result=function(n,t){if(n){var r=n[t]; +return Gt(r)?n[t]():r}},i.runInContext=j,i.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:te(n).length},i.some=Wt,i.sortedIndex=kt,i.template=function(n,t,r){var e=i.templateSettings;n=sr(n||""),r=Kt({},r,e);var u,o=Kt({},r.imports,e.imports),e=te(o),o=Yt(o),a=0,f=r.interpolate||P,l="__p+='",f=pr((r.escape||P).source+"|"+f.source+"|"+(f===B?q:P).source+"|"+(r.evaluate||P).source+"|$","g");n.replace(f,function(t,r,e,o,i,f){return e||(e=o),l+=n.slice(a,f).replace(M,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(R,""):l).replace(I,"$1").replace(S,"$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=ar(e,"return "+l).apply(k,o)}catch(s){throw s.source=l,s}return t?c(t):(c.source=l,c)},i.trim=re,i.trimLeft=ee,i.trimRight=ue,i.unescape=function(n){return null==n?"":(n=sr(n),0>n.indexOf(";")?n:n.replace(T,w)) +},i.uniqueId=function(n){var t=++O;return sr(null==n?"":n)+t},i.all=Nt,i.any=Wt,i.detect=It,i.findWhere=It,i.foldl=$t,i.foldr=Bt,i.include=Et,i.inject=$t,tr(function(){var n={};return Mt(i,function(t,r){i.prototype[r]||(n[r]=t)}),n}(),false),i.first=dt,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,jt(n,0"']/g,F=/<%-([\s\S]+?)%>/g,$=/<%([\s\S]+?)%>/g,B=/<%=([\s\S]+?)%>/g,q=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,W=/\w*$/,z=/^\s*function[ \n\r\t]+\w/,L=/^0[xX]/,P=/($^)/,K=/\bthis\b/,M=/['\n\r\t\u2028\u2029\\]/g,U="Array Boolean Date Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),V="[object Arguments]",X="[object Array]",G="[object Boolean]",H="[object Date]",J="[object Function]",Q="[object Number]",Y="[object Object]",Z="[object RegExp]",nt="[object String]",tt={}; +tt[J]=false,tt[V]=tt[X]=tt[G]=tt[H]=tt[Q]=tt[Y]=tt[Z]=tt[nt]=true;var rt={leading:false,maxWait:0,trailing:false},et={configurable:false,enumerable:false,value:null,writable:false},ut={"&":"&","<":"<",">":">",'"':""","'":"'"},ot={"&":"&","<":"<",">":">",""":'"',"'":"'"},it={"function":true,object:true},at={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},ft=it[typeof window]&&window||this,lt=it[typeof exports]&&exports&&!exports.nodeType&&exports,ct=it[typeof global]&&global; +!ct||ct.global!==ct&&ct.window!==ct||(ft=ct);var ct=(it=it[typeof module]&&module&&!module.nodeType&&module)&&it.exports===lt&<,pt=j();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(ft._=pt, define(function(){return pt})):lt&&it?ct?(it.exports=pt)._=pt:lt._=pt:ft._=pt}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 89aa24d3d..922d6bae8 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -69,24 +69,10 @@ ''': "'" }; - /** 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, 'function': true, - 'object': true, - 'number': false, - 'string': false, - 'undefined': false + 'object': true }; /** Used to escape characters for inclusion in compiled string literals */ @@ -644,8 +630,8 @@ otherType = typeof b; if (a === a && - !(a && objectTypes[type]) && - !(b && objectTypes[otherType])) { + !(a && (type == 'function' || type == 'object')) && + !(b && (otherType == 'function' || otherType == 'object'))) { return false; } if (a == null || b == null) { @@ -938,7 +924,7 @@ */ var shimKeys = function(object) { var result = []; - if (!(object && objectTypes[typeof object])) { + if (!isObject(object)) { return result; } for (var key in object) { @@ -1682,11 +1668,19 @@ * // => [{ 'x': 1 }, { 'x': 2 }] */ function uniq(array, isSorted, callback, thisArg) { + var type = typeof isSorted; + // juggle arguments - if (typeof isSorted != 'boolean' && isSorted != null) { + if (type != 'boolean' && isSorted != null) { thisArg = callback; - callback = (indexTypes[typeof isSorted] && thisArg && thisArg[isSorted] === array) ? null : isSorted; + callback = isSorted; isSorted = false; + + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === array) { + callback = null; + } } if (callback != null) { callback = createCallback(callback, thisArg, 3); @@ -2486,11 +2480,12 @@ */ function max(collection, callback, thisArg) { var computed = -Infinity, - result = computed; + result = computed, + type = typeof callback; // allows working with functions like `_.map` without using // their `index` argument as a callback - if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === collection) { callback = null; } var index = -1, @@ -2559,11 +2554,12 @@ */ function min(collection, callback, thisArg) { var computed = Infinity, - result = computed; + result = computed, + type = typeof callback; // allows working with functions like `_.map` without using // their `index` argument as a callback - if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === collection) { callback = null; } var index = -1, @@ -3579,8 +3575,12 @@ } var args = arguments, argsIndex = 0, - argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + argsLength = args.length, + type = typeof guard; + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + argsLength = 2; + } while (++argsIndex < argsLength) { source = args[argsIndex]; if (source) { @@ -3648,8 +3648,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. + * @param- {Object} [guard] Allows working with functions like `_.reduce` + * without using their `key` and `object` arguments as sources. * @returns {Object} Returns the destination object. * @example * @@ -3663,8 +3663,12 @@ } var args = arguments, argsIndex = 0, - argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + argsLength = args.length, + type = typeof guard; + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + argsLength = 2; + } while (++argsIndex < argsLength) { source = args[argsIndex]; if (source) { @@ -3711,7 +3715,7 @@ */ var forIn = function(object, callback) { var result = object; - if (!(object && objectTypes[typeof object])) { + if (!isObject(object)) { return result; } for (var key in object) { @@ -4071,7 +4075,8 @@ // http://es5.github.io/#x8 // and avoid a V8 bug // http://code.google.com/p/v8/issues/detail?id=2291 - return !!(value && objectTypes[typeof value]); + var type = typeof value; + return value && (type == 'function' || type == 'object') || false; } /** @@ -4143,8 +4148,9 @@ * // => true */ function isNumber(value) { - return typeof value == 'number' || - value && typeof value == 'object' && toString.call(value) == numberClass || false; + var type = typeof value; + return type == 'number' || + value && type == 'object' && toString.call(value) == numberClass || false; } /** @@ -4161,7 +4167,9 @@ * // => true */ function isRegExp(value) { - return value && objectTypes[typeof value] && toString.call(value) == regexpClass || false; + var type = typeof value; + return value && (type == 'function' || type == 'object') && + toString.call(value) == regexpClass || false; } /** diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index bcf37ca58..416b66583 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,37 +3,38 @@ * 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,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,kr=Object.prototype,Sr=jr._,Nr=kr.toString,qr=RegExp("^"+(Nr+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Fr=Math.ceil,Br=Math.floor,Rr=Function.prototype.toString,$r=kr.hasOwnProperty,Ir=Or.push,Mr=kr.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){for(var r=-1,t=rt(n),e=t.length,u={};++rr?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._=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+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=S,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,0e||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,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t;for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,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={"&":"&","<":"<",">":">",""":'"',"'":"'"},br={"function":true,object:true},dr={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},wr=br[typeof window]&&window||this,jr=br[typeof exports]&&exports&&!exports.nodeType&&exports,xr=br[typeof global]&&global; +!xr||xr.global!==xr&&xr.window!==xr||(wr=xr);var Tr=br[typeof module]&&module&&!module.nodeType&&module,Ar=Tr&&Tr.exports===jr&&jr,Er=Array.prototype,Or=Object.prototype,kr=wr._,Sr=Or.toString,Nr=RegExp("^"+(Sr+"").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()}}()),b(arguments)||(b=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(!J(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(!J(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"&&Sr.call(n)==lr||false};H(/x/)&&(H=function(n){return typeof n=="function"&&"[object Function]"==Sr.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){for(var r=-1,t=nt(n),e=t.length,u={};++rr?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._=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+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=S,o.findWhere=function(n,r){return D(n,r,true)},o.foldl=R,o.foldr=$,o.include=E,o.inject=R,o.first=d,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;\n' + // exit early if the first argument is not an object - 'if (!(object && objectTypes[typeof object])) {\n' + + "if (!isObject(object)) {\n" + ' return result;\n' + '}\n' + @@ -1559,8 +1545,8 @@ // exit early for unlike primitive values if (a === a && - !(a && objectTypes[type]) && - !(b && objectTypes[otherType])) { + !(a && (type == 'function' || type == 'object')) && + !(b && (otherType == 'function' || otherType == 'object'))) { return false; } // exit early for `null` and `undefined` avoiding ES3's Function#call behavior @@ -1960,14 +1946,14 @@ // create the function factory var factory = Function( 'baseCreateCallback, errorClass, errorProto, hasOwnProperty, isArguments, ' + - 'objectProto, objectTypes, nonEnumProps, stringClass, stringProto, toString', + 'isObject, objectProto, nonEnumProps, stringClass, stringProto, toString', 'return function(' + options.args + ') {\n' + iteratorTemplate(options) + '\n}' ); // return the compiled function return factory( baseCreateCallback, errorClass, errorProto, hasOwnProperty, isArguments, - objectProto, objectTypes, nonEnumProps, stringClass, stringProto, toString + isObject, objectProto, nonEnumProps, stringClass, stringProto, toString ); } @@ -2366,11 +2352,19 @@ * // => ['hoppy', 'baby puss', 'dino'] */ function flatten(array, isShallow, callback, thisArg) { + var type = typeof isShallow; + // juggle arguments - if (typeof isShallow != 'boolean' && isShallow != null) { + if (type != 'boolean' && isShallow != null) { thisArg = callback; - callback = (indexTypes[typeof isShallow] && thisArg && thisArg[isShallow] === array) ? null : isShallow; + callback = isShallow; isShallow = false; + + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === array) { + callback = null; + } } if (callback != null) { array = map(array, callback, thisArg); @@ -3045,11 +3039,19 @@ * // => [{ 'x': 1 }, { 'x': 2 }] */ function uniq(array, isSorted, callback, thisArg) { + var type = typeof isSorted; + // juggle arguments - if (typeof isSorted != 'boolean' && isSorted != null) { + if (type != 'boolean' && isSorted != null) { thisArg = callback; - callback = (indexTypes[typeof isSorted] && thisArg && thisArg[isSorted] === array) ? null : isSorted; + callback = isSorted; isSorted = false; + + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === array) { + callback = null; + } } if (callback != null) { callback = lodash.createCallback(callback, thisArg, 3); @@ -3326,12 +3328,18 @@ var args = arguments, index = -1, props = baseFlatten(args, true, false, 1), - length = (indexTypes[typeof guard] && args[2] && args[2][guard] === collection) ? 1 : props.length, - result = Array(length); + length = props.length, + type = typeof guard; + // allows working with functions like `_.map` without using + // their `index` arguments + if ((type == 'number' || type == 'string') && args[2] && args[2][guard] === collection) { + length = 1; + } if (support.unindexedChars && isString(collection)) { collection = collection.split(''); } + var result = Array(length); while(++index < length) { result[index] = collection[props[index]]; } @@ -3963,11 +3971,12 @@ */ function max(collection, callback, thisArg) { var computed = -Infinity, - result = computed; + result = computed, + type = typeof callback; // allows working with functions like `_.map` without using // their `index` argument as a callback - if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -4038,11 +4047,12 @@ */ function min(collection, callback, thisArg) { var computed = Infinity, - result = computed; + result = computed, + type = typeof callback; // allows working with functions like `_.map` without using // their `index` argument as a callback - if (indexTypes[typeof callback] && thisArg && thisArg[callback] === collection) { + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === collection) { callback = null; } if (callback == null && isArray(collection)) { @@ -5176,8 +5186,14 @@ function assign(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + argsLength = args.length, + type = typeof guard; + // allows working with functions like `_.reduce` without using their + // `key` and `object` arguments as sources + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + argsLength = 2; + } // juggle arguments if (argsLength > 3 && typeof args[argsLength - 2] == 'function') { var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2); @@ -5241,11 +5257,19 @@ * // => 0 */ function clone(value, isDeep, callback, thisArg) { + var type = typeof isDeep; + // juggle arguments - if (typeof isDeep != 'boolean' && isDeep != null) { + if (type != 'boolean' && isDeep != null) { thisArg = callback; - callback = (indexTypes[typeof isDeep] && thisArg && thisArg[isDeep] === value) ? null : isDeep; + callback = isDeep; isDeep = false; + + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === value) { + callback = null; + } } return baseClone(value, isDeep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1)); } @@ -5342,8 +5366,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. + * @param- {Object} [guard] Allows working with functions like `_.reduce` + * without using their `key` and `object` arguments as sources. * @returns {Object} Returns the destination object. * @example * @@ -5354,8 +5378,14 @@ function defaults(object, source, guard) { var args = arguments, argsIndex = 0, - argsLength = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + argsLength = args.length, + type = typeof guard; + // allows working with functions like `_.reduce` without using their + // `key` and `object` arguments as sources + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + argsLength = 2; + } while (++argsIndex < argsLength) { source = args[argsIndex]; if (isObject(source)) { @@ -5969,7 +5999,8 @@ // http://es5.github.io/#x8 // and avoid a V8 bug // http://code.google.com/p/v8/issues/detail?id=2291 - return !!(value && objectTypes[typeof value]); + var type = typeof value; + return value && (type == 'function' || type == 'object') || false; } /** @@ -6041,8 +6072,9 @@ * // => true */ function isNumber(value) { - return typeof value == 'number' || - value && typeof value == 'object' && toString.call(value) == numberClass || false; + var type = typeof value; + return type == 'number' || + value && type == 'object' && toString.call(value) == numberClass || false; } /** @@ -6095,7 +6127,9 @@ * // => true */ function isRegExp(value) { - return value && objectTypes[typeof value] && toString.call(value) == regexpClass || false; + var type = typeof value; + return value && (type == 'function' || type == 'object') && + toString.call(value) == regexpClass || false; } /** @@ -6259,8 +6293,14 @@ return object; } var args = arguments, - length = indexTypes[typeof guard] && args[3] && args[3][guard] === source ? 2 : args.length; + length = args.length, + type = typeof guard; + // allows working with functions like `_.reduce` without using their + // `key` and `object` arguments as sources + if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { + length = 2; + } // juggle arguments if (length > 3 && typeof args[length - 2] == 'function') { var callback = baseCreateCallback(args[--length - 1], args[length--], 2);