diff --git a/build/pre-compile.js b/build/pre-compile.js index 7314d2c07..21fc8e6d5 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -5,7 +5,7 @@ /** The Node filesystem module */ var fs = require('fs'); - /** Used to minify string values embedded in compiled strings */ + /** Used to minify string literals embedded in compiled strings */ var compiledValues = [ 'arrays', 'objects' @@ -33,9 +33,11 @@ 'initial', 'isArray', 'isEmpty', + 'isFunc', 'length', 'object', 'Math', + 'prop', 'property', 'result', 'slice', @@ -83,7 +85,6 @@ 'interpolate', 'isEqual', 'isFinite', - 'lodash', 'setTimeout', 'templateSettings', 'toArray', diff --git a/lodash.js b/lodash.js index 771068301..c771d70e5 100644 --- a/lodash.js +++ b/lodash.js @@ -67,8 +67,7 @@ hasOwnProperty = ObjProto.hasOwnProperty, push = ArrayProto.push, slice = ArrayProto.slice, - toString = ObjProto.toString, - unshift = ArrayProto.unshift; + toString = ObjProto.toString; /* Native method shortcuts for methods with the same name as other `lodash` methods */ var nativeIsArray = Array.isArray, @@ -481,18 +480,13 @@ * _.groupBy(['one', 'two', 'three'], 'length'); * // => { '3': ['one', 'two'], '5': ['three'] } */ - function groupBy(collection, callback, thisArg) { - var result = {}; - if (!isFunction(callback)) { - var prop = callback; - callback = function(collection) { return collection[prop]; }; - } - forEach(collection, function(value, index, collection) { - var prop = callback(value, index, collection); - (result[prop] || (result[prop] = [])).push(value); - }); - return result; - } + var groupBy = iterationFactory(forEachFactoryOptions, { + 'top': 'var prop,isFunc=toString.call(callback)==funcClass', + 'init': '{}', + 'inLoop': + 'prop=isFunc?callback(collection[index],index,collection):collection[index][callback];\n' + + '(result[prop]||(result[prop]=[])).push(collection[index])' + }); /** * Calls the method named by `methodName` for each value of the `collection`. @@ -1025,14 +1019,18 @@ if (shallow) { return concat.apply([], array); } - return reduce(array, function(accumulator, value) { - if (isArray(value)) { - push.apply(accumulator, flatten(value)); - return accumulator; + var index = -1, + length = array.length, + result = []; + + while (++index < length) { + if (isArray(array[index])) { + push.apply(result, flatten(array[index])); + } else { + result.push(array[index]); } - accumulator.push(value); - return accumulator; - }, []); + } + return result; } /** @@ -1109,7 +1107,7 @@ var rest = slice.call(arguments, 1); return filter(uniq(array), function(value) { return every(rest, function(other) { - return indexOf(other, value) >= 0; + return indexOf(other, value) > -1; }); }); } @@ -1248,7 +1246,7 @@ * // => [1, 2, 3, 101, 10] */ function union() { - return uniq(flatten(arguments, true)); + return uniq(concat.apply([], arguments)); } /** @@ -2215,7 +2213,7 @@ function pick(object) { var prop, index = -1, - props = flatten(slice.call(arguments, 1)), + props = concat.apply([], slice.call(arguments, 1)), length = props.length, result = {}; @@ -2326,12 +2324,8 @@ var func = lodash[methodName] = object[methodName]; lodash.prototype[methodName] = function() { - // In Opera < 9.50 and some older/beta Mobile Safari versions using `unshift()` - // generically to augment the `arguments` object will pave the value at - // index `0` without incrimenting the other values's indexes. - // https://github.com/documentcloud/underscore/issues/9 - var args = slice.call(arguments); - unshift.call(args, this._wrapped); + var args = [this._wrapped]; + push.apply(args, arguments); var result = func.apply(lodash, args); return this._chain ? new Lodash(result).chain() : result; diff --git a/lodash.min.js b/lodash.min.js index fa4a6b962..a1692bddd 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -2,25 +2,25 @@ Lo-Dash 0.1.0 github.com/bestiejs/lodash/blob/master/LICENSE.txt Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE */ -;(function(r,h){"use strict";var n=!0,o=!1;function Q(a){return"[object Arguments]"==k.call(a)}function i(a){return new p(a)}function p(a){this.o=a}function g(){for(var a,b=-1,c={},d={},f={},e=["d","j","g","a"];++b>1;c(a[e])a.length&&(b=n);z(c,function(c,e,j){if(b?ha(c)!==e||!c.length:0>E(c,e))c.push(e),d.push(a[j]); -return c},[]);return d}function u(a,b){var c=l.call(arguments,2),d=c.length;return function(){c.length=d;V.apply(c,arguments);return a.apply(b,c)}}function ja(a,b,c){var d;return function(){var f=arguments,e=this;c&&!d&&a.apply(e,f);va(d);d=J(function(){d=h;c||a.apply(e,f)},b)}}function Y(a,b,c){c||(c=[]);if(a===b)return 0!==a||1/a==1/b;if(a==h||b==h)return a===b;a.p&&(a=a.o);b.p&&(b=b.o);if(a.isEqual&&q(a.isEqual))return a.isEqual(b);if(b.isEqual&&q(b.isEqual))return b.isEqual(a);var d=k.call(a); -if(d!=k.call(b))return o;switch(d){case G:return a==""+b;case K:return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case ka:case la:return+a==+b;case ma:return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return o;for(var f=c.length;f--;)if(c[f]==a)return n;var f=n,e=0;c.push(a);if(d==D){if(e=a.length,f=e==b.length)for(;e--&&(f=e in a==e in b&&Y(a[e],b[e],c)););}else{if("constructor"in a!="constructor"in b||a.constructor!= -b.constructor)return o;for(var j in a)if(s.call(a,j)&&(e++,!(f=s.call(b,j)&&Y(a[j],b[j],c))))break;if(f){for(j in b)if(s.call(b,j)&&!e--)break;f=!e}}c.pop();return f}function q(a){return k.call(a)==ca}function R(a){return a}function na(a){t(L(a),function(b){var c=i[b]=a[b];i.prototype[b]=function(){var a=l.call(arguments);wa.call(a,this.o);a=c.apply(i,a);return this.p?(new p(a)).chain():a}})}var y={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"};(function(){for(var a in y)y[y[a]]= -a})();var Z="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(r=global),exports),xa=0,ya=r._,za=/\\|'|\r|\n|\t|\u2028|\u2029/g,$=/.^/,ua=/\\(\\|'|r|n|t|u2028|u2029)/g,D="[object Array]",ka="[object Boolean]",la="[object Date]",ca="[object Function]",K="[object Number]",ma="[object RegExp]",G="[object String]",v=Array.prototype,M=Object.prototype,ba=v.concat,s=M.hasOwnProperty,V=v.push,l=v.slice,k=M.toString,wa=v.unshift,Aa=r.isFinite,M=Object.keys,va=r.clearTimeout, -J=r.setTimeout,N={b:"b",m:"var I=i.apply([],z.call(arguments,1))",h:"[]",g:"if(p(I,b[o])<0)y.push(b[o])"},w={h:"F",g:"if(!e(g[o],o,g))return !y"},aa={b:"v",h:"v",d:"for(var A,j=1,u=arguments.length;j=h)h=j,y=g[o]"},F=Array.isArray||function(a){return k.call(a)==D},da=g({b:"H",i:"b",m:"var f=E.call(H)",h:"F",d:"if(f==c||f==B)return !H.length",g:"return k"}),pa=g({b:"g,C",h:"k",g:"if(g[o]===C)return F"}),X=g(m,w),W=g(m,B),qa=g(m,{g:"if(e(g[o],o,g))return g[o]"}),t=g(m),A=g(m,C),ra=g(m,x),x=g(m,x,{m:x.m.replace("-","").replace("max", -"min"),g:x.g.replace(">=","<")}),O=g(C,{b:"g,x",g:{c:"y[o]=g[o][x]",k:"y[y.length]=g[o][x]"}}),z=g({b:"g,e,a,D",m:"var r=arguments.length>2;if(D)e=d(e,D)",h:"a",d:{c:"if(!r)y=g[++o]"},g:{c:"y=e(y,g[o],o,g)",k:"y=r?e(y,g[o],o,g):(r=F,g[o])"}}),B=g(m,B,{g:"!"+B.g}),w=g(m,w,{h:"k",g:w.g.replace("!","")}),sa=g(C,{b:"g",g:{c:"y[o]=g[o]",k:"y[y.length]=g[o]"}}),C=g({b:"b",h:"[]",g:"if(b[o])y.push(b[o])"}),m=g(N),N=g(N,{m:"var I=z.call(arguments,1)",h:"[]"}),ta=g(aa,{g:"if(v[o]==G)"+aa.g}),P=g(aa),L=g(oa, -{m:"",n:o,g:"if(E.call(v[o])==l)y.push(o)",l:"y.sort()"});Q(arguments)||(Q=function(a){return!(!a||!s.call(a,"callee"))});var T=M||g(oa);P(i,{VERSION:"0.1.0",templateSettings:{escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g},after:function(a,b){return 1>a?b():function(){if(1>--a)return b.apply(this,arguments)}},bind:u,bindAll:function(a){var b=arguments,c=1;1==b.length&&(c=0,b=L(a));for(var d=b.length;c/g, -">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")},every:X,extend:P,filter:W,find:qa,first:U,flatten:H,forEach:t,functions:L,groupBy:function(a,b){var c={};if(!q(b))var d=b,b=function(a){return a[d]};t(a,function(a,e,d){e=b(a,e,d);(c[e]||(c[e]=[])).push(a)});return c},has:function(a,b){return s.call(a,b)},identity:R,indexOf:E,initial:function(a,b,c){return l.call(a,0,-(b==h||c?1:b))},intersection:ga,invoke:function(a,b){var c=l.call(arguments,2),d=q(b);return A(a,function(a){return(d? -b||a:a[b]).apply(a,c)})},isArguments:Q,isArray:F,isBoolean:function(a){return a===n||a===o||k.call(a)==ka},isDate:function(a){return k.call(a)==la},isElement:function(a){return!!(a&&1==a.nodeType)},isEmpty:da,isEqual:Y,isFinite:function(a){return Aa(a)&&k.call(a)==K},isFunction:q,isNaN:function(a){return k.call(a)==K&&a!=+a},isNull:function(a){return null===a},isNumber:function(a){return k.call(a)==K},isObject:function(a){return a===Object(a)},isRegExp:function(a){return k.call(a)==ma},isString:function(a){return k.call(a)== -G},isUndefined:function(a){return a===h},keys:T,last:ha,lastIndexOf:function(a,b){if(a==h)return-1;for(var c=a.length;c--;)if(a[c]===b)return c;return-1},map:A,max:ra,memoize:function(a,b){var c={};return function(){var d=b?b.apply(this,arguments):arguments[0];return s.call(c,d)?c[d]:c[d]=a.apply(this,arguments)}},min:x,mixin:na,noConflict:function(){r._=ya;return this},once:function(a){var b,c=o;return function(){if(c)return b;c=n;return b=a.apply(this,arguments)}},pick:function(a){for(var b,c=-1, -d=H(l.call(arguments,1)),f=d.length,e={};++carguments.length&&(b=a||0,a=0);for(var d=-1,f=Math.max(Math.ceil((b-a)/c),0),e=Array(f);++dd?1:0}),"b")},sortedIndex:fa,tap:function(a,b){b(a);return a},template:function(a,b,c){function d(a){return f.call(this,a,i)}c=ta(c||{},i.templateSettings);a="__p+='"+a.replace(za,function(a){return"\\"+y[a]}).replace(c.escape||$,function(a,b){return"'+((__t=("+ -S(b)+"))==null?'':_['escape'](__t))+'"}).replace(c.interpolate||$,function(a,b){return"'+((__t=("+S(b)+"))==null?'':__t)+'"}).replace(c.evaluate||$,function(a,b){return"';"+S(b)+";__p+='"})+"';";c.variable||(a="with(object||{}){"+a+"}");var a='var __t,__j=Array.prototype.join,__p="";function print(){__p+=__j.call(arguments,"")}'+a+"return __p",f=Function(c.variable||"object","_",a);if(b)return f(b,i);d.source="function("+(c.variable||"object")+"){"+a+"}";return d},throttle:function(a,b){var c,d,f, -e,g,i,k=ja(function(){d=g=o},b);return function(){c=arguments;e=this;i||(i=J(function(){i=h;d&&a.apply(e,c);k()},b));g?d=n:f=a.apply(e,c);k();g=n;return f}},times:function(a,b,c){c&&(b=u(b,c));for(c=0;c>1;c(a[f])a.length&&(b=n);J(c,function(c,f,j){if(b?ha(c)!==f||!c.length:0>E(c,f))c.push(f),d.push(a[j]); +return c},[]);return d}function t(a,b){var c=l.call(arguments,2),d=c.length;return function(){c.length=d;H.apply(c,arguments);return a.apply(b,c)}}function ja(a,b,c){var d;return function(){var e=arguments,f=this;c&&!d&&a.apply(f,e);va(d);d=K(function(){d=h;c||a.apply(f,e)},b)}}function Y(a,b,c){c||(c=[]);if(a===b)return 0!==a||1/a==1/b;if(a==h||b==h)return a===b;a.p&&(a=a.o);b.p&&(b=b.o);if(a.isEqual&&s(a.isEqual))return a.isEqual(b);if(b.isEqual&&s(b.isEqual))return b.isEqual(a);var d=k.call(a); +if(d!=k.call(b))return o;switch(d){case G:return a==""+b;case L:return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case ka:case la:return+a==+b;case ma:return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return o;for(var e=c.length;e--;)if(c[e]==a)return n;var e=n,f=0;c.push(a);if(d==C){if(f=a.length,e=f==b.length)for(;f--&&(e=f in a==f in b&&Y(a[f],b[f],c)););}else{if("constructor"in a!="constructor"in b||a.constructor!= +b.constructor)return o;for(var j in a)if(r.call(a,j)&&(f++,!(e=r.call(b,j)&&Y(a[j],b[j],c))))break;if(e){for(j in b)if(r.call(b,j)&&!f--)break;e=!f}}c.pop();return e}function s(a){return k.call(a)==ba}function S(a){return a}function na(a){u(M(a),function(b){var c=i[b]=a[b];i.prototype[b]=function(){var a=[this.o];H.apply(a,arguments);a=c.apply(i,a);return this.p?(new p(a)).chain():a}})}var x={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"};(function(){for(var a in x)x[x[a]]= +a})();var Z="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(q=global),exports),wa=0,xa=q._,ya=/\\|'|\r|\n|\t|\u2028|\u2029/g,$=/.^/,ua=/\\(\\|'|r|n|t|u2028|u2029)/g,C="[object Array]",ka="[object Boolean]",la="[object Date]",ba="[object Function]",L="[object Number]",ma="[object RegExp]",G="[object String]",z=Array.prototype,N=Object.prototype,D=z.concat,r=N.hasOwnProperty,H=z.push,l=z.slice,k=N.toString,za=q.isFinite,N=Object.keys,va=q.clearTimeout,K= +q.setTimeout,O={b:"b",m:"var K=i.apply([],B.call(arguments,1))",h:"[]",g:"if(p(K,b[o])<0)A.push(b[o])"},v={h:"H",g:"if(!e(g[o],o,g))return !A"},aa={b:"w",h:"w",d:"for(var C,j=1,v=arguments.length;j=h)h=j,A=g[o]"},F=Array.isArray||function(a){return k.call(a)==C},ca=g({b:"J",i:"b",m:"var f=G.call(J)",h:"H",d:"if(f==c||f==D)return !J.length",g:"return k"}),pa=g({b:"g,E",h:"k",g:"if(g[o]===E)return H"}),X=g(m,v),W=g(m,A),qa=g(m,{g:"if(e(g[o],o,g))return g[o]"}),u=g(m),Aa=g(m,{m:"var y,u=G.call(e)==l",h:"{}",g:"y=u?e(g[o],o,g):g[o][e];(A[y]||(A[y]=[])).push(g[o])"}), +y=g(m,B),ra=g(m,w),w=g(m,w,{m:w.m.replace("-","").replace("max","min"),g:w.g.replace(">=","<")}),P=g(B,{b:"g,z",g:{c:"A[o]=g[o][z]",k:"A[A.length]=g[o][z]"}}),J=g({b:"g,e,a,F",m:"var r=arguments.length>2;if(F)e=d(e,F)",h:"a",d:{c:"if(!r)A=g[++o]"},g:{c:"A=e(A,g[o],o,g)",k:"A=r?e(A,g[o],o,g):(r=H,g[o])"}}),A=g(m,A,{g:"!"+A.g}),v=g(m,v,{h:"k",g:v.g.replace("!","")}),sa=g(B,{b:"g",g:{c:"A[o]=g[o]",k:"A[A.length]=g[o]"}}),B=g({b:"b",h:"[]",g:"if(b[o])A.push(b[o])"}),m=g(O),O=g(O,{m:"var K=B.call(arguments,1)", +h:"[]"}),ta=g(aa,{g:"if(w[o]==I)"+aa.g}),Q=g(aa),M=g(oa,{m:"",n:o,g:"if(G.call(w[o])==l)A.push(o)",l:"A.sort()"});R(arguments)||(R=function(a){return!(!a||!r.call(a,"callee"))});var U=N||g(oa);Q(i,{VERSION:"0.1.0",templateSettings:{escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g},after:function(a,b){return 1>a?b():function(){if(1>--a)return b.apply(this,arguments)}},bind:t,bindAll:function(a){var b=arguments,c=1;1==b.length&&(c=0,b=M(a));for(var d=b.length;c/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")},every:X,extend:Q,filter:W,find:qa,first:V,flatten:fa,forEach:u,functions:M,groupBy:Aa,has:function(a,b){return r.call(a,b)},identity:S,indexOf:E,initial:function(a,b,c){return l.call(a,0,-(b==h||c?1:b))},intersection:ga,invoke:function(a,b){var c=l.call(arguments,2),d=s(b);return y(a,function(a){return(d?b||a:a[b]).apply(a,c)})},isArguments:R,isArray:F,isBoolean:function(a){return a=== +n||a===o||k.call(a)==ka},isDate:function(a){return k.call(a)==la},isElement:function(a){return!!(a&&1==a.nodeType)},isEmpty:ca,isEqual:Y,isFinite:function(a){return za(a)&&k.call(a)==L},isFunction:s,isNaN:function(a){return k.call(a)==L&&a!=+a},isNull:function(a){return null===a},isNumber:function(a){return k.call(a)==L},isObject:function(a){return a===Object(a)},isRegExp:function(a){return k.call(a)==ma},isString:function(a){return k.call(a)==G},isUndefined:function(a){return a===h},keys:U,last:ha, +lastIndexOf:function(a,b){if(a==h)return-1;for(var c=a.length;c--;)if(a[c]===b)return c;return-1},map:y,max:ra,memoize:function(a,b){var c={};return function(){var d=b?b.apply(this,arguments):arguments[0];return r.call(c,d)?c[d]:c[d]=a.apply(this,arguments)}},min:w,mixin:na,noConflict:function(){q._=xa;return this},once:function(a){var b,c=o;return function(){if(c)return b;c=n;return b=a.apply(this,arguments)}},pick:function(a){for(var b,c=-1,d=D.apply([],l.call(arguments,1)),e=d.length,f={};++c< +e;)b=d[c],b in a&&(f[b]=a[b]);return f},pluck:P,range:function(a,b,c){c||(c=1);2>arguments.length&&(b=a||0,a=0);for(var d=-1,e=Math.max(Math.ceil((b-a)/c),0),f=Array(e);++dd?1:0}),"b")},sortedIndex:ea,tap:function(a,b){b(a);return a},template:function(a,b,c){function d(a){return e.call(this,a,i)}c=ta(c||{},i.templateSettings);a="__p+='"+a.replace(ya,function(a){return"\\"+x[a]}).replace(c.escape||$,function(a,b){return"'+((__t=("+T(b)+"))==null?'':_['escape'](__t))+'"}).replace(c.interpolate|| +$,function(a,b){return"'+((__t=("+T(b)+"))==null?'':__t)+'"}).replace(c.evaluate||$,function(a,b){return"';"+T(b)+";__p+='"})+"';";c.variable||(a="with(object||{}){"+a+"}");var a='var __t,__j=Array.prototype.join,__p="";function print(){__p+=__j.call(arguments,"")}'+a+"return __p",e=Function(c.variable||"object","_",a);if(b)return e(b,i);d.source="function("+(c.variable||"object")+"){"+a+"}";return d},throttle:function(a,b){var c,d,e,f,g,i,k=ja(function(){d=g=o},b);return function(){c=arguments;f= +this;i||(i=K(function(){i=h;d&&a.apply(f,c);k()},b));g?d=n:e=a.apply(f,c);k();g=n;return e}},times:function(a,b,c){c&&(b=t(b,c));for(c=0;c