From 677fb934943219d0970f65cd088be1414fcb65f5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 19 Jan 2014 12:10:09 -0800 Subject: [PATCH] Use `baseEach`, `baseForOwn` and `baseForIn` to reduce dependencies on `baseCreateCallback`. --- dist/lodash.compat.js | 133 +++++++++++++----------- dist/lodash.compat.min.js | 110 ++++++++++---------- dist/lodash.js | 166 +++++++++++++++++++----------- dist/lodash.min.js | 101 +++++++++--------- dist/lodash.underscore.js | 188 ++++++++++++++++------------------ dist/lodash.underscore.min.js | 70 ++++++------- lodash.js | 135 +++++++++++++----------- 7 files changed, 491 insertions(+), 412 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 6a8228c48..73b7c46bd 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -984,9 +984,7 @@ var __p = 'var result = ' + (obj.init) + - ';\nif (!isObject(object)) {\n return result;\n}\n' + - (obj.top) + - ';'; + ';\nif (!isObject(object)) {\n return result;\n}'; if (support.nonEnumArgs) { __p += '\nvar length = object.length;\nif (length && isArguments(object)) {\n key = -1;\n while (++key < length) {\n key += \'\';\n ' + (obj.loop) + @@ -1158,7 +1156,7 @@ stackB.push(result); // recursively populate clone (susceptible to call stack limits) - (isArr ? baseEach : forOwn)(value, function(objValue, key) { + (isArr ? baseEach : baseForOwn)(value, function(objValue, key) { result[key] = baseClone(objValue, isDeep, callback, stackA, stackB); }); @@ -1335,24 +1333,19 @@ } /** - * Iterates `arguments` objects, arrays, objects, and strings consistently - * across environments, executing the callback for each element in the - * collection. The callback is bound to `thisArg` and invoked with three - * arguments; (value, index|key, collection). Callbacks may exit iteration - * early by explicitly returning `false`. + * The base implementation of `_.forEach` without support for callback + * shorthands or `thisArg` binding. * * @private * @param {Array|Object|string} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. - * @param {*} [thisArg] The `this` binding of `callback`. + * @param {Function} callback The function called per iteration. * @returns {Array|Object|string} Returns `collection`. */ - function baseEach(collection, callback, thisArg) { + function baseEach(collection, callback) { var index = -1, iterable = collection, length = collection ? collection.length : 0; - callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); if (typeof length == 'number') { if (support.unindexedChars && isString(iterable)) { iterable = iterable.split(''); @@ -1363,7 +1356,7 @@ } } } else { - forOwn(collection, callback); + baseForOwn(collection, callback); } return collection; } @@ -1408,6 +1401,29 @@ return result; } + /** + * The base implementation of `_.forOwn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, callback) { + var index = -1, + props = keys(object), + length = props.length; + + while (++index < length) { + var key = props[index]; + if (callback(object[key], key, object) === false) { + break; + } + } + return object; + } + /** * The base implementation of `_.isEqual`, without support for `thisArg` binding, * that allows partial "_.where" style comparisons. @@ -1555,7 +1571,7 @@ else { // deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys` // which, in this case, is more costly - forIn(b, function(value, key, b) { + baseForIn(b, function(value, key, b) { if (hasOwnProperty.call(b, key)) { // count the number of properties. size++; @@ -1566,7 +1582,7 @@ if (result && !isWhere) { // ensure both objects have the same number of properties - forIn(a, function(value, key, a) { + baseForIn(a, function(value, key, a) { if (hasOwnProperty.call(a, key)) { // `size` will be `-1` if `a` has more properties than `b` return (result = --size > -1); @@ -1596,7 +1612,7 @@ * @param {Array} [stackB=[]] Associates values with source counterparts. */ function baseMerge(object, source, callback, stackA, stackB) { - (isArray(source) ? forEach : forOwn)(source, function(source, key) { + (isArray(source) ? baseEach : baseForOwn)(source, function(source, key) { var found, isArr, result = source, @@ -1842,7 +1858,6 @@ * @param {Object} [options] The compile options object. * @param {string} [options.args] A comma separated string of iteration function arguments. * @param {string} [options.init] The string representation of the initial `result` value. - * @param {string} [options.top] Code to execute before the iteration branches. * @param {string} [options.loop] Code to execute in the object loop. * @param {boolean} [options.useHas] Specify using `hasOwnProperty` checks in the object loop. * @returns {Function} Returns the compiled function. @@ -1852,15 +1867,15 @@ // create the function factory var factory = Function( - 'baseCreateCallback, errorClass, errorProto, hasOwnProperty, isArguments, ' + - 'isObject, objectProto, nonEnumProps, stringClass, stringProto, toString', + 'errorClass, errorProto, hasOwnProperty, isArguments, 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, - isObject, objectProto, nonEnumProps, stringClass, stringProto, toString + errorClass, errorProto, hasOwnProperty, isArguments, isObject, objectProto, + nonEnumProps, stringClass, stringProto, toString ); } @@ -1926,7 +1941,7 @@ // iterated property is an object's own property then there are no inherited // enumerable properties. if (support.ownLast) { - forIn(value, function(value, key, object) { + baseForIn(value, function(value, key, object) { result = hasOwnProperty.call(object, key); return false; }); @@ -1935,7 +1950,7 @@ // In most environments an object's own properties are iterated before // its inherited properties. If the last iterated property is an object's // own property then there are no inherited enumerable properties. - forIn(value, function(value, key) { + baseForIn(value, function(value, key) { result = key; }); return typeof result == 'undefined' || hasOwnProperty.call(value, result); @@ -1971,6 +1986,22 @@ }; } + /** + * The base implementation of `_.forIn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + var baseForIn = createIterator({ + 'args': 'object, callback', + 'init': 'object', + 'loop': 'if (callback(object[key], key, object) === false) {\n return result;\n }', + 'useHas': false + }); + /** * A fallback implementation of `Object.keys` which produces an array of the * given object's own enumerable property names. @@ -1983,7 +2014,6 @@ var shimKeys = createIterator({ 'args': 'object', 'init': '[]', - 'top': '', 'loop': 'result.push(key)', 'useHas': true }); @@ -3603,7 +3633,7 @@ } } } else { - baseEach(collection, callback, thisArg); + baseEach(collection, baseCreateCallback(callback, thisArg, 3)); } return collection; } @@ -3766,7 +3796,7 @@ length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - forEach(collection, function(value) { + baseEach(collection, function(value) { result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); }); return result; @@ -4184,7 +4214,7 @@ length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - forEach(collection, function(value) { + baseEach(collection, function(value) { var rand = baseRandom(0, ++index); result[index] = result[rand]; result[rand] = value; @@ -4339,7 +4369,7 @@ if (!multi) { callback = lodash.createCallback(callback, thisArg, 3); } - forEach(collection, function(value, key, collection) { + baseEach(collection, function(value, key, collection) { var object = result[++index] = getObject(); object.index = index; object.value = value; @@ -5347,7 +5377,7 @@ function findKey(object, callback, thisArg) { var result; callback = lodash.createCallback(callback, thisArg, 3); - forOwn(object, function(value, key, object) { + baseForOwn(object, function(value, key, object) { if (callback(value, key, object)) { result = key; return false; @@ -5440,13 +5470,10 @@ * }); * // => logs 'x', 'y', and 'move' (property order is not guaranteed across environments) */ - var forIn = createIterator({ - 'args': 'object, callback, thisArg', - 'init': 'object', - 'top': "callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3)", - 'loop': 'if (callback(object[key], key, object) === false) {\n return result;\n }', - 'useHas': false - }); + function forIn(object, callback, thisArg) { + callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); + return baseForIn(object, callback); + } /** * This method is like `_.forIn` except that it iterates over elements @@ -5479,7 +5506,7 @@ function forInRight(object, callback, thisArg) { var pairs = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { pairs.push(key, value); }); @@ -5514,18 +5541,8 @@ * // => logs '0', '1', and 'length' (property order is not guaranteed across environments) */ function forOwn(object, callback, thisArg) { - var index = -1, - props = keys(object), - length = props.length; - callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); - while (++index < length) { - var key = props[index]; - if (callback(object[key], key, object) === false) { - break; - } - } - return object; + return baseForOwn(object, callback); } /** @@ -5577,7 +5594,7 @@ */ function functions(object) { var result = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { if (isFunction(value)) { result.push(key); } @@ -5769,7 +5786,7 @@ (className == objectClass && typeof length == 'number' && isFunction(value.splice))) { return !length; } - forOwn(value, function() { + baseForOwn(value, function() { return (result = false); }); return result; @@ -6130,7 +6147,7 @@ var result = {}; callback = lodash.createCallback(callback, thisArg, 3); - forOwn(object, function(value, key, object) { + baseForOwn(object, function(value, key, object) { result[key] = callback(value, key, object); }); return result; @@ -6249,7 +6266,7 @@ var result = {}; if (typeof callback != 'function') { var props = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { props.push(key); }); props = baseDifference(props, baseFlatten(arguments, true, false, 1)); @@ -6263,7 +6280,7 @@ } } else { callback = lodash.createCallback(callback, thisArg, 3); - forIn(object, function(value, key, object) { + baseForIn(object, function(value, key, object) { if (!callback(value, key, object)) { result[key] = value; } @@ -6341,7 +6358,7 @@ } } else { callback = lodash.createCallback(callback, thisArg, 3); - forIn(object, function(value, key, object) { + baseForIn(object, function(value, key, object) { if (callback(value, key, object)) { result[key] = value; } @@ -6395,7 +6412,7 @@ } if (callback) { callback = lodash.createCallback(callback, thisArg, 4); - (isArr ? baseEach : forOwn)(object, function(value, index, object) { + (isArr ? baseEach : baseForOwn)(object, function(value, index, object) { return callback(accumulator, value, index, object); }); } @@ -7390,7 +7407,7 @@ mixin(function() { var source = {} - forOwn(lodash, function(func, methodName) { + baseForOwn(lodash, function(func, methodName) { if (!lodash.prototype[methodName]) { source[methodName] = func; } @@ -7409,7 +7426,7 @@ lodash.take = first; lodash.head = first; - forOwn(lodash, function(func, methodName) { + baseForOwn(lodash, function(func, methodName) { var callbackable = methodName !== 'sample'; if (!lodash.prototype[methodName]) { lodash.prototype[methodName]= function(n, guard) { diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 29f303480..bb43895f2 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -3,60 +3,60 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE * Build: `lodash -o ./dist/lodash.compat.js` */ -;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202=I&&o===t&&(o=r,e=wt(e));++uo(e,l)&&i.push(l)}return i}function st(n,t,r){var e=-1,u=n,o=n?n.length:0;if(t=t&&typeof r=="undefined"?t:N(t,r,3),typeof o=="number")for(ae.unindexedChars&&ar(u)&&(u=u.split(""));++e=I&&a===t,f=[];if(l)var p=wt(),a=r;else p=u?c():f;for(;++oa(p,h))&&((u||l)&&p.push(h),f.push(g)) -}return!l&&u&&s(p),f}function _t(n){return function(t,r,e){var o={};if(r=u.createCallback(r,e,3),he(t)){e=-1;for(var a=t.length;++eu;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;")+"}")(N,tt,Cr,Dr,Et,ur,kr,oe,at,Or,Sr)}function Ct(){var n=(n=u.indexOf)===St?t:n;return n}function kt(n){return typeof n=="function"&&Ar.test(Tr.call(n))}function Ot(n){var t,r;return!n||Sr.call(n)!=ut||!Dr.call(n,"constructor")&&(t=n.constructor,er(t)&&!(t instanceof t))||!ae.argsClass&&Et(n)||!ae.nodeClass&&p(n)?false:ae.ownLast?(ge(n,function(n,t,e){return r=Dr.call(e,t),false}),false!==r):(ge(n,function(n,t){r=t}),typeof r=="undefined"||Dr.call(n,r)) -}function Et(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Sr.call(n)==Q||false}function qt(n,t,r){var e=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=-1;for(t=u.createCallback(t,r,3);++ae?Jr(0,u+e):e||0;else if(e)return e=Nt(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function At(n,t,r){if(typeof t!="number"&&null!=t){var e=0,o=-1,a=n?n.length:0; -for(t=u.createCallback(t,r,3);++ot?t=Jr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Jr(u+r,0):r>u&&(r=u),u=r-t||0,r=gr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!he(n)&&ar(n))return Mr?Mr.call(n,t,r):-1r?Jr(0,e+r):r)||0,-1a&&(a=l)}else t=null==t&&ar(n)?e:u.createCallback(t,r,3),st(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Ut(n,t,r,e){var o=3>arguments.length; -if(t=u.createCallback(t,e,4),he(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=u.createCallback(t,e,4),zt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Xt(n){var t=-1,r=n?n.length:0,e=gr(typeof r=="number"?r:0);return Wt(n,function(n){var r=dt(0,++t);e[t]=e[r],e[r]=n}),e}function Gt(n,t,r){var e;if(t=u.createCallback(t,r,3),he(n)){r=-1;for(var o=n.length;++r=y;m?(a&&(a=Nr(a)),s=l,i=n.apply(f,o)):a||(a=Br(e,y))}return m&&c?c=Nr(c):c||t===g||(c=Br(u,t)),r&&(m=true,i=n.apply(f,o)),!m||c||a||(o=f=null),i}}function Qt(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}},u.assign=Qt,u.at=function(n,t){var r=arguments,e=-1,u=gt(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),ae.unindexedChars&&ar(n)&&(n=n.split("")),r=gr(o);++e=I&&wt(e?n[e]:l)))}var i=n[0],p=-1,g=i?i.length:0,h=[];n:for(;++p(v?r(v,f):a(l,f))){for(e=u,(v||l).push(f);--e;)if(v=o[e],0>(v?r(v,f):a(n[e],f)))continue n;h.push(f) -}}return s(o),s(l),h},u.invert=function(n,t){for(var r=-1,e=ye(n),u=e.length,o={};++rr?Jr(0,e+r):Qr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=cr,u.noConflict=function(){return n._=qr,this},u.noop=pr,u.now=_e,u.parseInt=we,u.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=ne(),Qr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):dt(n,t) -},u.reduce=Ut,u.reduceRight=Vt,u.result=function(n,t,r){return null==n?r:(r="undefined"!=typeof n[t]?n[t]:r,er(r)?n[t]():r)},u.runInContext=_,u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ye(n).length},u.some=Gt,u.sortedIndex=Nt,u.template=function(n,t,r){var e=u.templateSettings;n=wr(n||""),r=Yt({},r,e);var o,a=Yt({},r.imports,e.imports),e=ye(a),a=ir(a),i=0,l=r.interpolate||V,c="__p+='",l=_r((r.escape||V).source+"|"+l.source+"|"+(l===W?z:V).source+"|"+(r.evaluate||V).source+"|$","g"); -n.replace(l,function(t,r,e,u,a,l){return e||(e=u),c+=n.slice(i,l).replace(G,f),r&&(c+="'+__e("+r+")+'"),a&&(o=true,c+="';"+a+";\n__p+='"),e&&(c+="'+((__t=("+e+"))==null?'':__t)+'"),i=l+t.length,t}),c+="';",l=r=r.variable,l||(r="obj",c="with("+r+"){"+c+"}"),c=(o?c.replace(T,""):c).replace(P,"$1").replace(D,"$1;"),c="function("+r+"){"+(l?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var p=yr(e,"return "+c).apply(w,a) -}catch(s){throw s.source=c,s}return t?p(t):(p.source=c,p)},u.trim=me,u.trimLeft=de,u.trimRight=be,u.unescape=function(n){return null==n?"":(n=wr(n),0>n.indexOf(";")?n:n.replace(F,b))},u.uniqueId=function(n){var t=++C;return wr(null==n?"":n)+t},u.all=$t,u.any=Gt,u.detect=Bt,u.findWhere=Bt,u.foldl=Ut,u.foldr=Vt,u.include=Ft,u.inject=Ut,cr(function(){var n={};return Zt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=qt,u.last=function(n,t,r){var e=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o; -for(t=u.createCallback(t,r,3);a--&&t(n[a],a,n);)e++}else if(e=t,null==e||r)return n?n[o-1]:w;return e=o-e,It(n,0"']/g,L=/<%-([\s\S]+?)%>/g,B=/<%([\s\S]+?)%>/g,W=/<%=([\s\S]+?)%>/g,z=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,K=/\w*$/,M=/^\s*function[ \n\r\t]+\w/,U=/^0[xX]/,V=/($^)/,X=/\bthis\b/,G=/['\n\r\t\u2028\u2029\\]/g,H="Array Boolean Date Error Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),Q="[object Arguments]",Y="[object Array]",Z="[object Boolean]",nt="[object Date]",tt="[object Error]",rt="[object Function]",et="[object Number]",ut="[object Object]",ot="[object RegExp]",at="[object String]",it={}; +;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202=N&&o===t&&(o=r,e=jt(e));++uo(e,l)&&i.push(l)}return i}function st(n,t){var r=-1,e=n,u=n?n.length:0;if(typeof u=="number")for(ae.unindexedChars&&ar(e)&&(e=e.split(""));++r=N&&a===t,f=[];if(l)var p=jt(),a=r;else p=u?c():f;for(;++oa(p,h))&&((u||l)&&p.push(h),f.push(g)) +}return!l&&u&&s(p),f}function wt(n){return function(t,r,e){var o={};if(r=u.createCallback(r,e,3),he(t)){e=-1;for(var a=t.length;++eu;u++)e+="l='"+n.d[u]+"';if((!(k&&n[l])&&g.call(p,l))",n.e||(e+="||(!n[l]&&p[l]!==q[l])"),e+="){"+n.c+"}"; +e+="}"}return t("e,f,g,i,j,q,o,u,v,w",r+(e+"return r;")+"}")(tt,Cr,qr,St,ur,kr,oe,at,Or,Ar)}function kt(){var n=(n=u.indexOf)===It?t:n;return n}function Ot(n){return typeof n=="function"&&Ir.test(Pr.call(n))}function Et(n){var t,r;return!n||Ar.call(n)!=ut||!qr.call(n,"constructor")&&(t=n.constructor,er(t)&&!(t instanceof t))||!ae.argsClass&&St(n)||!ae.nodeClass&&p(n)?false:ae.ownLast?(le(n,function(n,t,e){return r=qr.call(e,t),false}),false!==r):(le(n,function(n,t){r=t}),typeof r=="undefined"||qr.call(n,r)) +}function St(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ar.call(n)==Q||false}function At(n,t,r){var e=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=-1;for(t=u.createCallback(t,r,3);++ae?Jr(0,u+e):e||0;else if(e)return e=Tt(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Nt(n,t,r){if(typeof t!="number"&&null!=t){var e=0,o=-1,a=n?n.length:0; +for(t=u.createCallback(t,r,3);++ot?t=Jr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Jr(u+r,0):r>u&&(r=u),u=r-t||0,r=gr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!he(n)&&ar(n))return Mr?Mr.call(n,t,r):-1r?Jr(0,e+r):r)||0,-1a&&(a=l)}else t=null==t&&ar(n)?e:u.createCallback(t,r,3),st(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Vt(n,t,r,e){var o=3>arguments.length; +if(t=u.createCallback(t,e,4),he(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=u.createCallback(t,e,4),Kt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Gt(n){var t=-1,r=n?n.length:0,e=gr(typeof r=="number"?r:0);return st(n,function(n){var r=bt(0,++t);e[t]=e[r],e[r]=n}),e}function Ht(n,t,r){var e;if(t=u.createCallback(t,r,3),he(n)){r=-1;for(var o=n.length;++r=y;m?(u&&(u=Rr(u)),c=a,o=n.apply(i,e)):u||(u=Br(v,y))}return m&&l?l=Rr(l):l||t===p||(l=Br(h,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o}}function Yt(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}},u.assign=Yt,u.at=function(n,t){var r=arguments,e=-1,u=gt(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),ae.unindexedChars&&ar(n)&&(n=n.split("")),r=gr(o);++e=N&&jt(e?n[e]:l)))}var i=n[0],p=-1,g=i?i.length:0,h=[];n:for(;++p(v?r(v,f):a(l,f))){for(e=u,(v||l).push(f);--e;)if(v=o[e],0>(v?r(v,f):a(n[e],f)))continue n;h.push(f)}}return s(o),s(l),h},u.invert=function(n,t){for(var r=-1,e=ye(n),u=e.length,o={};++rr?Jr(0,e+r):Qr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=cr,u.noConflict=function(){return n._=Sr,this},u.noop=pr,u.now=_e,u.parseInt=we,u.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=ne(),Qr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):bt(n,t) +},u.reduce=Vt,u.reduceRight=Xt,u.result=function(n,t,r){return null==n?r:(r="undefined"!=typeof n[t]?n[t]:r,er(r)?n[t]():r)},u.runInContext=_,u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ye(n).length},u.some=Ht,u.sortedIndex=Tt,u.template=function(n,t,r){var e=u.templateSettings;n=wr(n||""),r=Zt({},r,e);var o,a=Zt({},r.imports,e.imports),e=ye(a),a=ir(a),i=0,l=r.interpolate||V,c="__p+='",l=_r((r.escape||V).source+"|"+l.source+"|"+(l===W?z:V).source+"|"+(r.evaluate||V).source+"|$","g"); +n.replace(l,function(t,r,e,u,a,l){return e||(e=u),c+=n.slice(i,l).replace(G,f),r&&(c+="'+__e("+r+")+'"),a&&(o=true,c+="';"+a+";\n__p+='"),e&&(c+="'+((__t=("+e+"))==null?'':__t)+'"),i=l+t.length,t}),c+="';",l=r=r.variable,l||(r="obj",c="with("+r+"){"+c+"}"),c=(o?c.replace(P,""):c).replace(D,"$1").replace(q,"$1;"),c="function("+r+"){"+(l?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var p=yr(e,"return "+c).apply(w,a) +}catch(s){throw s.source=c,s}return t?p(t):(p.source=c,p)},u.trim=me,u.trimLeft=de,u.trimRight=be,u.unescape=function(n){return null==n?"":(n=wr(n),0>n.indexOf(";")?n:n.replace(F,b))},u.uniqueId=function(n){var t=++C;return wr(null==n?"":n)+t},u.all=Lt,u.any=Ht,u.detect=Wt,u.findWhere=Wt,u.foldl=Vt,u.foldr=Xt,u.include=$t,u.inject=Vt,cr(function(){var n={};return vt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=At,u.last=function(n,t,r){var e=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o; +for(t=u.createCallback(t,r,3);a--&&t(n[a],a,n);)e++}else if(e=t,null==e||r)return n?n[o-1]:w;return e=o-e,Rt(n,0"']/g,L=/<%-([\s\S]+?)%>/g,B=/<%([\s\S]+?)%>/g,W=/<%=([\s\S]+?)%>/g,z=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,K=/\w*$/,M=/^\s*function[ \n\r\t]+\w/,U=/^0[xX]/,V=/($^)/,X=/\bthis\b/,G=/['\n\r\t\u2028\u2029\\]/g,H="Array Boolean Date Error Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),Q="[object Arguments]",Y="[object Array]",Z="[object Boolean]",nt="[object Date]",tt="[object Error]",rt="[object Function]",et="[object Number]",ut="[object Object]",ot="[object RegExp]",at="[object String]",it={}; it[rt]=false,it[Q]=it[Y]=it[Z]=it[nt]=it[et]=it[ut]=it[ot]=it[at]=true;var lt={leading:false,maxWait:0,trailing:false},ft={configurable:false,enumerable:false,value:null,writable:false},ct={"&":"&","<":"<",">":">",'"':""","'":"'"},pt={"&":"&","<":"<",">":">",""":'"',"'":"'"},st={"function":true,object:true},gt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},ht=st[typeof window]&&window||this,vt=st[typeof exports]&&exports&&!exports.nodeType&&exports,yt=st[typeof global]&&global; !yt||yt.global!==yt&&yt.window!==yt||(ht=yt);var yt=(st=st[typeof module]&&module&&!module.nodeType&&module)&&st.exports===vt&&vt,mt=_();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(ht._=mt, define(function(){return mt})):vt&&st?yt?(st.exports=mt)._=mt:vt._=mt:ht._=mt}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index c4d8b318a..452fd7a45 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -934,7 +934,7 @@ stackB.push(result); // recursively populate clone (susceptible to call stack limits) - (isArr ? forEach : forOwn)(value, function(objValue, key) { + (isArr ? baseEach : baseForOwn)(value, function(objValue, key) { result[key] = baseClone(objValue, isDeep, callback, stackA, stackB); }); @@ -1110,6 +1110,32 @@ return result; } + /** + * The base implementation of `_.forEach` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Array|Object|string} Returns `collection`. + */ + function baseEach(collection, callback) { + var index = -1, + iterable = collection, + length = collection ? collection.length : 0; + + if (typeof length == 'number') { + while (++index < length) { + if (callback(iterable[index], index, collection) === false) { + break; + } + } + } else { + baseForOwn(collection, callback); + } + return collection; + } + /** * The base implementation of `_.flatten` without support for callback * shorthands or `thisArg` binding. @@ -1150,6 +1176,29 @@ return result; } + /** + * The base implementation of `_.forOwn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, callback) { + var index = -1, + props = keys(object), + length = props.length; + + while (++index < length) { + var key = props[index]; + if (callback(object[key], key, object) === false) { + break; + } + } + return object; + } + /** * The base implementation of `_.isEqual`, without support for `thisArg` binding, * that allows partial "_.where" style comparisons. @@ -1297,7 +1346,7 @@ else { // deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys` // which, in this case, is more costly - forIn(b, function(value, key, b) { + baseForIn(b, function(value, key, b) { if (hasOwnProperty.call(b, key)) { // count the number of properties. size++; @@ -1308,7 +1357,7 @@ if (result && !isWhere) { // ensure both objects have the same number of properties - forIn(a, function(value, key, a) { + baseForIn(a, function(value, key, a) { if (hasOwnProperty.call(a, key)) { // `size` will be `-1` if `a` has more properties than `b` return (result = --size > -1); @@ -1338,7 +1387,7 @@ * @param {Array} [stackB=[]] Associates values with source counterparts. */ function baseMerge(object, source, callback, stackA, stackB) { - (isArray(source) ? forEach : forOwn)(source, function(source, key) { + (isArray(source) ? baseEach : baseForOwn)(source, function(source, key) { var found, isArr, result = source, @@ -1471,7 +1520,7 @@ setter(result, value, callback(value, index, collection), collection); } } else { - forOwn(collection, function(value, key, collection) { + baseEach(collection, function(value, key, collection) { setter(result, value, callback(value, key, collection), collection); }); } @@ -1636,7 +1685,7 @@ // In most environments an object's own properties are iterated before // its inherited properties. If the last iterated property is an object's // own property then there are no inherited enumerable properties. - forIn(value, function(value, key) { + baseForIn(value, function(value, key) { result = key; }); return typeof result == 'undefined' || hasOwnProperty.call(value, result); @@ -1665,6 +1714,28 @@ toString.call(value) == argsClass || false; } + /** + * The base implementation of `_.forIn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + var baseForIn = function(object, callback) { + var result = object; + if (!isObject(object)) { + return result; + } + for (var key in object) { + if (callback(object[key], key, object) === false) { + return result; + } + } + return result; + }; + /** * A fallback implementation of `Object.keys` which produces an array of the * given object's own enumerable property names. @@ -2989,7 +3060,7 @@ var index = -1, result = false; - forOwn(collection, function(value) { + baseEach(collection, function(value) { if (++index >= fromIndex) { return !(result = value === target); } @@ -3091,7 +3162,7 @@ } } } else { - forOwn(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { return (result = !!callback(value, index, collection)); }); } @@ -3153,7 +3224,7 @@ } } } else { - forOwn(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { if (callback(value, index, collection)) { result.push(value); } @@ -3220,7 +3291,7 @@ } } else { var result; - forOwn(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { if (callback(value, index, collection)) { result = value; return false; @@ -3300,7 +3371,7 @@ } } } else { - forOwn(collection, callback); + baseEach(collection, callback); } return collection; } @@ -3334,7 +3405,7 @@ } else { var props = keys(collection); length = props.length; - forOwn(collection, function(value, key, collection) { + baseEach(collection, function(value, key, collection) { key = props ? props[--length] : --length; return callback(collection[key], key, collection); }); @@ -3457,7 +3528,7 @@ length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - forEach(collection, function(value) { + baseEach(collection, function(value) { result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); }); return result; @@ -3514,7 +3585,7 @@ } } else { result = []; - forOwn(collection, function(value, key, collection) { + baseEach(collection, function(value, key, collection) { result[++index] = callback(value, key, collection); }); } @@ -3586,7 +3657,7 @@ ? charAtCallback : lodash.createCallback(callback, thisArg, 3); - forEach(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { var current = callback(value, index, collection); if (current > computed) { computed = current; @@ -3662,7 +3733,7 @@ ? charAtCallback : lodash.createCallback(callback, thisArg, 3); - forEach(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { var current = callback(value, index, collection); if (current < computed) { computed = current; @@ -3740,7 +3811,7 @@ accumulator = callback(accumulator, collection[index], index, collection); } } else { - forOwn(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { accumulator = noaccum ? (noaccum = false, value) : callback(accumulator, value, index, collection) @@ -3874,7 +3945,7 @@ length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - forEach(collection, function(value) { + baseEach(collection, function(value) { var rand = baseRandom(0, ++index); result[index] = result[rand]; result[rand] = value; @@ -3964,7 +4035,7 @@ } } } else { - forOwn(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { return !(result = callback(value, index, collection)); }); } @@ -4029,7 +4100,7 @@ if (!multi) { callback = lodash.createCallback(callback, thisArg, 3); } - forEach(collection, function(value, key, collection) { + baseEach(collection, function(value, key, collection) { var object = result[++index] = getObject(); object.index = index; object.value = value; @@ -5035,7 +5106,7 @@ function findKey(object, callback, thisArg) { var result; callback = lodash.createCallback(callback, thisArg, 3); - forOwn(object, function(value, key, object) { + baseForOwn(object, function(value, key, object) { if (callback(value, key, object)) { result = key; return false; @@ -5128,19 +5199,10 @@ * }); * // => logs 'x', 'y', and 'move' (property order is not guaranteed across environments) */ - var forIn = function(object, callback, thisArg) { - var result = object; - if (!isObject(object)) { - return result; - } + function forIn(object, callback, thisArg) { callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); - for (var key in object) { - if (callback(object[key], key, object) === false) { - return result; - } - } - return result; - }; + return baseForIn(object, callback); + } /** * This method is like `_.forIn` except that it iterates over elements @@ -5173,7 +5235,7 @@ function forInRight(object, callback, thisArg) { var pairs = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { pairs.push(key, value); }); @@ -5208,18 +5270,8 @@ * // => logs '0', '1', and 'length' (property order is not guaranteed across environments) */ function forOwn(object, callback, thisArg) { - var index = -1, - props = keys(object), - length = props.length; - callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); - while (++index < length) { - var key = props[index]; - if (callback(object[key], key, object) === false) { - break; - } - } - return object; + return baseForOwn(object, callback); } /** @@ -5271,7 +5323,7 @@ */ function functions(object) { var result = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { if (isFunction(value)) { result.push(key); } @@ -5462,7 +5514,7 @@ (className == objectClass && typeof length == 'number' && isFunction(value.splice))) { return !length; } - forOwn(value, function() { + baseForOwn(value, function() { return (result = false); }); return result; @@ -5811,7 +5863,7 @@ var result = {}; callback = lodash.createCallback(callback, thisArg, 3); - forOwn(object, function(value, key, object) { + baseForOwn(object, function(value, key, object) { result[key] = callback(value, key, object); }); return result; @@ -5930,7 +5982,7 @@ var result = {}; if (typeof callback != 'function') { var props = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { props.push(key); }); props = baseDifference(props, baseFlatten(arguments, true, false, 1)); @@ -5944,7 +5996,7 @@ } } else { callback = lodash.createCallback(callback, thisArg, 3); - forIn(object, function(value, key, object) { + baseForIn(object, function(value, key, object) { if (!callback(value, key, object)) { result[key] = value; } @@ -6022,7 +6074,7 @@ } } else { callback = lodash.createCallback(callback, thisArg, 3); - forIn(object, function(value, key, object) { + baseForIn(object, function(value, key, object) { if (callback(value, key, object)) { result[key] = value; } @@ -6076,7 +6128,7 @@ } if (callback) { callback = lodash.createCallback(callback, thisArg, 4); - (isArr ? forEach : forOwn)(object, function(value, index, object) { + (isArr ? baseEach : baseForOwn)(object, function(value, index, object) { return callback(accumulator, value, index, object); }); } @@ -7071,7 +7123,7 @@ mixin(function() { var source = {} - forOwn(lodash, function(func, methodName) { + baseForOwn(lodash, function(func, methodName) { if (!lodash.prototype[methodName]) { source[methodName] = func; } @@ -7090,7 +7142,7 @@ lodash.take = first; lodash.head = first; - forOwn(lodash, function(func, methodName) { + baseForOwn(lodash, function(func, methodName) { var callbackable = methodName !== 'sample'; if (!lodash.prototype[methodName]) { lodash.prototype[methodName]= function(n, guard) { @@ -7122,7 +7174,7 @@ lodash.prototype.valueOf = wrapperValueOf; // add `Array` functions that return unwrapped values - forEach(['join', 'pop', 'shift'], function(methodName) { + baseEach(['join', 'pop', 'shift'], function(methodName) { var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { var chainAll = this.__chain__, @@ -7135,7 +7187,7 @@ }); // add `Array` functions that return the existing wrapped value - forEach(['push', 'reverse', 'sort', 'unshift'], function(methodName) { + baseEach(['push', 'reverse', 'sort', 'unshift'], function(methodName) { var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { func.apply(this.__wrapped__, arguments); @@ -7144,7 +7196,7 @@ }); // add `Array` functions that return new wrapped values - forEach(['concat', 'splice'], function(methodName) { + baseEach(['concat', 'splice'], function(methodName) { var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { return new lodashWrapper(func.apply(this.__wrapped__, arguments), this.__chain__); diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 3b04def67..8a9f30d33 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -3,56 +3,57 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE * Build: `lodash modern -o ./dist/lodash.js` */ -;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202=N&&o===t&&(o=r,e=bt(e));++uo(e,f)&&a.push(f)}return a}function st(n,t,r,e){e=(e||0)-1;for(var u=n?n.length:0,o=[];++e=N&&i===t,l=[];if(f)var s=bt(),i=r;else s=u?c():l;for(;++oi(s,h))&&((u||f)&&s.push(h),l.push(g)) -}return!f&&u&&p(s),l}function dt(n){return function(t,r,e){var u={};r=y.createCallback(r,e,3),e=-1;var o=t?t.length:0;if(typeof o=="number")for(;++ee?Ur(0,u+e):e||0;else if(e)return e=Et(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function At(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,o=n?n.length:0;for(t=y.createCallback(t,r,3);++ut?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=cr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!ae(n)&&er(n))return Wr?Wr.call(n,t,r):-1r?Ur(0,e+r):r)||0,-1o&&(o=a)}else t=null==t&&er(n)?e:y.createCallback(t,r,3),qt(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function Pt(n,t,r,e){var u=3>arguments.length;t=y.createCallback(t,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(r=n[++o]);++oarguments.length;return t=y.createCallback(t,e,4),Wt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Mt(n){var t=-1,r=n?n.length:0,e=cr(typeof r=="number"?r:0); -return qt(n,function(n){var r=yt(0,++t);e[t]=e[r],e[r]=n}),e}function Ut(n,t,r){var e;t=y.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++r=y;m?(i&&(i=Sr(i)),s=f,a=n.apply(l,o)):i||(i=Fr(e,y))}return m&&c?c=Sr(c):c||t===g||(c=Fr(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a}}function Gt(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}},y.assign=Gt,y.at=function(n,t){var r=arguments,e=-1,u=st(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=cr(o);++e=N&&bt(e?n[e]:f)))}var a=n[0],s=-1,g=a?a.length:0,h=[];n:for(;++s(v?r(v,l):i(f,l))){for(e=u,(v||f).push(l);--e;)if(v=o[e],0>(v?r(v,l):i(n[e],l)))continue n;h.push(l)}}return p(o),p(f),h},y.invert=function(n,t){for(var r=-1,e=le(n),u=e.length,o={};++rr?Ur(0,e+r):Vr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},y.mixin=ar,y.noConflict=function(){return n._=xr,this},y.noop=fr,y.now=ge,y.parseInt=he,y.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(),Vr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):yt(n,t) -},y.reduce=Pt,y.reduceRight=Kt,y.result=function(n,t,r){return null==n?r:(r="undefined"!=typeof n[t]?n[t]:r,nr(r)?n[t]():r)},y.runInContext=b,y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:le(n).length},y.some=Ut,y.sortedIndex=Et,y.template=function(n,t,r){var e=y.templateSettings;n=dr(n||""),r=Ht({},r,e);var u,o=Ht({},r.imports,e.imports),e=le(o),o=ur(o),i=0,a=r.interpolate||U,f="__p+='",a=mr((r.escape||U).source+"|"+a.source+"|"+(a===z?L:U).source+"|"+(r.evaluate||U).source+"|$","g"); -n.replace(a,function(t,r,e,o,a,c){return e||(e=o),f+=n.slice(i,c).replace(X,l),r&&(f+="'+__e("+r+")+'"),a&&(u=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=c+t.length,t}),f+="';",a=r=r.variable,a||(r="obj",f="with("+r+"){"+f+"}"),f=(u?f.replace(T,""):f).replace(D,"$1").replace(F,"$1;"),f="function("+r+"){"+(a?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=gr(e,"return "+f).apply(_,o) -}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},y.trim=ce,y.trimLeft=pe,y.trimRight=se,y.unescape=function(n){return null==n?"":(n=dr(n),0>n.indexOf(";")?n:n.replace($,d))},y.uniqueId=function(n){var t=++k;return dr(null==n?"":n)+t},y.all=Ft,y.any=Ut,y.detect=Bt,y.findWhere=Bt,y.foldl=Pt,y.foldr=Kt,y.include=Dt,y.inject=Pt,ar(function(){var n={};return Jt(y,function(t,r){y.prototype[r]||(n[r]=t)}),n}(),false),y.first=Ct,y.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u; -for(t=y.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:_;return e=u-e,St(n,0t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202=N&&o===t&&(o=r,e=wt(e));++uo(e,f)&&a.push(f)}return a}function st(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(;++r=N&&i===t,l=[];if(f)var s=wt(),i=r;else s=u?c():l;for(;++oi(s,h))&&((u||f)&&s.push(h),l.push(g))}return!f&&u&&p(s),l}function _t(n){return function(t,r,e){var u={};r=y.createCallback(r,e,3),e=-1;var o=t?t.length:0;if(typeof o=="number")for(;++ee?Vr(0,u+e):e||0;else if(e)return e=Rt(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Et(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,o=n?n.length:0;for(t=y.createCallback(t,r,3);++ut?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=pr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!fe(n)&&ur(n))return zr?zr.call(n,t,r):-1r?Vr(0,e+r):r)||0,-1o&&(o=a)}else t=null==t&&ur(n)?e:y.createCallback(t,r,3),st(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function Mt(n,t,r,e){var u=3>arguments.length;t=y.createCallback(t,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(r=n[++o]);++oarguments.length;return t=y.createCallback(t,e,4),Lt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Vt(n){var t=-1,r=n?n.length:0,e=pr(typeof r=="number"?r:0); +return st(n,function(n){var r=dt(0,++t);e[t]=e[r],e[r]=n}),e}function Xt(n,t,r){var e;t=y.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++r=y;m?(i&&(i=Er(i)),s=f,a=n.apply(l,o)):i||(i=$r(e,y))}return m&&c?c=Er(c):c||t===g||(c=$r(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a}}function Jt(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}},y.assign=Jt,y.at=function(n,t){var r=arguments,e=-1,u=gt(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=pr(o);++e=N&&wt(e?n[e]:f)))}var a=n[0],s=-1,g=a?a.length:0,h=[];n:for(;++s(v?r(v,l):i(f,l))){for(e=u,(v||f).push(l);--e;)if(v=o[e],0>(v?r(v,l):i(n[e],l)))continue n;h.push(l) +}}return p(o),p(f),h},y.invert=function(n,t){for(var r=-1,e=ce(n),u=e.length,o={};++rr?Vr(0,e+r):Xr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},y.mixin=fr,y.noConflict=function(){return n._=Cr,this},y.noop=lr,y.now=he,y.parseInt=ve,y.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=Jr(),Xr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):dt(n,t) +},y.reduce=Mt,y.reduceRight=Ut,y.result=function(n,t,r){return null==n?r:(r="undefined"!=typeof n[t]?n[t]:r,tr(r)?n[t]():r)},y.runInContext=b,y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ce(n).length},y.some=Xt,y.sortedIndex=Rt,y.template=function(n,t,r){var e=y.templateSettings;n=br(n||""),r=Qt({},r,e);var u,o=Qt({},r.imports,e.imports),e=ce(o),o=or(o),i=0,a=r.interpolate||U,f="__p+='",a=dr((r.escape||U).source+"|"+a.source+"|"+(a===z?L:U).source+"|"+(r.evaluate||U).source+"|$","g"); +n.replace(a,function(t,r,e,o,a,c){return e||(e=o),f+=n.slice(i,c).replace(X,l),r&&(f+="'+__e("+r+")+'"),a&&(u=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=c+t.length,t}),f+="';",a=r=r.variable,a||(r="obj",f="with("+r+"){"+f+"}"),f=(u?f.replace(T,""):f).replace(D,"$1").replace(F,"$1;"),f="function("+r+"){"+(a?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=hr(e,"return "+f).apply(_,o) +}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},y.trim=pe,y.trimLeft=se,y.trimRight=ge,y.unescape=function(n){return null==n?"":(n=br(n),0>n.indexOf(";")?n:n.replace($,d))},y.uniqueId=function(n){var t=++k;return br(null==n?"":n)+t},y.all=Bt,y.any=Xt,y.detect=Wt,y.findWhere=Wt,y.foldl=Mt,y.foldr=Ut,y.include=$t,y.inject=Mt,fr(function(){var n={};return vt(y,function(t,r){y.prototype[r]||(n[r]=t)}),n}(),false),y.first=At,y.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u; +for(t=y.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:_;return e=u-e,Nt(n,0"']/g,q=/<%-([\s\S]+?)%>/g,W=/<%([\s\S]+?)%>/g,z=/<%=([\s\S]+?)%>/g,L=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,P=/\w*$/,K=/^\s*function[ \n\r\t]+\w/,M=/^0[xX]/,U=/($^)/,V=/\bthis\b/,X=/['\n\r\t\u2028\u2029\\]/g,G="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),H="[object Arguments]",J="[object Array]",Q="[object Boolean]",Y="[object Date]",Z="[object Function]",nt="[object Number]",tt="[object Object]",rt="[object RegExp]",et="[object String]",ut={}; ut[Z]=false,ut[H]=ut[J]=ut[Q]=ut[Y]=ut[nt]=ut[tt]=ut[rt]=ut[et]=true;var ot={leading:false,maxWait:0,trailing:false},it={configurable:false,enumerable:false,value:null,writable:false},at={"&":"&","<":"<",">":">",'"':""","'":"'"},ft={"&":"&","<":"<",">":">",""":'"',"'":"'"},lt={"function":true,object:true},ct={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},pt=lt[typeof window]&&window||this,st=lt[typeof exports]&&exports&&!exports.nodeType&&exports,gt=lt[typeof global]&&global; !gt||gt.global!==gt&>.window!==gt||(pt=gt);var gt=(lt=lt[typeof module]&&module&&!module.nodeType&&module)&<.exports===st&&st,ht=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(pt._=ht, define(function(){return ht})):st&<?gt?(lt.exports=ht)._=ht:st._=ht:pt._=ht}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 9f62fb0bf..7f9150ddf 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -579,6 +579,31 @@ return result; } + /** + * The base implementation of `_.forEach` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Array|Object|string} Returns `collection`. + */ + function baseEach(collection, callback) { + var index = -1, + iterable = collection, + length = collection ? collection.length : 0; + + if (typeof length == 'number') { + while (++index < length) { + if (callback(iterable[index], index, collection) === breakIndicator) { + break; + } + } + } else { + baseForOwn(collection, callback); + } + } + /** * The base implementation of `_.flatten` without support for callback * shorthands or `thisArg` binding. @@ -619,6 +644,29 @@ return result; } + /** + * The base implementation of `_.forOwn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, callback) { + var index = -1, + props = keys(object), + length = props.length; + + while (++index < length) { + var key = props[index]; + if (callback(object[key], key, object) === breakIndicator) { + break; + } + } + return object; + } + /** * The base implementation of `_.isEqual`, without support for `thisArg` binding, * that allows partial "_.where" style comparisons. @@ -724,7 +772,7 @@ } } else { - forIn(b, function(value, key, b) { + baseForIn(b, function(value, key, b) { if (hasOwnProperty.call(b, key)) { size++; return !(result = hasOwnProperty.call(a, key) && baseIsEqual(a[key], value, stackA, stackB)) && breakIndicator; @@ -732,7 +780,7 @@ }); if (result) { - forIn(a, function(value, key, a) { + baseForIn(a, function(value, key, a) { if (hasOwnProperty.call(a, key)) { return !(result = --size > -1) && breakIndicator; } @@ -815,7 +863,7 @@ setter(result, value, callback(value, index, collection), collection); } } else { - forOwn(collection, function(value, key, collection) { + baseEach(collection, function(value, key, collection) { setter(result, value, callback(value, key, collection), collection); }); } @@ -923,6 +971,28 @@ }; } + /** + * The base implementation of `_.forIn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + var baseForIn = function(object, callback) { + var result = object; + if (!isObject(object)) { + return result; + } + for (var key in object) { + if (callback(object[key], key, object) === breakIndicator) { + return result; + } + } + return result; + }; + /** * A fallback implementation of `Object.keys` which produces an array of the * given object's own enumerable property names. @@ -1926,7 +1996,7 @@ if (length && typeof length == 'number') { result = indexOf(collection, target) > -1; } else { - forOwn(collection, function(value) { + baseEach(collection, function(value) { return (result = value === target) && breakIndicator; }); } @@ -2026,7 +2096,7 @@ } } } else { - forOwn(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { return !(result = !!callback(value, index, collection)) && breakIndicator; }); } @@ -2088,7 +2158,7 @@ } } } else { - forOwn(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { if (callback(value, index, collection)) { result.push(value); } @@ -2155,7 +2225,7 @@ } } else { var result; - forOwn(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { if (callback(value, index, collection)) { result = value; return breakIndicator; @@ -2230,7 +2300,7 @@ } } } else { - forOwn(collection, callback); + baseEach(collection, callback); } } @@ -2262,7 +2332,7 @@ } else { var props = keys(collection); length = props.length; - forOwn(collection, function(value, key, collection) { + baseEach(collection, function(value, key, collection) { key = props ? props[--length] : --length; return callback(collection[key], key, collection) === false && breakIndicator; }); @@ -2384,7 +2454,7 @@ length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - forEach(collection, function(value) { + baseEach(collection, function(value) { result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); }); return result; @@ -2441,7 +2511,7 @@ } } else { result = []; - forOwn(collection, function(value, key, collection) { + baseEach(collection, function(value, key, collection) { result[++index] = callback(value, key, collection); }); } @@ -2511,7 +2581,7 @@ } else { callback = createCallback(callback, thisArg, 3); - forEach(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { var current = callback(value, index, collection); if (current > computed) { computed = current; @@ -2585,7 +2655,7 @@ } else { callback = createCallback(callback, thisArg, 3); - forEach(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { var current = callback(value, index, collection); if (current < computed) { computed = current; @@ -2663,7 +2733,7 @@ accumulator = callback(accumulator, collection[index], index, collection); } } else { - forOwn(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { accumulator = noaccum ? (noaccum = false, value) : callback(accumulator, value, index, collection) @@ -2797,7 +2867,7 @@ length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - forEach(collection, function(value) { + baseEach(collection, function(value) { var rand = baseRandom(0, ++index); result[index] = result[rand]; result[rand] = value; @@ -2887,7 +2957,7 @@ } } } else { - forOwn(collection, function(value, index, collection) { + baseEach(collection, function(value, index, collection) { return (result = callback(value, index, collection)) && breakIndicator; }); } @@ -3692,84 +3762,6 @@ return object; } - /** - * Iterates over own and inherited enumerable properties of an object, - * executing the callback for each property. The callback is bound to `thisArg` - * and invoked with three arguments; (value, key, object). Callbacks may exit - * iteration early by explicitly returning `false`. - * - * @static - * @memberOf _ - * @type Function - * @category Objects - * @param {Object} object The object to iterate over. - * @param {Function} [callback=identity] The function called per iteration. - * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Object} Returns `object`. - * @example - * - * function Shape() { - * this.x = 0; - * this.y = 0; - * } - * - * Shape.prototype.move = function(x, y) { - * this.x += x; - * this.y += y; - * }; - * - * _.forIn(new Shape, function(value, key) { - * console.log(key); - * }); - * // => logs 'x', 'y', and 'move' (property order is not guaranteed across environments) - */ - var forIn = function(object, callback) { - var result = object; - if (!isObject(object)) { - return result; - } - for (var key in object) { - if (callback(object[key], key, object) === breakIndicator) { - return result; - } - } - return result; - }; - - /** - * Iterates over own enumerable properties of an object, executing the callback - * for each property. The callback is bound to `thisArg` and invoked with three - * arguments; (value, key, object). Callbacks may exit iteration early by - * explicitly returning `false`. - * - * @static - * @memberOf _ - * @category Objects - * @param {Object} object The object to iterate over. - * @param {Function} [callback=identity] The function called per iteration. - * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Object} Returns `object`. - * @example - * - * _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { - * console.log(key); - * }); - * // => logs '0', '1', and 'length' (property order is not guaranteed across environments) - */ - function forOwn(object, callback) { - var index = -1, - props = keys(object), - length = props.length; - - while (++index < length) { - var key = props[index]; - if (callback(object[key], key, object) === breakIndicator) { - break; - } - } - return object; - } - /** * Creates a sorted array of property names of all enumerable properties, * own and inherited, of `object` that have function values. @@ -3787,7 +3779,7 @@ */ function functions(object) { var result = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { if (isFunction(value)) { result.push(key); } @@ -4265,7 +4257,7 @@ */ function omit(object) { var props = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { props.push(key); }); props = baseDifference(props, baseFlatten(arguments, true, false, 1)); @@ -5083,7 +5075,7 @@ lodash.prototype.value = wrapperValueOf; // add `Array` mutator functions to the wrapper - forEach(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { + baseEach(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { var value = this.__wrapped__; @@ -5099,7 +5091,7 @@ }); // add `Array` accessor functions to the wrapper - forEach(['concat', 'join', 'slice'], function(methodName) { + baseEach(['concat', 'join', 'slice'], function(methodName) { var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { var value = this.__wrapped__, diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 17c47fd4d..0750d2aee 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,38 +3,38 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.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?Lr(0,u+e):e||0;else if(e)return e=T(r,t),u&&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=Lr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Lr(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+Dr(Yr()*(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,gr=/($^)/,vr=/['\n\r\t\u2028\u2029\\]/g,hr="[object Arguments]",yr="[object Array]",mr="[object Boolean]",_r="[object Date]",br="[object Number]",dr="[object Object]",wr="[object RegExp]",jr="[object String]",xr={"&":"&","<":"<",">":">",'"':""","'":"'"},Tr={"&":"&","<":"<",">":">",""":'"',"'":"'"},Ar={"function":true,object:true},Er={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Or=Ar[typeof window]&&window||this,kr=Ar[typeof exports]&&exports&&!exports.nodeType&&exports,Sr=Ar[typeof global]&&global; -!Sr||Sr.global!==Sr&&Sr.window!==Sr||(Or=Sr);var Nr=Ar[typeof module]&&module&&!module.nodeType&&module,qr=Nr&&Nr.exports===kr&&kr,Fr=Array.prototype,Br=Object.prototype,Rr=Or._,$r=Br.toString,Ir=RegExp("^"+($r+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Mr=Math.ceil,Dr=Math.floor,Wr=Function.prototype.toString,zr=Br.hasOwnProperty,Cr=Fr.push,Pr=Br.propertyIsEnumerable,Ur=Fr.splice,Vr=_(Vr=Object.create)&&Vr,Gr=_(Gr=Array.isArray)&&Gr,Hr=Or.isFinite,Jr=Or.isNaN,Kr=_(Kr=Object.keys)&&Kr,Lr=Math.max,Qr=Math.min,Xr=_(Xr=Date.now)&&Xr,Yr=Math.random; -i.prototype=o.prototype;var Zr={};!function(){var n={0:1,length:1};Zr.spliceObjects=(Ur.call(n,0,1),!n[0])}(1),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Vr||(a=function(){function n(){}return function(r){if(J(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Or.Object()}}()),b(arguments)||(b=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&zr.call(n,"callee")&&!Pr.call(n,"callee")||false});var nt=function(n){var r=[]; -if(!J(n))return r;for(var t in n)zr.call(n,t)&&r.push(t);return r},rt=h(function(n,r,t){zr.call(n,t)?n[t]++:n[t]=1}),tt=h(function(n,r,t){zr.call(n,t)?n[t].push(r):n[t]=[r]}),et=h(function(n,r,t){n[t]=r}),ut=F,ot=function(n,r){if(!J(n))return n;for(var t in n)if(r(n[t],t,n)===ur)break;return n},it=Gr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&$r.call(n)==yr||false};H(/x/)&&(H=function(n){return typeof n=="function"&&"[object Function]"==$r.call(n)});var ft=Kr?function(n){return J(n)?Kr(n):[] -}:nt,at=Xr||function(){return(new Date).getTime()};o.after=function(n,r){if(!H(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=W,o.bindAll=function(n){for(var r=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=ft(n),e=t.length,u={};++rr?0:r);++nt?Lr(0,e+t):Qr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=nr,o.noConflict=function(){return Or._=Rr,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+Dr(Yr()*(r-n+1))},o.reduce=R,o.reduceRight=$,o.result=function(n,r,t){return null==n?t:(t="undefined"!=typeof n[r]?n[r]:t,H(t)?n[r]():t) -},o.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:ft(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||gr).source+"|"+(t.interpolate||gr).source+"|"+(t.evaluate||gr).source+"|$","g"),function(r,t,u,o,i){return a+=n.slice(f,i).replace(vr,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(pr,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,0e||typeof t=="undefined"){t=1;break n}if(te(r,i)&&o.push(i)}return o}function h(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(;++tu(f,c))&&(t&&f.push(c),i.push(a))}return i}function _(n){return function(r,t,e){var u={};t=Z(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++ee?Xr(0,u+e):e||0;else if(e)return e=O(n,r),u&&n[e]===r?e:-1; +return t(n,r,e)}function A(n,r,t){if(typeof r!="number"&&null!=r){var e=0,u=-1,o=n?n.length:0;for(r=Z(r,t,3);++ur?r=Xr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Xr(u+t,0):t>u&&(t=u),u=t-r||0,t=Array(u);++e>>1,t(n[e])u&&(u=t);else r=Z(r,t,3),h(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function M(n,r,t,e){var u=3>arguments.length; +r=Z(r,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=Z(r,e,4),R(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function W(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0);return h(n,function(n){var t;t=++r,t=0+zr(nt()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function z(n,r,t){var e;r=Z(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number")for(;++t=y;m?(i&&(i=clearTimeout(i)),s=a,f=n.apply(c,o)):i||(i=setTimeout(e,y))}return m&&l?l=clearTimeout(l):l||r===g||(l=setTimeout(u,r)),t&&(m=true,f=n.apply(c,o)),!m||l||i||(o=c=null),f}}function V(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,vr=/($^)/,yr=/['\n\r\t\u2028\u2029\\]/g,mr="[object Arguments]",_r="[object Array]",br="[object Boolean]",dr="[object Date]",wr="[object Number]",jr="[object Object]",xr="[object RegExp]",Tr="[object String]",Ar={"&":"&","<":"<",">":">",'"':""","'":"'"},Er={"&":"&","<":"<",">":">",""":'"',"'":"'"},Or={"function":true,object:true},Sr={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},kr=Or[typeof window]&&window||this,Nr=Or[typeof exports]&&exports&&!exports.nodeType&&exports,qr=Or[typeof global]&&global; +!qr||qr.global!==qr&&qr.window!==qr||(kr=qr);var Fr=Or[typeof module]&&module&&!module.nodeType&&module,Br=Fr&&Fr.exports===Nr&&Nr,Rr=Array.prototype,$r=Object.prototype,Ir=kr._,Mr=$r.toString,Dr=RegExp("^"+(Mr+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Wr=Math.ceil,zr=Math.floor,Cr=Function.prototype.toString,Pr=$r.hasOwnProperty,Ur=Rr.push,Vr=$r.propertyIsEnumerable,Gr=Rr.splice,Hr=w(Hr=Object.create)&&Hr,Jr=w(Jr=Array.isArray)&&Jr,Kr=kr.isFinite,Lr=kr.isNaN,Qr=w(Qr=Object.keys)&&Qr,Xr=Math.max,Yr=Math.min,Zr=w(Zr=Date.now)&&Zr,nt=Math.random; +a.prototype=f.prototype;var rt={};!function(){var n={0:1,length:1};rt.spliceObjects=(Gr.call(n,0,1),!n[0])}(1),f.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Hr||(l=function(){function n(){}return function(r){if(L(r)){n.prototype=r;var t=new n;n.prototype=null}return t||kr.Object()}}()),j(arguments)||(j=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Pr.call(n,"callee")&&!Vr.call(n,"callee")||false});var tt=_(function(n,r,t){Pr.call(n,t)?n[t]++:n[t]=1 +}),et=_(function(n,r,t){Pr.call(n,t)?n[t].push(r):n[t]=[r]}),ut=_(function(n,r,t){n[t]=r}),ot=$,it=Jr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Mr.call(n)==_r||false};K(/x/)&&(K=function(n){return typeof n=="function"&&"[object Function]"==Mr.call(n)});var ft=Qr?function(n){return L(n)?Qr(n):[]}:n,at=Zr||function(){return(new Date).getTime()};f.after=function(n,r){if(!K(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},f.bind=P,f.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},f.invert=function(n){for(var r=-1,t=ft(n),e=t.length,u={};++rr?0:r);++nt?Xr(0,e+t):Yr(t,e-1))+1);e--;)if(n[e]===r)return e; +return-1},f.mixin=tr,f.noConflict=function(){return kr._=Ir,this},f.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+zr(nt()*(r-n+1))},f.reduce=M,f.reduceRight=D,f.result=function(n,r,t){return null==n?t:(t="undefined"!=typeof n[r]?n[r]:t,K(t)?n[r]():t)},f.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:ft(n).length},f.some=z,f.sortedIndex=O,f.template=function(n,r,t){var e=f,u=e.templateSettings;n=(n||"")+"",t=G({},t,u);var i=0,a="__p+='",u=t.variable; +n.replace(RegExp((t.escape||vr).source+"|"+(t.interpolate||vr).source+"|"+(t.evaluate||vr).source+"|$","g"),function(r,t,e,u,f){return a+=n.slice(i,f).replace(yr,o),t&&(a+="'+_.escape("+t+")+'"),u&&(a+="';"+u+";\n__p+='"),e&&(a+="'+((__t=("+e+"))==null?'':__t)+'"),i=f+r.length,r}),a+="';",u||(u="obj",a="with("+u+"||{}){"+a+"}"),a="function("+u+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var c=Function("_","return "+a)(e)}catch(l){throw l.source=a,l +}return r?c(r):(c.source=a,c)},f.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(gr,i))},f.uniqueId=function(n){var r=++or+"";return n?n+r:r},f.all=N,f.any=z,f.detect=F,f.findWhere=function(n,r){return C(n,r,true)},f.foldl=M,f.foldr=D,f.include=k,f.inject=M,f.first=x,f.last=function(n,r,t){var e=0,u=n?n.length:0;if(typeof r!="number"&&null!=r){var o=u;for(r=Z(r,t,3);o--&&r(n[o],o,n);)e++}else if(e=r,null==e||t)return n?n[u-1]:ur;return e=u-e,E(n,0;' + + '}' + // add support for iterating over `arguments` objects if needed '<% if (support.nonEnumArgs) { %>\n' + @@ -1173,7 +1170,7 @@ stackB.push(result); // recursively populate clone (susceptible to call stack limits) - (isArr ? baseEach : forOwn)(value, function(objValue, key) { + (isArr ? baseEach : baseForOwn)(value, function(objValue, key) { result[key] = baseClone(objValue, isDeep, callback, stackA, stackB); }); @@ -1350,24 +1347,19 @@ } /** - * Iterates `arguments` objects, arrays, objects, and strings consistently - * across environments, executing the callback for each element in the - * collection. The callback is bound to `thisArg` and invoked with three - * arguments; (value, index|key, collection). Callbacks may exit iteration - * early by explicitly returning `false`. + * The base implementation of `_.forEach` without support for callback + * shorthands or `thisArg` binding. * * @private * @param {Array|Object|string} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. - * @param {*} [thisArg] The `this` binding of `callback`. + * @param {Function} callback The function called per iteration. * @returns {Array|Object|string} Returns `collection`. */ - function baseEach(collection, callback, thisArg) { + function baseEach(collection, callback) { var index = -1, iterable = collection, length = collection ? collection.length : 0; - callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); if (typeof length == 'number') { if (support.unindexedChars && isString(iterable)) { iterable = iterable.split(''); @@ -1378,7 +1370,7 @@ } } } else { - forOwn(collection, callback); + baseForOwn(collection, callback); } return collection; } @@ -1423,6 +1415,29 @@ return result; } + /** + * The base implementation of `_.forOwn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, callback) { + var index = -1, + props = keys(object), + length = props.length; + + while (++index < length) { + var key = props[index]; + if (callback(object[key], key, object) === false) { + break; + } + } + return object; + } + /** * The base implementation of `_.isEqual`, without support for `thisArg` binding, * that allows partial "_.where" style comparisons. @@ -1570,7 +1585,7 @@ else { // deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys` // which, in this case, is more costly - forIn(b, function(value, key, b) { + baseForIn(b, function(value, key, b) { if (hasOwnProperty.call(b, key)) { // count the number of properties. size++; @@ -1581,7 +1596,7 @@ if (result && !isWhere) { // ensure both objects have the same number of properties - forIn(a, function(value, key, a) { + baseForIn(a, function(value, key, a) { if (hasOwnProperty.call(a, key)) { // `size` will be `-1` if `a` has more properties than `b` return (result = --size > -1); @@ -1611,7 +1626,7 @@ * @param {Array} [stackB=[]] Associates values with source counterparts. */ function baseMerge(object, source, callback, stackA, stackB) { - (isArray(source) ? forEach : forOwn)(source, function(source, key) { + (isArray(source) ? baseEach : baseForOwn)(source, function(source, key) { var found, isArr, result = source, @@ -1857,7 +1872,6 @@ * @param {Object} [options] The compile options object. * @param {string} [options.args] A comma separated string of iteration function arguments. * @param {string} [options.init] The string representation of the initial `result` value. - * @param {string} [options.top] Code to execute before the iteration branches. * @param {string} [options.loop] Code to execute in the object loop. * @param {boolean} [options.useHas] Specify using `hasOwnProperty` checks in the object loop. * @returns {Function} Returns the compiled function. @@ -1868,15 +1882,15 @@ // create the function factory var factory = Function( - 'baseCreateCallback, errorClass, errorProto, hasOwnProperty, isArguments, ' + - 'isObject, objectProto, nonEnumProps, stringClass, stringProto, toString', + 'errorClass, errorProto, hasOwnProperty, isArguments, 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, - isObject, objectProto, nonEnumProps, stringClass, stringProto, toString + errorClass, errorProto, hasOwnProperty, isArguments, isObject, objectProto, + nonEnumProps, stringClass, stringProto, toString ); } @@ -1942,7 +1956,7 @@ // iterated property is an object's own property then there are no inherited // enumerable properties. if (support.ownLast) { - forIn(value, function(value, key, object) { + baseForIn(value, function(value, key, object) { result = hasOwnProperty.call(object, key); return false; }); @@ -1951,7 +1965,7 @@ // In most environments an object's own properties are iterated before // its inherited properties. If the last iterated property is an object's // own property then there are no inherited enumerable properties. - forIn(value, function(value, key) { + baseForIn(value, function(value, key) { result = key; }); return typeof result == 'undefined' || hasOwnProperty.call(value, result); @@ -1987,6 +2001,22 @@ }; } + /** + * The base implementation of `_.forIn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + var baseForIn = createIterator({ + 'args': 'object, callback', + 'init': 'object', + 'loop': 'if (callback(object[key], key, object) === false) {\n return result;\n }', + 'useHas': false + }); + /** * A fallback implementation of `Object.keys` which produces an array of the * given object's own enumerable property names. @@ -1999,7 +2029,6 @@ var shimKeys = createIterator({ 'args': 'object', 'init': '[]', - 'top': '', 'loop': 'result.push(key)', 'useHas': true }); @@ -3620,7 +3649,7 @@ } } } else { - baseEach(collection, callback, thisArg); + baseEach(collection, baseCreateCallback(callback, thisArg, 3)); } return collection; } @@ -3783,7 +3812,7 @@ length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - forEach(collection, function(value) { + baseEach(collection, function(value) { result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); }); return result; @@ -4201,7 +4230,7 @@ length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - forEach(collection, function(value) { + baseEach(collection, function(value) { var rand = baseRandom(0, ++index); result[index] = result[rand]; result[rand] = value; @@ -4356,7 +4385,7 @@ if (!multi) { callback = lodash.createCallback(callback, thisArg, 3); } - forEach(collection, function(value, key, collection) { + baseEach(collection, function(value, key, collection) { var object = result[++index] = getObject(); object.index = index; object.value = value; @@ -5365,7 +5394,7 @@ function findKey(object, callback, thisArg) { var result; callback = lodash.createCallback(callback, thisArg, 3); - forOwn(object, function(value, key, object) { + baseForOwn(object, function(value, key, object) { if (callback(value, key, object)) { result = key; return false; @@ -5458,13 +5487,10 @@ * }); * // => logs 'x', 'y', and 'move' (property order is not guaranteed across environments) */ - var forIn = createIterator({ - 'args': 'object, callback, thisArg', - 'init': 'object', - 'top': "callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3)", - 'loop': 'if (callback(object[key], key, object) === false) {\n return result;\n }', - 'useHas': false - }); + function forIn(object, callback, thisArg) { + callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); + return baseForIn(object, callback); + } /** * This method is like `_.forIn` except that it iterates over elements @@ -5497,7 +5523,7 @@ function forInRight(object, callback, thisArg) { var pairs = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { pairs.push(key, value); }); @@ -5532,18 +5558,8 @@ * // => logs '0', '1', and 'length' (property order is not guaranteed across environments) */ function forOwn(object, callback, thisArg) { - var index = -1, - props = keys(object), - length = props.length; - callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); - while (++index < length) { - var key = props[index]; - if (callback(object[key], key, object) === false) { - break; - } - } - return object; + return baseForOwn(object, callback); } /** @@ -5595,7 +5611,7 @@ */ function functions(object) { var result = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { if (isFunction(value)) { result.push(key); } @@ -5787,7 +5803,7 @@ (className == objectClass && typeof length == 'number' && isFunction(value.splice))) { return !length; } - forOwn(value, function() { + baseForOwn(value, function() { return (result = false); }); return result; @@ -6148,7 +6164,7 @@ var result = {}; callback = lodash.createCallback(callback, thisArg, 3); - forOwn(object, function(value, key, object) { + baseForOwn(object, function(value, key, object) { result[key] = callback(value, key, object); }); return result; @@ -6267,7 +6283,7 @@ var result = {}; if (typeof callback != 'function') { var props = []; - forIn(object, function(value, key) { + baseForIn(object, function(value, key) { props.push(key); }); props = baseDifference(props, baseFlatten(arguments, true, false, 1)); @@ -6281,7 +6297,7 @@ } } else { callback = lodash.createCallback(callback, thisArg, 3); - forIn(object, function(value, key, object) { + baseForIn(object, function(value, key, object) { if (!callback(value, key, object)) { result[key] = value; } @@ -6359,7 +6375,7 @@ } } else { callback = lodash.createCallback(callback, thisArg, 3); - forIn(object, function(value, key, object) { + baseForIn(object, function(value, key, object) { if (callback(value, key, object)) { result[key] = value; } @@ -6413,7 +6429,7 @@ } if (callback) { callback = lodash.createCallback(callback, thisArg, 4); - (isArr ? baseEach : forOwn)(object, function(value, index, object) { + (isArr ? baseEach : baseForOwn)(object, function(value, index, object) { return callback(accumulator, value, index, object); }); } @@ -7408,7 +7424,7 @@ mixin(function() { var source = {} - forOwn(lodash, function(func, methodName) { + baseForOwn(lodash, function(func, methodName) { if (!lodash.prototype[methodName]) { source[methodName] = func; } @@ -7427,7 +7443,7 @@ lodash.take = first; lodash.head = first; - forOwn(lodash, function(func, methodName) { + baseForOwn(lodash, function(func, methodName) { var callbackable = methodName !== 'sample'; if (!lodash.prototype[methodName]) { lodash.prototype[methodName]= function(n, guard) { @@ -7511,6 +7527,7 @@ } // add pseudo private property to be used and removed during the build process + lodash._baseForIn = baseForIn; lodash._iteratorTemplate = iteratorTemplate; lodash._shimKeys = shimKeys;