From 04fb4aff28df285474f44a205e19e96b31c1e49b Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 11 Sep 2012 20:15:13 -0700 Subject: [PATCH 01/82] Update underscore. Former-commit-id: 7041883ef258e3dc80d3c3751a5e4beecf0b4767 --- vendor/underscore/test/collections.js | 6 ------ vendor/underscore/underscore-min.js | 14 +++++++------- vendor/underscore/underscore.js | 5 +++-- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/vendor/underscore/test/collections.js b/vendor/underscore/test/collections.js index 56e4ece599..1063021c35 100644 --- a/vendor/underscore/test/collections.js +++ b/vendor/underscore/test/collections.js @@ -44,12 +44,6 @@ $(document).ready(function() { var doubled = _([1, 2, 3]).map(function(num){ return num * 2; }); equal(doubled.join(', '), '2, 4, 6', 'OO-style doubled numbers'); - var ids = _.map($('#map-test').children(), function(n){ return n.id; }); - deepEqual(ids, ['id1', 'id2'], 'Can use collection methods on NodeLists.'); - - var ids = _.map(document.images, function(n){ return n.id; }); - ok(ids[0] == 'chart_image', 'can use collection methods on HTMLCollections'); - var ifnull = _.map(null, function(){}); ok(_.isArray(ifnull) && ifnull.length === 0, 'handles a null properly'); }); diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index 29cb190099..4c886ad386 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -6,15 +6,15 @@ // For all details and documentation: // http://documentcloud.github.com/underscore (function(){var s=this,K=s._,o={},k=Array.prototype,p=Object.prototype,L=k.push,g=k.slice,l=p.toString,M=p.hasOwnProperty,y=k.forEach,z=k.map,A=k.reduce,B=k.reduceRight,C=k.filter,D=k.every,E=k.some,q=k.indexOf,F=k.lastIndexOf,p=Array.isArray,N=Object.keys,t=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._=b):s._=b; -b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,c,d){if(a!=null)if(y&&a.forEach===y)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,h=a.length;e2;a==null&&(a=[]);if(A&& -a.reduce===A){e&&(c=b.bind(c,e));return h?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,g){if(h)d=c.call(e,d,a,b,g);else{d=a;h=true}});if(!h)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var h=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));return h?a.reduceRight(c,d):a.reduceRight(c)}var f=b.toArray(a).reverse();e&&!h&&(c=b.bind(c,e));return h?b.reduce(f,c,d,e):b.reduce(f,c)};b.find=b.detect=function(a, -c,b){var e;G(a,function(a,f,i){if(c.call(b,a,f,i)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(C&&a.filter===C)return a.filter(c,b);j(a,function(a,f,i){c.call(b,a,f,i)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,f,i){c.call(b,a,f,i)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(D&&a.every===D)return a.every(c,d);j(a,function(a,b, -i){if(!(e=e&&c.call(d,a,b,i)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,i){if(e||(e=c.call(d,a,b,i)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=g.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a, +b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,c,d){if(a!=null)if(y&&a.forEach===y)a.forEach(c,d);else if(b.isArray(a)||b.isArguments(a))for(var e=0,h=a.length;e2;a==null&&(a= +[]);if(A&&a.reduce===A){e&&(c=b.bind(c,e));return h?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,g){if(h)d=c.call(e,d,a,b,g);else{d=a;h=true}});if(!h)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var h=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));return h?a.reduceRight(c,d):a.reduceRight(c)}var f=b.toArray(a).reverse();e&&!h&&(c=b.bind(c,e));return h?b.reduce(f,c,d,e):b.reduce(f,c)};b.find=b.detect= +function(a,c,b){var e;G(a,function(a,f,i){if(c.call(b,a,f,i)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(C&&a.filter===C)return a.filter(c,b);j(a,function(a,f,i){c.call(b,a,f,i)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,f,i){c.call(b,a,f,i)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(D&&a.every===D)return a.every(c,d);j(a,function(a, +b,i){if(!(e=e&&c.call(d,a,b,i)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,i){if(e||(e=c.call(d,a,b,i)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=g.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a, d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,i){b=c?c.call(d,a,b,i):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a, function(a,b,i){b=c?c.call(d,a,b,i):a;bd?1:0}),"value")};var H=function(a,c){return b.isFunction(c)?c:function(a){return a[c]}}, -I=function(a,c,b){var e={},h=H(a,c);j(a,function(a,c){var g=h(a,c);b(e,g,a)});return e};b.groupBy=function(a,c){return I(a,c,function(a,c,b){(a[c]||(a[c]=[])).push(b)})};b.countBy=function(a,c){return I(a,c,function(a,c){a[c]||(a[c]=0);a[c]++})};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var c=d(c),e=0,h=a.length;e>1;d(a[f])>1;d(a[f])=0})})};b.difference=function(a){var c=r(g.call(arguments,1),true,[]);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=g.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e Date: Tue, 11 Sep 2012 22:30:23 -0700 Subject: [PATCH 02/82] Add "mobile" build unit test. Former-commit-id: f067b42618abe6a9f747fea000522de6a9117b3c --- test/test-build.js | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/test/test-build.js b/test/test-build.js index 4ff47b471d..5dea94fd40 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -686,8 +686,7 @@ (function() { ['-c', '--stdout'].forEach(function(command, index) { - var descriptor = Object.getOwnPropertyDescriptor(global, 'console'), - start = _.once(QUnit.start); + var start = _.once(QUnit.start); asyncTest('`lodash ' + command +'`', function() { build([command, 'exports=', 'include='], function(source, filepath) { @@ -727,4 +726,42 @@ }); }()); + /*--------------------------------------------------------------------------*/ + + QUnit.module('mobile build'); + + (function() { + var start = _.after(2, _.once(QUnit.start)); + + asyncTest('`lodash mobile`', function() { + build(['-s', 'mobile'], function(source, filepath) { + var basename = path.basename(filepath, '.js'), + context = createContext(); + + try { + vm.runInContext(source, context); + } catch(e) { } + + var array = [1, 2, 3], + object1 = [{ 'a': 1 }], + object2 = [{ 'b': 2 }], + object3 = [{ 'a': 1, 'b': 2 }], + circular1 = { 'a': 1 }, + circular2 = { 'a': 1 }, + lodash = context._; + + circular1.b = circular1; + circular2.b = circular2; + + deepEqual(lodash.merge(object1, object2), object3, basename); + deepEqual(lodash.sortBy([3, 2, 1], _.identity), array, basename); + equal(lodash.isEqual(circular1, circular2), true, basename); + + var actual = lodash.clone(circular1, true); + ok(actual != circular1 && actual.b == actual, basename); + start(); + }); + }); + }()); + }()); From d5a8fa0b978ceafdc39a0fd35c5052b89b62ff91 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 12 Sep 2012 08:39:18 -0700 Subject: [PATCH 03/82] Update underscore unit tests. Former-commit-id: ae00a864c7cb3bff9970289917df681ad5e295d9 --- vendor/underscore/test/objects.js | 8 ----- vendor/underscore/underscore-min.js | 46 ++++++++++++++--------------- vendor/underscore/underscore.js | 13 ++++---- 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/vendor/underscore/test/objects.js b/vendor/underscore/test/objects.js index 1d708d98f4..4e77d32725 100644 --- a/vendor/underscore/test/objects.js +++ b/vendor/underscore/test/objects.js @@ -228,14 +228,6 @@ $(document).ready(function() { ok(_.isEqual(Array(3), Array(3)), "Sparse arrays of identical lengths are equal"); ok(!_.isEqual(Array(3), Array(6)), "Sparse arrays of different lengths are not equal when both are empty"); - // According to the Microsoft deviations spec, section 2.1.26, JScript 5.x treats `undefined` - // elements in arrays as elisions. Thus, sparse arrays and dense arrays containing `undefined` - // values are equivalent. - if (0 in [undefined]) { - ok(!_.isEqual(Array(3), [undefined, undefined, undefined]), "Sparse and dense arrays are not equal"); - ok(!_.isEqual([undefined, undefined, undefined], Array(3)), "Commutative equality is implemented for sparse and dense arrays"); - } - // Simple objects. ok(_.isEqual({a: "Curly", b: 1, c: true}, {a: "Curly", b: 1, c: true}), "Objects containing identical primitives are equal"); ok(_.isEqual({a: /Curly/g, b: new Date(2009, 11, 13)}, {a: /Curly/g, b: new Date(2009, 11, 13)}), "Objects containing equivalent members are equal"); diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index 4c886ad386..f8e5302672 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -5,29 +5,29 @@ // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: // http://documentcloud.github.com/underscore -(function(){var s=this,K=s._,o={},k=Array.prototype,p=Object.prototype,L=k.push,g=k.slice,l=p.toString,M=p.hasOwnProperty,y=k.forEach,z=k.map,A=k.reduce,B=k.reduceRight,C=k.filter,D=k.every,E=k.some,q=k.indexOf,F=k.lastIndexOf,p=Array.isArray,N=Object.keys,t=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._=b):s._=b; -b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,c,d){if(a!=null)if(y&&a.forEach===y)a.forEach(c,d);else if(b.isArray(a)||b.isArguments(a))for(var e=0,h=a.length;e2;a==null&&(a= -[]);if(A&&a.reduce===A){e&&(c=b.bind(c,e));return h?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,g){if(h)d=c.call(e,d,a,b,g);else{d=a;h=true}});if(!h)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var h=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));return h?a.reduceRight(c,d):a.reduceRight(c)}var f=b.toArray(a).reverse();e&&!h&&(c=b.bind(c,e));return h?b.reduce(f,c,d,e):b.reduce(f,c)};b.find=b.detect= +(function(){var s=this,K=s._,o={},k=Array.prototype,p=Object.prototype,L=k.push,h=k.slice,l=p.toString,M=p.hasOwnProperty,y=k.forEach,z=k.map,A=k.reduce,B=k.reduceRight,C=k.filter,D=k.every,E=k.some,q=k.indexOf,F=k.lastIndexOf,p=Array.isArray,N=Object.keys,t=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._=b):s._=b; +b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,c,d){if(a!=null)if(y&&a.forEach===y)a.forEach(c,d);else if(b.isArray(a)||b.isArguments(a))for(var e=0,g=a.length;e2;a==null&&(a= +[]);if(A&&a.reduce===A){e&&(c=b.bind(c,e));return g?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,h){if(g)d=c.call(e,d,a,b,h);else{d=a;g=true}});if(!g)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var g=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));return g?a.reduceRight(c,d):a.reduceRight(c)}var f=b.toArray(a).reverse();e&&!g&&(c=b.bind(c,e));return g?b.reduce(f,c,d,e):b.reduce(f,c)};b.find=b.detect= function(a,c,b){var e;G(a,function(a,f,i){if(c.call(b,a,f,i)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(C&&a.filter===C)return a.filter(c,b);j(a,function(a,f,i){c.call(b,a,f,i)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,f,i){c.call(b,a,f,i)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(D&&a.every===D)return a.every(c,d);j(a,function(a, -b,i){if(!(e=e&&c.call(d,a,b,i)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,i){if(e||(e=c.call(d,a,b,i)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=g.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a, +b,i){if(!(e=e&&c.call(d,a,b,i)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,i){if(e||(e=c.call(d,a,b,i)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=h.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a, d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,i){b=c?c.call(d,a,b,i):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a, function(a,b,i){b=c?c.call(d,a,b,i):a;bd?1:0}),"value")};var H=function(a,c){return b.isFunction(c)?c:function(a){return a[c]}}, -I=function(a,b,d){var e={},h=H(a,b);j(a,function(a,b){var c=h(a,b);d(e,c,a)});return e};b.groupBy=function(a,b){return I(a,b,function(a,b,c){(a[b]||(a[b]=[])).push(c)})};b.countBy=function(a,b){return I(a,b,function(a,b){a[b]||(a[b]=0);a[b]++})};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var c=d(c),e=0,h=a.length;e>1;d(a[f])=0})})};b.difference=function(a){var c=r(g.call(arguments,1),true,[]);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=g.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}}; -b.keys=N||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(g.call(arguments,1),function(b){for(var d in b)a[d]= -b[d]});return a};b.pick=function(a){var c={},d=b.flatten(g.call(arguments,1));j(d,function(b){b in a&&(c[b]=a[b])});return c};b.omit=function(a){var c={},d=b.flatten(g.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){j(g.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d,e){if(a===c)return a!== -0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var h=l.call(a);if(h!=l.call(c))return false;switch(h){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==c.source&&a.global==c.global&& -a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return e[f]==c;d.push(a);e.push(c);var f=0,i=true;if(h=="[object Array]"){f=a.length;if(i=f==c.length)for(;f--;)if(!(i=f in a==f in c&&u(a[f],c[f],d,e)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var g in a)if(b.has(a,g)){f++;if(!(i=b.has(c,g)&&u(a[g],c[g],d,e)))break}if(i){for(g in c)if(b.has(c,g)&&!f--)break; -i=!f}}d.pop();e.pop();return i};b.isEqual=function(a,b){return u(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};j("Arguments,Function,String,Number,Date,RegExp".split(","),function(a){b["is"+a]=function(b){return l.call(b)=="[object "+ -a+"]"}});b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return M.call(a,b)};b.noConflict=function(){s._=K;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e= -0;e":">",'"':""","'":"'","/":"/"}};m.unescape=b.invert(m.escape);var O={escape:RegExp("["+b.keys(m.escape).join("")+"]","g"),unescape:RegExp("("+b.keys(m.unescape).join("|")+")","g")};b.each(["escape","unescape"],function(a){b[a]=function(b){return b==null?"":(""+b).replace(O[a],function(b){return m[a][b]})}});b.result=function(a,c){if(a==null)return null;var d= -a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){var d=b[c]=a[c];b.prototype[c]=function(){var a=g.call(arguments);a.unshift(this._wrapped);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var P=0;b.uniqueId=function(a){var b=P++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var v=/.^/,n={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},w;for(w in n)n[n[w]]= -w;var Q=/\\|'|\r|\n|\t|\u2028|\u2029/g,R=/\\(\\|'|r|n|t|u2028|u2029)/g,x=function(a){return a.replace(R,function(a,b){return n[b]})};b.template=function(a,c,d){d=b.defaults({},d,b.templateSettings);a="__p+='"+a.replace(Q,function(a){return"\\"+n[a]}).replace(d.escape||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':_.escape(__t))+\n'"}).replace(d.interpolate||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':__t)+\n'"}).replace(d.evaluate||v,function(a,b){return"';\n"+x(b)+"\n__p+='"})+ -"';\n";d.variable||(a="with(obj||{}){\n"+a+"}\n");a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{var e=new Function(d.variable||"obj","_",a)}catch(g){g.source=a;throw g;}if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c=k[a];b.prototype[a]= -function(){var d=this._wrapped;c.apply(d,arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain():d}});j(["concat","join","slice"],function(a){var c=k[a];b.prototype[a]=function(){var a=c.apply(this._wrapped,arguments);return this._chain?b(a).chain():a}});b.extend(b.prototype,{chain:function(){this._chain=true;return this},value:function(){return this._wrapped}})}).call(this); +I=function(a,c,b){var e={},g=H(a,c);j(a,function(a,c){var h=g(a,c);b(e,h,a)});return e};b.groupBy=function(a,c){return I(a,c,function(a,c,b){(a[c]||(a[c]=[])).push(b)})};b.countBy=function(a,c){return I(a,c,function(a,c){a[c]||(a[c]=0);a[c]++})};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var c=d(c),e=0,g=a.length;e>1;d(a[f])=0})})};b.difference=function(a){var c=r(h.call(arguments,1),true,[]);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=h.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}}; +b.keys=N||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(h.call(arguments,1),function(b){for(var d in b)a[d]= +b[d]});return a};b.pick=function(a){var c={},d=b.flatten(h.call(arguments,1));j(d,function(b){b in a&&(c[b]=a[b])});return c};b.omit=function(a){var c={},d=b.flatten(h.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){j(h.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d,e){if(a===c)return a!== +0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var g=l.call(a);if(g!=l.call(c))return false;switch(g){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==c.source&&a.global==c.global&& +a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return e[f]==c;d.push(a);e.push(c);var f=0,i=true;if(g=="[object Array]"){f=a.length;if(i=f==c.length)for(;f--;)if(!(i=u(a[f],c[f],d,e)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)){f++;if(!(i=b.has(c,h)&&u(a[h],c[h],d,e)))break}if(i){for(h in c)if(b.has(c,h)&&!f--)break;i=!f}}d.pop(); +e.pop();return i};b.isEqual=function(a,b){return u(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};j("Arguments,Function,String,Number,Date,RegExp".split(","),function(a){b["is"+a]=function(b){return l.call(b)=="[object "+a+"]"}}); +b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return M.call(a,b)};b.noConflict=function(){s._=K;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e":">",'"':""","'":"'","/":"/"}};m.unescape=b.invert(m.escape);var O={escape:RegExp("["+b.keys(m.escape).join("")+"]","g"),unescape:RegExp("("+b.keys(m.unescape).join("|")+")","g")};b.each(["escape","unescape"],function(a){b[a]=function(b){return b==null?"":(""+b).replace(O[a],function(b){return m[a][b]})}});b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)? +d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){var d=b[c]=a[c];b.prototype[c]=function(){var a=h.call(arguments);a.unshift(this._wrapped);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var P=0;b.uniqueId=function(a){var b=P++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var v=/.^/,n={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},w;for(w in n)n[n[w]]=w;var Q=/\\|'|\r|\n|\t|\u2028|\u2029/g, +R=/\\(\\|'|r|n|t|u2028|u2029)/g,x=function(a){return a.replace(R,function(a,b){return n[b]})};b.template=function(a,c,d){d=b.defaults({},d,b.templateSettings);a="__p+='"+a.replace(Q,function(a){return"\\"+n[a]}).replace(d.escape||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':_.escape(__t))+\n'"}).replace(d.interpolate||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':__t)+\n'"}).replace(d.evaluate||v,function(a,b){return"';\n"+x(b)+"\n__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+ +a+"}\n");a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{var e=new Function(d.variable||"obj","_",a)}catch(g){g.source=a;throw g;}if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c=k[a];b.prototype[a]=function(){var d=this._wrapped;c.apply(d, +arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain():d}});j(["concat","join","slice"],function(a){var c=k[a];b.prototype[a]=function(){var a=c.apply(this._wrapped,arguments);return this._chain?b(a).chain():a}});b.extend(b.prototype,{chain:function(){this._chain=true;return this},value:function(){return this._wrapped}})}).call(this); diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index cffdeb873a..ecffbf9463 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -416,13 +416,13 @@ _.uniq = _.unique = function(array, isSorted, iterator) { var initial = iterator ? _.map(array, iterator) : array; var results = []; - _.reduce(initial, function(memo, value, index) { - if (isSorted ? (_.last(memo) !== value || !memo.length) : !_.include(memo, value)) { - memo.push(value); + var seen = []; + each(initial, function(value, index) { + if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.include(seen, value)) { + seen.push(value); results.push(array[index]); } - return memo; - }, []); + }); return results; }; @@ -830,8 +830,7 @@ if (result) { // Deep compare the contents, ignoring non-numeric properties. while (size--) { - // Ensure commutative equality for sparse arrays. - if (!(result = size in a == size in b && eq(a[size], b[size], aStack, bStack))) break; + if (!(result = eq(a[size], b[size], aStack, bStack))) break; } } } else { From f88ea1ee7d7e7b1d73178de0d6699dff79cfa553 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 12 Sep 2012 08:40:01 -0700 Subject: [PATCH 04/82] Re-order test-build unit tests and make the `iife` test a bit more thorough. Former-commit-id: f798639cfa58241b052d16b9ca6fbf4537482349 --- test/test-build.js | 199 ++++++++++++++++++++++----------------------- 1 file changed, 99 insertions(+), 100 deletions(-) diff --git a/test/test-build.js b/test/test-build.js index 5dea94fd40..5c68407824 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -418,103 +418,6 @@ /*--------------------------------------------------------------------------*/ - QUnit.module('lodash build'); - - (function() { - var commands = [ - 'backbone', - 'csp', - 'legacy', - 'mobile', - 'strict', - 'underscore', - 'category=arrays', - 'category=chaining', - 'category=collections', - 'category=functions', - 'category=objects', - 'category=utilities', - 'exclude=union,uniq,zip', - 'include=each,filter,map', - 'category=collections,functions', - 'underscore backbone', - 'backbone legacy category=utilities exclude=first,last', - 'underscore mobile strict category=functions exports=amd,global include=pick,uniq', - ] - .concat( - allMethods.map(function(methodName) { - return 'include=' + methodName; - }) - ); - - commands.forEach(function(command) { - var start = _.after(2, _.once(QUnit.start)); - - asyncTest('`lodash ' + command +'`', function() { - build(['--silent'].concat(command.split(' ')), function(source, filepath) { - var basename = path.basename(filepath, '.js'), - context = createContext(), - methodNames = []; - - try { - vm.runInContext(source, context); - } catch(e) { } - - if (/underscore/.test(command)) { - methodNames = underscoreMethods; - } - if (/backbone/.test(command)) { - methodNames = backboneDependencies; - } - if (/include/.test(command)) { - methodNames = methodNames.concat(command.match(/include=(\S*)/)[1].split(/, */)); - } - if (/category/.test(command)) { - methodNames = command.match(/category=(\S*)/)[1].split(/, */).reduce(function(result, category) { - switch (category) { - case 'arrays': - return result.concat(arraysMethods); - case 'chaining': - return result.concat(chainingMethods); - case 'collections': - return result.concat(collectionsMethods); - case 'functions': - return result.concat(functionsMethods); - case 'objects': - return result.concat(objectsMethods); - case 'utilities': - return result.concat(utilityMethods); - } - return result; - }, methodNames); - } - if (!methodNames.length) { - methodNames = allMethods; - } - - if (/exclude/.test(command)) { - methodNames = _.without.apply(_, [methodNames].concat( - expandMethodNames(command.match(/exclude=(\S*)/)[1].split(/, */)) - )); - } else { - methodNames = expandMethodNames(methodNames); - } - - var lodash = context._ || {}; - methodNames = _.unique(methodNames); - - methodNames.forEach(function(methodName) { - testMethod(lodash, methodName, basename); - }); - - start(); - }); - }); - }); - }()); - - /*--------------------------------------------------------------------------*/ - QUnit.module('strict modifier'); (function() { @@ -647,7 +550,7 @@ var start = _.after(2, _.once(QUnit.start)); asyncTest('`lodash iife=...`', function() { - build(['-s', 'iife=!function(window,undefined){%output%}(this)'], function(source, filepath) { + build(['-s', 'exports=none', 'iife=this["lodash"]=(function(window,undefined){%output%;return lodash}(this))'], function(source, filepath) { var basename = path.basename(filepath, '.js'), context = createContext(); @@ -655,9 +558,8 @@ vm.runInContext(source, context); } catch(e) { } - var lodash = context._ || {}; + var lodash = context.lodash || {}; ok(_.isString(lodash.VERSION), basename); - ok(/!function/.test(source), basename); start(); }); }); @@ -764,4 +666,101 @@ }); }()); + /*--------------------------------------------------------------------------*/ + + QUnit.module('lodash build'); + + (function() { + var commands = [ + 'backbone', + 'csp', + 'legacy', + 'mobile', + 'strict', + 'underscore', + 'category=arrays', + 'category=chaining', + 'category=collections', + 'category=functions', + 'category=objects', + 'category=utilities', + 'exclude=union,uniq,zip', + 'include=each,filter,map', + 'category=collections,functions', + 'underscore backbone', + 'backbone legacy category=utilities exclude=first,last', + 'underscore mobile strict category=functions exports=amd,global include=pick,uniq', + ] + .concat( + allMethods.map(function(methodName) { + return 'include=' + methodName; + }) + ); + + commands.forEach(function(command) { + var start = _.after(2, _.once(QUnit.start)); + + asyncTest('`lodash ' + command +'`', function() { + build(['--silent'].concat(command.split(' ')), function(source, filepath) { + var basename = path.basename(filepath, '.js'), + context = createContext(), + methodNames = []; + + try { + vm.runInContext(source, context); + } catch(e) { } + + if (/underscore/.test(command)) { + methodNames = underscoreMethods; + } + if (/backbone/.test(command)) { + methodNames = backboneDependencies; + } + if (/include/.test(command)) { + methodNames = methodNames.concat(command.match(/include=(\S*)/)[1].split(/, */)); + } + if (/category/.test(command)) { + methodNames = command.match(/category=(\S*)/)[1].split(/, */).reduce(function(result, category) { + switch (category) { + case 'arrays': + return result.concat(arraysMethods); + case 'chaining': + return result.concat(chainingMethods); + case 'collections': + return result.concat(collectionsMethods); + case 'functions': + return result.concat(functionsMethods); + case 'objects': + return result.concat(objectsMethods); + case 'utilities': + return result.concat(utilityMethods); + } + return result; + }, methodNames); + } + if (!methodNames.length) { + methodNames = allMethods; + } + + if (/exclude/.test(command)) { + methodNames = _.without.apply(_, [methodNames].concat( + expandMethodNames(command.match(/exclude=(\S*)/)[1].split(/, */)) + )); + } else { + methodNames = expandMethodNames(methodNames); + } + + var lodash = context._ || {}; + methodNames = _.unique(methodNames); + + methodNames.forEach(function(methodName) { + testMethod(lodash, methodName, basename); + }); + + start(); + }); + }); + }); + }()); + }()); From 569caa0bf21116eb6055d4b4449bc008af3872e7 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 12 Sep 2012 22:00:23 -0700 Subject: [PATCH 05/82] Remove custom `isEqual` checks from `_.isEqual` and custom `clone` checks from `_.clone` and simply `_.clone`, `_.isEqual`, and `_.merge`. Former-commit-id: 45e90ab1494e46e281265f660c87e27f59581308 --- build/pre-compile.js | 18 ++---- lodash.js | 140 ++++++++++++++++++------------------------- test/test.js | 24 -------- 3 files changed, 64 insertions(+), 118 deletions(-) diff --git a/build/pre-compile.js b/build/pre-compile.js index 08e0bef5d4..27b97f1b9d 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -44,7 +44,6 @@ 'callee', 'className', 'compareAscending', - 'data', 'forIn', 'found', 'funcs', @@ -64,13 +63,12 @@ 'properties', 'property', 'propsLength', - 'recursive', 'source', - 'sources', + 'stackA', + 'stackB', 'stackLength', 'target', - 'valueProp', - 'values' + 'valueProp' ]; /** Used to minify `compileIterator` option properties */ @@ -118,7 +116,6 @@ 'chain', 'clearTimeout', 'clone', - 'clones', 'collect', 'compact', 'compose', @@ -214,9 +211,6 @@ 'sortBy', 'sortedIndex', 'source', - 'sources', - 'stackA', - 'stackB', 'tail', 'take', 'tap', @@ -305,10 +299,10 @@ // remove debug sourceURL use in `_.template` source = source.replace(/(?:\s*\/\/.*\n)* *if *\(useSourceURL[^}]+}/, ''); - // minify internal properties used by 'compareAscending', `_.clone`, `_.isEqual`, `_.merge`, and `_.sortBy` + // minify internal properties used by 'compareAscending', `_.merge`, and `_.sortBy` (function() { - var properties = ['clones', 'criteria', 'index', 'sources', 'thorough', 'value', 'values'], - snippets = source.match(/( +)(?:function (?:clone|compareAscending|isEqual)|var merge|var sortBy)\b[\s\S]+?\n\1}/g); + var properties = ['criteria', 'index', 'value'], + snippets = source.match(/( +)(?:function compareAscending|var merge|var sortBy)\b[\s\S]+?\n\1}/g); if (!snippets) { return; diff --git a/lodash.js b/lodash.js index 142ac23876..47585cff4c 100644 --- a/lodash.js +++ b/lodash.js @@ -1051,10 +1051,9 @@ /** * Creates a clone of `value`. If `deep` is `true`, all nested objects will - * also be cloned otherwise they will be assigned by reference. If a value has - * a `clone` method it will be used to perform the clone. Functions, DOM nodes, - * `arguments` objects, and objects created by constructors other than `Object` - * are **not** cloned unless they have a custom `clone` method. + * also be cloned otherwise they will be assigned by reference. Functions, DOM + * nodes, `arguments` objects, and objects created by constructors other than + * `Object` are **not** cloned. * * @static * @memberOf _ @@ -1063,9 +1062,9 @@ * @param {Boolean} deep A flag to indicate a deep clone. * @param {Object} [guard] Internally used to allow this method to work with * others like `_.map` without using their callback `index` argument for `deep`. - * @param {Object} [data={}] Internally used to track traversed objects to avoid - * circular references and indicate whether to perform a more thorough clone - * of non-object values. + * @param {Array} [stackA=[]] Internally used to track traversed source objects. + * @param {Array} [stackB=[]] Internally used to associate clones with their + * source counterparts. * @returns {Mixed} Returns the cloned `value`. * @example * @@ -1086,28 +1085,15 @@ * shallow[0] === stooges[0]; * // => false */ - function clone(value, deep, guard, data) { + function clone(value, deep, guard, stackA, stackB) { if (value == null) { return value; } if (guard) { deep = false; } - // init internal data - data || (data = { 'thorough': null }); - - // avoid slower checks on primitives - if (data.thorough == null) { - // primitives passed from iframes use the primary document's native prototypes - data.thorough = !!(BoolProto.clone || NumberProto.clone || StringProto.clone); - } - // use custom `clone` method if available - var isObj = objectTypes[typeof value]; - if ((isObj || data.thorough) && value.clone && isFunction(value.clone)) { - data.thorough = null; - return value.clone(deep); - } // inspect [[Class]] + var isObj = objectTypes[typeof value]; if (isObj) { // don't clone `arguments` objects, functions, or non-object Objects var className = toString.call(value); @@ -1141,33 +1127,34 @@ return ctor(value.source, reFlags.exec(value)); } - var clones = data.clones || (data.clones = []), - sources = data.sources || (data.sources = []), - length = clones.length; - // check for circular references and return corresponding clone + stackA || (stackA = []); + stackB || (stackB = []); + + var length = stackA.length; while (length--) { - if (sources[length] == value) { - return clones[length]; + if (stackA[length] == value) { + return stackB[length]; } } // init cloned object var result = isArr ? ctor(length = value.length) : {}; - // add current clone and original source value to the stack of traversed objects - clones.push(result); - sources.push(value); + // add the source value to the stack of traversed objects + // and associate it with its clone + stackA.push(value); + stackB.push(result); // recursively populate clone (susceptible to call stack limits) if (isArr) { var index = -1; while (++index < length) { - result[index] = clone(value[index], deep, null, data); + result[index] = clone(value[index], deep, null, stackA, stackB); } } else { forOwn(value, function(objValue, key) { - result[key] = clone(objValue, deep, null, data); + result[key] = clone(objValue, deep, null, stackA, stackB); }); } return result; @@ -1418,17 +1405,15 @@ /** * Performs a deep comparison between two values to determine if they are - * equivalent to each other. If a value has an `isEqual` method it will be - * used to perform the comparison. + * equivalent to each other. * * @static * @memberOf _ * @category Objects * @param {Mixed} a The value to compare. * @param {Mixed} b The other value to compare. - * @param {Object} [data={}] Internally used track traversed objects to avoid - * circular references and indicate whether to perform a more thorough comparison - * of non-object values. + * @param {Object} [stackA=[]] Internally used track traversed `a` objects. + * @param {Object} [stackB=[]] Internally used track traversed `b` objects. * @returns {Boolean} Returns `true` if the values are equvalent, else `false`. * @example * @@ -1441,39 +1426,21 @@ * _.isEqual(moe, clone); * // => true */ - function isEqual(a, b, data) { + function isEqual(a, b, stackA, stackB) { // a strict comparison is necessary because `null == undefined` if (a == null || b == null) { return a === b; } - // init internal data - data || (data = { 'thorough': null }); - - // avoid slower checks on non-objects - if (data.thorough == null) { - // primitives passed from iframes use the primary document's native prototypes - data.thorough = !!(BoolProto.isEqual || NumberProto.isEqual || StringProto.isEqual); - } - if (objectTypes[typeof a] || objectTypes[typeof b] || data.thorough) { - // unwrap any LoDash wrapped values - a = a.__wrapped__ || a; - b = b.__wrapped__ || b; - - // use custom `isEqual` method if available - if (a.isEqual && isFunction(a.isEqual)) { - data.thorough = null; - return a.isEqual(b); - } - if (b.isEqual && isFunction(b.isEqual)) { - data.thorough = null; - return b.isEqual(a); - } - } // exit early for identical values if (a === b) { // treat `+0` vs. `-0` as not equal return a !== 0 || (1 / a == 1 / b); } + // unwrap any LoDash wrapped values + if (objectTypes[typeof a] || objectTypes[typeof b]) { + a = a.__wrapped__ || a; + b = b.__wrapped__ || b; + } // compare [[Class]] names var className = toString.call(a); if (className != toString.call(b)) { @@ -1514,10 +1481,10 @@ // assume cyclic structures are equal // the algorithm for detecting cyclic structures is adapted from ES 5.1 // section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3) - var stackA = data.stackA || (data.stackA = []), - stackB = data.stackB || (data.stackB = []), - length = stackA.length; + stackA || (stackA = []); + stackB || (stackB = []); + var length = stackA.length; while (length--) { if (stackA[length] == a) { return stackB[length] == b; @@ -1541,7 +1508,7 @@ if (result) { // deep compare the contents, ignoring non-numeric properties while (size--) { - if (!(result = isEqual(a[size], b[size], data))) { + if (!(result = isEqual(a[size], b[size], stackA, stackB))) { break; } } @@ -1565,7 +1532,7 @@ // count the number of properties. size++; // deep compare each property value. - if (!(hasOwnProperty.call(b, prop) && isEqual(a[prop], b[prop], data))) { + if (!(hasOwnProperty.call(b, prop) && isEqual(a[prop], b[prop], stackA, stackB))) { return false; } } @@ -1585,7 +1552,7 @@ while (++index < 7) { prop = shadowed[index]; if (hasOwnProperty.call(a, prop) && - !(hasOwnProperty.call(b, prop) && isEqual(a[prop], b[prop], data))) { + !(hasOwnProperty.call(b, prop) && isEqual(a[prop], b[prop], stackA, stackB))) { return false; } } @@ -1804,8 +1771,9 @@ * @param {Object} [source1, source2, ...] The source objects. * @param {Object} [indicator] Internally used to indicate that the `stack` * argument is an array of traversed objects instead of another source object. - * @param {Object} [data={}] Internally used to track traversed objects to avoid - * circular references. + * @param {Array} [stackA=[]] Internally used to track traversed source objects. + * @param {Array} [stackB=[]] Internally used to associate clones with their + * source counterparts. * @returns {Object} Returns the destination object. * @example * @@ -1825,25 +1793,34 @@ var merge = createIterator(extendIteratorOptions, { 'args': 'object, source, indicator', 'top': - 'var isArr, recursive = indicator == isPlainObject,\n' + - ' data = recursive ? arguments[3] : { values: [], sources: [] };\n' + - 'for (var argsIndex = 1, argsLength = recursive ? 2 : arguments.length; argsIndex < argsLength; argsIndex++) {\n' + - ' if (iteratee = arguments[argsIndex]) {', + 'var argsLength, isArr, stackA, stackB,\n' + + ' args = arguments, argsIndex = 0;\n' + + 'if (indicator == isPlainObject) {\n' + + ' argsLength = 2;\n' + + ' stackA = args[3];\n' + + ' stackB = args[4]\n' + + '} else {\n' + + ' argsLength = args.length;\n' + + ' stackA = [];\n' + + ' stackB = []\n' + + '}\n' + + 'while (++argsIndex < argsLength) {\n' + + ' if (iteratee = args[argsIndex]) {', 'inLoop': 'if ((source = value) && ((isArr = isArray(source)) || isPlainObject(source))) {\n' + - ' var found = false, values = data.values, sources = data.sources, stackLength = sources.length;\n' + + ' var found = false, stackLength = stackA.length;\n' + ' while (stackLength--) {\n' + - ' if (found = sources[stackLength] == source) break\n' + + ' if (found = stackA[stackLength] == source) break\n' + ' }\n' + ' if (found) {\n' + - ' result[index] = values[stackLength]\n' + + ' result[index] = stackB[stackLength]\n' + ' } else {\n' + - ' values.push(value = (value = result[index]) && isArr\n' + + ' stackA.push(source);\n' + + ' stackB.push(value = (value = result[index]) && isArr\n' + ' ? (isArray(value) ? value : [])\n' + ' : (isPlainObject(value) ? value : {})\n' + ' );\n' + - ' sources.push(source);\n' + - ' result[index] = callee(value, source, isPlainObject, data)\n' + + ' result[index] = callee(value, source, isPlainObject, stackA, stackB)\n' + ' }\n' + '} else if (source != null) {\n' + ' result[index] = source\n' + @@ -2446,8 +2423,7 @@ }); /** - * Converts the `collection`, to an array. Useful for converting the - * `arguments` object. + * Converts the `collection`, to an array. * * @static * @memberOf _ diff --git a/test/test.js b/test/test.js index 173d3847ac..067cf33494 100644 --- a/test/test.js +++ b/test/test.js @@ -260,19 +260,6 @@ ok(clone.bar.b === clone.foo.b && clone === clone.foo.b.foo.c && clone !== object); }); - test('should clone using Klass#clone', function() { - var object = new Klass; - Klass.prototype.clone = function() { return new Klass; }; - - var clone = _.clone(object); - ok(clone !== object && clone instanceof Klass); - - clone = _.clone(object, true); - ok(clone !== object && clone instanceof Klass); - - delete Klass.prototype.clone; - }); - test('should clone problem JScript properties (test in IE < 9)', function() { deepEqual(_.clone(shadowed), shadowed); ok(_.clone(shadowed) != shadowed); @@ -755,17 +742,6 @@ equal(_.isEqual(args1, args3), false); }); - test('should respect custom `isEqual` result despite objects strict equaling each other', function() { - var object = { 'isEqual': function() { return false; } }; - equal(_.isEqual(object, object), false); - }); - - test('should use custom `isEqual` methods on primitives', function() { - Boolean.prototype.isEqual = function() { return true; }; - equal(_.isEqual(true, false), true); - delete Boolean.prototype.isEqual; - }); - test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() { equal(_.isEqual(shadowed, {}), false); }); From c0d7dbf639dd880252d8205e319264ae701dbf6c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 13 Sep 2012 00:04:00 -0700 Subject: [PATCH 06/82] Reduce code around `_.bind` and `_.partial`, and add `_.lateBind`. Former-commit-id: 4c962d066ecfa54882cee2216a7310ab34b3b5a3 --- build.js | 7 +++++-- build/pre-compile.js | 3 ++- test/test-build.js | 8 ++++++-- test/test.js | 40 +++++++++++++++++++++++----------------- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/build.js b/build.js index d412e73e8e..446cf3d161 100755 --- a/build.js +++ b/build.js @@ -109,6 +109,7 @@ 'keys': ['isArguments'], 'last': [], 'lastIndexOf': [], + 'lateBind': ['isFunction'], 'map': ['identity'], 'max': [], 'memoize': [], @@ -120,7 +121,7 @@ 'omit': ['indexOf', 'isArguments'], 'once': [], 'pairs': [], - 'partial': [], + 'partial': ['isFunction'], 'pick': [], 'pluck': [], 'random': [], @@ -205,6 +206,7 @@ 'keys', 'last', 'lastIndexOf', + 'lateBind', 'map', 'max', 'min', @@ -230,6 +232,7 @@ 'forIn', 'forOwn', 'invert', + 'lateBind', 'merge', 'object', 'omit', @@ -1052,7 +1055,7 @@ // remove native `Function#bind` branch in `_.bind` if (methodName == 'bind') { - modified = modified.replace(/(?:\s*\/\/.*)*\s*else if *\(isBindFast[^}]+}/, ''); + modified = modified.replace(/(?:\s*\/\/.*)*\s*return isBindFast[^:]+:\s*/, 'return '); } // remove native `Array.isArray` branch in `_.isArray` else { diff --git a/build/pre-compile.js b/build/pre-compile.js index 27b97f1b9d..44e3c056e2 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -9,6 +9,7 @@ var compiledVars = [ 'argsIndex', 'argsLength', + 'bindIterator', 'callback', 'collection', 'concat', @@ -17,7 +18,6 @@ 'identity', 'index', 'iteratee', - 'iteratorBind', 'length', 'nativeKeys', 'object', @@ -180,6 +180,7 @@ 'keys', 'last', 'lastIndexOf', + 'lateBind', 'map', 'max', 'memoize', diff --git a/test/test-build.js b/test/test-build.js index 5c68407824..16b34ac3a9 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -134,6 +134,7 @@ 'debounce', 'defer', 'delay', + 'lateBind', 'memoize', 'once', 'partial', @@ -241,6 +242,7 @@ 'forIn', 'forOwn', 'invert', + 'lateBind', 'merge', 'object', 'omit', @@ -370,14 +372,16 @@ else if (functionsMethods.indexOf(methodName) > -1) { if (methodName == 'after') { func(1, noop); + } else if (methodName == 'bindAll') { + func({ 'noop': noop }); + } else if (methodName == 'lateBind') { + func(lodash, 'identity', array, string); } else if (/^(?:bind|partial)$/.test(methodName)) { func(noop, object, array, string); } else if (/^(?:compose|memoize|wrap)$/.test(methodName)) { func(noop, noop); } else if (/^(?:debounce|throttle)$/.test(methodName)) { func(noop, 100); - } else if (methodName == 'bindAll') { - func({ 'noop': noop }); } else { func(noop); } diff --git a/test/test.js b/test/test.js index 067cf33494..4ecdaf24c8 100644 --- a/test/test.js +++ b/test/test.js @@ -167,23 +167,6 @@ bound(['b'], 'c'); deepEqual(args, ['a', ['b'], 'c']); }); - - test('supports lazy bind', function() { - var object = { - 'name': 'moe', - 'greet': function(greeting) { - return greeting + ': ' + this.name; - } - }; - - var func = _.bind(object, 'greet', 'hi'); - equal(func(), 'hi: moe'); - - object.greet = function(greeting) { - return greeting + ' ' + this.name + '!'; - }; - equal(func(), 'hi moe!'); - }); }()); /*--------------------------------------------------------------------------*/ @@ -914,6 +897,29 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.lateBind'); + + (function() { + test('should work when the target function is overwritten', function() { + var object = { + 'name': 'moe', + 'greet': function(greeting) { + return greeting + ': ' + this.name; + } + }; + + var func = _.lateBind(object, 'greet', 'hi'); + equal(func(), 'hi: moe'); + + object.greet = function(greeting) { + return greeting + ' ' + this.name + '!'; + }; + equal(func(), 'hi moe!'); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.merge'); (function() { From 82a7c01898257edb9d9399735bac823ace630b30 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 13 Sep 2012 00:04:53 -0700 Subject: [PATCH 07/82] Simplify "underscore" build of `_.clone`. Former-commit-id: 32975bb5966f1ded4f007eb76dcf2d4677478e7d --- build.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/build.js b/build.js index 446cf3d161..81bf00bde0 100755 --- a/build.js +++ b/build.js @@ -826,23 +826,16 @@ // remove `deep` clone functionality source = source.replace(/( +)function clone[\s\S]+?\n\1}/, [ ' function clone(value) {', - ' if (value == null) {', - ' return value;', - ' }', - ' var isObj = objectTypes[typeof value];', - ' if (isObj && value.clone && isFunction(value.clone)) {', - ' return value.clone(deep);', - ' }', - ' if (isObj) {', + ' if (value && objectTypes[typeof value]) {', ' var className = toString.call(value);', ' if (!cloneableClasses[className] || (noArgsClass && isArguments(value))) {', - ' return value;', + ' return value', ' }', - ' var isArr = className == arrayClass;', + ' return className == arrayClass', + ' ? slice.call(value)', + ' : extend({}, value)', ' }', - ' return isObj', - ' ? (isArr ? slice.call(value) : extend({}, value))', - ' : value;', + ' return value', ' }' ].join('\n')); } From 49e3a49dc5ed5d43ecdfda3c399b7c305464d07c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 13 Sep 2012 00:08:52 -0700 Subject: [PATCH 08/82] Update docs, minified, build, and vendors. Former-commit-id: 8b1425b8c4a5238a42185dfa974bb3b2468eebea --- doc/README.md | 287 ++++++++++++++------------ lodash.js | 228 ++++++++++---------- lodash.min.js | 75 ++++--- vendor/underscore/test/collections.js | 11 + vendor/underscore/test/objects.js | 53 +---- vendor/underscore/underscore-min.js | 38 ++-- vendor/underscore/underscore.js | 22 +- 7 files changed, 354 insertions(+), 360 deletions(-) diff --git a/doc/README.md b/doc/README.md index c48f6f141d..eb62678d69 100644 --- a/doc/README.md +++ b/doc/README.md @@ -14,7 +14,7 @@ * [`_.bind`](#_bindfunc--thisarg-arg1-arg2-) * [`_.bindAll`](#_bindallobject--methodname1-methodname2-) * [`_.chain`](#_chainvalue) -* [`_.clone`](#_clonevalue-deep--guard-data) +* [`_.clone`](#_clonevalue-deep--guard-stacka-stackb) * [`_.collect`](#_mapcollection--callbackidentity-thisarg) * [`_.compact`](#_compactarray) * [`_.compose`](#_composefunc1-func2-) @@ -58,7 +58,7 @@ * [`_.isDate`](#_isdatevalue) * [`_.isElement`](#_iselementvalue) * [`_.isEmpty`](#_isemptyvalue) -* [`_.isEqual`](#_isequala-b--data) +* [`_.isEqual`](#_isequala-b--stacka-stackb) * [`_.isFinite`](#_isfinitevalue) * [`_.isFunction`](#_isfunctionvalue) * [`_.isNaN`](#_isnanvalue) @@ -71,10 +71,11 @@ * [`_.keys`](#_keysobject) * [`_.last`](#_lastarray--n-guard) * [`_.lastIndexOf`](#_lastindexofarray-value--fromindexarraylength-1) +* [`_.lateBind`](#_latebindobject-methodname--arg1-arg2-) * [`_.map`](#_mapcollection--callbackidentity-thisarg) * [`_.max`](#_maxarray--callback-thisarg) * [`_.memoize`](#_memoizefunc--resolver) -* [`_.merge`](#_mergeobject--source1-source2--indicator-data) +* [`_.merge`](#_mergeobject--source1-source2--indicator-stacka-stackb) * [`_.methods`](#_functionsobject) * [`_.min`](#_minarray--callback-thisarg) * [`_.mixin`](#_mixinobject) @@ -172,7 +173,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4260 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4249 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -184,7 +185,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3297 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3325 "View in source") [Ⓣ][1] Creates a new function that is restricted to executing only after it is called `n` times. @@ -212,13 +213,13 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3351 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3358 "View in source") [Ⓣ][1] -Creates a new function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. Lazy defined methods may be bound by passing the object they are bound to as `func` and the method name as `thisArg`. +Creates a new function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. #### Arguments -1. `func` *(Function|Object)*: The function to bind or the object the method belongs to. -2. `[thisArg]` *(Mixed)*: The `this` binding of `func` or the method name. +1. `func` *(Function)*: The function to bind. +2. `[thisArg]` *(Mixed)*: The `this` binding of `func`. 3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. #### Returns @@ -226,7 +227,6 @@ Creates a new function that, when called, invokes `func` with the `this` binding #### Example ```js -// basic bind var func = function(greeting) { return greeting + ' ' + this.name; }; @@ -234,25 +234,6 @@ var func = function(greeting) { func = _.bind(func, { 'name': 'moe' }, 'hi'); func(); // => 'hi moe' - -// lazy bind -var object = { - 'name': 'moe', - 'greet': function(greeting) { - return greeting + ' ' + this.name; - } -}; - -var func = _.bind(object, 'greet', 'hi'); -func(); -// => 'hi moe' - -object.greet = function(greeting) { - return greeting + ', ' + this.name + '!'; -}; - -func(); -// => 'hi, moe!' ``` * * * @@ -263,7 +244,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3421 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3388 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -294,7 +275,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4185 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4174 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -327,16 +308,17 @@ var youngest = _.chain(stooges) -### `_.clone(value, deep [, guard, data={}])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1089 "View in source") [Ⓣ][1] +### `_.clone(value, deep [, guard, stackA=[], stackB=[]])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1140 "View in source") [Ⓣ][1] -Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. If a value has a `clone` method it will be used to perform the clone. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned unless they have a custom `clone` method. +Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned. #### Arguments 1. `value` *(Mixed)*: The value to clone. 2. `deep` *(Boolean)*: A flag to indicate a deep clone. 3. `[guard]` *(Object)*: Internally used to allow this method to work with others like `_.map` without using their callback `index` argument for `deep`. -4. `[data={}]` *(Object)*: Internally used to track traversed objects to avoid circular references and indicate whether to perform a more thorough clone of non-object values. +4. `[stackA=[]]` *(Array)*: Internally used to track traversed source objects. +5. `[stackB=[]]` *(Array)*: Internally used to associate clones with their source counterparts. #### Returns *(Mixed)*: Returns the cloned `value`. @@ -369,7 +351,7 @@ shallow[0] === stooges[0]; ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2529 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2557 "View in source") [Ⓣ][1] Creates a new array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -393,7 +375,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3459 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3426 "View in source") [Ⓣ][1] Creates a new function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -420,7 +402,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1985 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2014 "View in source") [Ⓣ][1] Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -454,7 +436,7 @@ _.contains('curly', 'ur'); ### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2021 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2050 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -486,7 +468,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3492 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3459 "View in source") [Ⓣ][1] Creates a new function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -512,7 +494,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1194 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1233 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -538,7 +520,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3557 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3524 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -563,7 +545,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3537 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3504 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -590,7 +572,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2561 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2589 "View in source") [Ⓣ][1] Creates a new array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -615,7 +597,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3754 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3743 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -639,7 +621,7 @@ _.escape('Moe, Larry & Curly'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2041 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2070 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -668,7 +650,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1214 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1253 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -693,7 +675,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2061 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2090 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -722,7 +704,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2082 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2111 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -751,7 +733,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2598 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2626 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -780,7 +762,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2622 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2650 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -808,7 +790,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2109 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2138 "View in source") [Ⓣ][1] Iterates over a `collection`, executing the `callback` for each element in the `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -840,7 +822,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1244 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1283 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -876,7 +858,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1268 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1307 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -904,7 +886,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1285 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1324 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -931,7 +913,7 @@ _.functions(_); ### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2137 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2166 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -963,7 +945,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1308 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1347 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -988,7 +970,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3774 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3763 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -1013,7 +995,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2666 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2694 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1045,7 +1027,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2706 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2734 "View in source") [Ⓣ][1] Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. @@ -1071,7 +1053,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2728 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2756 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -1095,7 +1077,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invert(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1325 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1364 "View in source") [Ⓣ][1] Creates an object composed of the inverted keys and values of the given `object`. @@ -1119,7 +1101,7 @@ _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2165 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2194 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1148,7 +1130,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L917 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L969 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1175,7 +1157,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L943 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L995 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1202,7 +1184,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1344 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1383 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1226,7 +1208,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1361 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1400 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1250,7 +1232,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1378 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1417 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1274,7 +1256,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1403 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1442 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1303,15 +1285,16 @@ _.isEmpty(''); -### `_.isEqual(a, b [, data={}])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1444 "View in source") [Ⓣ][1] +### `_.isEqual(a, b [, stackA=[], stackB=[]])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1481 "View in source") [Ⓣ][1] -Performs a deep comparison between two values to determine if they are equivalent to each other. If a value has an `isEqual` method it will be used to perform the comparison. +Performs a deep comparison between two values to determine if they are equivalent to each other. #### Arguments 1. `a` *(Mixed)*: The value to compare. 2. `b` *(Mixed)*: The other value to compare. -3. `[data={}]` *(Object)*: Internally used track traversed objects to avoid circular references and indicate whether to perform a more thorough comparison of non-object values. +3. `[stackA=[]]` *(Object)*: Internally used track traversed `a` objects. +4. `[stackB=[]]` *(Object)*: Internally used track traversed `b` objects. #### Returns *(Boolean)*: Returns `true` if the values are equvalent, else `false`. @@ -1336,7 +1319,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1619 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1638 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1366,7 +1349,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L960 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1012 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1390,7 +1373,7 @@ _.isFunction(''.concat); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1674 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1693 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1423,7 +1406,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1697 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1716 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1450,7 +1433,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1714 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1733 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1474,7 +1457,7 @@ _.isNumber(8.4 * 5; ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1640 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1659 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -1501,7 +1484,7 @@ _.isObject(1); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1731 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1750 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1525,7 +1508,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1748 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1767 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1549,7 +1532,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1766 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1785 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1573,7 +1556,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1783 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1802 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of `object`. @@ -1597,7 +1580,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2771 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2799 "View in source") [Ⓣ][1] Gets the last element of the `array`. Pass `n` to return the lasy `n` elementsvof the `array`. @@ -1623,7 +1606,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2797 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2825 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1649,10 +1632,51 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); + + +### `_.lateBind(object, methodName [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3561 "View in source") [Ⓣ][1] + +Creates a new function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method + +#### Arguments +1. `object` *(Object)*: The object the method belongs to. +2. `methodName` *(String)*: The method name. +3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. + +#### Returns +*(Function)*: Returns the new bound function. + +#### Example +```js +var object = { + 'name': 'moe', + 'greet': function(greeting) { + return greeting + ' ' + this.name; + } +}; + +var func = _.bind(object, 'greet', 'hi'); +func(); +// => 'hi moe' + +object.greet = function(greeting) { + return greeting + ', ' + this.name + '!'; +}; + +func(); +// => 'hi, moe!' +``` + +* * * + + + + ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2200 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2229 "View in source") [Ⓣ][1] Creates a new array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -1684,7 +1708,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2837 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2865 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1716,7 +1740,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3580 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3583 "View in source") [Ⓣ][1] Creates a new function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1741,8 +1765,8 @@ var fibonacci = _.memoize(function(n) { -### `_.merge(object [, source1, source2, ..., indicator, data={}])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1825 "View in source") [Ⓣ][1] +### `_.merge(object [, source1, source2, ..., indicator, stackA=[], stackB=[]])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1845 "View in source") [Ⓣ][1] Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -1750,7 +1774,8 @@ Merges enumerable properties of the source object(s) into the `destination` obje 1. `object` *(Object)*: The destination object. 2. `[source1, source2, ...]` *(Object)*: The source objects. 3. `[indicator]` *(Object)*: Internally used to indicate that the `stack` argument is an array of traversed objects instead of another source object. -4. `[data={}]` *(Object)*: Internally used to track traversed objects to avoid circular references. +4. `[stackA=[]]` *(Array)*: Internally used to track traversed source objects. +5. `[stackB=[]]` *(Array)*: Internally used to associate clones with their source counterparts. #### Returns *(Object)*: Returns the destination object. @@ -1779,7 +1804,7 @@ _.merge(stooges, ages); ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2887 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2915 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1805,7 +1830,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3800 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3789 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1835,7 +1860,7 @@ _('curly').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3831 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3820 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1855,7 +1880,7 @@ var lodash = _.noConflict(); ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2936 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2964 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. @@ -1880,7 +1905,7 @@ _.object(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1878 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1907 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -1911,7 +1936,7 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3606 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3609 "View in source") [Ⓣ][1] Creates a new function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1937,7 +1962,7 @@ initialize(); ### `_.pairs(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1894 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1923 "View in source") [Ⓣ][1] Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. @@ -1961,9 +1986,9 @@ _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3641 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3644 "View in source") [Ⓣ][1] -Creates a new function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar `bind`, except it does **not** alter the `this` binding. +Creates a new function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `bind`, except it does **not** alter the `this` binding. #### Arguments 1. `func` *(Function)*: The function to partially apply arguments to. @@ -1988,7 +2013,7 @@ hi('moe'); ### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1925 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1954 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, picking the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -2019,7 +2044,7 @@ _.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2223 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2252 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -2050,7 +2075,7 @@ _.pluck(stooges, 'name'); ### `_.random(min, max)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3858 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3847 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. If no arguments are passed `_.random` will act as `Math.random`. @@ -2081,7 +2106,7 @@ _.random(); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2983 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3011 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -2119,7 +2144,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2251 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2280 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -2149,7 +2174,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2288 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2317 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -2180,7 +2205,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2344 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2373 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -2206,7 +2231,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3022 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3050 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2235,7 +2260,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3897 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3886 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2270,7 +2295,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3043 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3071 "View in source") [Ⓣ][1] Creates a new array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2294,7 +2319,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2368 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2397 "View in source") [Ⓣ][1] Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. @@ -2324,7 +2349,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2395 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2424 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -2353,7 +2378,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2425 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2454 "View in source") [Ⓣ][1] Creates a new array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2385,7 +2410,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3095 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3123 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with `1` argument; *(value)*. @@ -2426,7 +2451,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4212 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4201 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2456,7 +2481,7 @@ _.chain([1,2,3,200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3970 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3959 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: In the development build `_.template` utilizes sourceURLs for easier debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. See http://developer.chrome.com/trunk/extensions/sandboxingEval.html @@ -2521,7 +2546,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3677 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3666 "View in source") [Ⓣ][1] Creates a new function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2546,7 +2571,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4110 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4099 "View in source") [Ⓣ][1] Executes the `callback` function `n` times. The `callback` is bound to `thisArg` and invoked with `1` argument; *(index)*. @@ -2572,9 +2597,9 @@ _.times(3, function(n) { this.grantWish(n); }, genie); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2462 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2490 "View in source") [Ⓣ][1] -Converts the `collection`, to an array. Useful for converting the `arguments` object. +Converts the `collection`, to an array. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to convert. @@ -2596,7 +2621,7 @@ Converts the `collection`, to an array. Useful for converting the `arguments` ob ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4137 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4126 "View in source") [Ⓣ][1] Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -2620,7 +2645,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3136 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3164 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -2644,7 +2669,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3180 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3208 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -2683,7 +2708,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4155 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4144 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2707,7 +2732,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1955 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1984 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2731,7 +2756,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2499 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2527 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. @@ -2762,7 +2787,7 @@ _.where(stooges, { 'age': 40 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3229 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3257 "View in source") [Ⓣ][1] Creates a new array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2787,7 +2812,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3728 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3717 "View in source") [Ⓣ][1] Creates a new function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2816,7 +2841,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3262 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3290 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2847,7 +2872,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4230 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4219 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2868,7 +2893,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4247 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4236 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.js b/lodash.js index 47585cff4c..654c1f6060 100644 --- a/lodash.js +++ b/lodash.js @@ -499,7 +499,7 @@ ' callback = identity\n' + '}\n' + 'else if (thisArg) {\n' + - ' callback = iteratorBind(callback, thisArg)\n' + + ' callback = bindIterator(callback, thisArg)\n' + '}', 'inLoop': 'if (callback(value, index, collection) === false) return result' }; @@ -514,7 +514,7 @@ ' callback = function(value) { return value[valueProp] }\n' + '}\n' + 'else if (thisArg) {\n' + - ' callback = iteratorBind(callback, thisArg)\n' + + ' callback = bindIterator(callback, thisArg)\n' + '}', 'inLoop': 'prop = callback(value, index, collection);\n' + @@ -548,7 +548,7 @@ /** Reusable iterator options for `find`, `forEach`, `forIn`, and `forOwn` */ var forEachIteratorOptions = { - 'top': 'if (thisArg) callback = iteratorBind(callback, thisArg)' + 'top': 'if (thisArg) callback = bindIterator(callback, thisArg)' }; /** Reusable iterator options for `forIn` and `forOwn` */ @@ -582,7 +582,7 @@ 'if (!isFunc) {\n' + ' var props = concat.apply(ArrayProto, arguments)\n' + '} else if (thisArg) {\n' + - ' callback = iteratorBind(callback, thisArg)\n' + + ' callback = bindIterator(callback, thisArg)\n' + '}', 'inLoop': 'if (isFunc\n' + @@ -593,6 +593,21 @@ /*--------------------------------------------------------------------------*/ + /** + * Creates a bound iterator function that, when called, invokes `func` with + * the `this` binding of `thisArg` and the arguments (value, index, object). + * + * @private + * @param {Function} func The function to bind. + * @param {Mixed} [thisArg] The `this` binding of `func`. + * @returns {Function} Returns the new bound function. + */ + function bindIterator(func, thisArg) { + return function(value, index, object) { + return func.call(thisArg, value, index, object); + }; + } + /** * Creates a new function optimized for searching large arrays for a given `value`, * starting at `fromIndex`, using strict equality for comparisons, i.e. `===`. @@ -725,19 +740,19 @@ } // create the function factory var factory = Function( - 'arrayLikeClasses, ArrayProto, bind, compareAscending, concat, forIn, ' + - 'hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, ' + - 'isPlainObject, iteratorBind, objectClass, objectTypes, nativeKeys, ' + - 'propertyIsEnumerable, slice, stringClass, toString', + 'arrayLikeClasses, ArrayProto, bind, bindIterator, compareAscending, concat, ' + + 'forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, ' + + 'isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, ' + + 'slice, stringClass, toString', 'var callee = function(' + args + ') {\n' + iteratorTemplate(data) + '\n};\n' + 'return callee' ); // return the compiled function return factory( - arrayLikeClasses, ArrayProto, bind, compareAscending, concat, forIn, - hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, - isPlainObject, iteratorBind, objectClass, objectTypes, nativeKeys, - propertyIsEnumerable, slice, stringClass, toString + arrayLikeClasses, ArrayProto, bind, bindIterator, compareAscending, concat, + forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, + isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, + slice, stringClass, toString ); } @@ -807,17 +822,54 @@ /** * Creates a new function that, when called, invokes `func` with the `this` - * binding of `thisArg` and the arguments (value, index, object). + * binding of `thisArg` and prepends any `partailArgs` to the arguments passed + * to the bound function. * * @private - * @param {Function} func The function to bind. + * @param {Function|String} func The function to bind or the method name. * @param {Mixed} [thisArg] The `this` binding of `func`. + * @param {Array} partialArgs An array of arguments to be partially applied. * @returns {Function} Returns the new bound function. */ - function iteratorBind(func, thisArg) { - return function(value, index, object) { - return func.call(thisArg, value, index, object); - }; + function makeBound(func, thisArg, partialArgs) { + var isFunc = isFunction(func), + isPartial = !partialArgs, + methodName = func; + + // juggle arguments + if (isPartial) { + partialArgs = thisArg; + } + + function bound() { + // `Function#bind` spec + // http://es5.github.com/#x15.3.4.5 + var args = arguments, + thisBinding = isPartial ? this : thisArg; + + if (!isFunc) { + func = thisArg[methodName]; + } + if (partialArgs.length) { + args = args.length + ? partialArgs.concat(slice.call(args)) + : partialArgs; + } + if (this instanceof bound) { + // get `func` instance if `bound` is invoked in a `new` expression + noop.prototype = func.prototype; + thisBinding = new noop; + + // mimic the constructor's `return` behavior + // http://es5.github.com/#x13.2.2 + var result = func.apply(thisBinding, args); + return result && objectTypes[typeof result] + ? result + : thisBinding + } + return func.apply(thisBinding, args); + } + return bound; } /** @@ -1910,7 +1962,7 @@ ' if (prop in object) result[prop] = object[prop]\n' + ' }\n' + '} else {\n' + - ' if (thisArg) callback = iteratorBind(callback, thisArg)', + ' if (thisArg) callback = bindIterator(callback, thisArg)', 'inLoop': 'if (callback(value, index, object)) result[index] = value', 'bottom': '}' @@ -2230,7 +2282,7 @@ 'init': 'accumulator', 'top': 'var noaccum = arguments.length < 3;\n' + - 'if (thisArg) callback = iteratorBind(callback, thisArg)', + 'if (thisArg) callback = bindIterator(callback, thisArg)', 'beforeLoop': { 'array': 'if (noaccum) result = iteratee[++index]' }, @@ -2271,7 +2323,7 @@ noaccum = arguments.length < 3; if(thisArg) { - callback = iteratorBind(callback, thisArg); + callback = bindIterator(callback, thisArg); } // Opera 10.53-10.60 JITted `length >>> 0` returns the wrong value for negative numbers if (length > -1 && length === length >>> 0) { @@ -2830,7 +2882,7 @@ return result; } if (thisArg) { - callback = iteratorBind(callback, thisArg); + callback = bindIterator(callback, thisArg); } while (++index < length) { current = callback(array[index], index, array); @@ -2880,7 +2932,7 @@ return result; } if (thisArg) { - callback = iteratorBind(callback, thisArg); + callback = bindIterator(callback, thisArg); } while (++index < length) { current = callback(array[index], index, array); @@ -3172,7 +3224,7 @@ if (!callback) { callback = identity; } else if (thisArg) { - callback = iteratorBind(callback, thisArg); + callback = bindIterator(callback, thisArg); } while (++index < length) { computed = callback(array[index], index, array); @@ -3284,19 +3336,17 @@ /** * Creates a new function that, when called, invokes `func` with the `this` * binding of `thisArg` and prepends any additional `bind` arguments to those - * passed to the bound function. Lazy defined methods may be bound by passing - * the object they are bound to as `func` and the method name as `thisArg`. + * passed to the bound function. * * @static * @memberOf _ * @category Functions - * @param {Function|Object} func The function to bind or the object the method belongs to. - * @param {Mixed} [thisArg] The `this` binding of `func` or the method name. + * @param {Function} func The function to bind. + * @param {Mixed} [thisArg] The `this` binding of `func`. * @param {Mixed} [arg1, arg2, ...] Arguments to be partially applied. * @returns {Function} Returns the new bound function. * @example * - * // basic bind * var func = function(greeting) { * return greeting + ' ' + this.name; * }; @@ -3304,72 +3354,13 @@ * func = _.bind(func, { 'name': 'moe' }, 'hi'); * func(); * // => 'hi moe' - * - * // lazy bind - * var object = { - * 'name': 'moe', - * 'greet': function(greeting) { - * return greeting + ' ' + this.name; - * } - * }; - * - * var func = _.bind(object, 'greet', 'hi'); - * func(); - * // => 'hi moe' - * - * object.greet = function(greeting) { - * return greeting + ', ' + this.name + '!'; - * }; - * - * func(); - * // => 'hi, moe!' */ function bind(func, thisArg) { - var methodName, - isFunc = isFunction(func); - - // juggle arguments - if (!isFunc) { - methodName = thisArg; - thisArg = func; - } // use `Function#bind` if it exists and is fast // (in V8 `Function#bind` is slower except when partially applied) - else if (isBindFast || (nativeBind && arguments.length > 2)) { - return nativeBind.call.apply(nativeBind, arguments); - } - - var partialArgs = slice.call(arguments, 2); - - function bound() { - // `Function#bind` spec - // http://es5.github.com/#x15.3.4.5 - var args = arguments, - thisBinding = thisArg; - - if (!isFunc) { - func = thisArg[methodName]; - } - if (partialArgs.length) { - args = args.length - ? partialArgs.concat(slice.call(args)) - : partialArgs; - } - if (this instanceof bound) { - // get `func` instance if `bound` is invoked in a `new` expression - noop.prototype = func.prototype; - thisBinding = new noop; - - // mimic the constructor's `return` behavior - // http://es5.github.com/#x13.2.2 - var result = func.apply(thisBinding, args); - return result && objectTypes[typeof result] - ? result - : thisBinding - } - return func.apply(thisBinding, args); - } - return bound; + return isBindFast || (nativeBind && arguments.length > 2) + ? nativeBind.call.apply(nativeBind, arguments) + : makeBound(func, thisArg, slice.call(arguments, 2)); } /** @@ -3535,6 +3526,42 @@ return setTimeout(function() { return func.apply(undefined, args); }, 1); } + /** + * Creates a new function that, when called, invokes `object[methodName]` and + * prepends any additional `lateBind` arguments to those passed to the bound + * function. This method + * + * @static + * @memberOf _ + * @category Functions + * @param {Object} object The object the method belongs to. + * @param {String} methodName The method name. + * @param {Mixed} [arg1, arg2, ...] Arguments to be partially applied. + * @returns {Function} Returns the new bound function. + * @example + * + * var object = { + * 'name': 'moe', + * 'greet': function(greeting) { + * return greeting + ' ' + this.name; + * } + * }; + * + * var func = _.bind(object, 'greet', 'hi'); + * func(); + * // => 'hi moe' + * + * object.greet = function(greeting) { + * return greeting + ', ' + this.name + '!'; + * }; + * + * func(); + * // => 'hi, moe!' + */ + function lateBind(object, methodName) { + return makeBound(methodName, object, slice.call(arguments, 2)); + } + /** * Creates a new function that memoizes the result of `func`. If `resolver` is * passed, it will be used to determine the cache key for storing the result @@ -3599,7 +3626,7 @@ /** * Creates a new function that, when called, invokes `func` with any additional * `partial` arguments prepended to those passed to the new function. This method - * is similar `bind`, except it does **not** alter the `this` binding. + * is similar to `bind`, except it does **not** alter the `this` binding. * * @static * @memberOf _ @@ -3615,21 +3642,7 @@ * // => 'hi: moe' */ function partial(func) { - var args = slice.call(arguments, 1), - argsLength = args.length; - - return function() { - var result, - others = arguments; - - if (others.length) { - args.length = argsLength; - push.apply(args, others); - } - result = args.length == 1 ? func.call(this, args[0]) : func.apply(this, args); - args.length = argsLength; - return result; - }; + return makeBound(func, slice.call(arguments, 1)); } /** @@ -4288,6 +4301,7 @@ lodash.keys = keys; lodash.last = last; lodash.lastIndexOf = lastIndexOf; + lodash.lateBind = lateBind; lodash.map = map; lodash.max = max; lodash.memoize = memoize; diff --git a/lodash.min.js b/lodash.min.js index ead0d5489e..b139e6dc43 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -2,41 +2,40 @@ Lo-Dash 0.7.0 lodash.com/license Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE */ -;(function(e,t){function s(e){return new o(e)}function o(e){if(e&&e.__wrapped__)return e;this.__wrapped__=e}function u(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||V),s=i?{}:e;if(i)for(var o=t-1;++on;n++)t+="i='"+u.p[n]+"';if(","constructor"==u.p[n]&&(t+="!(f&&f.prototype===j)&&"),t+="g.call(j,i)){A=j[i];"+u.m.i+"}"}if(u.c||u.n)t+="}"}return t+=u.e+";return u",Function("D,E,F,I,e,K,g,h,N,P,R,T,U,k,X,Y,m,r,w,x,z","var G=function("+e+"){"+t+"};return G")(Xt,q,_,f,ft,hn,lt,D,k,b,un,w,an,p,Lt,Kt,bt,ht,pt,Ot,dt)}function f(e,n){var r=e.c,i=n.c,e=e.b,n=n.b;if(e!==n){if(e>n||e===t)return 1;if(e";var n=at.length;return at[n]="'+__e("+t+")+'",ot+n+ut}function m(e,t,n,i){return i?(e=at.length,at[e]="';"+i+";__p+='",ot+e+ut):t?v(r,t):g(r,n)}function g(e,t){if(e&&J.test(t))return"";var n=at.length;return at[n]="'+((__t=("+t+"))==null?'':__t)+'",ot+n+ut}function y(e){return Jt[e]}function b(e){return dt -.call(e)==xt}function w(e){return"function"==typeof e}function E(e,t){var n=i;if(!e||"object"!=typeof e||!t&&b(e))return n;var r=e.constructor;return(!qt||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!w(r)||r instanceof r)?Ht?(hn(e,function(e,t,r){return n=!lt.call(r,t),i}),n===i):(hn(e,function(e,t){n=t}),n===i||lt.call(e,n)):n}function S(e,t,s,o){if(e==r)return e;s&&(t=i),o||(o={e:r}),o.t==r&&(o.t=!(!R.clone&&!z.clone&&!W.clone));if(((s=Kt[typeof e])||o.t)&&e.clone&&w(e.clone))return o -.t=r,e.clone(t);if(s){var u=dt.call(e);if(!Vt[u]||jt&&b(e))return e;var a=u==Tt,s=a||(u==Lt?an(e,n):s)}if(!s||!t)return s?a?pt.call(e):cn({},e):e;s=e.constructor;switch(u){case Nt:return new s(e==n);case Ct:return new s(+e);case kt:case Ot:return new s(e);case At:return s(e.source,Z.exec(e))}for(var f=o.a||(o.a=[]),l=o.d||(o.d=[]),u=f.length;u--;)if(l[u]==e)return f[u];var c=a?s(u=e.length):{};f.push(c),l.push(e);if(a)for(a=-1;++a++o;)if(h=st[o],lt.call(e,h)&&(!lt.call(t,h)||!x(e[h],t[h],s)))return i;return n}function T(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(-1>>0){var o=It&&dt.call(e)==Ot?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=gn(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function N(e,t,n){if(e)return t==r||n?e[0] -:pt.call(e,0,t)}function C(e,t){var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?wt(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=p(t,n));++sr&&(r=n,i=e[s]);return i} -function A(e,t,n){return e?pt.call(e,t==r||n?1:t):[]}function O(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=_(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]k(a,r))a.push(r),s.push(e[o]);return s}function _(e,t){function n(){var o=arguments,u=t;return i|| -(e=t[r]),s.length&&(o=o.length?s.concat(pt.call(o)):s),this instanceof n?(d.prototype=e.prototype,u=new d,(o=e.apply(u,o))&&Kt[typeof o]?o:u):e.apply(u,o)}var r,i=w(e);if(i){if(Ut||vt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,K=/&(?:amp|lt|gt|quot|#x27);/g,Q=/\b__p\+='';/g,G=/\b(__p\+=)''\+/g,Y=/(__e\(.*?\)|\b__t\))\+'';/g,Z=/\w*$/,et=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,tt= -RegExp("^"+(U.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),nt=/__token(\d+)__/g,rt=/[&<>"']/g,it=/['\n\r\t\u2028\u2029\\]/g,st="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),ot="__token",ut="__",at=[],ft=q.concat,lt=U.hasOwnProperty,ct=q.push,ht=U.propertyIsEnumerable,pt=q.slice,dt=U.toString,vt=tt.test(vt=pt.bind)&&vt,mt=Math.floor,gt=tt.test(gt=Array.isArray)&>,yt=e.isFinite,bt=tt.test -(bt=Object.keys)&&bt,wt=Math.max,Et=Math.min,St=Math.random,xt="[object Arguments]",Tt="[object Array]",Nt="[object Boolean]",Ct="[object Date]",kt="[object Number]",Lt="[object Object]",At="[object RegExp]",Ot="[object String]",Mt=e.clearTimeout,_t=e.setTimeout,Dt,Pt,Ht,Bt=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in arguments)Bt=!r;Dt=4>(n+"").length,Ht="x"!=n[0],Pt=(n.splice.call(t,0,1),t[0])})(1);var jt=!b(arguments -),Ft="x"!=pt.call("x")[0],It="xx"!="x"[0]+Object("x")[0];try{var qt=("[object Object]",dt.call(e.document||0)==Lt)}catch(Rt){}var Ut=vt&&/\n|Opera/.test(vt+dt.call(e.opera)),zt=bt&&/^.+$|true/.test(bt+!!e.attachEvent),Wt=!Ut,Xt={};Xt[Nt]=Xt[Ct]=Xt["[object Function]"]=Xt[kt]=Xt[Lt]=Xt[At]=i,Xt[xt]=Xt[Tt]=Xt[Ot]=n;var Vt={};Vt[xt]=Vt["[object Function]"]=i,Vt[Tt]=Vt[Nt]=Vt[Ct]=Vt[kt]=Vt[Lt]=Vt[At]=Vt[Ot]=n;var $t={"&":"&","<":"<",">":">",'"':""","'":"'"},Jt={"&":"&","<":"<" -,">":">",""":'"',"'":"'"},Kt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Qt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Gt={a:"d,c,y",j:"d",q:"if(!c)c=h;else if(y)c=k(c,y)",i:"if(c(A,i,d)===false)return u"},Yt={j:"{}",q:"var q;if(typeof c!='function'){var ii=c;c=function(A){return A[ii]}}else if(y)c=k(c,y)" -,i:"q=c(A,i,d);(g.call(u,q)?u[q]++:u[q]=1)"},Zt={j:"true",i:"if(!c(A,i,d))return!u"},en={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1&&l===l>>>0&&T(A.splice)))return!l",i:{l:"return false"}}),gn=bt?function(e){var t=typeof e;return"function"==t&&ht.call(e,"prototype")?fn(e):e&&Kt[t]?bt(e):[]}:fn,yn=a(en,{a:"n,ee,O",q:"var Q,dd=O==U,J=dd?arguments[3]:{g:[],d:[]};for(var a=1,b=dd?2:arguments.length;a-1"},i:"if(A===hh)return true"}),Tn=a(Gt,Yt),Nn=a(Gt,Zt),Cn=a(Gt,tn),kn=a(Gt,nn,{j:"",i:"if(c(A,i,d))return A"}),Ln=a(Gt,nn),An=a(Gt,Yt,{i:"q=c(A,i,d);(g.call(u,q)?u[q]:u[q]=[]).push(A)" -}),On=a(sn,{a:"d,V",q:"var C=w.call(arguments,2),S=typeof V=='function'",i:{b:"u[i]=(S?V:A[V]).apply(A,C)",l:"u"+(zt?"[o]=":".push")+"((S?V:A[V]).apply(A,C))"}}),Mn=a(Gt,sn),_n=a(sn,{a:"d,bb",i:{b:"u[i]=A[bb]",l:"u"+(zt?"[o]=":".push")+"(A[bb])"}}),Dn=a({a:"d,c,B,y",j:"B",q:"var W=arguments.length<3;if(y)c=k(c,y)",d:{b:"if(W)u=j[++i]"},i:{b:"u=c(u,A,i,d)",l:"u=W?(W=false,A):c(u,A,i,d)"}}),Pn=a(Gt,tn,{i:"!"+tn.i}),Hn=a(Gt,Zt,{j:"false",i:Zt.i.replace("!","")}),Bn=a(Gt,Yt,sn,{i:{b:"u[i]={b:c(A,i,d),c:i,f:A}" -,l:"u"+(zt?"[o]=":".push")+"({b:c(A,i,d),c:i,f:A})"},e:"u.sort(I);l=u.length;while(l--)u[l]=u[l].f"}),jn=a(tn,{a:"d,aa",q:"var t=[];K(aa,function(A,q){t.push(q)});var cc=t.length",i:"for(var q,Z=true,s=0;s1){for(var i=1;ie?t():function(){if(1>--e)return t.apply -(this,arguments)}},s.bind=_,s.bindAll=Fn,s.chain=function(e){return e=new o(e),e.__chain__=n,e},s.clone=S,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nk(t,n)){for(var a=1;an?wt(0,r+n):Et(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=Mn,s.max=L,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return lt.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=yn,s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s>>0?t:gn(e).length},s.some=Hn,s.sortBy=Bn,s.sortedIndex=O,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var e=e+"",o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,h=s.templateSettings,p=n=n.variable||h.variable;o==r&&(o=h.escape),a==r&&(a=h.evaluate||i),f==r&&(f=h.interpolate),o&&(e=e.replace(o,v)),f&&(e=e.replace(f,g)),a!=H&&(H=a,F=RegExp("|"+(a?"|"+a.source:""),"g")),o=at.length,e=e.replace(F,m),o=o!=at.length,e="__p += '"+e -.replace(it,c).replace(nt,l)+"';",at.length=0,p||(n=B||"obj",o?e="with("+n+"){"+e+"}":(n!=B&&(B=n,j=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(et,"$&"+n+".").replace(j,"$1__d"))),e=(o?e.replace(Q,""):e).replace(G,"$1").replace(Y,"$1;"),e="function("+n+"){"+(p?"":n+"||("+n+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(p?"":",__d="+n+"."+n+"||"+n)+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(d){throw d -.source=e,d}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,s=e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=_t(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(Ft?dt.call(e)==Ot:"string"==typeof e)?e.split(""):pt.call -(e):Sn(e)},s.unescape=function(e){return e==r?"":(e+"").replace(K,y)},s.union=function(){for(var e=-1,t=[],n=ft.apply(t,arguments),r=n.length;++ek(t,n[e])&&t.push(n[e]);return t},s.uniq=M,s.uniqueId=function(e){var t=X++;return e?e+t:t},s.values=Sn,s.where=jn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n=(n||W),s=i?{}:e;if(i)for(var o=t-1;++on;n++)t+="j='"+a.p[n]+"';if(","constructor"==a.p[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){A=k[j];"+a.m.i+"}"}if(a.c||a.n)t+="}"}return t+=a.e+";return u",Function("D,E,F,c,I,f,J,h,i,M,O,Q,S,T,W,X,m,r,w,x,z","var G=function("+e+"){"+t+"};return G")(zt,R,D,u,l,ut,ln,at,P,L,w,sn,E,on,Ct,$t,gt,lt,ct,Lt,ht)}function l(e,n){var r=e.b,i=n.b,e=e.a,n=n.a;if(e!==n){if(e>n|| +e===t)return 1;if(e";var n=ot.length;return ot[n]="'+__e("+ +t+")+'",it+n+st}function g(e,t,n,i){return i?(e=ot.length,ot[e]="';"+i+";__p+='",it+e+st):t?m(r,t):y(r,n)}function y(e,t){if(e&&V.test(t))return"";var n=ot.length;return ot[n]="'+((__t=("+t+"))==null?'':__t)+'",it+n+st}function b(e){return Vt[e]}function w(e){return ht.call(e)==Et}function E(e){return"function"==typeof e}function S(e,t){var n=i;if(!e||"object"!=typeof e||!t&&w(e))return n;var r=e.constructor;return(!Ft||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!E(r)||r instanceof +r)?Dt?(ln(e,function(e,t,r){return n=!at.call(r,t),i}),n===i):(ln(e,function(e,t){n=t}),n===i||at.call(e,n)):n}function x(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=$t[typeof e]){var a=ht.call(e);if(!Wt[a]||Ht&&w(e))return e;var f=a==St,s=f||(a==Ct?on(e,n):s)}if(!s||!t)return s?f?ct.call(e):fn({},e):e;s=e.constructor;switch(a){case xt:return new s(e==n);case Tt:return new s(+e);case Nt:case Lt:return new s(e);case kt:return s(e.source,G.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u +[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=rt[u],at.call(e,c)&&(!at.call(t,c)||!T(e[c],t[c],s,o)))return i;return n}function N(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=u(t,r));if(-1>>0){var o=jt&&ht.call(e)==Lt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=vn(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function C(e,t,n){if(e)return t==r||n?e[0]:ct.call(e,0,t)}function k(e,t){var n=[];if(!e)return n;for( +var r,i=-1,s=e.length;++in?yt(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=u(t,n));++sr&&(r=n,i=e[s]);return i}function O(e,t,n){return e?ct.call(e,t==r||n?1:t):[]}function M +(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=D(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]L(f,r))f.push(r),s.push(e[o]);return s}function D(e,t){return qt||pt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,$=/&(?:amp|lt|gt|quot|#x27);/g +,J=/\b__p\+='';/g,K=/\b(__p\+=)''\+/g,Q=/(__e\(.*?\)|\b__t\))\+'';/g,G=/\w*$/,Y=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,Z=RegExp("^"+(U.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),et=/__token(\d+)__/g,tt=/[&<>"']/g,nt=/['\n\r\t\u2028\u2029\\]/g,rt="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),it="__token",st="__",ot=[],ut=R.concat,at=U.hasOwnProperty,ft=R.push,lt=U.propertyIsEnumerable +,ct=R.slice,ht=U.toString,pt=Z.test(pt=ct.bind)&&pt,dt=Math.floor,vt=Z.test(vt=Array.isArray)&&vt,mt=e.isFinite,gt=Z.test(gt=Object.keys)&>,yt=Math.max,bt=Math.min,wt=Math.random,Et="[object Arguments]",St="[object Array]",xt="[object Boolean]",Tt="[object Date]",Nt="[object Number]",Ct="[object Object]",kt="[object RegExp]",Lt="[object String]",At=e.clearTimeout,Ot=e.setTimeout,Mt,_t,Dt,Pt=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e) +n.push(r);for(r in arguments)Pt=!r;Mt=4>(n+"").length,Dt="x"!=n[0],_t=(n.splice.call(t,0,1),t[0])})(1);var Ht=!w(arguments),Bt="x"!=ct.call("x")[0],jt="xx"!="x"[0]+Object("x")[0];try{var Ft=("[object Object]",ht.call(e.document||0)==Ct)}catch(It){}var qt=pt&&/\n|Opera/.test(pt+ht.call(e.opera)),Rt=gt&&/^.+$|true/.test(gt+!!e.attachEvent),Ut=!qt,zt={};zt[xt]=zt[Tt]=zt["[object Function]"]=zt[Nt]=zt[Ct]=zt[kt]=i,zt[Et]=zt[St]=zt[Lt]=n;var Wt={};Wt[Et]=Wt["[object Function]"]=i,Wt[St]=Wt[xt]=Wt[Tt]= +Wt[Nt]=Wt[Ct]=Wt[kt]=Wt[Lt]=n;var Xt={"&":"&","<":"<",">":">",'"':""","'":"'"},Vt={"&":"&","<":"<",">":">",""":'"',"'":"'"},$t={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Kt={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y)d=c(d,y)" +,i:"if(d(A,j,e)===false)return u"},Qt={j:"{}",q:"var q;if(typeof d!='function'){var hh=d;d=function(A){return A[hh]}}else if(y)d=c(d,y)",i:"q=d(A,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},Gt={j:"true",i:"if(!d(A,j,e))return!u"},Yt={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1&&l===l>>>0&&S(A.splice)))return!l",i:{l:"return false"}}),vn=gt?function(e){var t=typeof e;return"function"==t&<.call(e,"prototype")?un(e):e&&$t[t]?gt(e):[]}:un,mn=f(Yt,{a:"n,cc,N",q:"var b,P,dd,ee,C=arguments,a=0;if(N==T){b=2;dd=C[3];ee=C[4]}else{b=C.length;dd=[];ee=[]}while(++a-1"},i:"if(A===gg)return true"}),Sn=f(Kt,Qt),xn=f(Kt,Gt),Tn=f(Kt,Zt),Nn=f(Kt,en,{j:"",i:"if(d(A,j,e))return A"}),Cn=f(Kt,en),kn=f(Kt,Qt,{i:"q=d(A,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(A)"}),Ln=f(nn,{a:"e,U",q:"var C=w.call(arguments,2),R=typeof U=='function'",i:{b:"u[j]=(R?U:A[U]).apply(A,C)",l:"u"+(Rt?"[o]=":".push")+"((R?U:A[U]).apply(A,C))"}}),An=f(Kt,nn),On=f(nn,{a:"e,aa",i:{b:"u[j]=A[aa]",l:"u"+(Rt?"[o]=":".push")+"(A[aa])"} +}),Mn=f({a:"e,d,B,y",j:"B",q:"var V=arguments.length<3;if(y)d=c(d,y)",d:{b:"if(V)u=k[++j]"},i:{b:"u=d(u,A,j,e)",l:"u=V?(V=false,A):d(u,A,j,e)"}}),_n=f(Kt,Zt,{i:"!"+Zt.i}),Dn=f(Kt,Gt,{j:"false",i:Gt.i.replace("!","")}),Pn=f(Kt,Qt,nn,{i:{b:"u[j]={a:d(A,j,e),b:j,c:A}",l:"u"+(Rt?"[o]=":".push")+"({a:d(A,j,e),b:j,c:A})"},e:"u.sort(I);l=u.length;while(l--)u[l]=u[l].c"}),Hn=f(Zt,{a:"e,Z",q:"var t=[];J(Z,function(A,q){t.push(q)});var bb=t.length",i:"for(var q,Y=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=D,s.bindAll=Bn,s.chain=function(e){return e=new o(e),e.__chain__=n,e},s.clone=x,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nL(t,n)){for(var u=1;un?yt(0,r+n):bt(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return d(t,e,ct.call(arguments,2))},s.map=An,s.max=A,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments) +:arguments[0];return at.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=mn,s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s>>0?t:vn(e).length},s.some=Dn,s.sortBy=Pn,s.sortedIndex=M,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var e=e+"",o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,l=s.templateSettings,p=n=n.variable||l.variable;o==r&&(o=l.escape),a==r&&(a=l.evaluate||i),f==r&&(f=l.interpolate),o&&(e=e.replace(o,m)) +,f&&(e=e.replace(f,y)),a!=B&&(B=a,I=RegExp("|"+(a?"|"+a.source:""),"g")),o=ot.length,e=e.replace(I,g),o=o!=ot.length,e="__p += '"+e.replace(nt,h).replace(et,c)+"';",ot.length=0,p||(n=j||"obj",o?e="with("+n+"){"+e+"}":(n!=j&&(j=n,F=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(Y,"$&"+n+".").replace(F,"$1__d"))),e=(o?e.replace(J,""):e).replace(K,"$1").replace(Q,"$1;"),e="function("+n+"){"+(p?"":n+"||("+n+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}" +:(p?"":",__d="+n+"."+n+"||"+n)+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(d){throw d.source=e,d}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,s=e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=Ot(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(Bt?ht.call(e)==Lt:"string"==typeof e)?e.split(""):ct.call(e):wn(e)},s.unescape=function(e){return e==r?"":(e+"").replace($,b)},s.union=function(){for(var e=-1,t=[],n=ut.apply(t,arguments),r=n.length;++eL(t,n[e])&&t.push(n[e]);return t},s.uniq=_,s.uniqueId=function(e){var t=z++;return e?e+t:t},s.values=wn,s.where=Hn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=a(arguments,1,20);++n2;a==null&&(a= +(function(){var s=this,L=s._,o={},k=Array.prototype,p=Object.prototype,M=k.push,h=k.slice,q=k.concat,l=p.toString,N=p.hasOwnProperty,y=k.forEach,z=k.map,A=k.reduce,B=k.reduceRight,C=k.filter,D=k.every,E=k.some,r=k.indexOf,F=k.lastIndexOf,p=Array.isArray,O=Object.keys,t=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._= +b):s._=b;b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,c,d){if(a!=null)if(y&&a.forEach===y)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,g=a.length;e2;a==null&&(a= []);if(A&&a.reduce===A){e&&(c=b.bind(c,e));return g?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,h){if(g)d=c.call(e,d,a,b,h);else{d=a;g=true}});if(!g)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var g=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));return g?a.reduceRight(c,d):a.reduceRight(c)}var f=b.toArray(a).reverse();e&&!g&&(c=b.bind(c,e));return g?b.reduce(f,c,d,e):b.reduce(f,c)};b.find=b.detect= function(a,c,b){var e;G(a,function(a,f,i){if(c.call(b,a,f,i)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(C&&a.filter===C)return a.filter(c,b);j(a,function(a,f,i){c.call(b,a,f,i)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,f,i){c.call(b,a,f,i)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(D&&a.every===D)return a.every(c,d);j(a,function(a, -b,i){if(!(e=e&&c.call(d,a,b,i)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,i){if(e||(e=c.call(d,a,b,i)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=h.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a, +b,i){if(!(e=e&&c.call(d,a,b,i)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,i){if(e||(e=c.call(d,a,b,i)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(r&&a.indexOf===r)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=h.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a, d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,i){b=c?c.call(d,a,b,i):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a, function(a,b,i){b=c?c.call(d,a,b,i):a;bd?1:0}),"value")};var H=function(a,c){return b.isFunction(c)?c:function(a){return a[c]}}, I=function(a,c,b){var e={},g=H(a,c);j(a,function(a,c){var h=g(a,c);b(e,h,a)});return e};b.groupBy=function(a,c){return I(a,c,function(a,c,b){(a[c]||(a[c]=[])).push(b)})};b.countBy=function(a,c){return I(a,c,function(a,c){a[c]||(a[c]=0);a[c]++})};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var c=d(c),e=0,g=a.length;e>1;d(a[f])=0})})};b.difference=function(a){var c=r(h.call(arguments,1),true,[]);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=h.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e= +0})})};b.difference=function(a){var c=q.apply(k,h.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=h.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}}; -b.keys=N||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(h.call(arguments,1),function(b){for(var d in b)a[d]= -b[d]});return a};b.pick=function(a){var c={},d=b.flatten(h.call(arguments,1));j(d,function(b){b in a&&(c[b]=a[b])});return c};b.omit=function(a){var c={},d=b.flatten(h.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){j(h.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d,e){if(a===c)return a!== -0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var g=l.call(a);if(g!=l.call(c))return false;switch(g){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==c.source&&a.global==c.global&& -a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return e[f]==c;d.push(a);e.push(c);var f=0,i=true;if(g=="[object Array]"){f=a.length;if(i=f==c.length)for(;f--;)if(!(i=u(a[f],c[f],d,e)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)){f++;if(!(i=b.has(c,h)&&u(a[h],c[h],d,e)))break}if(i){for(h in c)if(b.has(c,h)&&!f--)break;i=!f}}d.pop(); -e.pop();return i};b.isEqual=function(a,b){return u(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};j("Arguments,Function,String,Number,Date,RegExp".split(","),function(a){b["is"+a]=function(b){return l.call(b)=="[object "+a+"]"}}); -b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return M.call(a,b)};b.noConflict=function(){s._=K;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e":">",'"':""","'":"'","/":"/"}};m.unescape=b.invert(m.escape);var O={escape:RegExp("["+b.keys(m.escape).join("")+"]","g"),unescape:RegExp("("+b.keys(m.unescape).join("|")+")","g")};b.each(["escape","unescape"],function(a){b[a]=function(b){return b==null?"":(""+b).replace(O[a],function(b){return m[a][b]})}});b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)? -d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){var d=b[c]=a[c];b.prototype[c]=function(){var a=h.call(arguments);a.unshift(this._wrapped);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var P=0;b.uniqueId=function(a){var b=P++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var v=/.^/,n={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},w;for(w in n)n[n[w]]=w;var Q=/\\|'|\r|\n|\t|\u2028|\u2029/g, -R=/\\(\\|'|r|n|t|u2028|u2029)/g,x=function(a){return a.replace(R,function(a,b){return n[b]})};b.template=function(a,c,d){d=b.defaults({},d,b.templateSettings);a="__p+='"+a.replace(Q,function(a){return"\\"+n[a]}).replace(d.escape||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':_.escape(__t))+\n'"}).replace(d.interpolate||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':__t)+\n'"}).replace(d.evaluate||v,function(a,b){return"';\n"+x(b)+"\n__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+ -a+"}\n");a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{var e=new Function(d.variable||"obj","_",a)}catch(g){g.source=a;throw g;}if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c=k[a];b.prototype[a]=function(){var d=this._wrapped;c.apply(d, -arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain():d}});j(["concat","join","slice"],function(a){var c=k[a];b.prototype[a]=function(){var a=c.apply(this._wrapped,arguments);return this._chain?b(a).chain():a}});b.extend(b.prototype,{chain:function(){this._chain=true;return this},value:function(){return this._wrapped}})}).call(this); +b.keys=O||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(h.call(arguments,1),function(b){for(var d in b)a[d]= +b[d]});return a};b.pick=function(a){var b={},d=q.apply(k,h.call(arguments,1));j(d,function(d){d in a&&(b[d]=a[d])});return b};b.omit=function(a){var c={},d=q.apply(k,h.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){j(h.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d,e){if(a===c)return a!== +0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;var g=l.call(a);if(g!=l.call(c))return false;switch(g){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f= +d.length;f--;)if(d[f]==a)return e[f]==c;d.push(a);e.push(c);var f=0,i=true;if(g=="[object Array]"){f=a.length;if(i=f==c.length)for(;f--;)if(!(i=u(a[f],c[f],d,e)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)){f++;if(!(i=b.has(c,h)&&u(a[h],c[h],d,e)))break}if(i){for(h in c)if(b.has(c,h)&&!f--)break;i=!f}}d.pop();e.pop();return i};b.isEqual=function(a,b){return u(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)|| +b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};j("Arguments,Function,String,Number,Date,RegExp".split(","),function(a){b["is"+a]=function(b){return l.call(b)=="[object "+a+"]"}});b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&& +isFinite(a)};b.isNaN=function(a){return b.isNumber(a)&&a!=+a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return N.call(a,b)};b.noConflict=function(){s._=L;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e":">", +'"':""","'":"'","/":"/"}};m.unescape=b.invert(m.escape);var P={escape:RegExp("["+b.keys(m.escape).join("")+"]","g"),unescape:RegExp("("+b.keys(m.unescape).join("|")+")","g")};b.each(["escape","unescape"],function(a){b[a]=function(b){return b==null?"":(""+b).replace(P[a],function(b){return m[a][b]})}});b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){var d=b[c]=a[c];b.prototype[c]=function(){var a= +h.call(arguments);a.unshift(this._wrapped);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var Q=0;b.uniqueId=function(a){var b=Q++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var v=/.^/,n={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},w;for(w in n)n[n[w]]=w;var R=/\\|'|\r|\n|\t|\u2028|\u2029/g,S=/\\(\\|'|r|n|t|u2028|u2029)/g,x=function(a){return a.replace(S,function(a,b){return n[b]})};b.template= +function(a,c,d){d=b.defaults({},d,b.templateSettings);a="__p+='"+a.replace(R,function(a){return"\\"+n[a]}).replace(d.escape||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':_.escape(__t))+\n'"}).replace(d.interpolate||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':__t)+\n'"}).replace(d.evaluate||v,function(a,b){return"';\n"+x(b)+"\n__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+a+"}\n");a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+ +a+"return __p;\n";try{var e=new Function(d.variable||"obj","_",a)}catch(g){g.source=a;throw g;}if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c=k[a];b.prototype[a]=function(){var d=this._wrapped;c.apply(d,arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain(): +d}});j(["concat","join","slice"],function(a){var c=k[a];b.prototype[a]=function(){var a=c.apply(this._wrapped,arguments);return this._chain?b(a).chain():a}});b.extend(b.prototype,{chain:function(){this._chain=true;return this},value:function(){return this._wrapped}})}).call(this); diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index ecffbf9463..d9dad9c4bf 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -26,6 +26,7 @@ // Create quick reference variables for speed access to core prototypes. var push = ArrayProto.push, slice = ArrayProto.slice, + concat = ArrayProto.concat, unshift = ArrayProto.unshift, toString = ObjProto.toString, hasOwnProperty = ObjProto.hasOwnProperty; @@ -79,7 +80,7 @@ if (obj == null) return; if (nativeForEach && obj.forEach === nativeForEach) { obj.forEach(iterator, context); - } else if (_.isArray(obj) || _.isArguments(obj)) { + } else if (obj.length === +obj.length) { for (var i = 0, l = obj.length; i < l; i++) { if (iterator.call(context, obj[i], i, obj) === breaker) return; } @@ -343,8 +344,7 @@ // Return the number of elements in an object. _.size = function(obj) { - var hasLength = _.isArray(obj) || _.isArguments(obj) || _.isString(obj); - return hasLength ? obj.length : _.keys(obj).length; + return (obj.length === +obj.length) ? obj.length : _.keys(obj).length; }; // Array Functions @@ -429,7 +429,7 @@ // Produce an array that contains the union: each distinct element from all of // the passed-in arrays. _.union = function() { - return _.uniq(flatten(arguments, true, [])); + return _.uniq(concat.apply(ArrayProto, arguments)); }; // Produce an array that contains every item shared between all the @@ -446,7 +446,7 @@ // Take the difference between one array and a number of other arrays. // Only the elements present in just the first array will remain. _.difference = function(array) { - var rest = flatten(slice.call(arguments, 1), true, []); + var rest = concat.apply(ArrayProto, slice.call(arguments, 1)); return _.filter(array, function(value){ return !_.include(rest, value); }); }; @@ -729,7 +729,7 @@ // Return a copy of the object only containing the whitelisted properties. _.pick = function(obj) { var copy = {}; - var keys = _.flatten(slice.call(arguments, 1)); + var keys = concat.apply(ArrayProto, slice.call(arguments, 1)); each(keys, function(key) { if (key in obj) copy[key] = obj[key]; }); @@ -739,7 +739,7 @@ // Return a copy of the object without the blacklisted properties. _.omit = function(obj) { var copy = {}; - var keys = _.flatten(slice.call(arguments, 1)); + var keys = concat.apply(ArrayProto, slice.call(arguments, 1)); for (var key in obj) { if (!_.include(keys, key)) copy[key] = obj[key]; } @@ -780,9 +780,6 @@ // Unwrap any wrapped objects. if (a instanceof _) a = a._wrapped; if (b instanceof _) b = b._wrapped; - // Invoke a custom `isEqual` method if one is provided. - if (a.isEqual && _.isFunction(a.isEqual)) return a.isEqual(b); - if (b.isEqual && _.isFunction(b.isEqual)) return b.isEqual(a); // Compare `[[Class]]` names. var className = toString.call(a); if (className != toString.call(b)) return false; @@ -909,10 +906,9 @@ return _.isNumber(obj) && isFinite(obj); }; - // Is the given value `NaN`? + // Is the given value `NaN`? (NaN is the only number which does not equal itself). _.isNaN = function(obj) { - // `NaN` is the only value for which `===` is not reflexive. - return obj !== obj; + return _.isNumber(obj) && obj != +obj; }; // Is a given value a boolean? From e8d19265e48a00b15c0cfa329744ab3aff7838ee Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 13 Sep 2012 00:10:16 -0700 Subject: [PATCH 09/82] Cleanup component.json. Former-commit-id: 0761bb592e5c643223848e2cd7fca0efc5b9c725 --- component.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/component.json b/component.json index 5fd89537ea..58181b8045 100644 --- a/component.json +++ b/component.json @@ -26,9 +26,5 @@ "name": "John-David Dalton", "email": "john.david.dalton@gmail.com", "web": "http://allyoucanleet.com/" - }, - "repository": { - "type": "git", - "url": "https://github.com/bestiejs/lodash.git" } } From e69bdabc99faf80053569f9ea022ad26ee588eff Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 13 Sep 2012 00:46:47 -0700 Subject: [PATCH 10/82] Rename `makeBound` to `createBound` for naming consistency. Former-commit-id: ec6845badba06231af0b1341b1f1efedb8adbc88 --- lodash.js | 168 +++++++++++++++++++++++++++--------------------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/lodash.js b/lodash.js index 654c1f6060..8d950fd121 100644 --- a/lodash.js +++ b/lodash.js @@ -647,6 +647,87 @@ } } + /** + * Used by `sortBy` to compare transformed `collection` values, stable sorting + * them in ascending order. + * + * @private + * @param {Object} a The object to compare to `b`. + * @param {Object} b The object to compare to `a`. + * @returns {Number} Returns the sort order indicator of `1` or `-1`. + */ + function compareAscending(a, b) { + var ai = a.index, + bi = b.index; + + a = a.criteria; + b = b.criteria; + + // ensure a stable sort in V8 and other engines + // http://code.google.com/p/v8/issues/detail?id=90 + if (a !== b) { + if (a > b || a === undefined) { + return 1; + } + if (a < b || b === undefined) { + return -1; + } + } + return ai < bi ? -1 : 1; + } + + /** + * Creates a new function that, when called, invokes `func` with the `this` + * binding of `thisArg` and prepends any `partailArgs` to the arguments passed + * to the bound function. + * + * @private + * @param {Function|String} func The function to bind or the method name. + * @param {Mixed} [thisArg] The `this` binding of `func`. + * @param {Array} partialArgs An array of arguments to be partially applied. + * @returns {Function} Returns the new bound function. + */ + function createBound(func, thisArg, partialArgs) { + var isFunc = isFunction(func), + isPartial = !partialArgs, + methodName = func; + + // juggle arguments + if (isPartial) { + partialArgs = thisArg; + } + + function bound() { + // `Function#bind` spec + // http://es5.github.com/#x15.3.4.5 + var args = arguments, + thisBinding = isPartial ? this : thisArg; + + if (!isFunc) { + func = thisArg[methodName]; + } + if (partialArgs.length) { + args = args.length + ? partialArgs.concat(slice.call(args)) + : partialArgs; + } + if (this instanceof bound) { + // get `func` instance if `bound` is invoked in a `new` expression + noop.prototype = func.prototype; + thisBinding = new noop; + + // mimic the constructor's `return` behavior + // http://es5.github.com/#x13.2.2 + var result = func.apply(thisBinding, args); + return result && objectTypes[typeof result] + ? result + : thisBinding + } + return func.apply(thisBinding, args); + } + return bound; + } + /** * Creates compiled iteration functions. The iteration function will be created * to iterate over only objects if the first argument of `options.args` is @@ -756,35 +837,6 @@ ); } - /** - * Used by `sortBy` to compare transformed `collection` values, stable sorting - * them in ascending order. - * - * @private - * @param {Object} a The object to compare to `b`. - * @param {Object} b The object to compare to `a`. - * @returns {Number} Returns the sort order indicator of `1` or `-1`. - */ - function compareAscending(a, b) { - var ai = a.index, - bi = b.index; - - a = a.criteria; - b = b.criteria; - - // ensure a stable sort in V8 and other engines - // http://code.google.com/p/v8/issues/detail?id=90 - if (a !== b) { - if (a > b || a === undefined) { - return 1; - } - if (a < b || b === undefined) { - return -1; - } - } - return ai < bi ? -1 : 1; - } - /** * Used by `template` to replace tokens with their corresponding code snippets. * @@ -820,58 +872,6 @@ return htmlEscapes[match]; } - /** - * Creates a new function that, when called, invokes `func` with the `this` - * binding of `thisArg` and prepends any `partailArgs` to the arguments passed - * to the bound function. - * - * @private - * @param {Function|String} func The function to bind or the method name. - * @param {Mixed} [thisArg] The `this` binding of `func`. - * @param {Array} partialArgs An array of arguments to be partially applied. - * @returns {Function} Returns the new bound function. - */ - function makeBound(func, thisArg, partialArgs) { - var isFunc = isFunction(func), - isPartial = !partialArgs, - methodName = func; - - // juggle arguments - if (isPartial) { - partialArgs = thisArg; - } - - function bound() { - // `Function#bind` spec - // http://es5.github.com/#x15.3.4.5 - var args = arguments, - thisBinding = isPartial ? this : thisArg; - - if (!isFunc) { - func = thisArg[methodName]; - } - if (partialArgs.length) { - args = args.length - ? partialArgs.concat(slice.call(args)) - : partialArgs; - } - if (this instanceof bound) { - // get `func` instance if `bound` is invoked in a `new` expression - noop.prototype = func.prototype; - thisBinding = new noop; - - // mimic the constructor's `return` behavior - // http://es5.github.com/#x13.2.2 - var result = func.apply(thisBinding, args); - return result && objectTypes[typeof result] - ? result - : thisBinding - } - return func.apply(thisBinding, args); - } - return bound; - } - /** * A no-operation function. * @@ -3360,7 +3360,7 @@ // (in V8 `Function#bind` is slower except when partially applied) return isBindFast || (nativeBind && arguments.length > 2) ? nativeBind.call.apply(nativeBind, arguments) - : makeBound(func, thisArg, slice.call(arguments, 2)); + : createBound(func, thisArg, slice.call(arguments, 2)); } /** @@ -3559,7 +3559,7 @@ * // => 'hi, moe!' */ function lateBind(object, methodName) { - return makeBound(methodName, object, slice.call(arguments, 2)); + return createBound(methodName, object, slice.call(arguments, 2)); } /** @@ -3642,7 +3642,7 @@ * // => 'hi: moe' */ function partial(func) { - return makeBound(func, slice.call(arguments, 1)); + return createBound(func, slice.call(arguments, 1)); } /** From 13d901bf8daf397901af4526a566d278a577dff5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 13 Sep 2012 01:40:28 -0700 Subject: [PATCH 11/82] Make the IIFE Closure Compiler regexp in `post process` more restrictive to work better with the "iife" build option. Former-commit-id: 999602451e50850eb82680b9c377d97605be8af4 --- build/post-compile.js | 2 +- lodash.min.js | 60 +++++++++++++++++++++---------------------- test/test-build.js | 47 +++++++++++++++++++++++---------- 3 files changed, 64 insertions(+), 45 deletions(-) diff --git a/build/post-compile.js b/build/post-compile.js index 2b83991360..6639c3979a 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -27,7 +27,7 @@ */ function postprocess(source) { // move vars exposed by Closure Compiler into the IIFE - source = source.replace(/^([^(\n]+)\s*(\(function[^)]+\){)/, '$2$1'); + source = source.replace(/^((?:(['"])use strict\2;)?(?:var (?:[a-z]+=(?:!0|!1|null)[,;])+)?)([\s\S]*?function[^)]+\){)/, '$3$1'); // unescape properties (i.e. foo["bar"] => foo.bar) source = source.replace(/(\w)\["([^."]+)"\]/g, function(match, left, right) { diff --git a/lodash.min.js b/lodash.min.js index b139e6dc43..5348d9830c 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -2,39 +2,39 @@ Lo-Dash 0.7.0 lodash.com/license Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE */ -;(function(e,t){function s(e){return new o(e)}function o(e){if(e&&e.__wrapped__)return e;this.__wrapped__=e}function u(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function a(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||W),s=i?{}:e;if(i)for(var o=t-1;++on;n++)t+="j='"+a.p[n]+"';if(","constructor"==a.p[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){A=k[j];"+a.m.i+"}"}if(a.c||a.n)t+="}"}return t+=a.e+";return u",Function("D,E,F,c,I,f,J,h,i,M,O,Q,S,T,W,X,m,r,w,x,z","var G=function("+e+"){"+t+"};return G")(zt,R,D,u,l,ut,ln,at,P,L,w,sn,E,on,Ct,$t,gt,lt,ct,Lt,ht)}function l(e,n){var r=e.b,i=n.b,e=e.a,n=n.a;if(e!==n){if(e>n|| -e===t)return 1;if(e";var n=ot.length;return ot[n]="'+__e("+ -t+")+'",it+n+st}function g(e,t,n,i){return i?(e=ot.length,ot[e]="';"+i+";__p+='",it+e+st):t?m(r,t):y(r,n)}function y(e,t){if(e&&V.test(t))return"";var n=ot.length;return ot[n]="'+((__t=("+t+"))==null?'':__t)+'",it+n+st}function b(e){return Vt[e]}function w(e){return ht.call(e)==Et}function E(e){return"function"==typeof e}function S(e,t){var n=i;if(!e||"object"!=typeof e||!t&&w(e))return n;var r=e.constructor;return(!Ft||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!E(r)||r instanceof -r)?Dt?(ln(e,function(e,t,r){return n=!at.call(r,t),i}),n===i):(ln(e,function(e,t){n=t}),n===i||at.call(e,n)):n}function x(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=$t[typeof e]){var a=ht.call(e);if(!Wt[a]||Ht&&w(e))return e;var f=a==St,s=f||(a==Ct?on(e,n):s)}if(!s||!t)return s?f?ct.call(e):fn({},e):e;s=e.constructor;switch(a){case xt:return new s(e==n);case Tt:return new s(+e);case Nt:case Lt:return new s(e);case kt:return s(e.source,G.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u -[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=rt[u],at.call(e,c)&&(!at.call(t,c)||!T(e[c],t[c],s,o)))return i;return n}function N(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=u(t,r));if(-1>>0){var o=jt&&ht.call(e)==Lt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=vn(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function C(e,t,n){if(e)return t==r||n?e[0]:ct.call(e,0,t)}function k(e,t){var n=[];if(!e)return n;for( -var r,i=-1,s=e.length;++in?yt(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=u(t,n));++sr&&(r=n,i=e[s]);return i}function O(e,t,n){return e?ct.call(e,t==r||n?1:t):[]}function M -(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=D(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]L(f,r))f.push(r),s.push(e[o]);return s}function D(e,t){return qt||pt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,$=/&(?:amp|lt|gt|quot|#x27);/g -,J=/\b__p\+='';/g,K=/\b(__p\+=)''\+/g,Q=/(__e\(.*?\)|\b__t\))\+'';/g,G=/\w*$/,Y=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,Z=RegExp("^"+(U.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),et=/__token(\d+)__/g,tt=/[&<>"']/g,nt=/['\n\r\t\u2028\u2029\\]/g,rt="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),it="__token",st="__",ot=[],ut=R.concat,at=U.hasOwnProperty,ft=R.push,lt=U.propertyIsEnumerable -,ct=R.slice,ht=U.toString,pt=Z.test(pt=ct.bind)&&pt,dt=Math.floor,vt=Z.test(vt=Array.isArray)&&vt,mt=e.isFinite,gt=Z.test(gt=Object.keys)&>,yt=Math.max,bt=Math.min,wt=Math.random,Et="[object Arguments]",St="[object Array]",xt="[object Boolean]",Tt="[object Date]",Nt="[object Number]",Ct="[object Object]",kt="[object RegExp]",Lt="[object String]",At=e.clearTimeout,Ot=e.setTimeout,Mt,_t,Dt,Pt=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e) -n.push(r);for(r in arguments)Pt=!r;Mt=4>(n+"").length,Dt="x"!=n[0],_t=(n.splice.call(t,0,1),t[0])})(1);var Ht=!w(arguments),Bt="x"!=ct.call("x")[0],jt="xx"!="x"[0]+Object("x")[0];try{var Ft=("[object Object]",ht.call(e.document||0)==Ct)}catch(It){}var qt=pt&&/\n|Opera/.test(pt+ht.call(e.opera)),Rt=gt&&/^.+$|true/.test(gt+!!e.attachEvent),Ut=!qt,zt={};zt[xt]=zt[Tt]=zt["[object Function]"]=zt[Nt]=zt[Ct]=zt[kt]=i,zt[Et]=zt[St]=zt[Lt]=n;var Wt={};Wt[Et]=Wt["[object Function]"]=i,Wt[St]=Wt[xt]=Wt[Tt]= -Wt[Nt]=Wt[Ct]=Wt[kt]=Wt[Lt]=n;var Xt={"&":"&","<":"<",">":">",'"':""","'":"'"},Vt={"&":"&","<":"<",">":">",""":'"',"'":"'"},$t={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Kt={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y)d=c(d,y)" -,i:"if(d(A,j,e)===false)return u"},Qt={j:"{}",q:"var q;if(typeof d!='function'){var hh=d;d=function(A){return A[hh]}}else if(y)d=c(d,y)",i:"q=d(A,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},Gt={j:"true",i:"if(!d(A,j,e))return!u"},Yt={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1&&l===l>>>0&&S(A.splice)))return!l",i:{l:"return false"}}),vn=gt?function(e){var t=typeof e;return"function"==t&<.call(e,"prototype")?un(e):e&&$t[t]?gt(e):[]}:un,mn=f(Yt,{a:"n,cc,N",q:"var b,P,dd,ee,C=arguments,a=0;if(N==T){b=2;dd=C[3];ee=C[4]}else{b=C.length;dd=[];ee=[]}while(++a-1"},i:"if(A===gg)return true"}),Sn=f(Kt,Qt),xn=f(Kt,Gt),Tn=f(Kt,Zt),Nn=f(Kt,en,{j:"",i:"if(d(A,j,e))return A"}),Cn=f(Kt,en),kn=f(Kt,Qt,{i:"q=d(A,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(A)"}),Ln=f(nn,{a:"e,U",q:"var C=w.call(arguments,2),R=typeof U=='function'",i:{b:"u[j]=(R?U:A[U]).apply(A,C)",l:"u"+(Rt?"[o]=":".push")+"((R?U:A[U]).apply(A,C))"}}),An=f(Kt,nn),On=f(nn,{a:"e,aa",i:{b:"u[j]=A[aa]",l:"u"+(Rt?"[o]=":".push")+"(A[aa])"} -}),Mn=f({a:"e,d,B,y",j:"B",q:"var V=arguments.length<3;if(y)d=c(d,y)",d:{b:"if(V)u=k[++j]"},i:{b:"u=d(u,A,j,e)",l:"u=V?(V=false,A):d(u,A,j,e)"}}),_n=f(Kt,Zt,{i:"!"+Zt.i}),Dn=f(Kt,Gt,{j:"false",i:Gt.i.replace("!","")}),Pn=f(Kt,Qt,nn,{i:{b:"u[j]={a:d(A,j,e),b:j,c:A}",l:"u"+(Rt?"[o]=":".push")+"({a:d(A,j,e),b:j,c:A})"},e:"u.sort(I);l=u.length;while(l--)u[l]=u[l].c"}),Hn=f(Zt,{a:"e,Z",q:"var t=[];J(Z,function(A,q){t.push(q)});var bb=t.length",i:"for(var q,Y=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=D,s.bindAll=Bn,s.chain=function(e){return e=new o(e),e.__chain__=n,e},s.clone=x,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++n=(n||W),s=i?{}:e;if(i)for(var o=t-1;++on||e===t)return 1;if(en;n++)t+="j='"+a.p[n]+"';if(" +,"constructor"==a.p[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){A=k[j];"+a.m.i+"}"}if(a.c||a.n)t+="}"}return t+=a.e+";return u",Function("D,E,F,c,I,f,J,h,i,M,O,Q,S,T,W,X,m,r,w,x,z","var G=function("+e+"){"+t+"};return G")(zt,R,D,u,f,ut,ln,at,P,L,w,sn,E,on,Ct,$t,gt,lt,ct,Lt,ht)}function h(e,t){return ot[t]}function p(e){return"\\"+Jt[e]}function d(e){return Xt[e]}function v(){}function m(e,t){if(e&&V.test(t))return"";var n=ot.length;return ot[n]="'+__e("+t+")+'",it+n+st}function g +(e,t,n,i){return i?(e=ot.length,ot[e]="';"+i+";__p+='",it+e+st):t?m(r,t):y(r,n)}function y(e,t){if(e&&V.test(t))return"";var n=ot.length;return ot[n]="'+((__t=("+t+"))==null?'':__t)+'",it+n+st}function b(e){return Vt[e]}function w(e){return ht.call(e)==Et}function E(e){return"function"==typeof e}function S(e,t){var n=i;if(!e||"object"!=typeof e||!t&&w(e))return n;var r=e.constructor;return(!Ft||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!E(r)||r instanceof r)?Dt?(ln(e,function( +e,t,r){return n=!at.call(r,t),i}),n===i):(ln(e,function(e,t){n=t}),n===i||at.call(e,n)):n}function x(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=$t[typeof e]){var a=ht.call(e);if(!Wt[a]||Ht&&w(e))return e;var f=a==St,s=f||(a==Ct?on(e,n):s)}if(!s||!t)return s?f?ct.call(e):fn({},e):e;s=e.constructor;switch(a){case xt:return new s(e==n);case Tt:return new s(+e);case Nt:case Lt:return new s(e);case kt:return s(e.source,G.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s( +a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=rt[u],at.call(e,c)&&(!at.call(t,c)||!T(e[c],t[c],s,o)))return i;return n}function N(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=u(t,r));if(-1>>0){var o=jt&&ht.call(e)==Lt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=vn(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function C(e,t,n){if(e)return t==r||n?e[0]:ct.call(e,0,t)}function k(e,t){var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?yt(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=u(t,n));++sr&&(r=n,i=e[s]);return i}function O(e,t,n){return e?ct.call(e,t==r||n?1:t):[]}function M(e,t,n,r){if(!e)return 0 +;var i=0,s=e.length;if(n){r&&(n=D(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]L(f,r))f.push(r),s.push(e[o]);return s}function D(e,t){return qt||pt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,$=/&(?:amp|lt|gt|quot|#x27);/g,J=/\b__p\+='';/g +,K=/\b(__p\+=)''\+/g,Q=/(__e\(.*?\)|\b__t\))\+'';/g,G=/\w*$/,Y=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,Z=RegExp("^"+(U.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),et=/__token(\d+)__/g,tt=/[&<>"']/g,nt=/['\n\r\t\u2028\u2029\\]/g,rt="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),it="__token",st="__",ot=[],ut=R.concat,at=U.hasOwnProperty,ft=R.push,lt=U.propertyIsEnumerable,ct=R.slice,ht=U +.toString,pt=Z.test(pt=ct.bind)&&pt,dt=Math.floor,vt=Z.test(vt=Array.isArray)&&vt,mt=e.isFinite,gt=Z.test(gt=Object.keys)&>,yt=Math.max,bt=Math.min,wt=Math.random,Et="[object Arguments]",St="[object Array]",xt="[object Boolean]",Tt="[object Date]",Nt="[object Number]",Ct="[object Object]",kt="[object RegExp]",Lt="[object String]",At=e.clearTimeout,Ot=e.setTimeout,Mt,_t,Dt,Pt=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in +arguments)Pt=!r;Mt=4>(n+"").length,Dt="x"!=n[0],_t=(n.splice.call(t,0,1),t[0])})(1);var Ht=!w(arguments),Bt="x"!=ct.call("x")[0],jt="xx"!="x"[0]+Object("x")[0];try{var Ft=("[object Object]",ht.call(e.document||0)==Ct)}catch(It){}var qt=pt&&/\n|Opera/.test(pt+ht.call(e.opera)),Rt=gt&&/^.+$|true/.test(gt+!!e.attachEvent),Ut=!qt,zt={};zt[xt]=zt[Tt]=zt["[object Function]"]=zt[Nt]=zt[Ct]=zt[kt]=i,zt[Et]=zt[St]=zt[Lt]=n;var Wt={};Wt[Et]=Wt["[object Function]"]=i,Wt[St]=Wt[xt]=Wt[Tt]=Wt[Nt]=Wt[Ct]=Wt[kt +]=Wt[Lt]=n;var Xt={"&":"&","<":"<",">":">",'"':""","'":"'"},Vt={"&":"&","<":"<",">":">",""":'"',"'":"'"},$t={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Kt={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y)d=c(d,y)",i:"if(d(A,j,e)===false)return u" +},Qt={j:"{}",q:"var q;if(typeof d!='function'){var hh=d;d=function(A){return A[hh]}}else if(y)d=c(d,y)",i:"q=d(A,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},Gt={j:"true",i:"if(!d(A,j,e))return!u"},Yt={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1&&l===l>>>0&&S(A.splice)))return!l",i:{l:"return false"}}),vn=gt?function(e){var t=typeof e;return"function"==t&<.call(e,"prototype")?un(e):e&&$t[t]?gt(e):[]}:un,mn=c(Yt,{a:"n,cc,N",q:"var b,P,dd,ee,C=arguments,a=0;if(N==T){b=2;dd=C[3];ee=C[4]}else{b=C.length;dd=[];ee=[]}while(++a-1"},i:"if(A===gg)return true"}),Sn=c(Kt,Qt),xn=c(Kt,Gt),Tn=c(Kt,Zt),Nn=c(Kt,en,{j:"",i:"if(d(A,j,e))return A"}),Cn=c(Kt,en),kn=c(Kt,Qt,{i:"q=d(A,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(A)"}),Ln=c(nn,{a:"e,U",q:"var C=w.call(arguments,2),R=typeof U=='function'",i:{b:"u[j]=(R?U:A[U]).apply(A,C)",l:"u"+(Rt?"[o]=":".push")+"((R?U:A[U]).apply(A,C))"}}),An=c(Kt,nn),On=c(nn,{a:"e,aa",i:{b:"u[j]=A[aa]",l:"u"+(Rt?"[o]=":".push")+"(A[aa])"} +}),Mn=c({a:"e,d,B,y",j:"B",q:"var V=arguments.length<3;if(y)d=c(d,y)",d:{b:"if(V)u=k[++j]"},i:{b:"u=d(u,A,j,e)",l:"u=V?(V=false,A):d(u,A,j,e)"}}),_n=c(Kt,Zt,{i:"!"+Zt.i}),Dn=c(Kt,Gt,{j:"false",i:Gt.i.replace("!","")}),Pn=c(Kt,Qt,nn,{i:{b:"u[j]={a:d(A,j,e),b:j,c:A}",l:"u"+(Rt?"[o]=":".push")+"({a:d(A,j,e),b:j,c:A})"},e:"u.sort(I);l=u.length;while(l--)u[l]=u[l].c"}),Hn=c(Zt,{a:"e,Z",q:"var t=[];J(Z,function(A,q){t.push(q)});var bb=t.length",i:"for(var q,Y=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=D,s.bindAll=Bn,s.chain=function(e){return e=new o(e),e.__chain__=n,e},s.clone=x,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nL(t,n)){for(var u=1;un?yt(0,r+n):bt(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return d(t,e,ct.call(arguments,2))},s.map=An,s.max=A,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments) +r},s.isObject=function(e){return e?$t[typeof e]:i},s.isUndefined=function(e){return e===t},s.keys=vn,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:ct.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(!e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?yt(0,r+n):bt(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return l(t,e,ct.call(arguments,2))},s.map=An,s.max=A,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments) :arguments[0];return at.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=mn,s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s>>0?t:vn(e).length},s.some=Dn,s.sortBy=Pn,s.sortedIndex=M,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var e=e+"",o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,l=s.templateSettings,p=n=n.variable||l.variable;o==r&&(o=l.escape),a==r&&(a=l.evaluate||i),f==r&&(f=l.interpolate),o&&(e=e.replace(o,m)) -,f&&(e=e.replace(f,y)),a!=B&&(B=a,I=RegExp("|"+(a?"|"+a.source:""),"g")),o=ot.length,e=e.replace(I,g),o=o!=ot.length,e="__p += '"+e.replace(nt,h).replace(et,c)+"';",ot.length=0,p||(n=j||"obj",o?e="with("+n+"){"+e+"}":(n!=j&&(j=n,F=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(Y,"$&"+n+".").replace(F,"$1__d"))),e=(o?e.replace(J,""):e).replace(K,"$1").replace(Q,"$1;"),e="function("+n+"){"+(p?"":n+"||("+n+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}" -:(p?"":",__d="+n+"."+n+"||"+n)+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(d){throw d.source=e,d}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,s=e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=Ot(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?t:vn(e).length},s.some=Dn,s.sortBy=Pn,s.sortedIndex=M,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var e=e+"",o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,l=s.templateSettings,c=n=n.variable||l.variable;o==r&&(o=l.escape),a==r&&(a=l.evaluate||i),f==r&&(f=l.interpolate),o&&(e=e.replace(o,m)) +,f&&(e=e.replace(f,y)),a!=B&&(B=a,I=RegExp("|"+(a?"|"+a.source:""),"g")),o=ot.length,e=e.replace(I,g),o=o!=ot.length,e="__p += '"+e.replace(nt,p).replace(et,h)+"';",ot.length=0,c||(n=j||"obj",o?e="with("+n+"){"+e+"}":(n!=j&&(j=n,F=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(Y,"$&"+n+".").replace(F,"$1__d"))),e=(o?e.replace(J,""):e).replace(K,"$1").replace(Q,"$1;"),e="function("+n+"){"+(c?"":n+"||("+n+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}" +:(c?"":",__d="+n+"."+n+"||"+n)+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(d){throw d.source=e,d}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,s=e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=Ot(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(Bt?ht.call(e)==Lt:"string"==typeof e)?e.split(""):ct.call(e):wn(e)},s.unescape=function(e){return e==r?"":(e+"").replace($,b)},s.union=function(){for(var e=-1,t=[],n=ut.apply(t,arguments),r=n.length;++eL(t,n[e])&&t.push(n[e]);return t},s.uniq=_,s.uniqueId=function(e){var t=z++;return e?e+t:t},s.values=wn,s.where=Hn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=a(arguments,1,20);++n Date: Thu, 13 Sep 2012 02:10:23 -0700 Subject: [PATCH 12/82] Remove "lazy" bind from README.md until next version bump. Former-commit-id: f132182f32670aa7df7ac418f58db0a1fb0f8547 --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index cd0b26894d..321e39c324 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ For more information check out these screencasts over Lo-Dash: ## Features * AMD loader support ([RequireJS](http://requirejs.org/), [curl.js](https://github.com/cujojs/curl), etc.) - * [_.bind](http://lodash.com/docs#bind) supports *“lazy”* binding * [_.clone](http://lodash.com/docs#clone) supports *“deep”* cloning * [_.countBy](http://lodash.com/docs#countBy) as a companion function for [_.groupBy](http://lodash.com/docs#groupBy) and [_.sortBy](http://lodash.com/docs#sortBy) * [_.debounce](http://lodash.com/docs#debounce)’ed functions match [_.throttle](http://lodash.com/docs#throttle)’ed functions’ return value behavior From 08249d78eacd0d1e48af8a7fc4eb199456e37cbf Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 13 Sep 2012 19:11:48 -0700 Subject: [PATCH 13/82] Add RequireJS "shim" test and a build test to ensure the AMD snippet is maintained for r.js. Former-commit-id: 708c07877cfca0022d6d56c16c36d8bae79e4796 --- test/index.html | 15 +++++++++++++-- test/test-build.js | 17 +++++++++++++++++ test/test.js | 8 ++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/test/index.html b/test/index.html index e41af99206..3b75bb9e2f 100644 --- a/test/index.html +++ b/test/index.html @@ -44,6 +44,7 @@ " ); iDoc.close(); diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index a499cf0465..ab6a0fcf73 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -5,29 +5,29 @@ // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: // http://documentcloud.github.com/underscore -(function(){var r=this,J=r._,n={},k=Array.prototype,o=Object.prototype,s=k.push,g=k.slice,p=k.concat,l=o.toString,K=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,q=k.indexOf,D=k.lastIndexOf,o=Array.isArray,L=Object.keys,t=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._= -b):r._=b;b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,h=a.length;e2;a==null&&(a= -[]);if(y&&a.reduce===y){e&&(c=b.bind(c,e));return h?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,M){if(h)d=c.call(e,d,a,b,M);else{d=a;h=true}});if(!h)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var h=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z){e&&(c=b.bind(c,e));return h?a.reduceRight(c,d):a.reduceRight(c)}var f=b.toArray(a).reverse();e&&!h&&(c=b.bind(c,e));return h?b.reduce(f,c,d,e):b.reduce(f,c)};b.find=b.detect= -function(a,c,b){var e;E(a,function(a,f,i){if(c.call(b,a,f,i)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,f,i){c.call(b,a,f,i)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,f,i){c.call(b,a,f,i)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,d);j(a,function(a, -b,i){if(!(e=e&&c.call(d,a,b,i)))return n});return!!e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,i){if(e||(e=c.call(d,a,b,i)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=g.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a, -d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.where=function(a,c){return b.isEmpty(c)?[]:b.filter(a,function(a){for(var b in c)if(c[b]!==a[b])return false;return true})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,i){b=c?c.call(d,a,b,i):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&& -a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,i){b=c?c.call(d,a,b,i):a;bd||b===void 0)return 1;if(b>1;d(a[f])=0})})};b.difference=function(a){var c=p.apply(k,g.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=g.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=L||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods=function(a){var c= -[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(g.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var b={},d=p.apply(k,g.call(arguments,1));j(d,function(d){d in a&&(b[d]=a[d])});return b};b.omit=function(a){var c={},d=p.apply(k,g.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){j(g.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)? -a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d,e){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;var h=l.call(a);if(h!=l.call(c))return false;switch(h){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==c.source&&a.global==c.global&& -a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return e[f]==c;d.push(a);e.push(c);var f=0,i=true;if(h=="[object Array]"){f=a.length;if(i=f==c.length)for(;f--;)if(!(i=u(a[f],c[f],d,e)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var g in a)if(b.has(a,g)){f++;if(!(i=b.has(c,g)&&u(a[g],c[g],d,e)))break}if(i){for(g in c)if(b.has(c,g)&&!f--)break;i=!f}}d.pop(); -e.pop();return i};b.isEqual=function(a,b){return u(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};j("Arguments,Function,String,Number,Date,RegExp".split(","),function(a){b["is"+a]=function(b){return l.call(b)=="[object "+a+"]"}}); -b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return b.isNumber(a)&&a!=+a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return K.call(a,b)};b.noConflict=function(){r._=J;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e= -0;e":">",'"':""","'":"'","/":"/"}};m.unescape=b.invert(m.escape);var N={escape:RegExp("["+b.keys(m.escape).join("")+"]","g"),unescape:RegExp("("+b.keys(m.unescape).join("|")+")","g")};b.each(["escape","unescape"],function(a){b[a]=function(b){return b==null?"":(""+b).replace(N[a],function(b){return m[a][b]})}});b.result=function(a,c){if(a==null)return null; -var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){var d=b[c]=a[c];b.prototype[c]=function(){var a=[this._wrapped];s.apply(a,arguments);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var O=0;b.uniqueId=function(a){var b=O++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var v=/(.)^/,P={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},Q=/\\|'|\r|\n|\t|\u2028|\u2029/g; -b.template=function(a,c,d){var d=b.defaults({},d,b.templateSettings),e=RegExp([(d.escape||v).source,(d.interpolate||v).source,(d.evaluate||v).source].join("|")+"|$","g"),h=0,f="__p+='";a.replace(e,function(b,c,d,e,g){f=f+a.slice(h,g).replace(Q,function(a){return"\\"+P[a]});f=f+(c?"'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'":d?"'+\n((__t=("+d+"))==null?'':__t)+\n'":e?"';\n"+e+"\n__p+='":"");h=g+b.length});f=f+"';\n";d.variable||(f="with(obj||{}){\n"+f+"}\n");f="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+ -f+"return __p;\n";try{var g=new Function(d.variable||"obj","_",f)}catch(j){j.source=f;throw j;}if(c)return g(c,b);c=function(a){return g.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+f+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c=k[a];b.prototype[a]=function(){var d=this._wrapped;c.apply(d,arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain(): -d}});j(["concat","join","slice"],function(a){var c=k[a];b.prototype[a]=function(){var a=c.apply(this._wrapped,arguments);return this._chain?b(a).chain():a}});b.extend(b.prototype,{chain:function(){this._chain=true;return this},value:function(){return this._wrapped}})}).call(this); +(function(){var r=this,J=r._,n={},k=Array.prototype,o=Object.prototype,s=k.push,h=k.slice,p=k.concat,l=o.toString,K=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,q=k.indexOf,D=k.lastIndexOf,o=Array.isArray,L=Object.keys,t=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._= +b):r._=b;b.VERSION="1.3.3";var i=b.each=b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,g=a.length;e2;a==null&& +(a=[]);if(!g&&y&&a.reduce===y){e&&(c=b.bind(c,e));return f?a.reduce(c,d):a.reduce(c)}i(a,function(a,b,h){if(g){b=g.keys[b];h=g.list}if(f)d=c.call(e,d,a,b,h);else{d=a;f=true}});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){a==null&&(a=[]);if(z&&a.reduceRight===z){e&&(c=b.bind(c,e));return arguments.length>2?a.reduceRight(c,d):a.reduceRight(c)}var g=b.keys(a).reverse(),f=b.toArray(a).reverse();return b.reduce(f,c,d,e,{keys:g, +list:a})};b.find=b.detect=function(a,c,b){var e;E(a,function(a,f,j){if(c.call(b,a,f,j)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);i(a,function(a,f,j){c.call(b,a,f,j)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;i(a,function(a,f,j){c.call(b,a,f,j)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c, +d);i(a,function(a,b,j){if(!(e=e&&c.call(d,a,b,j)))return n});return!!e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);i(a,function(a,b,j){if(e||(e=c.call(d,a,b,j)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=h.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)? +c:a[c]).apply(a,d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.where=function(a,c){return b.isEmpty(c)?[]:b.filter(a,function(a){for(var b in c)if(c[b]!==a[b])return false;return true})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};i(a,function(a,b,j){b=c?c.call(d,a,b,j):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&& +b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};i(a,function(a,b,j){b=c?c.call(d,a,b,j):a;bd||b===void 0)return 1;if(b>1;d(a[f])=0})})};b.difference=function(a){var c=p.apply(k,h.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=h.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=L||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods= +function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){i(h.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var b={},d=p.apply(k,h.call(arguments,1));i(d,function(d){d in a&&(b[d]=a[d])});return b};b.omit=function(a){var c={},d=p.apply(k,h.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){i(h.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a}; +b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d,e){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;var g=l.call(a);if(g!=l.call(c))return false;switch(g){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== +c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return e[f]==c;d.push(a);e.push(c);var f=0,j=true;if(g=="[object Array]"){f=a.length;if(j=f==c.length)for(;f--;)if(!(j=u(a[f],c[f],d,e)))break}else{var g=a.constructor,h=c.constructor;if(g!==h&&(!b.isFunction(g)||!(g instanceof g&&b.isFunction(h)&&h instanceof h)))return false;for(var i in a)if(b.has(a,i)){f++;if(!(j=b.has(c,i)&& +u(a[i],c[i],d,e)))break}if(j){for(i in c)if(b.has(c,i)&&!f--)break;j=!f}}d.pop();e.pop();return j};b.isEqual=function(a,b){return u(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};i("Arguments,Function,String,Number,Date,RegExp".split(","), +function(a){b["is"+a]=function(b){return l.call(b)=="[object "+a+"]"}});b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return b.isNumber(a)&&a!=+a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return K.call(a,b)};b.noConflict=function(){r._=J; +return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e":">",'"':""","'":"'","/":"/"}};m.unescape=b.invert(m.escape);var M={escape:RegExp("["+b.keys(m.escape).join("")+"]","g"),unescape:RegExp("("+b.keys(m.unescape).join("|")+")","g")};b.each(["escape","unescape"],function(a){b[a]=function(b){return b==null?"":(""+ +b).replace(M[a],function(b){return m[a][b]})}});b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){i(b.functions(a),function(c){var d=b[c]=a[c];b.prototype[c]=function(){var a=[this._wrapped];s.apply(a,arguments);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var N=0;b.uniqueId=function(a){var b=N++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var v=/(.)^/, +O={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},P=/\\|'|\r|\n|\t|\u2028|\u2029/g;b.template=function(a,c,d){var d=b.defaults({},d,b.templateSettings),e=RegExp([(d.escape||v).source,(d.interpolate||v).source,(d.evaluate||v).source].join("|")+"|$","g"),g=0,f="__p+='";a.replace(e,function(b,c,d,e,h){f=f+a.slice(g,h).replace(P,function(a){return"\\"+O[a]});f=f+(c?"'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'":d?"'+\n((__t=("+d+"))==null?'':__t)+\n'":e?"';\n"+e+"\n__p+='": +"");g=h+b.length});f=f+"';\n";d.variable||(f="with(obj||{}){\n"+f+"}\n");f="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+f+"return __p;\n";try{var h=new Function(d.variable||"obj","_",f)}catch(i){i.source=f;throw i;}if(c)return h(c,b);c=function(a){return h.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+f+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);i("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c= +k[a];b.prototype[a]=function(){var d=this._wrapped;c.apply(d,arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain():d}});i(["concat","join","slice"],function(a){var c=k[a];b.prototype[a]=function(){var a=c.apply(this._wrapped,arguments);return this._chain?b(a).chain():a}});b.extend(b.prototype,{chain:function(){this._chain=true;return this},value:function(){return this._wrapped}})}).call(this); diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index ede5757fe9..b4521f5d5d 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -107,14 +107,18 @@ // **Reduce** builds up a single result from a list of values, aka `inject`, // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. - _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { + _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context, right) { var initial = arguments.length > 2; if (obj == null) obj = []; - if (nativeReduce && obj.reduce === nativeReduce) { + if (!right && nativeReduce && obj.reduce === nativeReduce) { if (context) iterator = _.bind(iterator, context); return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); } each(obj, function(value, index, list) { + if (right) { + index = right.keys[index]; + list = right.list; + } if (!initial) { memo = value; initial = true; @@ -129,15 +133,14 @@ // The right-associative version of reduce, also known as `foldr`. // Delegates to **ECMAScript 5**'s native `reduceRight` if available. _.reduceRight = _.foldr = function(obj, iterator, memo, context) { - var initial = arguments.length > 2; if (obj == null) obj = []; if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { if (context) iterator = _.bind(iterator, context); - return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); + return arguments.length > 2 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); } - var reversed = _.toArray(obj).reverse(); - if (context && !initial) iterator = _.bind(iterator, context); - return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator); + var keys = _.keys(obj).reverse(); + var values = _.toArray(obj).reverse(); + return _.reduce(values, iterator, memo, context, {keys: keys, list: obj}); }; // Return the first value which passes a truth test. Aliased as `detect`. @@ -848,8 +851,13 @@ } } } else { - // Objects with different constructors are not equivalent. - if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false; + // Objects with different constructors are not equivalent, but `Object`s + // from different frames are. + var aCtor = a.constructor, bCtor = b.constructor; + if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) && + _.isFunction(bCtor) && (bCtor instanceof bCtor))) { + return false; + } // Deep compare objects. for (var key in a) { if (_.has(a, key)) { From 5afeed56ef88a288ae8e8302ed7a09970d63e890 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 19 Sep 2012 22:15:15 -0700 Subject: [PATCH 31/82] Cleanup `_.difference` and `_.union`. Former-commit-id: 1fcaab3989caaaacd9fe73de071d8f360f52b715 --- lodash.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index 4b6e675943..e1d16d6e3d 100644 --- a/lodash.js +++ b/lodash.js @@ -2493,7 +2493,7 @@ } var index = -1, length = array.length, - flattened = concat.apply(result, arguments), + flattened = concat.apply(ArrayProto, arguments), contains = cachedContains(flattened, length); while (++index < length) { @@ -3065,9 +3065,9 @@ */ function union() { var index = -1, - result = [], - flattened = concat.apply(result, arguments), - length = flattened.length; + flattened = concat.apply(ArrayProto, arguments), + length = flattened.length, + result = []; while (++index < length) { if (indexOf(result, flattened[index]) < 0) { From 473dd7660ba8c5e051e129df0c5c301e2c3a10c4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 20 Sep 2012 21:06:32 -0700 Subject: [PATCH 32/82] Reduce `_.reduceRight` and update vendors. Former-commit-id: f7250ccb4b8f15052c1f1420947c2ac68963a92c --- build.js | 2 +- lodash.js | 38 +++--------- lodash.min.js | 56 ++++++++--------- vendor/underscore/test/arrays.js | 8 +++ vendor/underscore/test/collections.js | 16 +++++ vendor/underscore/test/objects.js | 7 ++- vendor/underscore/underscore-min.js | 34 +++------- vendor/underscore/underscore.js | 89 ++++++++++++++++----------- 8 files changed, 130 insertions(+), 120 deletions(-) diff --git a/build.js b/build.js index 53a3736a78..bb195371c4 100755 --- a/build.js +++ b/build.js @@ -133,7 +133,7 @@ 'random': [], 'range': [], 'reduce': [], - 'reduceRight': ['keys'], + 'reduceRight': ['keys', 'reduce'], 'reject': ['identity'], 'rest': [], 'result': ['isFunction'], diff --git a/lodash.js b/lodash.js index e1d16d6e3d..8595b3e38c 100644 --- a/lodash.js +++ b/lodash.js @@ -2220,39 +2220,19 @@ if (!collection) { return accumulator; } - var length = collection.length, noaccum = arguments.length < 3; - if(thisArg) { - callback = bindIterator(callback, thisArg); - } - if (length === +length) { - var iteratee = noCharByIndex && toString.call(collection) == stringClass - ? collection.split('') - : collection; - - if (length && noaccum) { - accumulator = iteratee[--length]; - } - while (length--) { - accumulator = callback(accumulator, iteratee[length], length, collection); - } - return accumulator; - } - - var prop, - props = keys(collection); - - length = props.length; - if (length && noaccum) { - accumulator = collection[props[--length]]; - } - while (length--) { - prop = props[length]; - accumulator = callback(accumulator, collection[prop], prop, collection); + if (length !== +length) { + var props = keys(collection); + length = props.length; } - return accumulator; + return reduce(collection, function(accumulator, value, index, object) { + var index = props ? props[--length] : --length; + return noaccum + ? (noaccum = false, object[index]) + : callback.call(thisArg, accumulator, object[index], index, object); + }, accumulator); } /** diff --git a/lodash.min.js b/lodash.min.js index fbfc2bcce6..af6567f543 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -10,31 +10,31 @@ a.m.i+"}}else{"),a.h||(t+="var v=typeof k=='function'&&r.call(k,'prototype');"); e||!t&&m(e))return n;var r=e.constructor;return(!kt||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!g(r)||r instanceof r)?St?(Yt(e,function(e,t,r){return n=!G.call(r,t),i}),n===i):(Yt(e,function(e,t){n=t}),n===i||G.call(e,n)):n}function b(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=Bt[typeof e]){var a=tt.call(e);if(!Dt[a]||Tt&&m(e))return e;var f=a==ct,s=f||(a==vt?Jt(e,n):s)}if(!s||!t)return s?f?et.call(e):Gt({},e):e;s=e.constructor;switch(a){case ht:return new s(e==n);case pt:return new s(+e);case dt:case gt:return new s(e);case mt:return s(e.source,z.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=K[u],G.call(e,c)&&(!G.call(t,c)||!w(e[c],t[c],s,o)))return i;return n}function E(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=u(t,r));if(i===+i){var o=Ct&&tt.call(e)==gt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=rn(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s], -s,e);return n}function S(e,t,n){if(e)return t==r||n?e[0]:et.call(e,0,t)}function x(e,t){var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?ut(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=u -(t,n));++sr&&(r=n,i=e[s]);return i}function C(e,t,n){return e?et.call(e,t==r||n?1:t):[]}function k(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=A(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]T(f,r))f.push(r),s.push(e[o]);return s}function A -(e,t){return At||nt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,I=/&(?:amp|lt|gt|quot|#x27);/g,q=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,U=/(__e\(.*?\)|\b__t\))\+'';/g,z=/\w*$/,W=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,X=RegExp("^"+(P.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),V=/($^)/,$=/[&<>"']/g,J=/['\n\r\t\u2028\u2029\\]/g,K="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf" -.split(" "),Q=D.concat,G=P.hasOwnProperty,Y=D.push,Z=P.propertyIsEnumerable,et=D.slice,tt=P.toString,nt=X.test(nt=et.bind)&&nt,rt=Math.floor,it=X.test(it=Array.isArray)&&it,st=e.isFinite,ot=X.test(ot=Object.keys)&&ot,ut=Math.max,at=Math.min,ft=Math.random,lt="[object Arguments]",ct="[object Array]",ht="[object Boolean]",pt="[object Date]",dt="[object Number]",vt="[object Object]",mt="[object RegExp]",gt="[object String]",yt=e.clearTimeout,bt=e.setTimeout,wt,Et,St,xt=n;(function(){function e(){this -.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in arguments)xt=!r;wt=4>(n+"").length,St="x"!=n[0],Et=(n.splice.call(t,0,1),t[0])})(1);var Tt=!m(arguments),Nt="x"!=et.call("x")[0],Ct="xx"!="x"[0]+Object("x")[0];try{var kt=("[object Object]",tt.call(e.document||0)==vt)}catch(Lt){}var At=nt&&/\n|Opera/.test(nt+tt.call(e.opera)),Ot=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Mt=!At,_t={};_t[ht]=_t[pt]=_t["[object Function]"]=_t[dt]=_t[vt]=_t[mt]=i,_t[lt]=_t[ct]= -_t[gt]=n;var Dt={};Dt[lt]=Dt["[object Function]"]=i,Dt[ct]=Dt[ht]=Dt[pt]=Dt[dt]=Dt[vt]=Dt[mt]=Dt[gt]=n;var Pt={"&":"&","<":"<",">":">",'"':""","'":"'"},Ht={"&":"&","<":"<",">":">",""":'"',"'":"'"},Bt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g -,variable:""};var Ft={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y)d=c(d,y)",i:"if(d(A,j,e)===false)return u"},It={j:"{}",q:"var q;if(typeof d!='function'){var hh=d;d=function(A){return A[hh]}}else if(y)d=c(d,y)",i:"q=d(A,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},qt={j:"true",i:"if(!d(A,j,e))return!u"},Rt={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1"},i:"if(A===gg)return true"}),cn=c(Ft,It),hn=c(Ft,qt),pn=c(Ft,Ut),dn=c(Ft,zt,{j:"",i:"if(d(A,j,e))return A"}),vn=c(Ft,zt),mn=c(Ft,It,{i:"q=d(A,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(A)"}),gn=c(Xt,{a:"e,U",q:"var C=w.call(arguments,2),R=typeof U=='function'",i:{b:"u[j]=(R?U:A[U]).apply(A,C)",l:"u"+(Ot?"[o]=":".push")+"((R?U:A[U]).apply(A,C))"}}),yn=c(Ft,Xt),bn= -c(Xt,{a:"e,aa",i:{b:"u[j]=A[aa]",l:"u"+(Ot?"[o]=":".push")+"(A[aa])"}}),wn=c({a:"e,d,B,y",j:"B",q:"var V=arguments.length<3;if(y)d=c(d,y)",d:{b:"if(V)u=k[++j]"},i:{b:"u=d(u,A,j,e)",l:"u=V?(V=false,A):d(u,A,j,e)"}}),En=c(Ft,Ut,{i:"!"+Ut.i}),Sn=c(Ft,qt,{j:"false",i:qt.i.replace("!","")}),xn=c(Ft,It,Xt,{i:{b:"u[j]={a:d(A,j,e),b:j,c:A}",l:"u"+(Ot?"[o]=":".push")+"({a:d(A,j,e),b:j,c:A})"},e:"u.sort(I);l=u.length;while(l--)u[l]=u[l].c"}),Tn=c(Ut,{a:"e,Z",q:"var t=[];J(Z,function(A,q){t.push(q)});var bb=t.length" -,i:"for(var q,Y=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=A,s.bindAll=Nn,s.chain=function(e){return e=new o(e),e.__chain__=n,e},s.clone=b,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++n< -r;)e[n]&&t.push(e[n]);return t},s.compose=function(){var e=arguments;return function(){for(var t=arguments,n=e.length;n--;)t=[e[n].apply(this,t)];return t[0]}},s.contains=ln,s.countBy=cn,s.debounce=function(e,t,n){function i(){a=r,n||(o=e.apply(u,s))}var s,o,u,a;return function(){var r=n&&!a;return s=arguments,u=this,yt(a),a=bt(i,t),r&&(o=e.apply(u,s)),o}},s.defaults=Qt,s.defer=function(e){var n=et.call(arguments,1);return bt(function(){return e.apply(t,n)},1)},s.delay=function(e,n){var r=et.call -(arguments,2);return bt(function(){return e.apply(t,r)},n)},s.difference=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=Q.apply(t,arguments),i=a(i,r);++nT(t,n)){for(var u=1;un?ut(0,r+n):at(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return l(t,e,et.call(arguments,2))},s.map=yn,s.max= -N,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return G.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=sn,s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s=f?(a=r,s=e.apply(o,i)):u||(u=bt(n,f)),s}},s.times=function(e,t,n){var r=-1,i=Array(e||0);if( -n)for(;++rT(t,n[e])&&t.push(n[e]);return t},s.uniq=L,s.uniqueId=function(e){var t=H++;return e?e+t:t},s.values=fn,s.where=Tn,s.without=function(e){var t=[];if(!e)return t -;for(var n=-1,r=e.length,i=a(arguments,1,20);++n++u;)if(c=K[u],G.call(e,c)&&(!G.call(t,c)||!w(e[c],t[c],s,o)))return i;return n}function E(e,t,n,r){if(!e)return n;var s=e.length,o=3>arguments.length;if(s!==+s)var u=rn(e),s=u.length;return wn(e,function(e,n,a,f){return a=u?u[--s]:--s,o?(o=i,f[a]):t.call(r,e,f[a],a,f)},n)}function S(e,t,n){if(e)return t==r||n?e[0]:et.call(e,0,t)} +function x(e,t){var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?ut(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=u(t,n));++sr&&(r=n,i=e[s]);return i}function C(e,t,n) +{return e?et.call(e,t==r||n?1:t):[]}function k(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=A(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]T(f,r))f.push(r),s.push(e[o]);return s}function A(e,t){return At||nt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/ +,I=/&(?:amp|lt|gt|quot|#x27);/g,q=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,U=/(__e\(.*?\)|\b__t\))\+'';/g,z=/\w*$/,W=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,X=RegExp("^"+(P.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),V=/($^)/,$=/[&<>"']/g,J=/['\n\r\t\u2028\u2029\\]/g,K="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),Q=D.concat,G=P.hasOwnProperty,Y=D.push,Z=P.propertyIsEnumerable,et=D.slice,tt= +P.toString,nt=X.test(nt=et.bind)&&nt,rt=Math.floor,it=X.test(it=Array.isArray)&&it,st=e.isFinite,ot=X.test(ot=Object.keys)&&ot,ut=Math.max,at=Math.min,ft=Math.random,lt="[object Arguments]",ct="[object Array]",ht="[object Boolean]",pt="[object Date]",dt="[object Number]",vt="[object Object]",mt="[object RegExp]",gt="[object String]",yt=e.clearTimeout,bt=e.setTimeout,wt,Et,St,xt=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in +arguments)xt=!r;wt=4>(n+"").length,St="x"!=n[0],Et=(n.splice.call(t,0,1),t[0])})(1);var Tt=!m(arguments),Nt="x"!=et.call("x")[0],Ct="xx"!="x"[0]+Object("x")[0];try{var kt=("[object Object]",tt.call(e.document||0)==vt)}catch(Lt){}var At=nt&&/\n|Opera/.test(nt+tt.call(e.opera)),Ot=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Mt=!At,_t={};_t[ht]=_t[pt]=_t["[object Function]"]=_t[dt]=_t[vt]=_t[mt]=i,_t[lt]=_t[ct]=_t[gt]=n;var Dt={};Dt[lt]=Dt["[object Function]"]=i,Dt[ct]=Dt[ht]=Dt[pt]=Dt[dt]=Dt[vt]=Dt[mt +]=Dt[gt]=n;var Pt={"&":"&","<":"<",">":">",'"':""","'":"'"},Ht={"&":"&","<":"<",">":">",""":'"',"'":"'"},Bt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Ft={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y)d=c(d,y)",i:"if(d(A,j,e)===false)return u" +},It={j:"{}",q:"var q;if(typeof d!='function'){var hh=d;d=function(A){return A[hh]}}else if(y)d=c(d,y)",i:"q=d(A,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},qt={j:"true",i:"if(!d(A,j,e))return!u"},Rt={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1"},i:"if(A===gg)return true"}),cn=c(Ft,It),hn=c(Ft,qt),pn=c(Ft,Ut),dn=c(Ft,zt,{j:"",i:"if(d(A,j,e))return A"}),vn=c(Ft,zt),mn=c(Ft,It,{i:"q=d(A,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(A)"}),gn=c(Xt,{a:"e,U",q:"var C=w.call(arguments,2),R=typeof U=='function'",i:{b:"u[j]=(R?U:A[U]).apply(A,C)",l:"u"+(Ot?"[o]=":".push")+"((R?U:A[U]).apply(A,C))"}}),yn=c(Ft,Xt),bn=c(Xt,{a:"e,aa",i:{b:"u[j]=A[aa]",l:"u"+(Ot?"[o]=":".push")+"(A[aa])"} +}),wn=c({a:"e,d,B,y",j:"B",q:"var V=arguments.length<3;if(y)d=c(d,y)",d:{b:"if(V)u=k[++j]"},i:{b:"u=d(u,A,j,e)",l:"u=V?(V=false,A):d(u,A,j,e)"}}),En=c(Ft,Ut,{i:"!"+Ut.i}),Sn=c(Ft,qt,{j:"false",i:qt.i.replace("!","")}),xn=c(Ft,It,Xt,{i:{b:"u[j]={a:d(A,j,e),b:j,c:A}",l:"u"+(Ot?"[o]=":".push")+"({a:d(A,j,e),b:j,c:A})"},e:"u.sort(I);l=u.length;while(l--)u[l]=u[l].c"}),Tn=c(Ut,{a:"e,Z",q:"var t=[];J(Z,function(A,q){t.push(q)});var bb=t.length",i:"for(var q,Y=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=A,s.bindAll=Nn,s.chain=function(e){return e=new o(e),e.__chain__=n,e},s.clone=b,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nT(t,n)){for(var u=1;un?ut(0,r+n):at(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return l(t,e,et.call(arguments,2))},s.map=yn,s.max=N,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments) +:arguments[0];return G.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=sn,s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s=f?(a=r,s=e.apply(o,i)):u||(u=bt(n,f)),s}},s.times=function(e,t,n){var r=-1,i=Array(e||0);if(n)for(;++rT(r,t[e])&&r.push(t[e]);return r},s.uniq=L,s.uniqueId=function(e){var t=H++;return e?e+t:t},s.values=fn,s.where=Tn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=a(arguments,1,20);++n 4 ? 'hasOwnProperty' : 'constructor'; + }); + equal(grouped.constructor.length, 1); + equal(grouped.hasOwnProperty.length, 2); + }); test('countBy', function() { @@ -341,6 +351,12 @@ $(document).ready(function() { var context = {}; _.countBy([{}], function(){ ok(this === context); }, context); + + grouped = _.countBy([4.2, 6.1, 6.4], function(num) { + return Math.floor(num) > 4 ? 'hasOwnProperty' : 'constructor'; + }); + equal(grouped.constructor, 1); + equal(grouped.hasOwnProperty, 2); }); test('sortedIndex', function() { diff --git a/vendor/underscore/test/objects.js b/vendor/underscore/test/objects.js index 236a9d9554..22949c3bfe 100644 --- a/vendor/underscore/test/objects.js +++ b/vendor/underscore/test/objects.js @@ -15,17 +15,22 @@ $(document).ready(function() { }); test("values", function() { - equal(_.values({one : 1, two : 2}).join(', '), '1, 2', 'can extract the values from an object'); + equal(_.values({one: 1, two: 2}).join(', '), '1, 2', 'can extract the values from an object'); + equal(_.values({one: 1, two: 2, length: 3}).join(', '), '1, 2, 3', '... even when one of them is "length"'); }); test("pairs", function() { deepEqual(_.pairs({one: 1, two: 2}), [['one', 1], ['two', 2]], 'can convert an object into pairs'); + deepEqual(_.pairs({one: 1, two: 2, length: 3}), [['one', 1], ['two', 2], ['length', 3]], '... even when one of them is "length"'); }); test("invert", function() { var obj = {first: 'Moe', second: 'Larry', third: 'Curly'}; equal(_.keys(_.invert(obj)).join(' '), 'Moe Larry Curly', 'can invert an object'); ok(_.isEqual(_.invert(_.invert(obj)), obj), 'two inverts gets you back where you started'); + + var obj = {length: 3}; + ok(_.invert(obj)['3'] == 'length', 'can invert an object with "length"') }); test("functions", function() { diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index ab6a0fcf73..6596e3d3ae 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -5,29 +5,11 @@ // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: // http://documentcloud.github.com/underscore -(function(){var r=this,J=r._,n={},k=Array.prototype,o=Object.prototype,s=k.push,h=k.slice,p=k.concat,l=o.toString,K=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,q=k.indexOf,D=k.lastIndexOf,o=Array.isArray,L=Object.keys,t=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._= -b):r._=b;b.VERSION="1.3.3";var i=b.each=b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,g=a.length;e2;a==null&& -(a=[]);if(!g&&y&&a.reduce===y){e&&(c=b.bind(c,e));return f?a.reduce(c,d):a.reduce(c)}i(a,function(a,b,h){if(g){b=g.keys[b];h=g.list}if(f)d=c.call(e,d,a,b,h);else{d=a;f=true}});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){a==null&&(a=[]);if(z&&a.reduceRight===z){e&&(c=b.bind(c,e));return arguments.length>2?a.reduceRight(c,d):a.reduceRight(c)}var g=b.keys(a).reverse(),f=b.toArray(a).reverse();return b.reduce(f,c,d,e,{keys:g, -list:a})};b.find=b.detect=function(a,c,b){var e;E(a,function(a,f,j){if(c.call(b,a,f,j)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);i(a,function(a,f,j){c.call(b,a,f,j)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;i(a,function(a,f,j){c.call(b,a,f,j)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c, -d);i(a,function(a,b,j){if(!(e=e&&c.call(d,a,b,j)))return n});return!!e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);i(a,function(a,b,j){if(e||(e=c.call(d,a,b,j)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=h.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)? -c:a[c]).apply(a,d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.where=function(a,c){return b.isEmpty(c)?[]:b.filter(a,function(a){for(var b in c)if(c[b]!==a[b])return false;return true})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};i(a,function(a,b,j){b=c?c.call(d,a,b,j):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&& -b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};i(a,function(a,b,j){b=c?c.call(d,a,b,j):a;bd||b===void 0)return 1;if(b>1;d(a[f])=0})})};b.difference=function(a){var c=p.apply(k,h.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=h.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=L||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods= -function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){i(h.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var b={},d=p.apply(k,h.call(arguments,1));i(d,function(d){d in a&&(b[d]=a[d])});return b};b.omit=function(a){var c={},d=p.apply(k,h.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){i(h.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a}; -b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d,e){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;var g=l.call(a);if(g!=l.call(c))return false;switch(g){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== -c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return e[f]==c;d.push(a);e.push(c);var f=0,j=true;if(g=="[object Array]"){f=a.length;if(j=f==c.length)for(;f--;)if(!(j=u(a[f],c[f],d,e)))break}else{var g=a.constructor,h=c.constructor;if(g!==h&&(!b.isFunction(g)||!(g instanceof g&&b.isFunction(h)&&h instanceof h)))return false;for(var i in a)if(b.has(a,i)){f++;if(!(j=b.has(c,i)&& -u(a[i],c[i],d,e)))break}if(j){for(i in c)if(b.has(c,i)&&!f--)break;j=!f}}d.pop();e.pop();return j};b.isEqual=function(a,b){return u(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};i("Arguments,Function,String,Number,Date,RegExp".split(","), -function(a){b["is"+a]=function(b){return l.call(b)=="[object "+a+"]"}});b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return b.isNumber(a)&&a!=+a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return K.call(a,b)};b.noConflict=function(){r._=J; -return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e":">",'"':""","'":"'","/":"/"}};m.unescape=b.invert(m.escape);var M={escape:RegExp("["+b.keys(m.escape).join("")+"]","g"),unescape:RegExp("("+b.keys(m.unescape).join("|")+")","g")};b.each(["escape","unescape"],function(a){b[a]=function(b){return b==null?"":(""+ -b).replace(M[a],function(b){return m[a][b]})}});b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){i(b.functions(a),function(c){var d=b[c]=a[c];b.prototype[c]=function(){var a=[this._wrapped];s.apply(a,arguments);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var N=0;b.uniqueId=function(a){var b=N++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var v=/(.)^/, -O={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},P=/\\|'|\r|\n|\t|\u2028|\u2029/g;b.template=function(a,c,d){var d=b.defaults({},d,b.templateSettings),e=RegExp([(d.escape||v).source,(d.interpolate||v).source,(d.evaluate||v).source].join("|")+"|$","g"),g=0,f="__p+='";a.replace(e,function(b,c,d,e,h){f=f+a.slice(g,h).replace(P,function(a){return"\\"+O[a]});f=f+(c?"'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'":d?"'+\n((__t=("+d+"))==null?'':__t)+\n'":e?"';\n"+e+"\n__p+='": -"");g=h+b.length});f=f+"';\n";d.variable||(f="with(obj||{}){\n"+f+"}\n");f="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+f+"return __p;\n";try{var h=new Function(d.variable||"obj","_",f)}catch(i){i.source=f;throw i;}if(c)return h(c,b);c=function(a){return h.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+f+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);i("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c= -k[a];b.prototype[a]=function(){var d=this._wrapped;c.apply(d,arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain():d}});i(["concat","join","slice"],function(a){var c=k[a];b.prototype[a]=function(){var a=c.apply(this._wrapped,arguments);return this._chain?b(a).chain():a}});b.extend(b.prototype,{chain:function(){this._chain=true;return this},value:function(){return this._wrapped}})}).call(this); +// Underscore.js 1.3.3 +// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. +// Underscore may be freely distributed under the MIT license. +// Portions of Underscore are inspired or borrowed from Prototype, +// Oliver Steele's Functional, and John Resig's Micro-Templating. +// For all details and documentation: +// http://documentcloud.github.com/underscore +(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.3.3";var N=T.each=T.forEach=function(e,t,r){if(e==null)return;if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i2;e==null&&(e=[]);if(!C&&d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){C&&(s=C.keys[s],o=C.list),i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=T.toArray(e).reverse();r&&!i&&(t=T.bind(t,r)),C={keys:T.keys(e).reverse(),list:e};var o=i?T.reduce(s,t,n,r):T.reduce(s,t);return C=null,o},T.find=T.detect=function(e,t,n){var r;return k(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return e==null?r:m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return e==null?r:(N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r)},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return e==null?i:g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var k=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return e==null?i:y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return e==null?n:b&&e.indexOf===b?e.indexOf(t)!=-1:(n=k(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;or||n===void 0)return 1;if(n>>1;n.call(r,e[u])=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var _=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=_(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&_(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return _(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r":">",'"':""","'":"'","/":"/"}};D.unescape=T.invert(D.escape);var P={escape:new RegExp("["+T.keys(D.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(D.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(P[e],function(t){return D[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),I.call(this,n.apply(T,e))}})};var H=0;T.uniqueId=function(e){var t=H++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var B=/(.)^/,j={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},F=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||B).source,(n.interpolate||B).source,(n.evaluate||B).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(F,function(e){return"\\"+j[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var I=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],I.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return I.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index b4521f5d5d..1ac8de1325 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -105,9 +105,12 @@ return results; }; + // Internal data flag for performing `reduceRight`. + var right = null; + // **Reduce** builds up a single result from a list of values, aka `inject`, // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. - _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context, right) { + _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { var initial = arguments.length > 2; if (obj == null) obj = []; if (!right && nativeReduce && obj.reduce === nativeReduce) { @@ -133,14 +136,18 @@ // The right-associative version of reduce, also known as `foldr`. // Delegates to **ECMAScript 5**'s native `reduceRight` if available. _.reduceRight = _.foldr = function(obj, iterator, memo, context) { + var initial = arguments.length > 2; if (obj == null) obj = []; if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { if (context) iterator = _.bind(iterator, context); return arguments.length > 2 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); } - var keys = _.keys(obj).reverse(); - var values = _.toArray(obj).reverse(); - return _.reduce(values, iterator, memo, context, {keys: keys, list: obj}); + var values = _.toArray(obj).reverse(); + if (context && !initial) iterator = _.bind(iterator, context); + right = {keys: _.keys(obj).reverse(), list: obj}; + var result = initial ? _.reduce(values, iterator, memo, context) : _.reduce(values, iterator); + right = null; + return result; }; // Return the first value which passes a truth test. Aliased as `detect`. @@ -206,9 +213,9 @@ return !!result; }; - // Determine if a given value is included in the array or object using `===`. - // Aliased as `contains`. - _.include = _.contains = function(obj, target) { + // Determine if the array or object contains a given value (using `===`). + // Aliased as `include`. + _.contains = _.include = function(obj, target) { var found = false; if (obj == null) return found; if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; @@ -326,7 +333,7 @@ // to group by, or a function that returns the criterion. _.groupBy = function(obj, value, context) { return group(obj, value, context, function(result, key, value) { - (result[key] || (result[key] = [])).push(value); + (_.has(result, key) ? result[key] : (result[key] = [])).push(value); }); }; @@ -335,20 +342,20 @@ // criterion. _.countBy = function(obj, value, context) { return group(obj, value, context, function(result, key, value) { - result[key] || (result[key] = 0); + if (!_.has(result, key)) result[key] = 0; result[key]++; }); }; // Use a comparator function to figure out the smallest index at which // an object should be inserted so as to maintain order. Uses binary search. - _.sortedIndex = function(array, obj, iterator) { + _.sortedIndex = function(array, obj, iterator, context) { iterator || (iterator = _.identity); - var value = iterator(obj); + var value = iterator.call(context, obj); var low = 0, high = array.length; while (low < high) { - var mid = (low + high) >> 1; - iterator(array[mid]) < value ? low = mid + 1 : high = mid; + var mid = (low + high) >>> 1; + iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid; } return low; }; @@ -431,12 +438,12 @@ // Produce a duplicate-free version of the array. If the array has already // been sorted, you have the option of using a faster algorithm. // Aliased as `unique`. - _.uniq = _.unique = function(array, isSorted, iterator) { - var initial = iterator ? _.map(array, iterator) : array; + _.uniq = _.unique = function(array, isSorted, iterator, context) { + var initial = iterator ? _.map(array, iterator, context) : array; var results = []; var seen = []; each(initial, function(value, index) { - if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.include(seen, value)) { + if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) { seen.push(value); results.push(array[index]); } @@ -465,7 +472,7 @@ // Only the elements present in just the first array will remain. _.difference = function(array) { var rest = concat.apply(ArrayProto, slice.call(arguments, 1)); - return _.filter(array, function(value){ return !_.include(rest, value); }); + return _.filter(array, function(value){ return !_.contains(rest, value); }); }; // Zip together multiple lists into a single array -- elements that share @@ -503,21 +510,25 @@ // for **isSorted** to use binary search. _.indexOf = function(array, item, isSorted) { if (array == null) return -1; - var i, l; + var i = 0, l = array.length; if (isSorted) { - i = _.sortedIndex(array, item); - return array[i] === item ? i : -1; + if (typeof isSorted == 'number') { + i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted); + } else { + i = _.sortedIndex(array, item); + return array[i] === item ? i : -1; + } } - if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item); - for (i = 0, l = array.length; i < l; i++) if (array[i] === item) return i; + if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted); + for (; i < l; i++) if (array[i] === item) return i; return -1; }; // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. - _.lastIndexOf = function(array, item) { + _.lastIndexOf = function(array, item, fromIndex) { if (array == null) return -1; - if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item); - var i = array.length; + if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item, fromIndex); + var i = (fromIndex != null ? fromIndex : array.length); while (i--) if (array[i] === item) return i; return -1; }; @@ -708,22 +719,23 @@ // Retrieve the values of an object's properties. _.values = function(obj) { - return _.map(obj, _.identity); + var values = []; + for (var key in obj) if (_.has(obj, key)) values.push(obj[key]); + return values; }; // Convert an object into a list of `[key, value]` pairs. _.pairs = function(obj) { - return _.map(obj, function(value, key) { - return [key, value]; - }); + var pairs = []; + for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]); + return pairs; }; // Invert the keys and values of an object. The values must be serializable. _.invert = function(obj) { - return _.reduce(obj, function(memo, value, key) { - memo[value] = key; - return memo; - }, {}); + var result = {}; + for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key; + return result; }; // Return a sorted list of the function names available on the object. @@ -761,7 +773,7 @@ var copy = {}; var keys = concat.apply(ArrayProto, slice.call(arguments, 1)); for (var key in obj) { - if (!_.include(keys, key)) copy[key] = obj[key]; + if (!_.contains(keys, key)) copy[key] = obj[key]; } return copy; }; @@ -897,7 +909,7 @@ // Is a given value a DOM element? _.isElement = function(obj) { - return !!(obj && obj.nodeType == 1); + return !!(obj && obj.nodeType === 1); }; // Is a given value an array? @@ -926,6 +938,13 @@ }; } + // Optimize `isFunction` if appropriate. + if (typeof (/./) !== 'function') { + _.isFunction = function(obj) { + return typeof obj === 'function'; + }; + } + // Is a given object a finite number? _.isFinite = function(obj) { return _.isNumber(obj) && isFinite(obj); From d8e3e823a7cf567371248579e68a9ad916370e55 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 20 Sep 2012 21:11:23 -0700 Subject: [PATCH 33/82] Removed Underscore's fixed issues from README.md and rebuild docs. Former-commit-id: 08db54926a791ab32b7e003143ae0f70a251068e --- README.md | 45 ++++++++++----------- doc/README.md | 108 +++++++++++++++++++++++++------------------------- 2 files changed, 74 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index f373bbbb52..0d24d173e8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Lo-Dash v0.7.0 -A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) for Underscore.js, from the devs behind [jsPerf.com](http://jsperf.com), delivering [performance](http://lodash.com/benchmarks), [bug fixes](https://github.com/bestiejs/lodash#resolved-underscorejs-issues-20), and [additional features](https://github.com/bestiejs/lodash#features). +A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) for Underscore.js, from the devs behind [jsPerf.com](http://jsperf.com), delivering [performance](http://lodash.com/benchmarks), [bug fixes](https://github.com/bestiejs/lodash#resolved-underscorejs-issues), and [additional features](https://github.com/bestiejs/lodash#features). Lo-Dash’s performance is gained by avoiding slower native methods, instead opting for simplified non-ES5 compliant methods optimized for common usage, and by leveraging function compilation to reduce the number of overall function calls. @@ -191,30 +191,24 @@ require({ }); ``` -## Resolved Underscore.js issues (20+) - - * Allow iteration of objects with a `length` property [[#148](https://github.com/documentcloud/underscore/issues/148), [#154](https://github.com/documentcloud/underscore/issues/154), [#252](https://github.com/documentcloud/underscore/issues/252), [#448](https://github.com/documentcloud/underscore/issues/448), [#659](https://github.com/documentcloud/underscore/issues/659), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L543-549)] - * Ensure array-like objects with invalid `length` properties are treated like regular objects [[#741](https://github.com/documentcloud/underscore/issues/741), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L491-501)] - * Ensure *“Arrays”*, *“Collections”*, and *“Objects”* methods don’t error when passed falsey arguments [[#650](https://github.com/documentcloud/underscore/pull/650), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1719-1754)] - * Ensure *“Collections”* methods allow string `collection` arguments [[#247](https://github.com/documentcloud/underscore/issues/247), [#276](https://github.com/documentcloud/underscore/issues/276), [#561](https://github.com/documentcloud/underscore/pull/561), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L503-520)] - * Fix cross-browser object iteration bugs [[#60](https://github.com/documentcloud/underscore/issues/60), [#376](https://github.com/documentcloud/underscore/issues/376), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L554-579)] - * Methods should work on pages with incorrectly shimmed native methods [[#7](https://github.com/documentcloud/underscore/issues/7), [#742](https://github.com/documentcloud/underscore/issues/742), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L134-140)] - * Register as an AMD module, but still export to global [[#431](https://github.com/documentcloud/underscore/pull/431), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L118-132)] - * `_.clone` should allow `deep` cloning [[#595](https://github.com/documentcloud/underscore/pull/595), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L223-234)] - * `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L289-298)] - * `_.countBy` and `_.groupBy` should only add values to own, not inherited, properties [[#736](https://github.com/documentcloud/underscore/issues/736), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L306-313)] - * `_.extend` should recursively extend objects [[#379](https://github.com/documentcloud/underscore/pull/379), [#718](https://github.com/documentcloud/underscore/issues/718), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L946-968)] - * `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L486-489)] - * `_.forEach` should allow exiting iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L581-600)] - * `_.isElement` should use strict equality for its duck type check [[#734](https://github.com/documentcloud/underscore/issues/734), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L696-705)] - * `_.isEmpty` should support jQuery/MooTools DOM query collections [[#690](https://github.com/documentcloud/underscore/pull/690), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L732-737)] - * `_.isEqual` should return `true` for like-objects from different documents [[#733](https://github.com/documentcloud/underscore/issues/733), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L784-795)] - * `_.isObject` should avoid V8 bug [#2291](http://code.google.com/p/v8/issues/detail?id=2291) [[#605](https://github.com/documentcloud/underscore/issues/605), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L803-815)] - * `_.keys` should work with `arguments` objects cross-browser [[#396](https://github.com/documentcloud/underscore/issues/396), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L879-881)] - * `_.range` should coerce arguments to numbers [[#634](https://github.com/documentcloud/underscore/issues/634), [#683](https://github.com/documentcloud/underscore/issues/683), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1222-1225)] - * `_.reduceRight` should pass correct callback arguments when iterating objects [[test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1257-1271)] - * `_.sortedIndex` should support arrays with high `length` values [[#735](https://github.com/documentcloud/underscore/issues/735), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1404-1413)] - * `_.throttle` should work when called in a loop [[#502](https://github.com/documentcloud/underscore/issues/502), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1534-1544)] +## Resolved Underscore.js issues + + * Allow iteration of objects with a `length` property [[#148](https://github.com/documentcloud/underscore/issues/148), [#154](https://github.com/documentcloud/underscore/issues/154), [#252](https://github.com/documentcloud/underscore/issues/252), [#448](https://github.com/documentcloud/underscore/issues/448), [#659](https://github.com/documentcloud/underscore/issues/659), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L543-549)] + * Ensure *“Arrays”*, *“Collections”*, and *“Objects”* methods don’t error when passed falsey arguments [[#650](https://github.com/documentcloud/underscore/pull/650), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L1719-1754)] + * Ensure *“Collections”* methods allow string `collection` arguments [[#247](https://github.com/documentcloud/underscore/issues/247), [#276](https://github.com/documentcloud/underscore/issues/276), [#561](https://github.com/documentcloud/underscore/pull/561), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L503-520)] + * Fix cross-browser object iteration bugs [[#60](https://github.com/documentcloud/underscore/issues/60), [#376](https://github.com/documentcloud/underscore/issues/376), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L554-579)] + * Methods should work on pages with incorrectly shimmed native methods [[#7](https://github.com/documentcloud/underscore/issues/7), [#742](https://github.com/documentcloud/underscore/issues/742), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L134-140)] + * Register as an AMD module, but still export to global [[#431](https://github.com/documentcloud/underscore/pull/431), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L118-132)] + * `_.clone` should allow `deep` cloning [[#595](https://github.com/documentcloud/underscore/pull/595), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L223-234)] + * `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L289-298)] + * `_.extend` should recursively extend objects [[#379](https://github.com/documentcloud/underscore/pull/379), [#718](https://github.com/documentcloud/underscore/issues/718), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L946-968)] + * `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L486-489)] + * `_.forEach` should allow exiting iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L581-600)] + * `_.isEmpty` should support jQuery/MooTools DOM query collections [[#690](https://github.com/documentcloud/underscore/pull/690), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L732-737)] + * `_.isObject` should avoid V8 bug [#2291](http://code.google.com/p/v8/issues/detail?id=2291) [[#605](https://github.com/documentcloud/underscore/issues/605), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L803-815)] + * `_.keys` should work with `arguments` objects cross-browser [[#396](https://github.com/documentcloud/underscore/issues/396), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L879-881)] + * `_.range` should coerce arguments to numbers [[#634](https://github.com/documentcloud/underscore/issues/634), [#683](https://github.com/documentcloud/underscore/issues/683), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L1222-1225)] + * `_.throttle` should work when called in a loop [[#502](https://github.com/documentcloud/underscore/issues/502), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L1534-1544)] ## Optimized methods (50+) @@ -273,6 +267,7 @@ require({ * `_.union` * `_.uniq`, `_.unique` * `_.values` + * `_.where` * `_.without` * `_.wrap` * `_.zip` diff --git a/doc/README.md b/doc/README.md index 3a041e6903..5a37364c9c 100644 --- a/doc/README.md +++ b/doc/README.md @@ -173,7 +173,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4129 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4109 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -185,7 +185,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3227 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3207 "View in source") [Ⓣ][1] Creates a function that is restricted to executing only after it is called `n` times. @@ -213,7 +213,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3260 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3240 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. @@ -244,7 +244,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3290 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3270 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -275,7 +275,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4054 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4034 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -351,7 +351,7 @@ shallow[0] === stooges[0]; ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2457 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2437 "View in source") [Ⓣ][1] Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -375,7 +375,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3328 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3308 "View in source") [Ⓣ][1] Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -468,7 +468,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3361 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3341 "View in source") [Ⓣ][1] Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -520,7 +520,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3426 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3406 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -545,7 +545,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3406 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3386 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -572,7 +572,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2489 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2469 "View in source") [Ⓣ][1] Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -597,7 +597,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3645 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3625 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -733,7 +733,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2526 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2506 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -762,7 +762,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2550 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2530 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -970,7 +970,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3665 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3645 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -995,7 +995,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2596 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2576 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1027,7 +1027,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2636 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2616 "View in source") [Ⓣ][1] Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. @@ -1053,7 +1053,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2658 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2638 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -1580,7 +1580,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2701 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2681 "View in source") [Ⓣ][1] Gets the last element of the `array`. Pass `n` to return the lasy `n` elementsvof the `array`. @@ -1606,7 +1606,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2727 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2707 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1635,7 +1635,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.lateBind(object, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3463 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3443 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method @@ -1708,7 +1708,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2767 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2747 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1740,7 +1740,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3485 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3465 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1804,7 +1804,7 @@ _.merge(stooges, ages); ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2817 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2797 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1830,7 +1830,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3691 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3671 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1860,7 +1860,7 @@ _('curly').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3722 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3702 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1880,7 +1880,7 @@ var lodash = _.noConflict(); ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2866 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2846 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. @@ -1936,7 +1936,7 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3511 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3491 "View in source") [Ⓣ][1] Creates a function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1986,7 +1986,7 @@ _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3546 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3526 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `bind`, except it does **not** alter the `this` binding. @@ -2075,7 +2075,7 @@ _.pluck(stooges, 'name'); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3745 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3725 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -2103,7 +2103,7 @@ _.random(5); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2913 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2893 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -2202,7 +2202,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2275 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2255 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -2228,7 +2228,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2952 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2932 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2257,7 +2257,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3784 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3764 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2292,7 +2292,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2973 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2953 "View in source") [Ⓣ][1] Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2316,7 +2316,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2299 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2279 "View in source") [Ⓣ][1] Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. @@ -2346,7 +2346,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2327 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2307 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2375,7 +2375,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2357 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2337 "View in source") [Ⓣ][1] Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2407,7 +2407,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3025 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3005 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. @@ -2448,7 +2448,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4081 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4061 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2478,7 +2478,7 @@ _.chain([1, 2, 3, 200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3857 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3837 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: In the development build `_.template` utilizes sourceURLs for easier debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. See http://developer.chrome.com/trunk/extensions/sandboxingEval.html @@ -2543,7 +2543,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3568 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3548 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2568,7 +2568,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3976 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3956 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -2600,7 +2600,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2393 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2373 "View in source") [Ⓣ][1] Converts the `collection`, to an array. @@ -2624,7 +2624,7 @@ Converts the `collection`, to an array. ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4006 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3986 "View in source") [Ⓣ][1] Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -2648,7 +2648,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3066 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3046 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -2672,7 +2672,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3110 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3090 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -2711,7 +2711,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4024 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4004 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2759,7 +2759,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2427 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2407 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. @@ -2790,7 +2790,7 @@ _.where(stooges, { 'age': 40 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3159 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3139 "View in source") [Ⓣ][1] Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2815,7 +2815,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3619 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3599 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2844,7 +2844,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3192 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3172 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2875,7 +2875,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4099 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4079 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2896,7 +2896,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4116 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4096 "View in source") [Ⓣ][1] Extracts the wrapped value. From 1ca26ce6768dc947fb2321a9e8670dbbc25ec47b Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 22 Sep 2012 15:39:37 -0700 Subject: [PATCH 34/82] Ensure methods accepting a `thisArg` argument allow `null` values. Former-commit-id: 368b943687291f0d7ed02304284ac076ef86e02b --- build/pre-compile.js | 1 + lodash.js | 31 ++++++++++++------------ test/test.js | 56 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 16 deletions(-) diff --git a/build/pre-compile.js b/build/pre-compile.js index e564f75a7c..7b2c582ed8 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -33,6 +33,7 @@ 'stringClass', 'thisArg', 'toString', + 'undefined', 'value', // lesser used variables diff --git a/lodash.js b/lodash.js index 8595b3e38c..b1811a625f 100644 --- a/lodash.js +++ b/lodash.js @@ -456,8 +456,8 @@ /** * Reusable iterator options shared by - * `every`, `filter`, `find`, `forEach`, `forIn`, `forOwn`, `groupBy`, `map`, - * `reject`, `some`, and `sortBy`. + * `countBy`, `every`, `filter`, `find`, `forEach`, `forIn`, `forOwn`, `groupBy`, + * `map`, `reject`, `some`, and `sortBy`. */ var baseIteratorOptions = { 'args': 'collection, callback, thisArg', @@ -466,7 +466,7 @@ 'if (!callback) {\n' + ' callback = identity\n' + '}\n' + - 'else if (thisArg) {\n' + + 'else if (thisArg !== undefined) {\n' + ' callback = bindIterator(callback, thisArg)\n' + '}', 'inLoop': 'if (callback(value, index, collection) === false) return result' @@ -481,7 +481,7 @@ ' var valueProp = callback;\n' + ' callback = function(value) { return value[valueProp] }\n' + '}\n' + - 'else if (thisArg) {\n' + + 'else if (thisArg !== undefined) {\n' + ' callback = bindIterator(callback, thisArg)\n' + '}', 'inLoop': @@ -516,7 +516,7 @@ /** Reusable iterator options for `find`, `forEach`, `forIn`, and `forOwn` */ var forEachIteratorOptions = { - 'top': 'if (thisArg) callback = bindIterator(callback, thisArg)' + 'top': 'if (thisArg !== undefined) callback = bindIterator(callback, thisArg)' }; /** Reusable iterator options for `forIn` and `forOwn` */ @@ -549,7 +549,7 @@ 'var isFunc = typeof callback == \'function\';\n' + 'if (!isFunc) {\n' + ' var props = concat.apply(ArrayProto, arguments)\n' + - '} else if (thisArg) {\n' + + '} else if (thisArg !== undefined) {\n' + ' callback = bindIterator(callback, thisArg)\n' + '}', 'inLoop': @@ -792,7 +792,7 @@ 'arrayLikeClasses, ArrayProto, bind, bindIterator, compareAscending, concat, ' + 'forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, ' + 'isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, ' + - 'slice, stringClass, toString', + 'slice, stringClass, toString, undefined', 'var callee = function(' + args + ') {\n' + iteratorTemplate(data) + '\n};\n' + 'return callee' ); @@ -1862,7 +1862,7 @@ ' if (prop in object) result[prop] = object[prop]\n' + ' }\n' + '} else {\n' + - ' if (thisArg) callback = bindIterator(callback, thisArg)', + ' if (thisArg !== undefined) callback = bindIterator(callback, thisArg)', 'inLoop': 'if (callback(value, index, object)) result[index] = value', 'bottom': '}' @@ -2184,7 +2184,7 @@ 'init': 'accumulator', 'top': 'var noaccum = arguments.length < 3;\n' + - 'if (thisArg) callback = bindIterator(callback, thisArg)', + 'if (thisArg !== undefined) callback = bindIterator(callback, thisArg)', 'beforeLoop': { 'array': 'if (noaccum) result = iteratee[++index]' }, @@ -2763,7 +2763,7 @@ } return result; } - if (thisArg) { + if (thisArg !== undefined) { callback = bindIterator(callback, thisArg); } while (++index < length) { @@ -2813,7 +2813,7 @@ } return result; } - if (thisArg) { + if (thisArg !== undefined) { callback = bindIterator(callback, thisArg); } while (++index < length) { @@ -3011,7 +3011,7 @@ high = array.length; if (callback) { - if (thisArg) { + if (thisArg !== undefined) { callback = bind(callback, thisArg); } value = callback(value); @@ -3105,7 +3105,7 @@ } if (!callback) { callback = identity; - } else if (thisArg) { + } else if (thisArg !== undefined) { callback = bindIterator(callback, thisArg); } while (++index < length) { @@ -3954,10 +3954,11 @@ * // => also calls `mage.castSpell(n)` three times */ function times(n, callback, thisArg) { + n = +n || 0; var index = -1, - result = Array(n || 0); + result = Array(n); - if (thisArg) { + if (thisArg !== undefined) { while (++index < n) { result[index] = callback.call(thisArg, index); } diff --git a/test/test.js b/test/test.js index badf879956..e6c752b076 100644 --- a/test/test.js +++ b/test/test.js @@ -1713,7 +1713,61 @@ } }); - ok(pass, methodName + ' allows falsey arguments'); + ok(pass, '_.' + methodName + ' allows falsey arguments'); + }); + }); + + test('should handle `null` `thisArg` arguments', function() { + var thisArg, + array = ['a'], + callback = function() { thisArg = this; }, + useStrict = Function('"use strict";return this')() === undefined; + + var funcs = [ + 'countBy', + 'every', + 'filter', + 'find', + 'forEach', + 'forIn', + 'forOwn', + 'groupBy', + 'map', + 'max', + 'min', + 'omit', + 'pick', + 'reduce', + 'reduceRight', + 'reject', + 'some', + 'sortBy', + 'sortedIndex', + 'times', + 'uniq' + ]; + + _.each(funcs, function(methodName) { + var func = _[methodName], + message = '_.' + methodName + ' handles `null` `thisArg` arguments'; + + thisArg = undefined; + + if (/^reduce/.test(methodName)) { + func(array, callback, 0, null); + } else if (methodName == 'sortedIndex') { + func(array, 'a', callback, null); + } else if (methodName == 'times') { + func(1, callback, null); + } else { + func(array, callback, null); + } + + if (useStrict) { + deepEqual(thisArg, null, message); + } else { + equal(thisArg, window, message); + } }); }); }()); From 8532dc4b756e8e1a7228b0a969bc54db1f4f56a5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 22 Sep 2012 15:55:57 -0700 Subject: [PATCH 35/82] Refactor `reduceRight` and modify a `_.difference` benchmark. Former-commit-id: b70272ac5316fe1bee52b9611a1a5ea4d761dd3c --- build.js | 4 ++-- lodash.js | 18 +++++++++++------- perf/perf.js | 10 +++------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/build.js b/build.js index bb195371c4..12df68099c 100755 --- a/build.js +++ b/build.js @@ -133,7 +133,7 @@ 'random': [], 'range': [], 'reduce': [], - 'reduceRight': ['keys', 'reduce'], + 'reduceRight': ['forEach', 'keys'], 'reject': ['identity'], 'rest': [], 'result': ['isFunction'], @@ -1146,7 +1146,7 @@ source = source.replace(/noArraySliceOnStrings *\?[^:]+: *([^)]+)/g, '$1'); // remove `noCharByIndex` from `_.reduceRight` - source = source.replace(/noCharByIndex *&&[^:]+: *([^;]+)/g, '$1'); + source = source.replace(/}\s*else if *\(noCharByIndex[^}]+/, ''); source = removeVar(source, 'extendIteratorOptions'); source = removeVar(source, 'iteratorTemplate'); diff --git a/lodash.js b/lodash.js index b1811a625f..a2984ada97 100644 --- a/lodash.js +++ b/lodash.js @@ -2220,19 +2220,23 @@ if (!collection) { return accumulator; } - var length = collection.length, + var iteratee = collection, + length = collection.length, noaccum = arguments.length < 3; if (length !== +length) { var props = keys(collection); length = props.length; + } else if (noCharByIndex && toString.call(collection) == stringClass) { + iteratee = collection.split(''); } - return reduce(collection, function(accumulator, value, index, object) { - var index = props ? props[--length] : --length; - return noaccum - ? (noaccum = false, object[index]) - : callback.call(thisArg, accumulator, object[index], index, object); - }, accumulator); + forEach(collection, function(value, index, object) { + index = props ? props[--length] : --length; + accumulator = noaccum + ? (noaccum = false, iteratee[index]) + : callback.call(thisArg, accumulator, iteratee[index], index, object); + }); + return accumulator; } /** diff --git a/perf/perf.js b/perf/perf.js index 51e8ea1d0a..399548cb95 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -276,7 +276,6 @@ var twentyFiveValues = Array(25),\ twentyFiveValues2 = Array(25),\ fiftyValues = Array(50),\ - fiftyValues2 = Array(50),\ seventyFiveValues = Array(75),\ seventyFiveValues2 = Array(75),\ lowerChars = "abcdefghijklmnopqrstuvwxyz".split(""),\ @@ -294,14 +293,11 @@ }\ fiftyValues[index] =\ seventyFiveValues[index] = lowerChars[index];\ - \ - fiftyValues2[index] =\ seventyFiveValues2[index] = upperChars[index];\ }\ else {\ if (index < 50) {\ fiftyValues[index] = index;\ - fiftyValues2[index] = index + (index < 40 ? 75 : 0);\ }\ seventyFiveValues[index] = index;\ seventyFiveValues2[index] = index + (index < 60 ? 75 : 0);\ @@ -575,13 +571,13 @@ ); suites.push( - Benchmark.Suite('`_.difference` iterating 50 elements') + Benchmark.Suite('`_.difference` iterating 50 and 75 elements') .add('Lo-Dash', { - 'fn': 'lodash.difference(fiftyValues, fiftyValues2)', + 'fn': 'lodash.difference(fiftyValues, seventyFiveValues2)', 'teardown': 'function multiArrays(){}' }) .add('Underscore', { - 'fn': '_.difference(fiftyValues, fiftyValues2)', + 'fn': '_.difference(fiftyValues, seventyFiveValues2)', 'teardown': 'function multiArrays(){}' }) ); From e4eb5dadda53c69c7d2ccdddcea35752e40c75f3 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 22 Sep 2012 20:03:43 -0700 Subject: [PATCH 36/82] Modify "underscore" build methods in prep for Underscore.next. Former-commit-id: 22503a046256915aa6667e32f6efb992c6ddbce9 --- build.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/build.js b/build.js index 12df68099c..c4ef4daa6d 100755 --- a/build.js +++ b/build.js @@ -234,19 +234,11 @@ /** List of methods used by Underscore */ var underscoreMethods = _.without.apply(_, [allMethods].concat([ - 'countBy', 'forIn', 'forOwn', - 'invert', 'lateBind', 'merge', - 'object', - 'omit', - 'pairs', - 'partial', - 'random', - 'unescape', - 'where' + 'partial' ])); /** List of ways to export the `LoDash` function */ From 8492c13e728a6dcdcc32e71612f75cc167a2af37 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 22 Sep 2012 20:50:59 -0700 Subject: [PATCH 37/82] Remove DRY modifications for smaller gzip size. Former-commit-id: 69391d792d76c6592e7d48aec44165a8db388f81 --- build.js | 123 +++++++++++++++---------------------------------------- 1 file changed, 33 insertions(+), 90 deletions(-) diff --git a/build.js b/build.js index c4ef4daa6d..f1e2a71664 100755 --- a/build.js +++ b/build.js @@ -395,16 +395,27 @@ } /** - * Gets the `_.isArguments` fallback snippet from `source`. + * Gets the `_.isArguments` fallback from `source`. * * @private * @param {String} source The source to inspect. - * @returns {String} Returns the `isArguments` fallback snippet. + * @returns {String} Returns the `isArguments` fallback. */ function getIsArgumentsFallback(source) { return (source.match(/(?:\s*\/\/.*)*\n( +)if *\(noArgsClass\)[\s\S]+?};\n\1}/) || [''])[0]; } + /** + * Gets the `_.isFunction` fallback from `source`. + * + * @private + * @param {String} source The source to inspect. + * @returns {String} Returns the `isFunction` fallback. + */ + function getIsFunctionFallback(source) { + return (source.match(/(?:\s*\/\/.*)*\n( +)if *\(isFunction\(\/x\/[\s\S]+?};\n\1}/) || [''])[0]; + } + /** * Gets the names of methods in `source` belonging to the given `category`. * @@ -579,7 +590,7 @@ * @returns {String} Returns the source with the `isFunction` fallback removed. */ function removeIsFunctionFallback(source) { - return source.replace(/(?:\s*\/\/.*)*\n( +)if *\(isFunction\(\/x\/[\s\S]+?};\n\1}/, ''); + return source.replace(getIsFunctionFallback(source), ''); } /** @@ -785,6 +796,11 @@ // backup `dependencyMap` to restore later var dependencyBackup = _.clone(dependencyMap, true); + // used to specify a custom IIFE to wrap Lo-Dash + var iife = options.reduce(function(result, value) { + return result || (result = value.match(/iife=(.*)/)) && result[1]; + }, null); + // flag used to specify a Backbone build var isBackbone = options.indexOf('backbone') > -1; @@ -810,23 +826,24 @@ // constructed using the "use strict" directive var isStrict = options.indexOf('strict') > -1; - // flag used to specify if the build should include the "use strict" directive - var useStrict = isStrict || !(isLegacy || isMobile); + // used to specify the ways to export the `LoDash` function + var exportsOptions = options.reduce(function(result, value) { + return /exports/.test(value) ? optionToArray(value).sort() : result; + }, isUnderscore + ? ['commonjs', 'global', 'node'] + : exportsAll.slice() + ); + + // used to specify the output path for builds + var outputPath = options.reduce(function(result, value, index) { + return result || (/^(?:-o|--output)$/.test(value) ? options[index + 1] : result); + }, ''); // the lodash.js source var source = fs.readFileSync(path.join(__dirname, 'lodash.js'), 'utf8'); - // used to specify the ways to export the `LoDash` function - var exportsOptions = options.reduce(function(result, value) { - return /exports/.test(value) - ? optionToArray(value).sort() - : result; - }, exportsAll.slice()); - - // used to specify a custom IIFE to wrap Lo-Dash - var iife = options.reduce(function(result, value) { - return result || (result = value.match(/iife=(.*)/)) && result[1]; - }, null); + // flag used to specify if the build should include the "use strict" directive + var useStrict = isStrict || !(isLegacy || isMobile); /*------------------------------------------------------------------------*/ @@ -985,75 +1002,6 @@ source = removeIsArgumentsFallback(source); } - // DRY out isType functions - (function() { - var iteratorName = _.find(['forEach', 'forOwn'], function(methodName) { - return !isRemoved(source, methodName); - }); - - // skip this optimization if there are no iteration methods to use - if (!iteratorName) { - return; - } - var funcNames = [], - objectSnippets = []; - - // build replacement code - _.forOwn({ - 'Arguments': 'argsClass', - 'Date': 'dateClass', - 'Number': 'numberClass', - 'RegExp': 'regexpClass', - 'String': 'stringClass' - }, - function(value, key) { - var funcName = 'is' + key, - funcCode = matchFunction(source, funcName); - - // only DRY `isArguments` for Underscore builds - if (key == 'Arguments' && !isUnderscore) { - return; - } - if (funcCode) { - funcNames.push(funcName); - objectSnippets.push("'" + key + "': " + value); - } - }); - - // skip this optimization if there are less than 2 isType functions - if (funcNames.length < 2) { - return; - } - - // remove existing isType functions - funcNames.forEach(function(funcName) { - source = removeFunction(source, funcName); - }); - - // insert new DRY code before the `lodash` method assignments - var snippet = getMethodAssignments(source); - source = source.replace(snippet, snippet += [ - '', - ' // add `_.' + funcNames.join('`, `_.') + '`', - ' ' + iteratorName + '({\n ' + objectSnippets.join(',\n ') + '\n }, function(className, key) {', - " lodash['is' + key] = function(value) {", - ' return toString.call(value) == className', - ' }', - ' });' - ].join('\n')); - - // move `isArguments` fallback to after the new DRY code - if (isUnderscore) { - var fallback = getIsArgumentsFallback(source); - source = removeIsArgumentsFallback(source).replace(snippet, - snippet + fallback - .replace(/\bisArguments\b/g, 'lodash.$&') - .replace(/\bnoArgsClass\b/g, '!lodash.isArguments(arguments)') + - '\n' - ); - } - }()); - /*------------------------------------------------------------------------*/ if (isLegacy) { @@ -1316,11 +1264,6 @@ /(?:category|exclude|exports|iife|include|minus|plus)=/.test(options) || !_.isEqual(exportsOptions, exportsAll); - // used to specify the output path for builds - var outputPath = options.reduce(function(result, value, index) { - return result || (/^(?:-o|--output)$/.test(value) ? options[index + 1] : result); - }, ''); - // used to name temporary files created in `dist/` var workingName = 'lodash' + (isCustom ? '.custom' : '') + '.min'; From 5d2d86bffcb606859fded885d4d52583efd8a18f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 23 Sep 2012 21:28:47 -0700 Subject: [PATCH 38/82] =?UTF-8?q?Initial=20`lodash=20template=3D=E2=80=A6`?= =?UTF-8?q?=20build=20support.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 9d13021463380556a997cb53f5ae89eb22a7b98b --- build.js | 688 ++++++++++++++++------------ build/pre-compile.js | 2 + test/index.html | 4 +- test/test-build.js | 16 +- vendor/underscore/underscore-min.js | 2 +- vendor/underscore/underscore.js | 31 +- 6 files changed, 421 insertions(+), 322 deletions(-) diff --git a/build.js b/build.js index f1e2a71664..d8175a31e9 100755 --- a/build.js +++ b/build.js @@ -67,7 +67,7 @@ 'bind': ['isFunction'], 'bindAll': ['bind', 'isFunction'], 'chain': ['mixin'], - 'clone': ['extend', 'forIn', 'forOwn', 'isArguments', 'isFunction'], + 'clone': ['extend', 'forOwn', 'isArguments', 'isPlainObject'], 'compact': [], 'compose': [], 'contains': [], @@ -109,6 +109,7 @@ 'isNull': [], 'isNumber': [], 'isObject': [], + 'isPlainObject': ['forIn', 'isArguments', 'isFunction'], 'isRegExp': [], 'isString': [], 'isUndefined': [], @@ -119,7 +120,7 @@ 'map': ['identity'], 'max': [], 'memoize': [], - 'merge': ['isArguments', 'isArray', 'forIn'], + 'merge': ['isArray', 'isPlainObject'], 'min': [], 'mixin': ['forEach', 'functions'], 'noConflict': [], @@ -236,6 +237,7 @@ var underscoreMethods = _.without.apply(_, [allMethods].concat([ 'forIn', 'forOwn', + 'isPlainObject', 'lateBind', 'merge', 'partial' @@ -251,6 +253,42 @@ /*--------------------------------------------------------------------------*/ + /** + * Creates a debug and minified build, executing the `callback` for each. + * The `callback` is invoked with 2 arguments; (filepath, source) + * + * @param {Array} options The options array. + * @param {Function} callback The function called per build. + */ + function buildTemplate(templatePattern, templateSettings) { + var directory = path.dirname(templatePattern); + + var pattern = RegExp( + path.basename(templatePattern) + .replace(/[.+?^=!:${}()|[\]\/\\]/g, '\\$&') + .replace(/\*/g, '.*?') + '$' + ); + + var source = [ + ';(function() {', + ' var templates = _.templates || (_.templates = {});' + ]; + + fs.readdirSync(directory).forEach(function(filename) { + var filepath = path.join(directory, filename); + if (pattern.test(filename)) { + var text = fs.readFileSync(filepath, 'utf8'), + precompiled = getFunctionSource(_.template(text, null, templateSettings)), + prop = filename.replace(/\..*$/, ''); + + source.push(' templates["' + prop + '"] = ' + precompiled + ';'); + } + }); + + source.push('}());'); + return source.join('\n'); + } + /** * Removes unnecessary comments, whitespace, and pseudo private properties. * @@ -294,9 +332,10 @@ ' lodash exports=... Comma separated names of ways to export the `LoDash` function', ' (i.e. “amd”, “commonjs”, “global”, “node”, and “none”)', ' lodash iife=... Code to replace the immediately-invoked function expression that wraps Lo-Dash', - ' (e.g. “!function(window,undefined){%output%}(this)”)', + ' (e.g. `lodash iife="!function(window,undefined){%output%}(this)"`)', + '', ' lodash template=... The file path pattern used for matching template files to compile', - ' (e.g. `lodash template=path/to/templates/*.tmpl`)', + ' (e.g. `lodash template=./*.jst`)', '', ' All arguments, except `legacy` with `csp` or `mobile`, may be combined.', ' Unless specified by `-o` or `--output`, all files created are saved to the current working directory.', @@ -304,7 +343,9 @@ ' Options:', '', ' -c, --stdout Write output to standard output', + ' -d, --debug Write only the debug output', ' -h, --help Display help information', + ' -m, --minify Write only the minified output', ' -o, --output Write output to a given path/filename', ' -s, --silent Skip status updates normally logged to the console', ' -V, --version Output current version of Lo-Dash', @@ -734,7 +775,7 @@ * Creates a debug and minified build, executing the `callback` for each. * The `callback` is invoked with 2 arguments; (filepath, source) * - * @param {Array} options The options array. + * @param {Array} options The build options array. * @param {Function} callback The function called per build. */ function build(options, callback) { @@ -746,7 +787,7 @@ // used to report invalid command-line arguments var invalidArgs = _.reject(options.slice(options[0] == 'node' ? 2 : 0), function(value, index, options) { if (/^(?:-o|--output)$/.test(options[index - 1]) || - /^(?:category|exclude|exports|iife|include|minus|plus|template)=.*$/.test(value)) { + /^(?:category|exclude|exports|iife|include|minus|plus|settings|template)=.*$/.test(value)) { return true; } return [ @@ -757,7 +798,9 @@ 'strict', 'underscore', '-c', '--stdout', + '-d', '--debug', '-h', '--help', + '-m', '--minify', '-o', '--output', '-s', '--silent', '-V', '--version' @@ -798,7 +841,8 @@ // used to specify a custom IIFE to wrap Lo-Dash var iife = options.reduce(function(result, value) { - return result || (result = value.match(/iife=(.*)/)) && result[1]; + var match = value.match(/iife=(.*)/); + return match ? match[1] : result; }, null); // flag used to specify a Backbone build @@ -807,12 +851,18 @@ // flag used to specify a Content Security Policy build var isCSP = options.indexOf('csp') > -1 || options.indexOf('CSP') > -1; + // flag used to specify only creating the debug build + var isDebug = options.indexOf('-d') > -1 || options.indexOf('--debug') > -1; + // flag used to specify a legacy build var isLegacy = options.indexOf('legacy') > -1; // flag used to specify an Underscore build var isUnderscore = options.indexOf('underscore') > -1; + // flag used to specify only creating the minified build + var isMinify = !isDebug && options.indexOf('-m') > -1 || options.indexOf('--minify')> -1; + // flag used to specify a mobile build var isMobile = !isLegacy && (isCSP || isUnderscore || options.indexOf('mobile') > -1); @@ -836,9 +886,32 @@ // used to specify the output path for builds var outputPath = options.reduce(function(result, value, index) { - return result || (/^(?:-o|--output)$/.test(value) ? options[index + 1] : result); + if (/-o|--output/.test(value)) { + result = options[index + 1]; + result = path.join(fs.realpathSync(path.dirname(result)), path.basename(result)); + } + return result; + }, ''); + + // used to match external template files to pre-compile + var templatePattern = options.reduce(function(result, value) { + var match = value.match(/template=(.+)$/); + return match + ? path.join(fs.realpathSync(path.dirname(match[1])), path.basename(match[1])) + : result; }, ''); + // used when pre-compiling template files + var templateSettings = options.reduce(function(result, value) { + var match = value.match(/settings=(.+)$/); + return match + ? JSON.parse(match[1]) + : result; + }, _.clone(_.templateSettings)); + + // flag used to specify a template build + var isTemplate = !!templatePattern; + // the lodash.js source var source = fs.readFileSync(path.join(__dirname, 'lodash.js'), 'utf8'); @@ -847,65 +920,68 @@ /*------------------------------------------------------------------------*/ - // collections of method names - var buildMethods; + // names of methods to include in the build + var buildMethods = !isTemplate && (function() { + var result; - var minusMethods = options.reduce(function(result, value) { - return /exclude|minus/.test(value) - ? _.union(result, optionToMethodsArray(source, value)) - : result; - }, []); - - var plusMethods = options.reduce(function(result, value) { - return /plus/.test(value) - ? _.union(result, optionToMethodsArray(source, value)) - : result; - }, []); + var minusMethods = options.reduce(function(accumulator, value) { + return /exclude|minus/.test(value) + ? _.union(accumulator, optionToMethodsArray(source, value)) + : accumulator; + }, []); - // add method names explicitly - options.some(function(value) { - return /include/.test(value) && - (buildMethods = getDependencies(optionToMethodsArray(source, value))); - }); + var plusMethods = options.reduce(function(accumulator, value) { + return /plus/.test(value) + ? _.union(accumulator, optionToMethodsArray(source, value)) + : accumulator; + }, []); - // add method names required by Backbone and Underscore builds - if (isBackbone && !buildMethods) { - buildMethods = getDependencies(backboneDependencies); - } - if (isUnderscore && !buildMethods) { - buildMethods = getDependencies(underscoreMethods); - } + // add method names explicitly + options.some(function(value) { + return /include/.test(value) && + (result = getDependencies(optionToMethodsArray(source, value))); + }); - // add method names by category - options.some(function(value) { - if (!/category/.test(value)) { - return false; + // add method names required by Backbone and Underscore builds + if (isBackbone && !result) { + result = getDependencies(backboneDependencies); + } + if (isUnderscore && !result) { + result = getDependencies(underscoreMethods); } - // resolve method names belonging to each category (case-insensitive) - var methodNames = optionToArray(value).reduce(function(result, category) { - var capitalized = category[0].toUpperCase() + category.toLowerCase().slice(1); - return result.concat(getMethodsByCategory(source, capitalized)); - }, []); - return (buildMethods = _.union(buildMethods || [], getDependencies(methodNames))); - }); + // add method names by category + options.some(function(value) { + if (!/category/.test(value)) { + return false; + } + // resolve method names belonging to each category (case-insensitive) + var methodNames = optionToArray(value).reduce(function(accumulator, category) { + var capitalized = category[0].toUpperCase() + category.toLowerCase().slice(1); + return accumulator.concat(getMethodsByCategory(source, capitalized)); + }, []); - // init `buildMethods` if it hasn't been inited - if (!buildMethods) { - buildMethods = allMethods.slice(); - } + return (result = _.union(result || [], getDependencies(methodNames))); + }); - if (plusMethods.length) { - buildMethods = _.union(buildMethods, getDependencies(plusMethods)); - } - if (minusMethods.length) { - buildMethods = _.without.apply(_, [buildMethods].concat(minusMethods, getDependants(buildMethods))); - } + // init `result` if it hasn't been inited + if (!result) { + result = allMethods.slice(); + } + + if (plusMethods.length) { + result = _.union(result, getDependencies(plusMethods)); + } + if (minusMethods.length) { + result = _.without.apply(_, [result].concat(minusMethods, getDependants(result))); + } + return result; + }()); /*------------------------------------------------------------------------*/ // load customized Lo-Dash module - var lodash = (function() { + var lodash = !isTemplate && (function() { var context = vm.createContext({ 'clearTimeout': clearTimeout, 'setTimeout': setTimeout @@ -980,156 +1056,191 @@ /*------------------------------------------------------------------------*/ - // simplify template snippets by removing unnecessary brackets - source = source.replace( - RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *([,\\n])", 'g'), "$1'$2" - ); + if (isTemplate) { + source = buildTemplate(templatePattern, templateSettings); + } + else { + // simplify template snippets by removing unnecessary brackets + source = source.replace( + RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *([,\\n])", 'g'), "$1'$2" + ); - source = source.replace( - RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *\\+", 'g'), "$1;\\n'+" - ); + source = source.replace( + RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *\\+", 'g'), "$1;\\n'+" + ); - // remove methods from the build - allMethods.forEach(function(otherName) { - if (!_.contains(buildMethods, otherName)) { - source = removeFunction(source, otherName); + // remove methods from the build + allMethods.forEach(function(otherName) { + if (!_.contains(buildMethods, otherName)) { + source = removeFunction(source, otherName); + } + }); + + // remove `isArguments` fallback before `isArguments` is transformed by + // other parts of the build process + if (isRemoved(source, 'isArguments')) { + source = removeIsArgumentsFallback(source); } - }); - // remove `isArguments` fallback before `isArguments` is transformed by - // other parts of the build process - if (isRemoved(source, 'isArguments')) { - source = removeIsArgumentsFallback(source); - } + /*----------------------------------------------------------------------*/ - /*------------------------------------------------------------------------*/ + if (isLegacy) { + _.each(['isBindFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'], function(varName) { + source = removeVar(source, varName); + }); - if (isLegacy) { - _.each(['isBindFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'], function(varName) { - source = removeVar(source, varName); - }); + _.each(['bind', 'isArray'], function(methodName) { + var snippet = matchFunction(source, methodName), + modified = snippet; + + // remove native `Function#bind` branch in `_.bind` + if (methodName == 'bind') { + modified = modified.replace(/(?:\s*\/\/.*)*\s*return isBindFast[^:]+:\s*/, 'return '); + } + // remove native `Array.isArray` branch in `_.isArray` + else { + modified = modified.replace(/nativeIsArray * \|\|/, ''); + } + source = source.replace(snippet, modified); + }); - _.each(['bind', 'isArray'], function(methodName) { - var snippet = matchFunction(source, methodName), - modified = snippet; + // replace `_.keys` with `shimKeys` + if (!isRemoved(source, 'keys')) { + source = source.replace( + matchFunction(source, 'keys').replace(/[\s\S]+?var keys *=/, ''), + matchFunction(source, 'shimKeys').replace(/[\s\S]+?var shimKeys *=/, '') + ); - // remove native `Function#bind` branch in `_.bind` - if (methodName == 'bind') { - modified = modified.replace(/(?:\s*\/\/.*)*\s*return isBindFast[^:]+:\s*/, 'return '); + source = removeFunction(source, 'shimKeys'); } - // remove native `Array.isArray` branch in `_.isArray` - else { - modified = modified.replace(/nativeIsArray * \|\|/, ''); + // replace `_.isArguments` with fallback + if (!isRemoved(source, 'isArguments')) { + source = source.replace( + matchFunction(source, 'isArguments').replace(/[\s\S]+?function isArguments/, ''), + getIsArgumentsFallback(source).match(/isArguments *= *function([\s\S]+?) *};/)[1] + ' }\n' + ); + + source = removeIsArgumentsFallback(source); } - source = source.replace(snippet, modified); - }); - - // replace `_.keys` with `shimKeys` - if (!isRemoved(source, 'keys')) { - source = source.replace( - matchFunction(source, 'keys').replace(/[\s\S]+?var keys *=/, ''), - matchFunction(source, 'shimKeys').replace(/[\s\S]+?var shimKeys *=/, '') - ); - source = removeFunction(source, 'shimKeys'); + source = removeVar(source, 'reNative'); + source = removeFromCreateIterator(source, 'nativeKeys'); } - // replace `_.isArguments` with fallback - if (!isRemoved(source, 'isArguments')) { - source = source.replace( - matchFunction(source, 'isArguments').replace(/[\s\S]+?function isArguments/, ''), - getIsArgumentsFallback(source).match(/isArguments *= *function([\s\S]+?) *};/)[1] + ' }\n' - ); - source = removeIsArgumentsFallback(source); - } + if (isMobile) { + // inline all functions defined with `createIterator` + _.functions(lodash).forEach(function(methodName) { + // match `methodName` with pseudo private `_` prefixes removed to allow matching `shimKeys` + var reFunc = RegExp('(\\bvar ' + methodName.replace(/^_/, '') + ' *= *)createIterator\\(((?:{|[a-zA-Z])[\\s\\S]+?)\\);\\n'); + + // skip if not defined with `createIterator` + if (!reFunc.test(source)) { + return; + } + // extract, format, and inject the compiled function's source code + source = source.replace(reFunc, '$1' + getFunctionSource(lodash[methodName]) + ';\n'); + }); - source = removeVar(source, 'reNative'); - source = removeFromCreateIterator(source, 'nativeKeys'); - } + // replace `callee` in `_.merge` with `merge` + source = source.replace(matchFunction(source, 'merge'), function(match) { + return match.replace(/\bcallee\b/g, 'merge'); + }); - if (isMobile) { - // inline all functions defined with `createIterator` - _.functions(lodash).forEach(function(methodName) { - // match `methodName` with pseudo private `_` prefixes removed to allow matching `shimKeys` - var reFunc = RegExp('(\\bvar ' + methodName.replace(/^_/, '') + ' *= *)createIterator\\(((?:{|[a-zA-Z])[\\s\\S]+?)\\);\\n'); + if (isUnderscore) { + (function() { + // replace `isArguments` and its fallback + var snippet = matchFunction(source, 'isArguments') + .replace(/function isArguments/, 'lodash.isArguments = function'); - // skip if not defined with `createIterator` - if (!reFunc.test(source)) { - return; - } - // extract, format, and inject the compiled function's source code - source = source.replace(reFunc, '$1' + getFunctionSource(lodash[methodName]) + ';\n'); - }); + source = removeFunction(source, 'isArguments'); - // replace `callee` in `_.merge` with `merge` - source = source.replace(matchFunction(source, 'merge'), function(match) { - return match.replace(/\bcallee\b/g, 'merge'); - }); + source = source.replace(getIsArgumentsFallback(source), function(match) { + return snippet + '\n' + match + .replace(/\bisArguments\b/g, 'lodash.$&') + .replace(/\bnoArgsClass\b/g, '!lodash.isArguments(arguments)'); + }); + }()); + } + else { + source = removeIsArgumentsFallback(source); + } - if (!isUnderscore) { - source = removeIsArgumentsFallback(source); - } + // remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, `noArgsEnum` assignment + source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b[\s\S]+?}\(1\)\);\n/, ''); - // remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, `noArgsEnum` assignment - source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b[\s\S]+?}\(1\)\);\n/, ''); + // remove `iteratesOwnLast` from `isPlainObject` + source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(iteratesOwnLast[\s\S]+?\n\1}/, ''); - // remove `iteratesOwnLast` from `isPlainObject` - source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(iteratesOwnLast[\s\S]+?\n\1}/, ''); + // remove JScript [[DontEnum]] fix from `_.isEqual` + source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasDontEnumBug[\s\S]+?\n\1}/, ''); - // remove JScript [[DontEnum]] fix from `_.isEqual` - source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasDontEnumBug[\s\S]+?\n\1}/, ''); + // remove `hasObjectSpliceBug` fix from the mutator Array functions mixin + source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasObjectSpliceBug[\s\S]+?\n\1}/, ''); - // remove `hasObjectSpliceBug` fix from the mutator Array functions mixin - source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasObjectSpliceBug[\s\S]+?\n\1}/, ''); + // remove `noArraySliceOnStrings` from `_.toArray` + source = source.replace(/noArraySliceOnStrings *\?[^:]+: *([^)]+)/g, '$1'); - // remove `noArraySliceOnStrings` from `_.toArray` - source = source.replace(/noArraySliceOnStrings *\?[^:]+: *([^)]+)/g, '$1'); + // remove `noCharByIndex` from `_.reduceRight` + source = source.replace(/}\s*else if *\(noCharByIndex[^}]+/, ''); - // remove `noCharByIndex` from `_.reduceRight` - source = source.replace(/}\s*else if *\(noCharByIndex[^}]+/, ''); + source = removeVar(source, 'extendIteratorOptions'); + source = removeVar(source, 'iteratorTemplate'); + source = removeVar(source, 'noArraySliceOnStrings'); + source = removeVar(source, 'noCharByIndex'); + source = removeNoArgsClass(source); + source = removeNoNodeClass(source); + } + else { + // inline `iteratorTemplate` template + source = source.replace(/(( +)var iteratorTemplate *= *)[\s\S]+?\n\2.+?;\n/, (function() { + var snippet = getFunctionSource(lodash._iteratorTemplate); + + // prepend data object references to property names to avoid having to + // use a with-statement + iteratorOptions.forEach(function(property) { + snippet = snippet.replace(RegExp('([^\\w.])\\b' + property + '\\b', 'g'), '$1obj.' + property); + }); - source = removeVar(source, 'extendIteratorOptions'); - source = removeVar(source, 'iteratorTemplate'); - source = removeVar(source, 'noArraySliceOnStrings'); - source = removeVar(source, 'noCharByIndex'); - source = removeNoArgsClass(source); - source = removeNoNodeClass(source); + // remove unnecessary code + snippet = snippet + .replace(/var __t.+/, "var __p = '';") + .replace(/function print[^}]+}/, '') + .replace(/'(?:\\n|\s)+'/g, "''") + .replace(/__p *\+= *' *';/g, '') + .replace(/(__p *\+= *)' *' *\+/g, '$1') + .replace(/(\{) *;|; *(\})/g, '$1$2') + .replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '$1'); + + // remove the with-statement + snippet = snippet.replace(/ *with *\(.+?\) *{/, '\n').replace(/}([^}]*}[^}]*$)/, '$1'); + + // minor cleanup + snippet = snippet + .replace(/obj *\|\| *\(obj *= *\{}\);/, '') + .replace(/var __p = '';\s*__p \+=/, 'var __p ='); + + // remove comments, including sourceURLs + snippet = snippet.replace(/\s*\/\/.*(?:\n|$)/g, ''); + + return '$1' + snippet + ';\n'; + }())); + } } - else { - // inline `iteratorTemplate` template - source = source.replace(/(( +)var iteratorTemplate *= *)[\s\S]+?\n\2.+?;\n/, (function() { - var snippet = getFunctionSource(lodash._iteratorTemplate); - - // prepend data object references to property names to avoid having to - // use a with-statement - iteratorOptions.forEach(function(property) { - snippet = snippet.replace(RegExp('([^\\w.])\\b' + property + '\\b', 'g'), '$1obj.' + property); - }); - // remove unnecessary code - snippet = snippet - .replace(/var __t.+/, "var __p = '';") - .replace(/function print[^}]+}/, '') - .replace(/'(?:\\n|\s)+'/g, "''") - .replace(/__p *\+= *' *';/g, '') - .replace(/(__p *\+= *)' *' *\+/g, '$1') - .replace(/(\{) *;|; *(\})/g, '$1$2') - .replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '$1'); - - // remove the with-statement - snippet = snippet.replace(/ *with *\(.+?\) *{/, '\n').replace(/}([^}]*}[^}]*$)/, '$1'); - - // minor cleanup - snippet = snippet - .replace(/obj *\|\| *\(obj *= *\{}\);/, '') - .replace(/var __p = '';\s*__p \+=/, 'var __p ='); - - // remove comments, including sourceURLs - snippet = snippet.replace(/\s*\/\/.*(?:\n|$)/g, ''); - - return '$1' + snippet + ';\n'; - }())); - } + /*------------------------------------------------------------------------*/ + + // customize Lo-Dash's IIFE + (function() { + if (typeof iife == 'string') { + var token = '%output%', + index = iife.indexOf(token); + + source = source.match(/\/\*![\s\S]+?\*\/\n/) + + iife.slice(0, index) + + source.replace(/^[^(]+?\(function[^{]+?{|}\(this\)\)[;\s]*$/g, '') + + iife.slice(index + token.length); + } + }()); /*------------------------------------------------------------------------*/ @@ -1156,107 +1267,88 @@ /*------------------------------------------------------------------------*/ - // customize Lo-Dash's IIFE - (function() { - if (typeof iife == 'string') { - var token = '%output%', - index = iife.indexOf(token); - - source = source.match(/\/\*![\s\S]+?\*\/\n/) + - iife.slice(0, index) + - source.replace(/^[^(]+?\(function[^{]+?{|}\(this\)\)[;\s]*$/g, '') + - iife.slice(index + token.length); - } - }()); - - /*------------------------------------------------------------------------*/ - - // modify/remove references to removed methods/variables - if (isRemoved(source, 'isArguments')) { - source = replaceVar(source, 'noArgsClass', 'false'); - } - if (isRemoved(source, 'isFunction')) { - source = removeIsFunctionFallback(source); - } - if (isRemoved(source, 'mixin')) { - // remove `LoDash` constructor - source = removeFunction(source, 'LoDash'); - // remove `LoDash` calls - source = source.replace(/(?:new +LoDash(?!\()|(?:new +)?LoDash\([^)]*\));?/g, ''); - // remove `LoDash.prototype` additions - source = source.replace(/(?:\s*\/\/.*)*\s*LoDash.prototype *=[\s\S]+?\/\*-+\*\//, ''); - // remove `hasObjectSpliceBug` assignment - source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasObjectSpliceBug;|.+?hasObjectSpliceBug *=.+/g, ''); + if (isTemplate) { + debugSource = source; } + else { + // modify/remove references to removed methods/variables + if (isRemoved(source, 'isArguments')) { + source = replaceVar(source, 'noArgsClass', 'false'); + } + if (isRemoved(source, 'isFunction')) { + source = removeIsFunctionFallback(source); + } + if (isRemoved(source, 'mixin')) { + // remove `LoDash` constructor + source = removeFunction(source, 'LoDash'); + // remove `LoDash` calls + source = source.replace(/(?:new +LoDash(?!\()|(?:new +)?LoDash\([^)]*\));?/g, ''); + // remove `LoDash.prototype` additions + source = source.replace(/(?:\s*\/\/.*)*\s*LoDash.prototype *=[\s\S]+?\/\*-+\*\//, ''); + // remove `hasObjectSpliceBug` assignment + source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasObjectSpliceBug;|.+?hasObjectSpliceBug *=.+/g, ''); + } - // remove pseudo private properties - source = source.replace(/(?:(?:\s*\/\/.*)*\s*lodash\._[^=]+=.+\n)+/g, '\n'); + // remove pseudo private properties + source = source.replace(/(?:(?:\s*\/\/.*)*\s*lodash\._[^=]+=.+\n)+/g, '\n'); - // assign debug source before further modifications that rely on the minifier - // to remove unused variables and other dead code - debugSource = source; + // assign debug source before further modifications that rely on the minifier + // to remove unused variables and other dead code + debugSource = source; - // remove associated functions, variables, and code snippets that the minifier may miss - if (isRemoved(source, 'clone')) { - source = removeVar(source, 'cloneableClasses'); - } - if (isRemoved(source, 'isArray')) { - source = removeVar(source, 'nativeIsArray'); - } - if (isRemoved(source, 'keys')) { - source = removeFunction(source, 'shimKeys'); - } - if (isRemoved(source, 'template')) { - // remove `templateSettings` assignment - source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *lodash\.templateSettings[\s\S]+?};\n/, ''); - } - if (isRemoved(source, 'toArray')) { - source = removeVar(source, 'noArraySliceOnStrings'); - } - if (isUnderscore - ? isRemoved(source, 'merge') - : isRemoved(source, 'clone', 'merge') - ) { - source = removeFunction(source, 'isPlainObject'); - } - if (isRemoved(source, 'clone', 'isArguments', 'isEmpty', 'isEqual')) { - source = removeNoArgsClass(source); - } - if (isRemoved(source, 'isEqual', 'isPlainObject')) { - source = removeNoNodeClass(source); - } - if ((source.match(/\bcreateIterator\b/g) || []).length < 2) { - source = removeFunction(source, 'createIterator'); - source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var noArgsEnum;|.+?noArgsEnum *=.+/g, ''); - } - if (isRemoved(source, 'createIterator', 'bind')) { - source = removeVar(source, 'isBindFast'); - source = removeVar(source, 'isStrictFast'); - source = removeVar(source, 'nativeBind'); - } - if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) { - source = removeVar(source, 'reNative'); - } - if (isRemoved(source, 'createIterator', 'isEmpty', 'isEqual')) { - source = removeVar(source, 'arrayLikeClasses'); - } - if (isRemoved(source, 'createIterator', 'isEqual')) { - source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug;|.+?hasDontEnumBug *=.+/g, ''); - } - if (isRemoved(source, 'createIterator', 'isPlainObject')) { - source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var iteratesOwnLast;|.+?iteratesOwnLast *=.+/g, ''); - } - if (isRemoved(source, 'createIterator', 'keys')) { - source = removeVar(source, 'nativeKeys'); - } - if (!source.match(/var (?:hasDontEnumBug|hasObjectSpliceBug|iteratesOwnLast|noArgsEnum)\b/g)) { - // remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, and `noArgsEnum` assignment - source = source.replace(/ *\(function\(\) *{[\s\S]+?}\(1\)\);/, ''); + // remove associated functions, variables, and code snippets that the minifier may miss + if (isRemoved(source, 'clone')) { + source = removeVar(source, 'cloneableClasses'); + } + if (isRemoved(source, 'isArray')) { + source = removeVar(source, 'nativeIsArray'); + } + if (isRemoved(source, 'keys')) { + source = removeFunction(source, 'shimKeys'); + } + if (isRemoved(source, 'template')) { + // remove `templateSettings` assignment + source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *lodash\.templateSettings[\s\S]+?};\n/, ''); + } + if (isRemoved(source, 'toArray')) { + source = removeVar(source, 'noArraySliceOnStrings'); + } + if (isRemoved(source, 'clone', 'isArguments', 'isEmpty', 'isEqual')) { + source = removeNoArgsClass(source); + } + if (isRemoved(source, 'isEqual', 'isPlainObject')) { + source = removeNoNodeClass(source); + } + if ((source.match(/\bcreateIterator\b/g) || []).length < 2) { + source = removeFunction(source, 'createIterator'); + source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var noArgsEnum;|.+?noArgsEnum *=.+/g, ''); + } + if (isRemoved(source, 'createIterator', 'bind')) { + source = removeVar(source, 'isBindFast'); + source = removeVar(source, 'isStrictFast'); + source = removeVar(source, 'nativeBind'); + } + if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) { + source = removeVar(source, 'reNative'); + } + if (isRemoved(source, 'createIterator', 'isEmpty', 'isEqual')) { + source = removeVar(source, 'arrayLikeClasses'); + } + if (isRemoved(source, 'createIterator', 'isEqual')) { + source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug;|.+?hasDontEnumBug *=.+/g, ''); + } + if (isRemoved(source, 'createIterator', 'isPlainObject')) { + source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var iteratesOwnLast;|.+?iteratesOwnLast *=.+/g, ''); + } + if (isRemoved(source, 'createIterator', 'keys')) { + source = removeVar(source, 'nativeKeys'); + } + if (!source.match(/var (?:hasDontEnumBug|hasObjectSpliceBug|iteratesOwnLast|noArgsEnum)\b/g)) { + // remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, and `noArgsEnum` assignment + source = source.replace(/ *\(function\(\) *{[\s\S]+?}\(1\)\);/, ''); + } } - debugSource = cleanupSource(debugSource); - source = cleanupSource(source); - /*------------------------------------------------------------------------*/ // used to specify creating a custom build @@ -1265,35 +1357,43 @@ !_.isEqual(exportsOptions, exportsAll); // used to name temporary files created in `dist/` - var workingName = 'lodash' + (isCustom ? '.custom' : '') + '.min'; + var workingName = 'lodash' + (isTemplate ? '.template' : isCustom ? '.custom' : ''); // restore `dependencyMap` dependencyMap = dependencyBackup; // output debug build - if (isCustom && !outputPath && !isStdOut) { - callback(debugSource, path.join(cwd, 'lodash.custom.js')); + if (!isMinify && (isCustom || isTemplate)) { + if (isDebug && isStdOut) { + stdout.write(debugSource); + callback(debugSource); + } else if (!isStdOut) { + callback(debugSource, (isDebug && outputPath) || path.join(cwd, workingName + '.js')); + } } // begin the minification process - minify(source, { - 'silent': isSilent, - 'workingName': workingName, - 'onComplete': function(source) { - // correct overly aggressive Closure Compiler minification - source = source.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}'); - - // inject "use strict" directive - if (isStrict) { - source = source.replace(/^(\/\*![\s\S]+?\*\/\n;\(function[^)]+\){)([^'"])/, '$1"use strict";$2'); + if (!isDebug) { + workingName += '.min'; + minify(source, { + 'silent': isSilent, + 'workingName': workingName, + 'onComplete': function(source) { + // correct overly aggressive Closure Compiler minification + source = source.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}'); + + // inject "use strict" directive + if (isStrict) { + source = source.replace(/^(\/\*![\s\S]+?\*\/\n;\(function[^)]+\){)([^'"])/, '$1"use strict";$2'); + } + if (isStdOut) { + stdout.write(source); + callback(source); + } else { + callback(source, outputPath || path.join(cwd, workingName + '.js')); + } } - if (isStdOut) { - stdout.write(source); - callback(source); - } else { - callback(source, outputPath || path.join(cwd, workingName + '.js')); - } - } - }); + }); + } } /*--------------------------------------------------------------------------*/ diff --git a/build/pre-compile.js b/build/pre-compile.js index 7b2c582ed8..4037e1fd20 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -175,6 +175,7 @@ 'isNull', 'isNumber', 'isObject', + 'isPlainObject', 'isRegExp', 'isString', 'isUndefined', @@ -217,6 +218,7 @@ 'take', 'tap', 'template', + 'templates', 'templateSettings', 'throttle', 'times', diff --git a/test/index.html b/test/index.html index 3b75bb9e2f..278db46d88 100644 --- a/test/index.html +++ b/test/index.html @@ -62,7 +62,7 @@ } }, ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) { - if (lodash.noConflict) { + if (lodash && lodash.noConflict) { lodashModule = lodash.noConflict(); lodashModule.moduleName = 'lodash'; } @@ -70,7 +70,7 @@ shimmedModule = shimmed.noConflict(); shimmedModule.moduleName = 'shimmed'; } - if (underscore.noConflict) { + if (underscore && underscore.noConflict) { underscoreModule = underscore.noConflict(); underscoreModule.moduleName = 'underscore'; } diff --git a/test/test-build.js b/test/test-build.js index 1b54c59473..d35fcb7374 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -165,6 +165,7 @@ 'isNull', 'isNumber', 'isObject', + 'isPlainObject', 'isRegExp', 'isString', 'isUndefined', @@ -238,19 +239,12 @@ /** List of methods used by Underscore */ var underscoreMethods = _.without.apply(_, [allMethods].concat([ - 'countBy', 'forIn', 'forOwn', - 'invert', + 'isPlainObject', 'lateBind', 'merge', - 'object', - 'omit', - 'pairs', - 'partial', - 'random', - 'unescape', - 'where' + 'partial' ])); /*--------------------------------------------------------------------------*/ @@ -654,7 +648,7 @@ asyncTest('`lodash ' + command +'`', function() { build(['-s'].concat(command.split(' ')), function(source, filepath) { - equal(filepath, 'a.js', command); + equal(path.basename(filepath), 'a.js', command); start(); }); }); @@ -670,7 +664,7 @@ var start = _.once(QUnit.start); asyncTest('`lodash ' + command +'`', function() { - build([command, 'exports=', 'include='], function(source, filepath) { + build([command, 'exports=', 'include='], function(source) { equal(source, ''); equal(arguments.length, 1); start(); diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index 6596e3d3ae..eecb3bd01c 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -12,4 +12,4 @@ // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: // http://documentcloud.github.com/underscore -(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.3.3";var N=T.each=T.forEach=function(e,t,r){if(e==null)return;if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i2;e==null&&(e=[]);if(!C&&d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){C&&(s=C.keys[s],o=C.list),i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=T.toArray(e).reverse();r&&!i&&(t=T.bind(t,r)),C={keys:T.keys(e).reverse(),list:e};var o=i?T.reduce(s,t,n,r):T.reduce(s,t);return C=null,o},T.find=T.detect=function(e,t,n){var r;return k(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return e==null?r:m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return e==null?r:(N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r)},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return e==null?i:g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var k=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return e==null?i:y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return e==null?n:b&&e.indexOf===b?e.indexOf(t)!=-1:(n=k(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;or||n===void 0)return 1;if(n>>1;n.call(r,e[u])=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var _=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=_(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&_(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return _(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r":">",'"':""","'":"'","/":"/"}};D.unescape=T.invert(D.escape);var P={escape:new RegExp("["+T.keys(D.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(D.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(P[e],function(t){return D[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),I.call(this,n.apply(T,e))}})};var H=0;T.uniqueId=function(e){var t=H++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var B=/(.)^/,j={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},F=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||B).source,(n.interpolate||B).source,(n.evaluate||B).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(F,function(e){return"\\"+j[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var I=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],I.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return I.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file +(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.3.3";var N=T.each=T.forEach=function(e,t,r){if(e==null)return;if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i2;e==null&&(e=[]);if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return e==null?r:m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return e==null?r:(N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r)},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return e==null?i:g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return e==null?i:y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return e==null?n:b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;or||n===void 0)return 1;if(n>>1;n.call(r,e[u])=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r":">",'"':""","'":"'","/":"/"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index 1ac8de1325..023ff7eee9 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -105,23 +105,16 @@ return results; }; - // Internal data flag for performing `reduceRight`. - var right = null; - // **Reduce** builds up a single result from a list of values, aka `inject`, // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { var initial = arguments.length > 2; if (obj == null) obj = []; - if (!right && nativeReduce && obj.reduce === nativeReduce) { + if (nativeReduce && obj.reduce === nativeReduce) { if (context) iterator = _.bind(iterator, context); return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); } each(obj, function(value, index, list) { - if (right) { - index = right.keys[index]; - list = right.list; - } if (!initial) { memo = value; initial = true; @@ -142,12 +135,22 @@ if (context) iterator = _.bind(iterator, context); return arguments.length > 2 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); } - var values = _.toArray(obj).reverse(); - if (context && !initial) iterator = _.bind(iterator, context); - right = {keys: _.keys(obj).reverse(), list: obj}; - var result = initial ? _.reduce(values, iterator, memo, context) : _.reduce(values, iterator); - right = null; - return result; + var length = obj.length; + if (length !== +length) { + var keys = _.keys(obj); + length = keys.length; + } + each(obj, function(value, index, list) { + index = keys ? keys[--length] : --length; + if (!initial) { + memo = obj[index]; + initial = true; + } else { + memo = iterator.call(context, memo, obj[index], index, list); + } + }); + if (!initial) throw new TypeError('Reduce of empty array with no initial value'); + return memo; }; // Return the first value which passes a truth test. Aliased as `detect`. From 77242bfb957d2c4374cafb2fcd6d62b112f6b3b2 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 23 Sep 2012 21:30:14 -0700 Subject: [PATCH 39/82] Expose `_.isPlainObject`. Former-commit-id: 884bc87df7773ef3cb5e52725d5a37f07812385a --- lodash.js | 65 ++++++++++++++++++++++++++++++++++----------------- lodash.min.js | 52 ++++++++++++++++++++--------------------- 2 files changed, 69 insertions(+), 48 deletions(-) diff --git a/lodash.js b/lodash.js index a2984ada97..f3dd15bd73 100644 --- a/lodash.js +++ b/lodash.js @@ -906,7 +906,7 @@ * @returns {Boolean} Returns `true` if the `value` is a function, else `false`. * @example * - * _.isFunction(''.concat); + * _.isFunction(_); * // => true */ function isFunction(value) { @@ -919,6 +919,44 @@ }; } + /** + * Checks if a given `value` is an object created by the `Object` constructor. + * + * @static + * @memberOf _ + * @category Objects + * @param {Mixed} value The value to check. + * @param {Boolean} [skipArgsCheck=false] Internally used to skip checks for + * `arguments` objects. + * @returns {Boolean} Returns `true` if `value` is a plain object, else `false`. + * @example + * + * function Stooge(name, age) { + * this.name = name; + * this.age = age; + * } + * + * _.isPlainObject(new Stooge('moe', 40)); + * // false + * + * _.isPlainObject([1, 2, 3]); + * // false + * + * _.isPlainObject({ 'name': 'moe', 'age': 40 }); + * // => true + */ + var isPlainObject = objectTypes.__proto__ != ObjectProto ? isPlainFallback : function(value, skipArgsCheck) { + if (!value) { + return false; + } + var valueOf = value.valueOf, + objProto = typeof valueOf == 'function' && (objProto = valueOf.__proto__) && objProto.__proto__; + + return objProto + ? value == objProto || (value.__proto__ == objProto && (skipArgsCheck || !isArguments(value))) + : isPlainFallback(value); + }; + /** * A fallback implementation of `isPlainObject` that checks if a given `value` * is an object created by the `Object` constructor, assuming objects created @@ -964,27 +1002,6 @@ return result; } - /** - * Checks if a given `value` is an object created by the `Object` constructor. - * - * @private - * @param {Mixed} value The value to check. - * @param {Boolean} [skipArgsCheck=false] Internally used to skip checks for - * `arguments` objects. - * @returns {Boolean} Returns `true` if `value` is a plain object, else `false`. - */ - var isPlainObject = objectTypes.__proto__ != ObjectProto ? isPlainFallback : function(value, skipArgsCheck) { - if (!value) { - return false; - } - var valueOf = value.valueOf, - objProto = typeof valueOf == 'function' && (objProto = valueOf.__proto__) && objProto.__proto__; - - return objProto - ? value == objProto || (value.__proto__ == objProto && (skipArgsCheck || !isArguments(value))) - : isPlainFallback(value); - }; - /** * A shim implementation of `Object.keys` that produces an array of the given * object's own enumerable property names. @@ -1553,6 +1570,9 @@ * _.isObject({}); * // => true * + * _.isObject([1, 2, 3]); + * // => true + * * _.isObject(1); * // => false */ @@ -4160,6 +4180,7 @@ lodash.isNull = isNull; lodash.isNumber = isNumber; lodash.isObject = isObject; + lodash.isPlainObject = isPlainObject; lodash.isRegExp = isRegExp; lodash.isString = isString; lodash.isUndefined = isUndefined; diff --git a/lodash.min.js b/lodash.min.js index af6567f543..e3b0ce6cd3 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -4,37 +4,37 @@ */ ;(function(e,t){function s(e){return new o(e)}function o(e){if(e&&e.__wrapped__)return e;this.__wrapped__=e}function u(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function a(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||B),s=i?{}:e;if(i)for(var o=t-1;++on||e===t)return 1;if(en;n++)t+="j='"+a.p[n]+"';if(" -,"constructor"==a.p[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){A=k[j];"+a.m.i+"}"}if(a.c||a.n)t+="}"}return t+=a.e+";return u",Function("D,E,F,c,I,f,J,h,i,M,O,Q,S,T,W,X,m,r,w,x,z","var G=function("+e+"){"+t+"};return G")(_t,D,A,u,f,Q,Yt,G,O,T,m,$t,g,Jt,vt,Bt,ot,Z,et,gt,tt)}function h(e){return"\\"+jt[e]}function p(e){return Pt[e]}function d(){}function v(e){return Ht[e]}function m(e){return tt.call(e)==lt}function g(e){return"function"==typeof e}function y(e,t){var n=i;if(!e||"object"!=typeof +a.a,t=/^[^,]+/.exec(e)[0],n=a.s,a.g=t,a.h=wt,a.k=Ot,a.n=xt,a.p=K,a.r=a.r!==i,a.s=n==r?Mt:n,a.o==r&&(a.o=Ct),a.f||(a.f="if(!"+t+")return u");if("e"!=t||!a.c.i)a.c=r;t="",a.s&&(t+="'use strict';"),t+="var j,B,k="+a.g+",u",a.j&&(t+="="+a.j),t+=";"+a.f+";"+a.q+";",a.c&&(t+="var l=k.length;j=-1;",a.m&&(t+="if(l===+l){"),a.o&&(t+="if(z.call(k)==x){k=k.split('')}"),t+=a.c.d+";while(++jn;n++)t+="j='"+a.p[n]+"';if(" +,"constructor"==a.p[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){B=k[j];"+a.m.i+"}"}if(a.c||a.n)t+="}"}return t+=a.e+";return u",Function("E,F,G,c,J,f,K,h,i,N,P,R,T,U,X,Y,m,r,w,x,z,A","var H=function("+e+"){"+t+"};return H")(_t,D,A,u,f,Q,Yt,G,O,T,m,$t,g,Jt,vt,Bt,ot,Z,et,gt,tt)}function h(e){return"\\"+jt[e]}function p(e){return Pt[e]}function d(){}function v(e){return Ht[e]}function m(e){return tt.call(e)==lt}function g(e){return"function"==typeof e}function y(e,t){var n=i;if(!e||"object"!=typeof e||!t&&m(e))return n;var r=e.constructor;return(!kt||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!g(r)||r instanceof r)?St?(Yt(e,function(e,t,r){return n=!G.call(r,t),i}),n===i):(Yt(e,function(e,t){n=t}),n===i||G.call(e,n)):n}function b(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=Bt[typeof e]){var a=tt.call(e);if(!Dt[a]||Tt&&m(e))return e;var f=a==ct,s=f||(a==vt?Jt(e,n):s)}if(!s||!t)return s?f?et.call(e):Gt({},e):e;s=e.constructor;switch(a){case ht:return new s(e==n);case pt:return new s(+e);case dt:case gt:return new s(e);case mt:return s(e.source,z.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=K[u],G.call(e,c)&&(!G.call(t,c)||!w(e[c],t[c],s,o)))return i;return n}function E(e,t,n,r){if(!e)return n;var s=e.length,o=3>arguments.length;if(s!==+s)var u=rn(e),s=u.length;return wn(e,function(e,n,a,f){return a=u?u[--s]:--s,o?(o=i,f[a]):t.call(r,e,f[a],a,f)},n)}function S(e,t,n){if(e)return t==r||n?e[0]:et.call(e,0,t)} -function x(e,t){var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?ut(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=u(t,n));++sr&&(r=n,i=e[s]);return i}function C(e,t,n) -{return e?et.call(e,t==r||n?1:t):[]}function k(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=A(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]T(f,r))f.push(r),s.push(e[o]);return s}function A(e,t){return At||nt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/ +a&&g(f)&&f instanceof f)))return i;for(var c in e)if(G.call(e,c)&&(l++,!G.call(t,c)||!w(e[c],t[c],s,o)))return i;for(c in t)if(G.call(t,c)&&!(l--))return i;if(wt)for(;7>++u;)if(c=K[u],G.call(e,c)&&(!G.call(t,c)||!w(e[c],t[c],s,o)))return i;return n}function E(e,t,n,r){if(!e)return n;var s=e,o=e.length,u=3>arguments.length;if(o!==+o)var a=rn(e),o=a.length;else Ct&&tt.call(e)==gt&&(s=e.split(""));return vn(e,function(e,f,l){f=a?a[--o]:--o,n=u?(u=i,s[f]):t.call(r,n,s[f],f,l)}),n}function S(e,t,n){if( +e)return t==r||n?e[0]:et.call(e,0,t)}function x(e,t){var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?ut(0,i+n):n)-1}for(;++rs&&(s=e[o]);return s}for(r!==t&&(n=u(n,r));++oi&& +(i=r,s=e[o]);return s}function C(e,t,n){return e?et.call(e,t==r||n?1:t):[]}function k(e,n,r,i){if(!e)return 0;var s=0,o=e.length;if(r){i!==t&&(r=A(r,i));for(n=r(n);s>>1,r(e[i])>>1,e[i]T(l,s))l.push(s),o.push(e[a]);return o}function A(e,t){return At||nt&&2< +arguments.length?nt.call.apply(nt,arguments):l(e,t,et.call(arguments,2))}function O(e){return e}function M(e){vn(en(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this.__wrapped__];return arguments.length&&Y.apply(e,arguments),e=r.apply(s,e),this.__chain__&&(e=new o(e),e.__chain__=n),e}})}var n=!0,r=null,i=!1,_="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),D=Array.prototype,P=Object.prototype,H=0,B=30,j=e._,F=/[-?+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/ ,I=/&(?:amp|lt|gt|quot|#x27);/g,q=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,U=/(__e\(.*?\)|\b__t\))\+'';/g,z=/\w*$/,W=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,X=RegExp("^"+(P.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),V=/($^)/,$=/[&<>"']/g,J=/['\n\r\t\u2028\u2029\\]/g,K="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),Q=D.concat,G=P.hasOwnProperty,Y=D.push,Z=P.propertyIsEnumerable,et=D.slice,tt= P.toString,nt=X.test(nt=et.bind)&&nt,rt=Math.floor,it=X.test(it=Array.isArray)&&it,st=e.isFinite,ot=X.test(ot=Object.keys)&&ot,ut=Math.max,at=Math.min,ft=Math.random,lt="[object Arguments]",ct="[object Array]",ht="[object Boolean]",pt="[object Date]",dt="[object Number]",vt="[object Object]",mt="[object RegExp]",gt="[object String]",yt=e.clearTimeout,bt=e.setTimeout,wt,Et,St,xt=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in arguments)xt=!r;wt=4>(n+"").length,St="x"!=n[0],Et=(n.splice.call(t,0,1),t[0])})(1);var Tt=!m(arguments),Nt="x"!=et.call("x")[0],Ct="xx"!="x"[0]+Object("x")[0];try{var kt=("[object Object]",tt.call(e.document||0)==vt)}catch(Lt){}var At=nt&&/\n|Opera/.test(nt+tt.call(e.opera)),Ot=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Mt=!At,_t={};_t[ht]=_t[pt]=_t["[object Function]"]=_t[dt]=_t[vt]=_t[mt]=i,_t[lt]=_t[ct]=_t[gt]=n;var Dt={};Dt[lt]=Dt["[object Function]"]=i,Dt[ct]=Dt[ht]=Dt[pt]=Dt[dt]=Dt[vt]=Dt[mt -]=Dt[gt]=n;var Pt={"&":"&","<":"<",">":">",'"':""","'":"'"},Ht={"&":"&","<":"<",">":">",""":'"',"'":"'"},Bt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Ft={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y)d=c(d,y)",i:"if(d(A,j,e)===false)return u" -},It={j:"{}",q:"var q;if(typeof d!='function'){var hh=d;d=function(A){return A[hh]}}else if(y)d=c(d,y)",i:"q=d(A,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},qt={j:"true",i:"if(!d(A,j,e))return!u"},Rt={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1"},i:"if(A===gg)return true"}),cn=c(Ft,It),hn=c(Ft,qt),pn=c(Ft,Ut),dn=c(Ft,zt,{j:"",i:"if(d(A,j,e))return A"}),vn=c(Ft,zt),mn=c(Ft,It,{i:"q=d(A,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(A)"}),gn=c(Xt,{a:"e,U",q:"var C=w.call(arguments,2),R=typeof U=='function'",i:{b:"u[j]=(R?U:A[U]).apply(A,C)",l:"u"+(Ot?"[o]=":".push")+"((R?U:A[U]).apply(A,C))"}}),yn=c(Ft,Xt),bn=c(Xt,{a:"e,aa",i:{b:"u[j]=A[aa]",l:"u"+(Ot?"[o]=":".push")+"(A[aa])"} -}),wn=c({a:"e,d,B,y",j:"B",q:"var V=arguments.length<3;if(y)d=c(d,y)",d:{b:"if(V)u=k[++j]"},i:{b:"u=d(u,A,j,e)",l:"u=V?(V=false,A):d(u,A,j,e)"}}),En=c(Ft,Ut,{i:"!"+Ut.i}),Sn=c(Ft,qt,{j:"false",i:qt.i.replace("!","")}),xn=c(Ft,It,Xt,{i:{b:"u[j]={a:d(A,j,e),b:j,c:A}",l:"u"+(Ot?"[o]=":".push")+"({a:d(A,j,e),b:j,c:A})"},e:"u.sort(I);l=u.length;while(l--)u[l]=u[l].c"}),Tn=c(Ut,{a:"e,Z",q:"var t=[];J(Z,function(A,q){t.push(q)});var bb=t.length",i:"for(var q,Y=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=A,s.bindAll=Nn,s.chain=function(e){return e=new o(e),e.__chain__=n,e},s.clone=b,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++n":">",'"':""","'":"'"},Ht={"&":"&","<":"<",">":">",""":'"',"'":"'"},Bt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Ft={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y!==A)d=c(d,y)",i:"if(d(B,j,e)===false)return u" +},It={j:"{}",q:"var q;if(typeof d!='function'){var ii=d;d=function(B){return B[ii]}}else if(y!==A)d=c(d,y)",i:"q=d(B,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},qt={j:"true",i:"if(!d(B,j,e))return!u"},Rt={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1"},i:"if(B===hh)return true"}),cn=c(Ft,It),hn=c(Ft,qt),pn=c(Ft,Ut),dn=c(Ft,zt,{j:"",i:"if(d(B,j,e))return B"}),vn=c(Ft,zt),mn=c(Ft,It,{i:"q=d(B,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(B)"}),gn=c(Xt,{a:"e,V",q:"var D=w.call(arguments,2),S=typeof V=='function'",i:{b:"u[j]=(S?V:B[V]).apply(B,D)",l:"u"+(Ot?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),yn=c(Ft,Xt),bn=c(Xt,{a:"e,bb",i:{b:"u[j]=B[bb]",l:"u"+(Ot?"[o]=":".push")+"(B[bb])" +}}),wn=c({a:"e,d,C,y",j:"C",q:"var W=arguments.length<3;if(y!==A)d=c(d,y)",d:{b:"if(W)u=k[++j]"},i:{b:"u=d(u,B,j,e)",l:"u=W?(W=false,B):d(u,B,j,e)"}}),En=c(Ft,Ut,{i:"!"+Ut.i}),Sn=c(Ft,qt,{j:"false",i:qt.i.replace("!","")}),xn=c(Ft,It,Xt,{i:{b:"u[j]={a:d(B,j,e),b:j,c:B}",l:"u"+(Ot?"[o]=":".push")+"({a:d(B,j,e),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--)u[l]=u[l].c"}),Tn=c(Ut,{a:"e,aa",q:"var t=[];K(aa,function(B,q){t.push(q)});var cc=t.length",i:"for(var q,Z=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=A,s.bindAll=Nn,s.chain=function(e){return e=new o(e),e.__chain__=n,e},s.clone=b,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nT(t,n)){for(var u=1;un?ut(0,r+n):at(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return l(t,e,et.call(arguments,2))},s.map=yn,s.max=N,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments) -:arguments[0];return G.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=sn,s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s=f?(a=r,s=e.apply(o,i)):u||(u=bt(n,f)),s}},s.times=function(e,t,n){var r=-1,i=Array(e||0);if(n)for(;++rT(r,t[e])&&r.push(t[e]);return r},s.uniq=L,s.uniqueId=function(e){var t=H++;return e?e+t:t},s.values=fn,s.where=Tn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=a(arguments,1,20);++nT(t,n)){for(var u=1;un?ut(0,r+n):at(n,r-1))+1 +);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return l(t,e,et.call(arguments,2))},s.map=yn,s.max=N,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return G.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=sn,s.min=function(e,n,r){var i=Infinity,s=i;if(!e)return s;var o=-1,a=e.length;if(!n){for(;++o=f?(a=r,s=e.apply(o,i)):u||(u=bt(n,f)),s}},s.times=function(e,n,r){var e=+e||0,i=-1,s=Array(e);if(r!==t)for(;++iT(r,t[e])&&r.push(t[e +]);return r},s.uniq=L,s.uniqueId=function(e){var t=H++;return e?e+t:t},s.values=fn,s.where=Tn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=a(arguments,1,20);++n Date: Mon, 24 Sep 2012 00:03:41 -0700 Subject: [PATCH 40/82] Cleanup `template` build option. Former-commit-id: 38b94dad822dd9030a6a71f66e65ff7aec0726cc --- build.js | 77 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/build.js b/build.js index d8175a31e9..38399d8706 100755 --- a/build.js +++ b/build.js @@ -254,38 +254,67 @@ /*--------------------------------------------------------------------------*/ /** - * Creates a debug and minified build, executing the `callback` for each. - * The `callback` is invoked with 2 arguments; (filepath, source) + * Compiles template files matched by the given file path `pattern` into a + * single source, extending `_.templates` with precompiled templates named after + * each template file's basename. * - * @param {Array} options The options array. - * @param {Function} callback The function called per build. + * @private + * @param {String} pattern The file path pattern. + * @param {Object} options The options object. + * @returns {String} Returns the compiled source. */ - function buildTemplate(templatePattern, templateSettings) { - var directory = path.dirname(templatePattern); + function buildTemplate(pattern, options) { + pattern || (pattern = './*.jst'); + options || (options = _.templateSettings); - var pattern = RegExp( - path.basename(templatePattern) - .replace(/[.+?^=!:${}()|[\]\/\\]/g, '\\$&') - .replace(/\*/g, '.*?') + '$' - ); + var directory = path.dirname(pattern); + + var moduleName = 'lodash'; var source = [ ';(function() {', - ' var templates = _.templates || (_.templates = {});' + " var freeExports = typeof exports == 'object' && exports;", + '', + ' var templates = {};', + '' ]; + // convert to a regexp + pattern = RegExp( + path.basename(pattern) + .replace(/[.+?^=!:${}()|[\]\/\\]/g, '\\$&') + .replace(/\*/g, '.*?') + '$' + ); + fs.readdirSync(directory).forEach(function(filename) { var filepath = path.join(directory, filename); if (pattern.test(filename)) { var text = fs.readFileSync(filepath, 'utf8'), - precompiled = getFunctionSource(_.template(text, null, templateSettings)), + precompiled = getFunctionSource(_.template(text, null, options)), prop = filename.replace(/\..*$/, ''); - source.push(' templates["' + prop + '"] = ' + precompiled + ';'); + source.push(" templates['" + prop + "'] = " + precompiled + ';'); } }); - source.push('}());'); + source.push( + '', + " if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {", + " define(['" + moduleName + "'], function(lodash) {", + ' lodash.templates = lodash.extend(lodash.templates || {}, templates);', + ' });', + " } else if (freeExports) {", + " if (typeof module == 'object' && module && module.exports == freeExports) {", + ' (module.exports = templates).templates = templates;', + ' } else {', + ' freeExports.templates = templates;', + ' }', + ' } else {', + ' _.templates = _.extend(_.templates || {}, templates);', + ' }', + '}());' + ); + return source.join('\n'); } @@ -334,8 +363,10 @@ ' lodash iife=... Code to replace the immediately-invoked function expression that wraps Lo-Dash', ' (e.g. `lodash iife="!function(window,undefined){%output%}(this)"`)', '', - ' lodash template=... The file path pattern used for matching template files to compile', + ' lodash template=... File path pattern used to match template files to precompile', ' (e.g. `lodash template=./*.jst`)', + ' lodash settings=... Template settings used when precompiling templates', + ' (e.g. `lodash settings="{interpolate:/\\{\\{(.+?)\\}\\}/g}"`)', '', ' All arguments, except `legacy` with `csp` or `mobile`, may be combined.', ' Unless specified by `-o` or `--output`, all files created are saved to the current working directory.', @@ -893,7 +924,7 @@ return result; }, ''); - // used to match external template files to pre-compile + // used to match external template files to precompile var templatePattern = options.reduce(function(result, value) { var match = value.match(/template=(.+)$/); return match @@ -901,11 +932,11 @@ : result; }, ''); - // used when pre-compiling template files + // used when precompiling template files var templateSettings = options.reduce(function(result, value) { var match = value.match(/settings=(.+)$/); return match - ? JSON.parse(match[1]) + ? Function('return {' + match[1].replace(/^{|}$/g, '') + '}')() : result; }, _.clone(_.templateSettings)); @@ -1249,17 +1280,17 @@ source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +define[\s\S]+?else /, '$1'); } if (exportsOptions.indexOf('node') == -1) { - source = source.replace(/(?: *\/\/.*\n)* *if *\(typeof +module[\s\S]+?else *{\n([\s\S]+?) *}\n/, '$1'); + source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +module[\s\S]+?else *{[\s\S]+?\n\1}\n/, '$1'); } if (exportsOptions.indexOf('commonjs') == -1) { - source = source.replace(/(?: *\/\/.*\n)*(?:( +)else *{)?\s*freeExports\._ *=.+(\n\1})?\n/, ''); + source = source.replace(/(?: *\/\/.*\n)*(?:( +)else *{)?\s*freeExports\.\w+ *=[\s\S]+?(?:\n\1})?\n/, ''); } if (exportsOptions.indexOf('global') == -1) { - source = source.replace(/(?:( +)else *{)?(?:\s*\/\/.*)*\s*window\._ *= *lodash.+(\n\1})?\n/g, ''); + source = source.replace(/(?:( +)else *{)?(?:\s*\/\/.*)*\s*(?:window\._|_\.templates) *=[\s\S]+?(?:\n\1})?\n/g, ''); } // remove `if (freeExports) {...}` if it's empty - source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}(?:\s*else *{\n([\s\S]+?) *})?/, '$1'); + source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}(?:\s*else *{([\s\S]+?) *})?\n/, '$1'); if ((source.match(/\bfreeExports\b/g) || []).length < 2) { source = removeVar(source, 'freeExports'); From 2fb93bac995ac0a98b3b3584cdf5ca0a11cd8c21 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 24 Sep 2012 01:06:58 -0700 Subject: [PATCH 41/82] Use a different private indicator for `_.merge` now that `isPlainObject` is exposed. Former-commit-id: 5c75de935eb3e5e9e035bd6520398c7fbd811ea6 --- build/pre-compile.js | 1 + doc/README.md | 228 +++++++++++++++++++++++++------------------ lodash.js | 8 +- lodash.min.js | 14 +-- 4 files changed, 146 insertions(+), 105 deletions(-) diff --git a/build/pre-compile.js b/build/pre-compile.js index 4037e1fd20..d30a249d25 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -58,6 +58,7 @@ 'isPlainObject', 'methodName', 'noaccum', + 'noop', 'objectClass', 'objectTypes', 'pass', diff --git a/doc/README.md b/doc/README.md index 5a37364c9c..a7fa74aa86 100644 --- a/doc/README.md +++ b/doc/README.md @@ -65,6 +65,7 @@ * [`_.isNull`](#_isnullvalue) * [`_.isNumber`](#_isnumbervalue) * [`_.isObject`](#_isobjectvalue) +* [`_.isPlainObject`](#_isplainobjectvalue--skipargscheckfalse) * [`_.isRegExp`](#_isregexpvalue) * [`_.isString`](#_isstringvalue) * [`_.isUndefined`](#_isundefinedvalue) @@ -173,7 +174,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4109 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4134 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -185,7 +186,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3207 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3231 "View in source") [Ⓣ][1] Creates a function that is restricted to executing only after it is called `n` times. @@ -213,7 +214,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3240 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3264 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. @@ -244,7 +245,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3270 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3294 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -275,7 +276,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4034 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4059 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -309,7 +310,7 @@ var youngest = _.chain(stooges) ### `_.clone(value, deep [, guard, stackA=[], stackB=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1040 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1057 "View in source") [Ⓣ][1] Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned. @@ -351,7 +352,7 @@ shallow[0] === stooges[0]; ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2437 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2461 "View in source") [Ⓣ][1] Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -375,7 +376,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3308 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3332 "View in source") [Ⓣ][1] Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -402,7 +403,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1914 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1934 "View in source") [Ⓣ][1] Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -436,7 +437,7 @@ _.contains('curly', 'ur'); ### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1950 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1970 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -468,7 +469,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3341 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3365 "View in source") [Ⓣ][1] Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -494,7 +495,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1133 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1150 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -520,7 +521,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3406 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3430 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -545,7 +546,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3386 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3410 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -572,7 +573,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2469 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2493 "View in source") [Ⓣ][1] Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -597,7 +598,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3625 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3649 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -621,7 +622,7 @@ _.escape('Moe, Larry & Curly'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1971 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1991 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -650,7 +651,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1153 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1170 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -675,7 +676,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1991 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2011 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -704,7 +705,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2013 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2033 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -733,7 +734,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2506 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2530 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -762,7 +763,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2530 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2554 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -790,7 +791,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2040 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2060 "View in source") [Ⓣ][1] Iterates over a `collection`, 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`. @@ -822,7 +823,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1183 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1200 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, 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`. @@ -858,7 +859,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1207 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1224 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, 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`. @@ -886,7 +887,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1224 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1241 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -913,7 +914,7 @@ _.functions(_); ### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2068 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2088 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -945,7 +946,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1247 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1264 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -970,7 +971,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3645 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3669 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -995,7 +996,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2576 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2600 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1027,7 +1028,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2616 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2640 "View in source") [Ⓣ][1] Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. @@ -1053,7 +1054,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2638 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2662 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -1077,7 +1078,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invert(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1264 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1281 "View in source") [Ⓣ][1] Creates an object composed of the inverted keys and values of the given `object`. @@ -1101,7 +1102,7 @@ _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2096 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2116 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`, returning an array of the results of each invoked method. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1184,7 +1185,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1283 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1300 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1208,7 +1209,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1300 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1317 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1232,7 +1233,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1317 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1334 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1256,7 +1257,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1342 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1359 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1286,7 +1287,7 @@ _.isEmpty(''); ### `_.isEqual(a, b [, stackA=[], stackB=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1381 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1398 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1319,7 +1320,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1538 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1555 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1361,7 +1362,7 @@ Checks if `value` is a function. #### Example ```js -_.isFunction(''.concat); +_.isFunction(_); // => true ``` @@ -1373,7 +1374,7 @@ _.isFunction(''.concat); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1593 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1613 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1406,7 +1407,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1616 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1636 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1433,7 +1434,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1633 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1653 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1457,7 +1458,7 @@ _.isNumber(8.4 * 5); ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1559 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1579 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -1472,6 +1473,9 @@ Checks if `value` is the language type of Object. *(e.g. arrays, functions, obje _.isObject({}); // => true +_.isObject([1, 2, 3]); +// => true + _.isObject(1); // => false ``` @@ -1481,10 +1485,46 @@ _.isObject(1); + + +### `_.isPlainObject(value [, skipArgsCheck=false])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L948 "View in source") [Ⓣ][1] + +Checks if a given `value` is an object created by the `Object` constructor. + +#### Arguments +1. `value` *(Mixed)*: The value to check. +2. `[skipArgsCheck=false]` *(Boolean)*: Internally used to skip checks for `arguments` objects. + +#### Returns +*(Boolean)*: Returns `true` if `value` is a plain object, else `false`. + +#### Example +```js +function Stooge(name, age) { + this.name = name; + this.age = age; +} + +_.isPlainObject(new Stooge('moe', 40)); +// false + +_.isPlainObject([1, 2, 3]); +// false + +_.isPlainObject({ 'name': 'moe', 'age': 40 }); +// => true +``` + +* * * + + + + ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1650 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1670 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1508,7 +1548,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1667 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1687 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1532,7 +1572,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1685 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1705 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1556,7 +1596,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1702 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1722 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of `object`. @@ -1580,7 +1620,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2681 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2705 "View in source") [Ⓣ][1] Gets the last element of the `array`. Pass `n` to return the lasy `n` elementsvof the `array`. @@ -1606,7 +1646,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2707 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2731 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1635,7 +1675,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.lateBind(object, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3443 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3467 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method @@ -1676,7 +1716,7 @@ func(); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2131 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2151 "View in source") [Ⓣ][1] Creates an array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1708,7 +1748,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2747 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2771 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1740,7 +1780,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3465 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3489 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1766,7 +1806,7 @@ var fibonacci = _.memoize(function(n) { ### `_.merge(object [, source1, source2, ..., indicator, stackA=[], stackB=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1745 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1765 "View in source") [Ⓣ][1] Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -1804,7 +1844,7 @@ _.merge(stooges, ages); ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2797 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2821 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1830,7 +1870,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3671 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3695 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1860,7 +1900,7 @@ _('curly').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3702 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3726 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1880,7 +1920,7 @@ var lodash = _.noConflict(); ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2846 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2870 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. @@ -1905,7 +1945,7 @@ _.object(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1807 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1827 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -1936,7 +1976,7 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3491 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3515 "View in source") [Ⓣ][1] Creates a function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1962,7 +2002,7 @@ initialize(); ### `_.pairs(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1823 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1843 "View in source") [Ⓣ][1] Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. @@ -1986,7 +2026,7 @@ _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3526 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3550 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `bind`, except it does **not** alter the `this` binding. @@ -2013,7 +2053,7 @@ hi('moe'); ### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1854 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1874 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, picking the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -2044,7 +2084,7 @@ _.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2154 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2174 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -2075,7 +2115,7 @@ _.pluck(stooges, 'name'); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3725 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3749 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -2103,7 +2143,7 @@ _.random(5); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2893 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2917 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -2141,7 +2181,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2182 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2202 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -2171,7 +2211,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2219 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2239 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -2202,7 +2242,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2255 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2279 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -2228,7 +2268,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2932 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2956 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2257,7 +2297,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3764 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3788 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2292,7 +2332,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2953 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2977 "View in source") [Ⓣ][1] Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2316,7 +2356,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2279 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2303 "View in source") [Ⓣ][1] Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. @@ -2346,7 +2386,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2307 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2331 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2375,7 +2415,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2337 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2361 "View in source") [Ⓣ][1] Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2407,7 +2447,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3005 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3029 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. @@ -2448,7 +2488,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4061 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4086 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2478,7 +2518,7 @@ _.chain([1, 2, 3, 200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3837 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3861 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: In the development build `_.template` utilizes sourceURLs for easier debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. See http://developer.chrome.com/trunk/extensions/sandboxingEval.html @@ -2543,7 +2583,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3548 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3572 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2568,7 +2608,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3956 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3980 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -2600,7 +2640,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2373 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2397 "View in source") [Ⓣ][1] Converts the `collection`, to an array. @@ -2624,7 +2664,7 @@ Converts the `collection`, to an array. ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3986 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4011 "View in source") [Ⓣ][1] Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -2648,7 +2688,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3046 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3070 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -2672,7 +2712,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3090 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3114 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -2711,7 +2751,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4004 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4029 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2735,7 +2775,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1884 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1904 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2759,7 +2799,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2407 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2431 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. @@ -2790,7 +2830,7 @@ _.where(stooges, { 'age': 40 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3139 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3163 "View in source") [Ⓣ][1] Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2815,7 +2855,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3599 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3623 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2844,7 +2884,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3172 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3196 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2875,7 +2915,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4079 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4104 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2896,7 +2936,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4096 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4121 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.js b/lodash.js index f3dd15bd73..10dcf97615 100644 --- a/lodash.js +++ b/lodash.js @@ -791,7 +791,7 @@ var factory = Function( 'arrayLikeClasses, ArrayProto, bind, bindIterator, compareAscending, concat, ' + 'forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, ' + - 'isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, ' + + 'isPlainObject, noop, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, ' + 'slice, stringClass, toString, undefined', 'var callee = function(' + args + ') {\n' + iteratorTemplate(data) + '\n};\n' + 'return callee' @@ -800,7 +800,7 @@ return factory( arrayLikeClasses, ArrayProto, bind, bindIterator, compareAscending, concat, forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, - isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, + isPlainObject, noop, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, slice, stringClass, toString ); } @@ -1767,7 +1767,7 @@ 'top': 'var argsLength, isArr, stackA, stackB,\n' + ' args = arguments, argsIndex = 0;\n' + - 'if (indicator == isPlainObject) {\n' + + 'if (indicator == noop) {\n' + ' argsLength = 2;\n' + ' stackA = args[3];\n' + ' stackB = args[4]\n' + @@ -1792,7 +1792,7 @@ ' ? (isArray(value) ? value : [])\n' + ' : (isPlainObject(value) ? value : {})\n' + ' );\n' + - ' result[index] = callee(value, source, isPlainObject, stackA, stackB)\n' + + ' result[index] = callee(value, source, noop, stackA, stackB)\n' + ' }\n' + '} else if (source != null) {\n' + ' result[index] = source\n' + diff --git a/lodash.min.js b/lodash.min.js index e3b0ce6cd3..1d69dd0bde 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -5,8 +5,8 @@ ;(function(e,t){function s(e){return new o(e)}function o(e){if(e&&e.__wrapped__)return e;this.__wrapped__=e}function u(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function a(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||B),s=i?{}:e;if(i)for(var o=t-1;++on||e===t)return 1;if(en;n++)t+="j='"+a.p[n]+"';if(" -,"constructor"==a.p[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){B=k[j];"+a.m.i+"}"}if(a.c||a.n)t+="}"}return t+=a.e+";return u",Function("E,F,G,c,J,f,K,h,i,N,P,R,T,U,X,Y,m,r,w,x,z,A","var H=function("+e+"){"+t+"};return H")(_t,D,A,u,f,Q,Yt,G,O,T,m,$t,g,Jt,vt,Bt,ot,Z,et,gt,tt)}function h(e){return"\\"+jt[e]}function p(e){return Pt[e]}function d(){}function v(e){return Ht[e]}function m(e){return tt.call(e)==lt}function g(e){return"function"==typeof e}function y(e,t){var n=i;if(!e||"object"!=typeof +a.m.i+"}}else{"),a.h||(t+="var v=typeof k=='function'&&r.call(k,'prototype');");if(a.k&&a.r)t+="var o=-1,p=Z[typeof k]?m(k):[],l=p.length;"+a.m.d+";while(++on;n++)t+="j='"+a.p[n]+"';if(" +,"constructor"==a.p[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){B=k[j];"+a.m.i+"}"}if(a.c||a.n)t+="}"}return t+=a.e+";return u",Function("E,F,G,c,J,f,K,h,i,N,P,R,T,U,X,Y,Z,m,r,w,x,z,A","var H=function("+e+"){"+t+"};return H")(_t,D,A,u,f,Q,Yt,G,O,T,m,$t,g,Jt,d,vt,Bt,ot,Z,et,gt,tt)}function h(e){return"\\"+jt[e]}function p(e){return Pt[e]}function d(){}function v(e){return Ht[e]}function m(e){return tt.call(e)==lt}function g(e){return"function"==typeof e}function y(e,t){var n=i;if(!e||"object"!=typeof e||!t&&m(e))return n;var r=e.constructor;return(!kt||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!g(r)||r instanceof r)?St?(Yt(e,function(e,t,r){return n=!G.call(r,t),i}),n===i):(Yt(e,function(e,t){n=t}),n===i||G.call(e,n)):n}function b(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=Bt[typeof e]){var a=tt.call(e);if(!Dt[a]||Tt&&m(e))return e;var f=a==ct,s=f||(a==vt?Jt(e,n):s)}if(!s||!t)return s?f?et.call(e):Gt({},e):e;s=e.constructor;switch(a){case ht:return new s(e==n);case pt:return new s(+e);case dt:case gt:return new s(e);case mt:return s(e.source,z.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f(n+"").length,St="x"!=n[0],Et=(n.splice.call(t,0,1),t[0])})(1);var Tt=!m(arguments),Nt="x"!=et.call("x")[0],Ct="xx"!="x"[0]+Object("x")[0];try{var kt=("[object Object]",tt.call(e.document||0)==vt)}catch(Lt){}var At=nt&&/\n|Opera/.test(nt+tt.call(e.opera)),Ot=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Mt=!At,_t={};_t[ht]=_t[pt]=_t["[object Function]"]=_t[dt]=_t[vt]=_t[mt]=i,_t[lt]=_t[ct]=_t[gt]=n;var Dt={};Dt[lt]=Dt["[object Function]"]=i,Dt[ct]=Dt[ht]=Dt[pt]=Dt[dt]=Dt[vt]=Dt[mt ]=Dt[gt]=n;var Pt={"&":"&","<":"<",">":">",'"':""","'":"'"},Ht={"&":"&","<":"<",">":">",""":'"',"'":"'"},Bt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Ft={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y!==A)d=c(d,y)",i:"if(d(B,j,e)===false)return u" -},It={j:"{}",q:"var q;if(typeof d!='function'){var ii=d;d=function(B){return B[ii]}}else if(y!==A)d=c(d,y)",i:"q=d(B,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},qt={j:"true",i:"if(!d(B,j,e))return!u"},Rt={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1"},i:"if(B===hh)return true"}),cn=c(Ft,It),hn=c(Ft,qt),pn=c(Ft,Ut),dn=c(Ft,zt,{j:"",i:"if(d(B,j,e))return B"}),vn=c(Ft,zt),mn=c(Ft,It,{i:"q=d(B,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(B)"}),gn=c(Xt,{a:"e,V",q:"var D=w.call(arguments,2),S=typeof V=='function'",i:{b:"u[j]=(S?V:B[V]).apply(B,D)",l:"u"+(Ot?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),yn=c(Ft,Xt),bn=c(Xt,{a:"e,bb",i:{b:"u[j]=B[bb]",l:"u"+(Ot?"[o]=":".push")+"(B[bb])" -}}),wn=c({a:"e,d,C,y",j:"C",q:"var W=arguments.length<3;if(y!==A)d=c(d,y)",d:{b:"if(W)u=k[++j]"},i:{b:"u=d(u,B,j,e)",l:"u=W?(W=false,B):d(u,B,j,e)"}}),En=c(Ft,Ut,{i:"!"+Ut.i}),Sn=c(Ft,qt,{j:"false",i:qt.i.replace("!","")}),xn=c(Ft,It,Xt,{i:{b:"u[j]={a:d(B,j,e),b:j,c:B}",l:"u"+(Ot?"[o]=":".push")+"({a:d(B,j,e),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--)u[l]=u[l].c"}),Tn=c(Ut,{a:"e,aa",q:"var t=[];K(aa,function(B,q){t.push(q)});var cc=t.length",i:"for(var q,Z=true,s=0;s-1"},i:"if(B===ii)return true"}),cn=c(Ft,It),hn=c(Ft,qt),pn=c(Ft,Ut),dn=c(Ft,zt,{j:"",i:"if(d(B,j,e))return B"}),vn=c(Ft,zt),mn=c(Ft,It,{i:"q=d(B,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(B)"}),gn=c(Xt,{a:"e,V",q:"var D=w.call(arguments,2),S=typeof V=='function'",i:{b:"u[j]=(S?V:B[V]).apply(B,D)",l:"u"+(Ot?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),yn=c(Ft,Xt),bn=c(Xt,{a:"e,cc",i:{b:"u[j]=B[cc]",l:"u"+(Ot?"[o]=":".push")+"(B[cc])" +}}),wn=c({a:"e,d,C,y",j:"C",q:"var W=arguments.length<3;if(y!==A)d=c(d,y)",d:{b:"if(W)u=k[++j]"},i:{b:"u=d(u,B,j,e)",l:"u=W?(W=false,B):d(u,B,j,e)"}}),En=c(Ft,Ut,{i:"!"+Ut.i}),Sn=c(Ft,qt,{j:"false",i:qt.i.replace("!","")}),xn=c(Ft,It,Xt,{i:{b:"u[j]={a:d(B,j,e),b:j,c:B}",l:"u"+(Ot?"[o]=":".push")+"({a:d(B,j,e),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--)u[l]=u[l].c"}),Tn=c(Ut,{a:"e,bb",q:"var t=[];K(bb,function(B,q){t.push(q)});var dd=t.length",i:"for(var q,aa=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=A,s.bindAll=Nn,s.chain=function(e){return e=new o(e),e.__chain__=n,e},s.clone=b,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++n Date: Mon, 24 Sep 2012 01:15:46 -0700 Subject: [PATCH 42/82] Remove internal params from built docs. Former-commit-id: 8b0be9d888ef88dae74554101463f4fa8d268dbc --- doc/README.md | 69 +++++++++++++++++++++------------------------------ lodash.js | 28 ++++++++++----------- 2 files changed, 42 insertions(+), 55 deletions(-) diff --git a/doc/README.md b/doc/README.md index a7fa74aa86..315f1fc008 100644 --- a/doc/README.md +++ b/doc/README.md @@ -14,7 +14,7 @@ * [`_.bind`](#_bindfunc--thisarg-arg1-arg2-) * [`_.bindAll`](#_bindallobject--methodname1-methodname2-) * [`_.chain`](#_chainvalue) -* [`_.clone`](#_clonevalue-deep--guard-stacka-stackb) +* [`_.clone`](#_clonevalue-deep) * [`_.collect`](#_mapcollection--callbackidentity-thisarg) * [`_.compact`](#_compactarray) * [`_.compose`](#_composefunc1-func2-) @@ -26,14 +26,14 @@ * [`_.delay`](#_delayfunc-wait--arg1-arg2-) * [`_.detect`](#_findcollection-callback--thisarg) * [`_.difference`](#_differencearray--array1-array2-) -* [`_.drop`](#_restarray--n-guard) +* [`_.drop`](#_restarray--n) * [`_.each`](#_foreachcollection-callback--thisarg) * [`_.escape`](#_escapestring) * [`_.every`](#_everycollection--callbackidentity-thisarg) * [`_.extend`](#_extendobject--source1-source2-) * [`_.filter`](#_filtercollection--callbackidentity-thisarg) * [`_.find`](#_findcollection-callback--thisarg) -* [`_.first`](#_firstarray--n-guard) +* [`_.first`](#_firstarray--n) * [`_.flatten`](#_flattenarray-shallow) * [`_.foldl`](#_reducecollection-callback--accumulator-thisarg) * [`_.foldr`](#_reducerightcollection-callback--accumulator-thisarg) @@ -43,11 +43,11 @@ * [`_.functions`](#_functionsobject) * [`_.groupBy`](#_groupbycollection-callbackproperty--thisarg) * [`_.has`](#_hasobject-property) -* [`_.head`](#_firstarray--n-guard) +* [`_.head`](#_firstarray--n) * [`_.identity`](#_identityvalue) * [`_.include`](#_containscollection-target) * [`_.indexOf`](#_indexofarray-value--fromindex0) -* [`_.initial`](#_initialarray--n-guard) +* [`_.initial`](#_initialarray--n) * [`_.inject`](#_reducecollection-callback--accumulator-thisarg) * [`_.intersection`](#_intersectionarray1-array2-) * [`_.invert`](#_invertobject) @@ -58,25 +58,25 @@ * [`_.isDate`](#_isdatevalue) * [`_.isElement`](#_iselementvalue) * [`_.isEmpty`](#_isemptyvalue) -* [`_.isEqual`](#_isequala-b--stacka-stackb) +* [`_.isEqual`](#_isequala-b) * [`_.isFinite`](#_isfinitevalue) * [`_.isFunction`](#_isfunctionvalue) * [`_.isNaN`](#_isnanvalue) * [`_.isNull`](#_isnullvalue) * [`_.isNumber`](#_isnumbervalue) * [`_.isObject`](#_isobjectvalue) -* [`_.isPlainObject`](#_isplainobjectvalue--skipargscheckfalse) +* [`_.isPlainObject`](#_isplainobjectvalue) * [`_.isRegExp`](#_isregexpvalue) * [`_.isString`](#_isstringvalue) * [`_.isUndefined`](#_isundefinedvalue) * [`_.keys`](#_keysobject) -* [`_.last`](#_lastarray--n-guard) +* [`_.last`](#_lastarray--n) * [`_.lastIndexOf`](#_lastindexofarray-value--fromindexarraylength-1) * [`_.lateBind`](#_latebindobject-methodname--arg1-arg2-) * [`_.map`](#_mapcollection--callbackidentity-thisarg) * [`_.max`](#_maxarray--callback-thisarg) * [`_.memoize`](#_memoizefunc--resolver) -* [`_.merge`](#_mergeobject--source1-source2--indicator-stacka-stackb) +* [`_.merge`](#_mergeobject--source1-source2-) * [`_.methods`](#_functionsobject) * [`_.min`](#_minarray--callback-thisarg) * [`_.mixin`](#_mixinobject) @@ -93,7 +93,7 @@ * [`_.reduce`](#_reducecollection-callback--accumulator-thisarg) * [`_.reduceRight`](#_reducerightcollection-callback--accumulator-thisarg) * [`_.reject`](#_rejectcollection--callbackidentity-thisarg) -* [`_.rest`](#_restarray--n-guard) +* [`_.rest`](#_restarray--n) * [`_.result`](#_resultobject-property) * [`_.select`](#_filtercollection--callbackidentity-thisarg) * [`_.shuffle`](#_shufflearray) @@ -101,8 +101,8 @@ * [`_.some`](#_somecollection--callbackidentity-thisarg) * [`_.sortBy`](#_sortbycollection-callbackproperty--thisarg) * [`_.sortedIndex`](#_sortedindexarray-value--callbackidentity-thisarg) -* [`_.tail`](#_restarray--n-guard) -* [`_.take`](#_firstarray--n-guard) +* [`_.tail`](#_restarray--n) +* [`_.take`](#_firstarray--n) * [`_.tap`](#_tapvalue-interceptor) * [`_.template`](#_templatetext-data-options) * [`_.throttle`](#_throttlefunc-wait) @@ -309,17 +309,14 @@ var youngest = _.chain(stooges) -### `_.clone(value, deep [, guard, stackA=[], stackB=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1057 "View in source") [Ⓣ][1] +### `_.clone(value, deep)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1057 "View in source") [Ⓣ][1] Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned. #### Arguments 1. `value` *(Mixed)*: The value to clone. 2. `deep` *(Boolean)*: A flag to indicate a deep clone. -3. `[guard]` *(Object)*: Internally used to allow this method to work with others like `_.map` without using their callback `index` argument for `deep`. -4. `[stackA=[]]` *(Array)*: Internally used to track traversed source objects. -5. `[stackB=[]]` *(Array)*: Internally used to associate clones with their source counterparts. #### Returns *(Mixed)*: Returns the cloned `value`. @@ -733,8 +730,8 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -### `_.first(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2530 "View in source") [Ⓣ][1] +### `_.first(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2530 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -744,7 +741,6 @@ Gets the first element of the `array`. Pass `n` to return the first `n` elements #### Arguments 1. `array` *(Array)*: The array to query. 2. `[n]` *(Number)*: The number of elements to return. -3. `[guard]` *(Object)*: Internally used to allow this method to work with others like `_.map` without using their callback `index` argument for `n`. #### Returns *(Mixed)*: Returns the first element or an array of the first `n` elements of `array`. @@ -1027,15 +1023,14 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); -### `_.initial(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2640 "View in source") [Ⓣ][1] +### `_.initial(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2640 "View in source") [Ⓣ][1] Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. #### Arguments 1. `array` *(Array)*: The array to query. 2. `[n]` *(Number)*: The number of elements to return. -3. `[guard]` *(Object)*: Internally used to allow this method to work with others like `_.map` without using their callback `index` argument for `n`. #### Returns *(Array)*: Returns all but the last element or `n` elements of `array`. @@ -1286,16 +1281,14 @@ _.isEmpty(''); -### `_.isEqual(a, b [, stackA=[], stackB=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1398 "View in source") [Ⓣ][1] +### `_.isEqual(a, b)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1398 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. #### Arguments 1. `a` *(Mixed)*: The value to compare. 2. `b` *(Mixed)*: The other value to compare. -3. `[stackA=[]]` *(Object)*: Internally used track traversed `a` objects. -4. `[stackB=[]]` *(Object)*: Internally used track traversed `b` objects. #### Returns *(Boolean)*: Returns `true` if the values are equvalent, else `false`. @@ -1487,14 +1480,13 @@ _.isObject(1); -### `_.isPlainObject(value [, skipArgsCheck=false])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L948 "View in source") [Ⓣ][1] +### `_.isPlainObject(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L948 "View in source") [Ⓣ][1] Checks if a given `value` is an object created by the `Object` constructor. #### Arguments 1. `value` *(Mixed)*: The value to check. -2. `[skipArgsCheck=false]` *(Boolean)*: Internally used to skip checks for `arguments` objects. #### Returns *(Boolean)*: Returns `true` if `value` is a plain object, else `false`. @@ -1619,15 +1611,14 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); -### `_.last(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2705 "View in source") [Ⓣ][1] +### `_.last(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2705 "View in source") [Ⓣ][1] Gets the last element of the `array`. Pass `n` to return the lasy `n` elementsvof the `array`. #### Arguments 1. `array` *(Array)*: The array to query. 2. `[n]` *(Number)*: The number of elements to return. -3. `[guard]` *(Object)*: Internally used to allow this method to work with others like `_.map` without using their callback `index` argument for `n`. #### Returns *(Mixed)*: Returns the last element or an array of the last `n` elements of `array`. @@ -1805,17 +1796,14 @@ var fibonacci = _.memoize(function(n) { -### `_.merge(object [, source1, source2, ..., indicator, stackA=[], stackB=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1765 "View in source") [Ⓣ][1] +### `_.merge(object [, source1, source2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1765 "View in source") [Ⓣ][1] Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. #### Arguments 1. `object` *(Object)*: The destination object. 2. `[source1, source2, ...]` *(Object)*: The source objects. -3. `[indicator]` *(Object)*: Internally used to indicate that the `stack` argument is an array of traversed objects instead of another source object. -4. `[stackA=[]]` *(Array)*: Internally used to track traversed source objects. -5. `[stackB=[]]` *(Array)*: Internally used to associate clones with their source counterparts. #### Returns *(Object)*: Returns the destination object. @@ -2267,8 +2255,8 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -### `_.rest(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2956 "View in source") [Ⓣ][1] +### `_.rest(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2956 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2278,7 +2266,6 @@ The opposite of `_.initial`, this method gets all but the first value of `array` #### Arguments 1. `array` *(Array)*: The array to query. 2. `[n]` *(Number)*: The number of elements to return. -3. `[guard]` *(Object)*: Internally used to allow this method to work with others like `_.map` without using their callback `index` argument for `n`. #### Returns *(Array)*: Returns all but the first value or `n` values of `array`. diff --git a/lodash.js b/lodash.js index 10dcf97615..7e5beec426 100644 --- a/lodash.js +++ b/lodash.js @@ -926,7 +926,7 @@ * @memberOf _ * @category Objects * @param {Mixed} value The value to check. - * @param {Boolean} [skipArgsCheck=false] Internally used to skip checks for + * @param- {Boolean} [skipArgsCheck=false] Internally used to skip checks for * `arguments` objects. * @returns {Boolean} Returns `true` if `value` is a plain object, else `false`. * @example @@ -965,7 +965,7 @@ * * @private * @param {Mixed} value The value to check. - * @param {Boolean} [skipArgsCheck=false] Internally used to skip checks for + * @param- {Boolean} [skipArgsCheck=false] Internally used to skip checks for * `arguments` objects. * @returns {Boolean} Returns `true` if `value` is a plain object, else `false`. */ @@ -1029,10 +1029,10 @@ * @category Objects * @param {Mixed} value The value to clone. * @param {Boolean} deep A flag to indicate a deep clone. - * @param {Object} [guard] Internally used to allow this method to work with + * @param- {Object} [guard] Internally used to allow this method to work with * others like `_.map` without using their callback `index` argument for `deep`. - * @param {Array} [stackA=[]] Internally used to track traversed source objects. - * @param {Array} [stackB=[]] Internally used to associate clones with their + * @param- {Array} [stackA=[]] Internally used to track traversed source objects. + * @param- {Array} [stackB=[]] Internally used to associate clones with their * source counterparts. * @returns {Mixed} Returns the cloned `value`. * @example @@ -1381,8 +1381,8 @@ * @category Objects * @param {Mixed} a The value to compare. * @param {Mixed} b The other value to compare. - * @param {Object} [stackA=[]] Internally used track traversed `a` objects. - * @param {Object} [stackB=[]] Internally used track traversed `b` objects. + * @param- {Object} [stackA=[]] Internally used track traversed `a` objects. + * @param- {Object} [stackB=[]] Internally used track traversed `b` objects. * @returns {Boolean} Returns `true` if the values are equvalent, else `false`. * @example * @@ -1741,10 +1741,10 @@ * @category Objects * @param {Object} object The destination object. * @param {Object} [source1, source2, ...] The source objects. - * @param {Object} [indicator] Internally used to indicate that the `stack` + * @param- {Object} [indicator] Internally used to indicate that the `stack` * argument is an array of traversed objects instead of another source object. - * @param {Array} [stackA=[]] Internally used to track traversed source objects. - * @param {Array} [stackB=[]] Internally used to associate clones with their + * @param- {Array} [stackA=[]] Internally used to track traversed source objects. + * @param- {Array} [stackB=[]] Internally used to associate clones with their * source counterparts. * @returns {Object} Returns the destination object. * @example @@ -2518,7 +2518,7 @@ * @category Arrays * @param {Array} array The array to query. * @param {Number} [n] The number of elements to return. - * @param {Object} [guard] Internally used to allow this method to work with + * @param- {Object} [guard] Internally used to allow this method to work with * others like `_.map` without using their callback `index` argument for `n`. * @returns {Mixed} Returns the first element or an array of the first `n` * elements of `array`. @@ -2629,7 +2629,7 @@ * @category Arrays * @param {Array} array The array to query. * @param {Number} [n] The number of elements to return. - * @param {Object} [guard] Internally used to allow this method to work with + * @param- {Object} [guard] Internally used to allow this method to work with * others like `_.map` without using their callback `index` argument for `n`. * @returns {Array} Returns all but the last element or `n` elements of `array`. * @example @@ -2693,7 +2693,7 @@ * @category Arrays * @param {Array} array The array to query. * @param {Number} [n] The number of elements to return. - * @param {Object} [guard] Internally used to allow this method to work with + * @param- {Object} [guard] Internally used to allow this method to work with * others like `_.map` without using their callback `index` argument for `n`. * @returns {Mixed} Returns the last element or an array of the last `n` * elements of `array`. @@ -2945,7 +2945,7 @@ * @category Arrays * @param {Array} array The array to query. * @param {Number} [n] The number of elements to return. - * @param {Object} [guard] Internally used to allow this method to work with + * @param- {Object} [guard] Internally used to allow this method to work with * others like `_.map` without using their callback `index` argument for `n`. * @returns {Array} Returns all but the first value or `n` values of `array`. * @example From 5e894be06b9a4feb354f765aeeea3d888017609f Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Mon, 24 Sep 2012 15:22:55 +0300 Subject: [PATCH 43/82] Fix typo Former-commit-id: b9fa32da8453a1a928b16bc712a9f2ec53722341 --- lodash.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index 7e5beec426..4b7d08364f 100644 --- a/lodash.js +++ b/lodash.js @@ -2685,8 +2685,8 @@ } /** - * Gets the last element of the `array`. Pass `n` to return the lasy `n` - * elementsvof the `array`. + * Gets the last element of the `array`. Pass `n` to return the last `n` + * elements of the `array`. * * @static * @memberOf _ From 3beda8eea04cc30838fd9f423cbc95579ee56212 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 25 Sep 2012 02:10:35 -0700 Subject: [PATCH 44/82] Add `_` references to precompiled templates. Former-commit-id: 4a6f38ec03790d647de4923262bba8d73378ce14 --- build.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/build.js b/build.js index 38399d8706..27bc50ed20 100755 --- a/build.js +++ b/build.js @@ -272,10 +272,13 @@ var moduleName = 'lodash'; var source = [ - ';(function() {', - " var freeExports = typeof exports == 'object' && exports;", + ';(function(window) {', + " var freeExports = typeof exports == 'object' && exports &&", + " (typeof global == 'object' && global && global == global.global && (window = global), exports);", '', ' var templates = {};', + '', + ' var _ = window._;', '' ]; @@ -301,7 +304,8 @@ '', " if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {", " define(['" + moduleName + "'], function(lodash) {", - ' lodash.templates = lodash.extend(lodash.templates || {}, templates);', + ' _ = lodash;', + ' _.templates = _.extend(_.templates || {}, templates);', ' });', " } else if (freeExports) {", " if (typeof module == 'object' && module && module.exports == freeExports) {", @@ -309,10 +313,10 @@ ' } else {', ' freeExports.templates = templates;', ' }', - ' } else {', + ' } else if (_) {', ' _.templates = _.extend(_.templates || {}, templates);', ' }', - '}());' + '}(this));' ); return source.join('\n'); @@ -1280,13 +1284,13 @@ source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +define[\s\S]+?else /, '$1'); } if (exportsOptions.indexOf('node') == -1) { - source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +module[\s\S]+?else *{[\s\S]+?\n\1}\n/, '$1'); + source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +module[\s\S]+?else *{([\s\S]+?\n)\1}\n/, '$1$2'); } if (exportsOptions.indexOf('commonjs') == -1) { source = source.replace(/(?: *\/\/.*\n)*(?:( +)else *{)?\s*freeExports\.\w+ *=[\s\S]+?(?:\n\1})?\n/, ''); } if (exportsOptions.indexOf('global') == -1) { - source = source.replace(/(?:( +)else *{)?(?:\s*\/\/.*)*\s*(?:window\._|_\.templates) *=[\s\S]+?(?:\n\1})?\n/g, ''); + source = source.replace(/(?:( +)(})? *else(?: *if *\(_\))? *{)?(?:\s*\/\/.*)*\s*(?:window\._|_\.templates) *=[\s\S]+?(?:\n\1})?\n/g, '$1$2\n'); } // remove `if (freeExports) {...}` if it's empty From 04459eaa50ab205b15c75b75a17119199e7d1083 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 25 Sep 2012 09:05:09 -0700 Subject: [PATCH 45/82] Remove internal `skipArgsCheck` from `_.isPlainObject` and add unit tests. Former-commit-id: 213c1e95f61368eb8912850248a97f44664384d8 --- doc/README.md | 190 +++++++++++++++++++++++++------------------------- lodash.js | 14 ++-- lodash.min.js | 12 ++-- test/test.js | 28 ++++++-- 4 files changed, 128 insertions(+), 116 deletions(-) diff --git a/doc/README.md b/doc/README.md index 315f1fc008..b9da3a7b07 100644 --- a/doc/README.md +++ b/doc/README.md @@ -174,7 +174,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4134 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4130 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -186,7 +186,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3231 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3227 "View in source") [Ⓣ][1] Creates a function that is restricted to executing only after it is called `n` times. @@ -214,7 +214,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3264 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3260 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. @@ -245,7 +245,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3294 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3290 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -276,7 +276,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4059 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4055 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -310,7 +310,7 @@ var youngest = _.chain(stooges) ### `_.clone(value, deep)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1057 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1053 "View in source") [Ⓣ][1] Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned. @@ -349,7 +349,7 @@ shallow[0] === stooges[0]; ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2461 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2457 "View in source") [Ⓣ][1] Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -373,7 +373,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3332 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3328 "View in source") [Ⓣ][1] Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -400,7 +400,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1934 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1930 "View in source") [Ⓣ][1] Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -434,7 +434,7 @@ _.contains('curly', 'ur'); ### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1970 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1966 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -466,7 +466,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3365 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3361 "View in source") [Ⓣ][1] Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -492,7 +492,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1150 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1146 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -518,7 +518,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3430 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3426 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -543,7 +543,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3410 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3406 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -570,7 +570,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2493 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2489 "View in source") [Ⓣ][1] Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -595,7 +595,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3649 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3645 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -619,7 +619,7 @@ _.escape('Moe, Larry & Curly'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1991 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1987 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -648,7 +648,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1170 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1166 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -673,7 +673,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2011 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2007 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -702,7 +702,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2033 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2029 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -731,7 +731,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2530 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2526 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -759,7 +759,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2554 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2550 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -787,7 +787,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2060 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2056 "View in source") [Ⓣ][1] Iterates over a `collection`, 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`. @@ -819,7 +819,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1200 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1196 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, 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`. @@ -855,7 +855,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1224 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1220 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, 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`. @@ -883,7 +883,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1241 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1237 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -910,7 +910,7 @@ _.functions(_); ### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2088 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2084 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -942,7 +942,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1264 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1260 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -967,7 +967,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3669 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3665 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -992,7 +992,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2600 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2596 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1024,7 +1024,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2640 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2636 "View in source") [Ⓣ][1] Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. @@ -1049,7 +1049,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2662 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2658 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -1073,7 +1073,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invert(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1281 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1277 "View in source") [Ⓣ][1] Creates an object composed of the inverted keys and values of the given `object`. @@ -1097,7 +1097,7 @@ _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2116 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2112 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`, returning an array of the results of each invoked method. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1180,7 +1180,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1300 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1296 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1204,7 +1204,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1317 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1313 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1228,7 +1228,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1334 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1330 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1252,7 +1252,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1359 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1355 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1282,7 +1282,7 @@ _.isEmpty(''); ### `_.isEqual(a, b)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1398 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1394 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1313,7 +1313,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1555 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1551 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1367,7 +1367,7 @@ _.isFunction(_); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1613 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1609 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1400,7 +1400,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1636 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1632 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1427,7 +1427,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1653 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1649 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1451,7 +1451,7 @@ _.isNumber(8.4 * 5); ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1579 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1575 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -1481,7 +1481,7 @@ _.isObject(1); ### `_.isPlainObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L948 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L946 "View in source") [Ⓣ][1] Checks if a given `value` is an object created by the `Object` constructor. @@ -1516,7 +1516,7 @@ _.isPlainObject({ 'name': 'moe', 'age': 40 }); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1670 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1666 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1540,7 +1540,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1687 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1683 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1564,7 +1564,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1705 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1701 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1588,7 +1588,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1722 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1718 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of `object`. @@ -1612,9 +1612,9 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2705 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2701 "View in source") [Ⓣ][1] -Gets the last element of the `array`. Pass `n` to return the lasy `n` elementsvof the `array`. +Gets the last element of the `array`. Pass `n` to return the last `n` elements of the `array`. #### Arguments 1. `array` *(Array)*: The array to query. @@ -1637,7 +1637,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2731 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2727 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1666,7 +1666,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.lateBind(object, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3467 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3463 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method @@ -1707,7 +1707,7 @@ func(); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2151 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2147 "View in source") [Ⓣ][1] Creates an array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1739,7 +1739,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2771 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2767 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1771,7 +1771,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3489 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3485 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1797,7 +1797,7 @@ var fibonacci = _.memoize(function(n) { ### `_.merge(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1765 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1761 "View in source") [Ⓣ][1] Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -1832,7 +1832,7 @@ _.merge(stooges, ages); ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2821 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2817 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1858,7 +1858,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3695 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3691 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1888,7 +1888,7 @@ _('curly').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3726 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3722 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1908,7 +1908,7 @@ var lodash = _.noConflict(); ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2870 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2866 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. @@ -1933,7 +1933,7 @@ _.object(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1827 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1823 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -1964,7 +1964,7 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3515 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3511 "View in source") [Ⓣ][1] Creates a function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1990,7 +1990,7 @@ initialize(); ### `_.pairs(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1843 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1839 "View in source") [Ⓣ][1] Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. @@ -2014,7 +2014,7 @@ _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3550 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3546 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `bind`, except it does **not** alter the `this` binding. @@ -2041,7 +2041,7 @@ hi('moe'); ### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1874 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1870 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, picking the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -2072,7 +2072,7 @@ _.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2174 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2170 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -2103,7 +2103,7 @@ _.pluck(stooges, 'name'); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3749 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3745 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -2131,7 +2131,7 @@ _.random(5); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2917 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2913 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -2169,7 +2169,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2202 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2198 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -2199,7 +2199,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2239 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2235 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -2230,7 +2230,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2279 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2275 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -2256,7 +2256,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2956 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2952 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2284,7 +2284,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3788 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3784 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2319,7 +2319,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2977 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2973 "View in source") [Ⓣ][1] Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2343,7 +2343,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2303 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2299 "View in source") [Ⓣ][1] Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. @@ -2373,7 +2373,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2331 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2327 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2402,7 +2402,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2361 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2357 "View in source") [Ⓣ][1] Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2434,7 +2434,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3029 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3025 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. @@ -2475,7 +2475,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4086 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4082 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2505,7 +2505,7 @@ _.chain([1, 2, 3, 200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3861 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3857 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: In the development build `_.template` utilizes sourceURLs for easier debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. See http://developer.chrome.com/trunk/extensions/sandboxingEval.html @@ -2570,7 +2570,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3572 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3568 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2595,7 +2595,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3980 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3976 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -2627,7 +2627,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2397 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2393 "View in source") [Ⓣ][1] Converts the `collection`, to an array. @@ -2651,7 +2651,7 @@ Converts the `collection`, to an array. ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4011 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4007 "View in source") [Ⓣ][1] Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -2675,7 +2675,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3070 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3066 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -2699,7 +2699,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3114 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3110 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -2738,7 +2738,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4029 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4025 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2762,7 +2762,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1904 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1900 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2786,7 +2786,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2431 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2427 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. @@ -2817,7 +2817,7 @@ _.where(stooges, { 'age': 40 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3163 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3159 "View in source") [Ⓣ][1] Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2842,7 +2842,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3623 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3619 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2871,7 +2871,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3196 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3192 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2902,7 +2902,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4104 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4100 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2923,7 +2923,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4121 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4117 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.js b/lodash.js index 4b7d08364f..d737747c66 100644 --- a/lodash.js +++ b/lodash.js @@ -926,8 +926,6 @@ * @memberOf _ * @category Objects * @param {Mixed} value The value to check. - * @param- {Boolean} [skipArgsCheck=false] Internally used to skip checks for - * `arguments` objects. * @returns {Boolean} Returns `true` if `value` is a plain object, else `false`. * @example * @@ -945,7 +943,7 @@ * _.isPlainObject({ 'name': 'moe', 'age': 40 }); * // => true */ - var isPlainObject = objectTypes.__proto__ != ObjectProto ? isPlainFallback : function(value, skipArgsCheck) { + var isPlainObject = objectTypes.__proto__ != ObjectProto ? isPlainFallback : function(value) { if (!value) { return false; } @@ -953,7 +951,7 @@ objProto = typeof valueOf == 'function' && (objProto = valueOf.__proto__) && objProto.__proto__; return objProto - ? value == objProto || (value.__proto__ == objProto && (skipArgsCheck || !isArguments(value))) + ? value == objProto || (value.__proto__ == objProto && !isArguments(value)) : isPlainFallback(value); }; @@ -965,14 +963,12 @@ * * @private * @param {Mixed} value The value to check. - * @param- {Boolean} [skipArgsCheck=false] Internally used to skip checks for - * `arguments` objects. * @returns {Boolean} Returns `true` if `value` is a plain object, else `false`. */ - function isPlainFallback(value, skipArgsCheck) { + function isPlainFallback(value) { // avoid non-objects and false positives for `arguments` objects var result = false; - if (!(value && typeof value == 'object') || (!skipArgsCheck && isArguments(value))) { + if (!(value && typeof value == 'object') || isArguments(value)) { return result; } // IE < 9 presents DOM nodes as `Object` objects except they have `toString` @@ -1070,7 +1066,7 @@ return value; } var isArr = className == arrayClass; - isObj = isArr || (className == objectClass ? isPlainObject(value, true) : isObj); + isObj = isArr || (className == objectClass ? isPlainObject(value) : isObj); } // shallow clone if (!isObj || !deep) { diff --git a/lodash.min.js b/lodash.min.js index 1d69dd0bde..203abcfe9e 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -6,10 +6,10 @@ i?-1:1}function l(e,t,n){function r(){var u=arguments,a=s?this:t;return i||(e=t[o]),n.length&&(u=u.length?n.concat(et.call(u)):n),this instanceof r?(d.prototype=e.prototype,a=new d,(u=e.apply(a,u))&&Bt[typeof u]?u:a):e.apply(a,u)}var i=g(e),s=!n,o=e;return s&&(n=t),r}function c(){for(var e,t,n,s=-1,o=arguments.length,a={e:"",f:"",j:"",q:"",c:{d:""},m:{d:""}};++sn;n++)t+="j='"+a.p[n]+"';if(" -,"constructor"==a.p[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){B=k[j];"+a.m.i+"}"}if(a.c||a.n)t+="}"}return t+=a.e+";return u",Function("E,F,G,c,J,f,K,h,i,N,P,R,T,U,X,Y,Z,m,r,w,x,z,A","var H=function("+e+"){"+t+"};return H")(_t,D,A,u,f,Q,Yt,G,O,T,m,$t,g,Jt,d,vt,Bt,ot,Z,et,gt,tt)}function h(e){return"\\"+jt[e]}function p(e){return Pt[e]}function d(){}function v(e){return Ht[e]}function m(e){return tt.call(e)==lt}function g(e){return"function"==typeof e}function y(e,t){var n=i;if(!e||"object"!=typeof -e||!t&&m(e))return n;var r=e.constructor;return(!kt||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!g(r)||r instanceof r)?St?(Yt(e,function(e,t,r){return n=!G.call(r,t),i}),n===i):(Yt(e,function(e,t){n=t}),n===i||G.call(e,n)):n}function b(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=Bt[typeof e]){var a=tt.call(e);if(!Dt[a]||Tt&&m(e))return e;var f=a==ct,s=f||(a==vt?Jt(e,n):s)}if(!s||!t)return s?f?et.call(e):Gt({},e):e;s=e.constructor;switch(a){case ht:return new s(e==n);case pt:return new -s(+e);case dt:case gt:return new s(e);case mt:return s(e.source,z.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=K[u],G.call(e,c)&&(!G.call(t,c)||!w(e[c],t[c],s,o)))return i;return n}function E(e,t,n,r){if(!e)return n;var s=e,o=e.length,u=3>arguments.length;if(o!==+o)var a=rn(e),o=a.length;else Ct&&tt.call(e)==gt&&(s=e.split(""));return vn(e,function(e,f,l){f=a?a[--o]:--o,n=u?(u=i,s[f]):t.call(r,n,s[f],f,l)}),n}function S(e,t,n){if( e)return t==r||n?e[0]:et.call(e,0,t)}function x(e,t){var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?ut(0,i+n):n)-1}for(;++rs&&(s=e[o]);return s}for(r!==t&&(n=u(n,r));++oi&& (i=r,s=e[o]);return s}function C(e,t,n){return e?et.call(e,t==r||n?1:t):[]}function k(e,n,r,i){if(!e)return 0;var s=0,o=e.length;if(r){i!==t&&(r=A(r,i));for(n=r(n);s>>1,r(e[i])>>1,e[i]T(l,s))l.push(s),o.push(e[a]);return o}function A(e,t){return At||nt&&2< @@ -19,8 +19,8 @@ P.toString,nt=X.test(nt=et.bind)&&nt,rt=Math.floor,it=X.test(it=Array.isArray)&& arguments)xt=!r;wt=4>(n+"").length,St="x"!=n[0],Et=(n.splice.call(t,0,1),t[0])})(1);var Tt=!m(arguments),Nt="x"!=et.call("x")[0],Ct="xx"!="x"[0]+Object("x")[0];try{var kt=("[object Object]",tt.call(e.document||0)==vt)}catch(Lt){}var At=nt&&/\n|Opera/.test(nt+tt.call(e.opera)),Ot=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Mt=!At,_t={};_t[ht]=_t[pt]=_t["[object Function]"]=_t[dt]=_t[vt]=_t[mt]=i,_t[lt]=_t[ct]=_t[gt]=n;var Dt={};Dt[lt]=Dt["[object Function]"]=i,Dt[ct]=Dt[ht]=Dt[pt]=Dt[dt]=Dt[vt]=Dt[mt ]=Dt[gt]=n;var Pt={"&":"&","<":"<",">":">",'"':""","'":"'"},Ht={"&":"&","<":"<",">":">",""":'"',"'":"'"},Bt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Ft={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y!==A)d=c(d,y)",i:"if(d(B,j,e)===false)return u" },It={j:"{}",q:"var q;if(typeof d!='function'){var jj=d;d=function(B){return B[jj]}}else if(y!==A)d=c(d,y)",i:"q=d(B,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},qt={j:"true",i:"if(!d(B,j,e))return!u"},Rt={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1"},i:"if(B===ii)return true"}),cn=c(Ft,It),hn=c(Ft,qt),pn=c(Ft,Ut),dn=c(Ft,zt,{j:"",i:"if(d(B,j,e))return B"}),vn=c(Ft,zt),mn=c(Ft,It,{i:"q=d(B,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(B)"}),gn=c(Xt,{a:"e,V",q:"var D=w.call(arguments,2),S=typeof V=='function'",i:{b:"u[j]=(S?V:B[V]).apply(B,D)",l:"u"+(Ot?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),yn=c(Ft,Xt),bn=c(Xt,{a:"e,cc",i:{b:"u[j]=B[cc]",l:"u"+(Ot?"[o]=":".push")+"(B[cc])" }}),wn=c({a:"e,d,C,y",j:"C",q:"var W=arguments.length<3;if(y!==A)d=c(d,y)",d:{b:"if(W)u=k[++j]"},i:{b:"u=d(u,B,j,e)",l:"u=W?(W=false,B):d(u,B,j,e)"}}),En=c(Ft,Ut,{i:"!"+Ut.i}),Sn=c(Ft,qt,{j:"false",i:qt.i.replace("!","")}),xn=c(Ft,It,Xt,{i:{b:"u[j]={a:d(B,j,e),b:j,c:B}",l:"u"+(Ot?"[o]=":".push")+"({a:d(B,j,e),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--)u[l]=u[l].c"}),Tn=c(Ut,{a:"e,bb",q:"var t=[];K(bb,function(B,q){t.push(q)});var dd=t.length",i:"for(var q,aa=true,s=0;s'); equal(compiled({ 'type': 1 }), ''); }); @@ -1480,7 +1496,7 @@ equal(compiled({ 'value': 'a' }), 'a'); }); - test('should parse delimiters with newlines correctly', function() { + test('should parse delimiters with newlines', function() { var expected = '<<\nprint("

" + (value ? "yes" : "no") + "

")\n>>', compiled = _.template(expected, null, { 'evaluate': /<<(.+?)>>/g }); From d421656be8a042e166b2782687f8725a236b78a0 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 25 Sep 2012 23:06:30 -0700 Subject: [PATCH 46/82] Cleanup build exports options. Former-commit-id: 75a5f57c0c9f71067cf6d55006f59fa0296a82e2 --- build.js | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/build.js b/build.js index 27bc50ed20..d8afe18b7b 100755 --- a/build.js +++ b/build.js @@ -1280,25 +1280,35 @@ /*------------------------------------------------------------------------*/ // customize Lo-Dash's export bootstrap - if (exportsOptions.indexOf('amd') == -1) { - source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +define[\s\S]+?else /, '$1'); - } - if (exportsOptions.indexOf('node') == -1) { - source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +module[\s\S]+?else *{([\s\S]+?\n)\1}\n/, '$1$2'); - } - if (exportsOptions.indexOf('commonjs') == -1) { - source = source.replace(/(?: *\/\/.*\n)*(?:( +)else *{)?\s*freeExports\.\w+ *=[\s\S]+?(?:\n\1})?\n/, ''); - } - if (exportsOptions.indexOf('global') == -1) { - source = source.replace(/(?:( +)(})? *else(?: *if *\(_\))? *{)?(?:\s*\/\/.*)*\s*(?:window\._|_\.templates) *=[\s\S]+?(?:\n\1})?\n/g, '$1$2\n'); - } + (function() { + var isAMD = exportsOptions.indexOf('amd') > -1, + isCommonJS = exportsOptions.indexOf('commonjs') > -1, + isGlobal = exportsOptions.indexOf('global') > -1, + isNode = exportsOptions.indexOf('node') > -1; - // remove `if (freeExports) {...}` if it's empty - source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}(?:\s*else *{([\s\S]+?) *})?\n/, '$1'); + if (!isAMD) { + source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +define[\s\S]+?else /, '$1'); + } + if (!isNode) { + source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +module[\s\S]+?else *{([\s\S]+?\n)\1}\n/, '$1$2'); + } + if (!isCommonJS) { + source = source.replace(/(?: *\/\/.*\n)*(?:( +)else *{)?\s*freeExports\.\w+ *=[\s\S]+?(?:\n\1})?\n/, ''); + } + if (!isGlobal) { + source = source.replace(/(?:( +)(})? *else(?: *if *\(_\))? *{)?(?:\s*\/\/.*)*\s*(?:window\._|_\.templates) *=[\s\S]+?(?:\n\1})?\n/g, '$1$2\n'); + } + // remove `if (freeExports) {...}` if it's empty + if (isAMD && isGlobal) { + source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}\n/, ''); + } else { + source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}(?:\s*else *{([\s\S]+?) *})?\n/, '$1'); + } - if ((source.match(/\bfreeExports\b/g) || []).length < 2) { - source = removeVar(source, 'freeExports'); - } + if ((source.match(/\bfreeExports\b/g) || []).length < 2) { + source = removeVar(source, 'freeExports'); + } + }()); /*------------------------------------------------------------------------*/ From 5311a0f903ef925cdd6ac869029d5e0a58a775c4 Mon Sep 17 00:00:00 2001 From: Kit Cambridge Date: Wed, 26 Sep 2012 08:59:33 -0600 Subject: [PATCH 47/82] Allow the `-d` option to be used independently. Former-commit-id: cb838b158edb8360d6d7c98ee18f2a7fbb4e9bb4 --- build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.js b/build.js index d8afe18b7b..41b6a93da0 100755 --- a/build.js +++ b/build.js @@ -1408,7 +1408,7 @@ dependencyMap = dependencyBackup; // output debug build - if (!isMinify && (isCustom || isTemplate)) { + if (!isMinify && (isCustom || isTemplate || isDebug)) { if (isDebug && isStdOut) { stdout.write(debugSource); callback(debugSource); From a77a0945feaa22043e76064a948ada1a5f69160f Mon Sep 17 00:00:00 2001 From: Kit Cambridge Date: Wed, 26 Sep 2012 09:26:40 -0600 Subject: [PATCH 48/82] Add tests for the `-d` and `-m` options. Former-commit-id: def5bcf323aaed96c037fea3e15c4a5c8c72a977 --- test/test-build.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/test-build.js b/test/test-build.js index d35fcb7374..382b9070eb 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -460,6 +460,40 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('independent builds'); + + (function() { + asyncTest('debug only', function() { + build(['-d', '-s'], function(source, filepath) { + equal(path.basename(filepath, '.js'), 'lodash'); + start(); + }); + }); + + asyncTest('debug custom', function () { + build(['-d', '-s', 'backbone'], function(source, filepath) { + equal(path.basename(filepath, '.js'), 'lodash.custom'); + start(); + }); + }); + + asyncTest('minified only', function() { + build(['-m', '-s'], function(source, filepath) { + equal(path.basename(filepath, '.js'), 'lodash.min'); + start(); + }); + }); + + asyncTest('minified custom', function () { + build(['-m', '-s', 'backbone'], function(source, filepath) { + equal(path.basename(filepath, '.js'), 'lodash.custom.min'); + start(); + }); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('strict modifier'); (function() { From 426ca78bf7f1e22ea2129f554fa6078a30c966cf Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 26 Sep 2012 20:42:52 -0700 Subject: [PATCH 49/82] Update vendors. Former-commit-id: 48e14b4b41c9b26382b09294127e552a794e49be --- vendor/backbone/backbone.js | 73 ++++++++++++--------------- vendor/backbone/test/collection.js | 40 ++++++++------- vendor/underscore/test/collections.js | 9 ++++ vendor/underscore/underscore-min.js | 2 +- vendor/underscore/underscore.js | 2 +- 5 files changed, 65 insertions(+), 61 deletions(-) diff --git a/vendor/backbone/backbone.js b/vendor/backbone/backbone.js index 1fbc894299..5fc0fe6e33 100644 --- a/vendor/backbone/backbone.js +++ b/vendor/backbone/backbone.js @@ -20,6 +20,7 @@ // Create a local reference to array methods. var ArrayProto = Array.prototype; + var push = ArrayProto.push; var slice = ArrayProto.slice; var splice = ArrayProto.splice; @@ -585,59 +586,51 @@ // Add a model, or list of models to the set. Pass **silent** to avoid // firing the `add` event for every new model. add: function(models, options) { - var i, index, length, model, cid, id, cids = {}, ids = {}, dups = []; - options || (options = {}); + var i, args, length, model, existing; + var at = options && options.at; models = _.isArray(models) ? models.slice() : [models]; // Begin by turning bare objects into model references, and preventing - // invalid models or duplicate models from being added. + // invalid models from being added. for (i = 0, length = models.length; i < length; i++) { - if (!(model = models[i] = this._prepareModel(models[i], options))) { - throw new Error("Can't add an invalid model to a collection"); - } - cid = model.cid; - id = model.id; - if (cids[cid] || this._byCid[cid] || ((id != null) && (ids[id] || this._byId[id]))) { - dups.push(i); - continue; - } - cids[cid] = ids[id] = model; + if (models[i] = this._prepareModel(models[i], options)) continue; + throw new Error("Can't add an invalid model to a collection"); } - // Remove duplicates. - i = dups.length; - while (i--) { - dups[i] = models.splice(dups[i], 1)[0]; - } + for (i = models.length - 1; i >= 0; i--) { + model = models[i]; + existing = model.id != null && this._byId[model.id]; - // Listen to added models' events, and index models for lookup by - // `id` and by `cid`. - for (i = 0, length = models.length; i < length; i++) { - (model = models[i]).on('all', this._onModelEvent, this); + // If a duplicate is found, splice it out and optionally merge it into + // the existing model. + if (existing || this._byCid[model.cid]) { + if (options && options.merge && existing) { + existing.set(model, options); + } + models.splice(i, 1); + continue; + } + + // Listen to added models' events, and index models for lookup by + // `id` and by `cid`. + model.on('all', this._onModelEvent, this); this._byCid[model.cid] = model; if (model.id != null) this._byId[model.id] = model; } - // Insert models into the collection, re-sorting if needed, and triggering - // `add` events unless silenced. - this.length += length; - index = options.at != null ? options.at : this.models.length; - splice.apply(this.models, [index, 0].concat(models)); - - // Merge in duplicate models. - if (options.merge) { - for (i = 0, length = dups.length; i < length; i++) { - if (model = this._byId[dups[i].id]) model.set(dups[i], options); - } - } + // Update `length` and splice in new models. + this.length += models.length; + args = [at != null ? at : this.models.length, 0]; + push.apply(args, models); + splice.apply(this.models, args); // Sort the collection if appropriate. - if (this.comparator && options.at == null) this.sort({silent: true}); + if (this.comparator && at == null) this.sort({silent: true}); + + if (options && options.silent) return this; - if (options.silent) return this; - for (i = 0, length = this.models.length; i < length; i++) { - if (!cids[(model = this.models[i]).cid]) continue; - options.index = i; + // Trigger `add` events. + while (model = models.shift()) { model.trigger('add', model, this, options); } @@ -1138,7 +1131,7 @@ fragment = this.getFragment(fragment || ''); if (this.fragment === fragment) return; this.fragment = fragment; - var url = (fragment.indexOf(this.root) !== 0 ? this.root : '') + fragment; + var url = this.root + fragment; // If pushState is available, we use it to set the fragment as a real URL. if (this._hasPushState) { diff --git a/vendor/backbone/test/collection.js b/vendor/backbone/test/collection.js index 1c44b0d0d0..576de3fe05 100644 --- a/vendor/backbone/test/collection.js +++ b/vendor/backbone/test/collection.js @@ -97,7 +97,7 @@ $(document).ready(function() { equal(col.pluck('label').join(' '), 'a b c d'); }); - test("add", 11, function() { + test("add", 10, function() { var added, opts, secondAdded; added = opts = secondAdded = null; e = new Backbone.Model({id: 10, label : 'e'}); @@ -107,7 +107,6 @@ $(document).ready(function() { }); col.on('add', function(model, collection, options){ added = model.get('label'); - equal(options.index, 4); opts = options; }); col.add(e, {amazing: true}); @@ -563,23 +562,6 @@ $(document).ready(function() { }); }); - test("index with comparator", 4, function() { - var counter = 0; - var col = new Backbone.Collection([{id: 2}, {id: 4}], { - comparator: function(model){ return model.id; } - }).on('add', function(model, colleciton, options){ - if (model.id == 1) { - equal(options.index, 0); - equal(counter++, 0); - } - if (model.id == 3) { - equal(options.index, 2); - equal(counter++, 1); - } - }); - col.add([{id: 3}, {id: 1}]); - }); - test("throwing during add leaves consistent state", 4, function() { var col = new Backbone.Collection(); col.on('test', function() { ok(false); }); @@ -699,4 +681,24 @@ $(document).ready(function() { deepEqual(values, [1, 2, 3]); }); + test("#1604 - Removal during iteration.", 0, function() { + var collection = new Backbone.Collection([{}, {}]); + collection.on('add', function() { + collection.at(0).destroy(); + }); + collection.add({}, {at: 0}); + }); + + test("#1638 - `sort` during `add` triggers correctly.", function() { + var collection = new Backbone.Collection; + collection.comparator = function(model) { return model.get('x'); }; + var added = []; + collection.on('add', function(model) { + model.set({x: 3}); + collection.sort(); + added.push(model.id); + }); + collection.add([{id: 1, x: 1}, {id: 2, x: 2}]); + deepEqual(added, [1, 2]); + }); }); diff --git a/vendor/underscore/test/collections.js b/vendor/underscore/test/collections.js index eea17e220b..b1eb11999c 100644 --- a/vendor/underscore/test/collections.js +++ b/vendor/underscore/test/collections.js @@ -366,6 +366,15 @@ $(document).ready(function() { var indexFor30 = _.sortedIndex(numbers, 30); equal(indexFor30, 2, '30 should be inserted at index 2'); + + var objects = [{x: 10}, {x: 20}, {x: 30}, {x: 40}]; + var iterator = function(obj){ return obj.x; }; + strictEqual(_.sortedIndex(objects, {x: 25}, iterator), 2); + strictEqual(_.sortedIndex(objects, {x: 35}, 'x'), 3); + + var context = {1: 2, 2: 3, 3: 4}; + iterator = function(obj){ return this[obj]; }; + strictEqual(_.sortedIndex([1, 3], 2, iterator, context), 1); }); test('shuffle', function() { diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index eecb3bd01c..bf9741db45 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -12,4 +12,4 @@ // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: // http://documentcloud.github.com/underscore -(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.3.3";var N=T.each=T.forEach=function(e,t,r){if(e==null)return;if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i2;e==null&&(e=[]);if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return e==null?r:m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return e==null?r:(N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r)},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return e==null?i:g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return e==null?i:y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return e==null?n:b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;or||n===void 0)return 1;if(n>>1;n.call(r,e[u])=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r":">",'"':""","'":"'","/":"/"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file +(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.3.3";var N=T.each=T.forEach=function(e,t,r){if(e==null)return;if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i2;e==null&&(e=[]);if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return e==null?r:m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return e==null?r:(N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r)},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return e==null?i:g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return e==null?i:y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return e==null?n:b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;or||n===void 0)return 1;if(n>>1;n.call(r,e[u])=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r":">",'"':""","'":"'","/":"/"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index 023ff7eee9..dc1cf676ac 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -353,7 +353,7 @@ // Use a comparator function to figure out the smallest index at which // an object should be inserted so as to maintain order. Uses binary search. _.sortedIndex = function(array, obj, iterator, context) { - iterator || (iterator = _.identity); + iterator = iterator == null ? _.identity : lookupIterator(iterator); var value = iterator.call(context, obj); var low = 0, high = array.length; while (low < high) { From 09d5222b1f5c3ca43ccf6894210d897ed32ff498 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 26 Sep 2012 22:30:15 -0700 Subject: [PATCH 50/82] Allow `_.sortedIndex` to accept a string value. Former-commit-id: 7ac17a6bb620ad16ecce17718a8110d422d49118 --- build.js | 2 +- build/pre-compile.js | 6 ++-- lodash.js | 58 +++++++++++++++++++++-------------- lodash.min.js | 73 ++++++++++++++++++++++---------------------- 4 files changed, 76 insertions(+), 63 deletions(-) diff --git a/build.js b/build.js index 41b6a93da0..1e629becac 100755 --- a/build.js +++ b/build.js @@ -1408,7 +1408,7 @@ dependencyMap = dependencyBackup; // output debug build - if (!isMinify && (isCustom || isTemplate || isDebug)) { + if (!isMinify && (isCustom || isDebug || isTemplate)) { if (isDebug && isStdOut) { stdout.write(debugSource); callback(debugSource); diff --git a/build/pre-compile.js b/build/pre-compile.js index d30a249d25..6cca03bf01 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -9,7 +9,7 @@ var compiledVars = [ 'argsIndex', 'argsLength', - 'bindIterator', + 'bindCallback', 'callback', 'collection', 'concat', @@ -64,13 +64,13 @@ 'pass', 'properties', 'property', + 'propertyCallback', 'propsLength', 'source', 'stackA', 'stackB', 'stackLength', - 'target', - 'valueProp' + 'target' ]; /** Used to minify `compileIterator` option properties */ diff --git a/lodash.js b/lodash.js index d737747c66..9d5fa0392c 100644 --- a/lodash.js +++ b/lodash.js @@ -467,7 +467,7 @@ ' callback = identity\n' + '}\n' + 'else if (thisArg !== undefined) {\n' + - ' callback = bindIterator(callback, thisArg)\n' + + ' callback = bindCallback(callback, thisArg)\n' + '}', 'inLoop': 'if (callback(value, index, collection) === false) return result' }; @@ -476,16 +476,13 @@ var countByIteratorOptions = { 'init': '{}', 'top': - 'var prop;\n' + 'if (typeof callback != \'function\') {\n' + - ' var valueProp = callback;\n' + - ' callback = function(value) { return value[valueProp] }\n' + - '}\n' + - 'else if (thisArg !== undefined) {\n' + - ' callback = bindIterator(callback, thisArg)\n' + + ' callback = propertyCallback(callback)\n' + + '} else if (thisArg !== undefined) {\n' + + ' callback = bindCallback(callback, thisArg)\n' + '}', 'inLoop': - 'prop = callback(value, index, collection);\n' + + 'var prop = callback(value, index, collection);\n' + '(hasOwnProperty.call(result, prop) ? result[prop]++ : result[prop] = 1)' }; @@ -516,7 +513,7 @@ /** Reusable iterator options for `find`, `forEach`, `forIn`, and `forOwn` */ var forEachIteratorOptions = { - 'top': 'if (thisArg !== undefined) callback = bindIterator(callback, thisArg)' + 'top': 'if (thisArg !== undefined) callback = bindCallback(callback, thisArg)' }; /** Reusable iterator options for `forIn` and `forOwn` */ @@ -550,7 +547,7 @@ 'if (!isFunc) {\n' + ' var props = concat.apply(ArrayProto, arguments)\n' + '} else if (thisArg !== undefined) {\n' + - ' callback = bindIterator(callback, thisArg)\n' + + ' callback = bindCallback(callback, thisArg)\n' + '}', 'inLoop': 'if (isFunc\n' + @@ -570,7 +567,7 @@ * @param {Mixed} [thisArg] The `this` binding of `func`. * @returns {Function} Returns the new bound function. */ - function bindIterator(func, thisArg) { + function bindCallback(func, thisArg) { return function(value, index, object) { return func.call(thisArg, value, index, object); }; @@ -789,19 +786,19 @@ } // create the function factory var factory = Function( - 'arrayLikeClasses, ArrayProto, bind, bindIterator, compareAscending, concat, ' + + 'arrayLikeClasses, ArrayProto, bind, bindCallback, compareAscending, concat, ' + 'forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, ' + 'isPlainObject, noop, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, ' + - 'slice, stringClass, toString, undefined', + 'propertyCallback, slice, stringClass, toString, undefined', 'var callee = function(' + args + ') {\n' + iteratorTemplate(data) + '\n};\n' + 'return callee' ); // return the compiled function return factory( - arrayLikeClasses, ArrayProto, bind, bindIterator, compareAscending, concat, + arrayLikeClasses, ArrayProto, bind, bindCallback, compareAscending, concat, forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, isPlainObject, noop, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, - slice, stringClass, toString + propertyCallback, slice, stringClass, toString ); } @@ -837,6 +834,19 @@ // no operation performed } + /** + * Creates a function that returns the `property` value of the given `object`. + * + * @private + * @param {String} property The property to get the value of. + * @returns {Function} Returns the new function. + */ + function propertyCallback(property) { + return function(object) { + return object[property]; + }; + } + /** * Used by `unescape` to convert HTML entities to characters. * @@ -1878,7 +1888,7 @@ ' if (prop in object) result[prop] = object[prop]\n' + ' }\n' + '} else {\n' + - ' if (thisArg !== undefined) callback = bindIterator(callback, thisArg)', + ' if (thisArg !== undefined) callback = bindCallback(callback, thisArg)', 'inLoop': 'if (callback(value, index, object)) result[index] = value', 'bottom': '}' @@ -2083,7 +2093,7 @@ */ var groupBy = createIterator(baseIteratorOptions, countByIteratorOptions, { 'inLoop': - 'prop = callback(value, index, collection);\n' + + 'var prop = callback(value, index, collection);\n' + '(hasOwnProperty.call(result, prop) ? result[prop] : result[prop] = []).push(value)' }); @@ -2200,7 +2210,7 @@ 'init': 'accumulator', 'top': 'var noaccum = arguments.length < 3;\n' + - 'if (thisArg !== undefined) callback = bindIterator(callback, thisArg)', + 'if (thisArg !== undefined) callback = bindCallback(callback, thisArg)', 'beforeLoop': { 'array': 'if (noaccum) result = iteratee[++index]' }, @@ -2784,7 +2794,7 @@ return result; } if (thisArg !== undefined) { - callback = bindIterator(callback, thisArg); + callback = bindCallback(callback, thisArg); } while (++index < length) { current = callback(array[index], index, array); @@ -2834,7 +2844,7 @@ return result; } if (thisArg !== undefined) { - callback = bindIterator(callback, thisArg); + callback = bindCallback(callback, thisArg); } while (++index < length) { current = callback(array[index], index, array); @@ -3031,7 +3041,9 @@ high = array.length; if (callback) { - if (thisArg !== undefined) { + if (typeof callback != 'function') { + callback = propertyCallback(callback); + } else if (thisArg !== undefined) { callback = bind(callback, thisArg); } value = callback(value); @@ -3126,7 +3138,7 @@ if (!callback) { callback = identity; } else if (thisArg !== undefined) { - callback = bindIterator(callback, thisArg); + callback = bindCallback(callback, thisArg); } while (++index < length) { computed = callback(array[index], index, array); @@ -3764,7 +3776,7 @@ * @memberOf _ * @category Utilities * @param {Object} object The object to inspect. - * @param {String} property The property to get the result of. + * @param {String} property The property to get the value of. * @returns {Mixed} Returns the resolved value. * @example * diff --git a/lodash.min.js b/lodash.min.js index 203abcfe9e..19f9831ee5 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -2,39 +2,40 @@ Lo-Dash 0.7.0 lodash.com/license Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE */ -;(function(e,t){function s(e){return new o(e)}function o(e){if(e&&e.__wrapped__)return e;this.__wrapped__=e}function u(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function a(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||B),s=i?{}:e;if(i)for(var o=t-1;++on||e===t)return 1;if(en;n++)t+="j='"+a.p[n]+"';if(" -,"constructor"==a.p[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){B=k[j];"+a.m.i+"}"}if(a.c||a.n)t+="}"}return t+=a.e+";return u",Function("E,F,G,c,J,f,K,h,i,N,P,R,T,U,X,Y,Z,m,r,w,x,z,A","var H=function("+e+"){"+t+"};return H")(_t,D,A,u,f,Q,Yt,G,O,T,m,$t,g,Jt,d,vt,Bt,ot,Z,et,gt,tt)}function h(e){return"\\"+jt[e]}function p(e){return Pt[e]}function d(){}function v(e){return Ht[e]}function m(e){return tt.call(e)==lt}function g(e){return"function"==typeof e}function y(e){var t=i;if(!e||"object"!=typeof -e||m(e))return t;var n=e.constructor;return(!kt||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!g(n)||n instanceof n)?St?(Yt(e,function(e,n,r){return t=!G.call(r,n),i}),t===i):(Yt(e,function(e,n){t=n}),t===i||G.call(e,t)):t}function b(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=Bt[typeof e]){var a=tt.call(e);if(!Dt[a]||Tt&&m(e))return e;var f=a==ct,s=f||(a==vt?Jt(e):s)}if(!s||!t)return s?f?et.call(e):Gt({},e):e;s=e.constructor;switch(a){case ht:return new s(e==n);case pt:return new s(+e -);case dt:case gt:return new s(e);case mt:return s(e.source,z.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=K[u],G.call(e,c)&&(!G.call(t,c)||!w(e[c],t[c],s,o)))return i;return n}function E(e,t,n,r){if(!e)return n;var s=e,o=e.length,u=3>arguments.length;if(o!==+o)var a=rn(e),o=a.length;else Ct&&tt.call(e)==gt&&(s=e.split(""));return vn(e,function(e,f,l){f=a?a[--o]:--o,n=u?(u=i,s[f]):t.call(r,n,s[f],f,l)}),n}function S(e,t,n){if( -e)return t==r||n?e[0]:et.call(e,0,t)}function x(e,t){var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?ut(0,i+n):n)-1}for(;++rs&&(s=e[o]);return s}for(r!==t&&(n=u(n,r));++oi&& -(i=r,s=e[o]);return s}function C(e,t,n){return e?et.call(e,t==r||n?1:t):[]}function k(e,n,r,i){if(!e)return 0;var s=0,o=e.length;if(r){i!==t&&(r=A(r,i));for(n=r(n);s>>1,r(e[i])>>1,e[i]T(l,s))l.push(s),o.push(e[a]);return o}function A(e,t){return At||nt&&2< -arguments.length?nt.call.apply(nt,arguments):l(e,t,et.call(arguments,2))}function O(e){return e}function M(e){vn(en(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this.__wrapped__];return arguments.length&&Y.apply(e,arguments),e=r.apply(s,e),this.__chain__&&(e=new o(e),e.__chain__=n),e}})}var n=!0,r=null,i=!1,_="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),D=Array.prototype,P=Object.prototype,H=0,B=30,j=e._,F=/[-?+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/ -,I=/&(?:amp|lt|gt|quot|#x27);/g,q=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,U=/(__e\(.*?\)|\b__t\))\+'';/g,z=/\w*$/,W=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,X=RegExp("^"+(P.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),V=/($^)/,$=/[&<>"']/g,J=/['\n\r\t\u2028\u2029\\]/g,K="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),Q=D.concat,G=P.hasOwnProperty,Y=D.push,Z=P.propertyIsEnumerable,et=D.slice,tt= -P.toString,nt=X.test(nt=et.bind)&&nt,rt=Math.floor,it=X.test(it=Array.isArray)&&it,st=e.isFinite,ot=X.test(ot=Object.keys)&&ot,ut=Math.max,at=Math.min,ft=Math.random,lt="[object Arguments]",ct="[object Array]",ht="[object Boolean]",pt="[object Date]",dt="[object Number]",vt="[object Object]",mt="[object RegExp]",gt="[object String]",yt=e.clearTimeout,bt=e.setTimeout,wt,Et,St,xt=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in -arguments)xt=!r;wt=4>(n+"").length,St="x"!=n[0],Et=(n.splice.call(t,0,1),t[0])})(1);var Tt=!m(arguments),Nt="x"!=et.call("x")[0],Ct="xx"!="x"[0]+Object("x")[0];try{var kt=("[object Object]",tt.call(e.document||0)==vt)}catch(Lt){}var At=nt&&/\n|Opera/.test(nt+tt.call(e.opera)),Ot=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Mt=!At,_t={};_t[ht]=_t[pt]=_t["[object Function]"]=_t[dt]=_t[vt]=_t[mt]=i,_t[lt]=_t[ct]=_t[gt]=n;var Dt={};Dt[lt]=Dt["[object Function]"]=i,Dt[ct]=Dt[ht]=Dt[pt]=Dt[dt]=Dt[vt]=Dt[mt -]=Dt[gt]=n;var Pt={"&":"&","<":"<",">":">",'"':""","'":"'"},Ht={"&":"&","<":"<",">":">",""":'"',"'":"'"},Bt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Ft={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y!==A)d=c(d,y)",i:"if(d(B,j,e)===false)return u" -},It={j:"{}",q:"var q;if(typeof d!='function'){var jj=d;d=function(B){return B[jj]}}else if(y!==A)d=c(d,y)",i:"q=d(B,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},qt={j:"true",i:"if(!d(B,j,e))return!u"},Rt={r:i,s:i,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1"},i:"if(B===ii)return true"}),cn=c(Ft,It),hn=c(Ft,qt),pn=c(Ft,Ut),dn=c(Ft,zt,{j:"",i:"if(d(B,j,e))return B"}),vn=c(Ft,zt),mn=c(Ft,It,{i:"q=d(B,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(B)"}),gn=c(Xt,{a:"e,V",q:"var D=w.call(arguments,2),S=typeof V=='function'",i:{b:"u[j]=(S?V:B[V]).apply(B,D)",l:"u"+(Ot?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),yn=c(Ft,Xt),bn=c(Xt,{a:"e,cc",i:{b:"u[j]=B[cc]",l:"u"+(Ot?"[o]=":".push")+"(B[cc])" -}}),wn=c({a:"e,d,C,y",j:"C",q:"var W=arguments.length<3;if(y!==A)d=c(d,y)",d:{b:"if(W)u=k[++j]"},i:{b:"u=d(u,B,j,e)",l:"u=W?(W=false,B):d(u,B,j,e)"}}),En=c(Ft,Ut,{i:"!"+Ut.i}),Sn=c(Ft,qt,{j:"false",i:qt.i.replace("!","")}),xn=c(Ft,It,Xt,{i:{b:"u[j]={a:d(B,j,e),b:j,c:B}",l:"u"+(Ot?"[o]=":".push")+"({a:d(B,j,e),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--)u[l]=u[l].c"}),Tn=c(Ut,{a:"e,bb",q:"var t=[];K(bb,function(B,q){t.push(q)});var dd=t.length",i:"for(var q,aa=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=A,s.bindAll=Nn,s.chain=function(e){return e=new o(e),e.__chain__=n,e},s.clone=b,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nT(t,n)){for(var u=1;un?ut(0,r+n):at(n,r-1))+1 -);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return l(t,e,et.call(arguments,2))},s.map=yn,s.max=N,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return G.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=sn,s.min=function(e,n,r){var i=Infinity,s=i;if(!e)return s;var o=-1,a=e.length;if(!n){for(;++o=f?(a=r,s=e.apply(o,i)):u||(u=bt(n,f)),s}},s.times=function(e,n,r){var e=+e||0,i=-1,s=Array(e);if(r!==t)for(;++iT(r,t[e])&&r.push(t[e -]);return r},s.uniq=L,s.uniqueId=function(e){var t=H++;return e?e+t:t},s.values=fn,s.where=Tn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=a(arguments,1,20);++n=(d||Za),e=c?{}:a;if(c)for(var i=b-1;++ib||a===v)return 1;if(ad;d++)b+="j='"+e.p[d]+"';if(", +"constructor"==e.p[d]&&(b+="!(g&&g.prototype===k)&&"),b+="h.call(k,j)){B=k[j];"+e.m.i+"}"}if(e.c||e.n)b+="}"}b+=e.e+";return u";return Function("E,F,G,c,J,f,K,h,i,N,P,R,T,U,X,Y,Z,m,r,dd,w,x,z,A","var H=function("+a+"){"+b+"};return H")(u,A,aa,N,$a,ba,O,q,ca,C,y,da,x,ea,Z,H,z,E,ya,za,n,B,k)}function bb(a){return"\\"+cb[a]}function db(a){return eb[a]}function Z(){}function za(a){return function(b){return b[a]}}function fb(a){return gb[a]}function y(a){return k.call(a)==fa}function x(a){return"function"== +typeof a}function Aa(a){var b=o;if(!(a&&"object"==typeof a)||y(a))return b;var d=a.constructor;if((!Ba||!("function"!=typeof a.toString&&"string"==typeof(a+"")))&&(!x(d)||d instanceof d)){if(Ca)return O(a,function(a,d,e){b=!q.call(e,d);return o}),b===o;O(a,function(a,d){b=d});return b===o||q.call(a,b)}return b}function ga(a,b,d,l,c){if(a==m)return a;d&&(b=o);if(d=z[typeof a]){var e=k.call(a);if(!w[e]||P&&y(a))return a;var i=e==Q,d=i||(e==H?ea(a):d)}if(!d||!b)return d?i?n.call(a):Da({},a):a;d=a.constructor; +switch(e){case J:return new d(a==j);case K:return new d(+a);case F:case B:return new d(a);case L:return d(a.source,hb.exec(a))}l||(l=[]);c||(c=[]);for(e=l.length;e--;)if(l[e]==a)return c[e];var h=i?d(e=a.length):{};l.push(a);c.push(h);if(i)for(i=-1;++i++f;)if(p=wa[f],q.call(a,p)&&(!q.call(b,p)||!R(a[p],b[p],d,c)))return o;return j}function Fa(a,b,d,c){if(!a)return d;var f=a,e=a.length,i=3>arguments.length;if(e!==+e)var h=ha(a),e=h.length;else xa&&k.call(a)==B&&(f=a.split(""));I(a,function(a,g,k){g=h?h[--e]:--e;d=i?(i=o,f[g]):b.call(c,d,f[g],g,k)});return d} +function ia(a,b,d){if(a)return b==m||d?a[0]:n.call(a,0,b)}function Ga(a,b){var d=[];if(!a)return d;for(var c,f=-1,e=a.length;++fd?ka(0,f+d):d)-1;else return c=Ha(a,b),a[c]===b?c:-1;for(;++cf&&(f=a[e]);return f}for(d!==v&&(b=N(b, +d));++ec&&(c=d,f=a[e]);return f}function la(a,b,d){return!a?[]:n.call(a,b==m||d?1:b)}function Ha(a,b,d,c){if(!a)return 0;var f=0,e=a.length;if(d){"function"!=typeof d?d=za(b):c!==v&&(d=aa(d,c));for(b=d(b);f>>1,d(a[c])>>1,a[c]C(h,c))h.push(c), +f.push(a[e]);return f}function aa(a,b){return Ka||G&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,lb=/&(?:amp|lt|gt|quot|#x27);/g,mb=/\b__p\+='';/g,nb=/\b(__p\+=)''\+/g,ob=/(__e\(.*?\)|\b__t\))\+'';/g,hb=/\w*$/,pb=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,oa=RegExp("^"+(M.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),pa=/($^)/,qb=/[&<>"']/g,rb=/['\n\r\t\u2028\u2029\\]/g,wa="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "), +ba=A.concat,q=M.hasOwnProperty,ja=A.push,ya=M.propertyIsEnumerable,n=A.slice,k=M.toString,G=oa.test(G=n.bind)&&G,Ma=Math.floor,qa=oa.test(qa=Array.isArray)&&qa,sb=s.isFinite,E=oa.test(E=Object.keys)&&E,ka=Math.max,tb=Math.min,Na=Math.random,fa="[object Arguments]",Q="[object Array]",J="[object Boolean]",K="[object Date]",F="[object Number]",H="[object Object]",L="[object RegExp]",B="[object String]",ub=s.clearTimeout,S=s.setTimeout,$,Oa,Ca,va=j;(function(){function a(){this.x=1}var b={"0":1,length:1}, +d=[];a.prototype={valueOf:1,y:1};for(var c in new a)d.push(c);for(c in arguments)va=!c;$=4>(d+"").length;Ca="x"!=d[0];Oa=(d.splice.call(b,0,1),b[0])})(1);var P=!y(arguments),vb="x"!=n.call("x")[0],xa="xx"!="x"[0]+Object("x")[0];try{var Ba=("[object Object]",k.call(s.document||0)==H)}catch(Kb){}var Ka=G&&/\n|Opera/.test(G+k.call(s.opera)),D=E&&/^.+$|true/.test(E+!!s.attachEvent),ab=!Ka,u={};u[J]=u[K]=u["[object Function]"]=u[F]=u[H]=u[L]=o;u[fa]=u[Q]=u[B]=j;var w={};w[fa]=w["[object Function]"]=o;w[Q]= +w[J]=w[K]=w[F]=w[H]=w[L]=w[B]=j;var eb={"&":"&","<":"<",">":">",'"':""","'":"'"},gb={"&":"&","<":"<",">":">",""":'"',"'":"'"},z={"boolean":o,"function":j,object:j,number:o,string:o,undefined:o,unknown:j},cb={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"};c.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var r={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y!==A)d=c(d,y)", +i:"if(d(B,j,e)===false)return u"},ra={j:"{}",q:"if(typeof d!='function'){d=dd(B,d)}else if(y!==A)d=c(d,y)",i:"var q=d(B,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},sa={j:"true",i:"if(!d(B,j,e))return!u"},T={r:o,s:o,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1"},i:"if(B===jj)return true"}),Db=g(r,ra),Ua=g(r,sa),Va=g(r,U),Wa=g(r,V,{j:"",i:"if(d(B,j,e))return B"}),I=g(r,V),Eb=g(r,ra,{i:"var q=d(B,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(B)"}),Fb=g(W,{a:"e,V",q:"var D=w.call(arguments,2),S=typeof V=='function'",i:{b:"u[j]=(S?V:B[V]).apply(B,D)",l:"u"+(D?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),Xa=g(r,W),ta=g(W,{a:"e,cc",i:{b:"u[j]=B[cc]",l:"u"+(D?"[o]=":".push")+"(B[cc])"}}),ua=g({a:"e,d,C,y", +j:"C",q:"var W=arguments.length<3;if(y!==A)d=c(d,y)",d:{b:"if(W)u=k[++j]"},i:{b:"u=d(u,B,j,e)",l:"u=W?(W=false,B):d(u,B,j,e)"}}),Gb=g(r,U,{i:"!"+U.i}),Ya=g(r,sa,{j:"false",i:sa.i.replace("!","")}),Hb=g(r,ra,W,{i:{b:"u[j]={a:d(B,j,e),b:j,c:B}",l:"u"+(D?"[o]=":".push")+"({a:d(B,j,e),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--)u[l]=u[l].c"}),Ib=g(U,{a:"e,bb",q:"var t=[];K(bb,function(B,q){t.push(q)});var ee=t.length",i:"for(var q,aa=true,s=0;s1){for(var j=1;ja?b():function(){if(1>--a)return b.apply(this,arguments)}};c.bind=aa;c.bindAll=Jb;c.chain=function(a){a=new t(a);a.__chain__=j;return a};c.clone=ga;c.compact=function(a){var b=[];if(!a)return b;for(var d=-1,c=a.length;++dC(b,d)){for(var h=1;hd?ka(0,c+d):tb(d,c-1))+1);c--;)if(a[c]===b)return c;return-1};c.lateBind= +function(a,b){return Y(b,a,n.call(arguments,2))};c.map=Xa;c.max=Ia;c.memoize=function(a,b){var d={};return function(){var c=b?b.apply(this,arguments):arguments[0];return q.call(d,c)?d[c]:d[c]=a.apply(this,arguments)}};c.merge=zb;c.min=function(a,b,d){var c=Infinity,f=c;if(!a)return f;var e=-1,i=a.length;if(!b){for(;++e=n?(h=k,f= +a.apply(e,g)):i||(i=S(c,n));return f}};c.times=function(a,b,c){var a=+a||0,g=-1,f=Array(a);if(c!==v)for(;++gC(g,b[a])&&g.push(b[a]);return g};c.uniq=Ja;c.uniqueId=function(a){var b= +ib++;return a?a+b:b};c.values=Sa;c.where=Ib;c.without=function(a){var b=[];if(!a)return b;for(var c=-1,g=a.length,f=X(arguments,1,20);++c Date: Wed, 26 Sep 2012 23:08:19 -0700 Subject: [PATCH 51/82] Cleanup test-build.js. Former-commit-id: d6588b8cc7cebe0ce44392269cdda1ebd851f1ae --- test/test-build.js | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/test/test-build.js b/test/test-build.js index 382b9070eb..2386a6fb2f 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -464,6 +464,7 @@ (function() { asyncTest('debug only', function() { + var start = _.once(QUnit.start); build(['-d', '-s'], function(source, filepath) { equal(path.basename(filepath, '.js'), 'lodash'); start(); @@ -471,6 +472,7 @@ }); asyncTest('debug custom', function () { + var start = _.once(QUnit.start); build(['-d', '-s', 'backbone'], function(source, filepath) { equal(path.basename(filepath, '.js'), 'lodash.custom'); start(); @@ -478,6 +480,7 @@ }); asyncTest('minified only', function() { + var start = _.once(QUnit.start); build(['-m', '-s'], function(source, filepath) { equal(path.basename(filepath, '.js'), 'lodash.min'); start(); @@ -485,6 +488,7 @@ }); asyncTest('minified custom', function () { + var start = _.once(QUnit.start); build(['-m', '-s', 'backbone'], function(source, filepath) { equal(path.basename(filepath, '.js'), 'lodash.custom.min'); start(); @@ -503,14 +507,13 @@ }); ['non-strict', 'strict'].forEach(function(strictMode, index) { - var start = _.after(2, _.once(QUnit.start)); - asyncTest(strictMode + ' should ' + (index ? 'error': 'silently fail') + ' attempting to overwrite read-only properties', function() { - var commands = ['-s', 'include=bindAll,defaults,extend']; + var commands = ['-s', 'include=bindAll,defaults,extend'], + start = _.after(2, _.once(QUnit.start)); + if (index) { commands.push('strict'); } - build(commands, function(source, filepath) { var basename = path.basename(filepath, '.js'), context = createContext(), @@ -587,9 +590,9 @@ ]; commands.forEach(function(command, index) { - var start = _.after(2, _.once(QUnit.start)); - asyncTest('`lodash ' + command +'`', function() { + var start = _.after(2, _.once(QUnit.start)); + build(['-s', command], function(source, filepath) { var basename = path.basename(filepath, '.js'), context = createContext(), @@ -647,9 +650,9 @@ ]; commands.forEach(function(command) { - var start = _.after(2, _.once(QUnit.start)); - asyncTest('`lodash ' + command +'`', function() { + var start = _.after(2, _.once(QUnit.start)); + build(['-s', 'exports=none', command], function(source, filepath) { var basename = path.basename(filepath, '.js'), context = createContext(); @@ -678,11 +681,11 @@ (function() { ['-o a.js', '--output a.js'].forEach(function(command, index) { - var start = _.once(QUnit.start); - asyncTest('`lodash ' + command +'`', function() { + var start = _.once(QUnit.start); + build(['-s'].concat(command.split(' ')), function(source, filepath) { - equal(path.basename(filepath), 'a.js', command); + equal(path.basename(filepath, '.js'), 'a', command); start(); }); }); @@ -695,9 +698,9 @@ (function() { ['-c', '--stdout'].forEach(function(command, index) { - var start = _.once(QUnit.start); - asyncTest('`lodash ' + command +'`', function() { + var start = _.once(QUnit.start); + build([command, 'exports=', 'include='], function(source) { equal(source, ''); equal(arguments.length, 1); @@ -712,10 +715,10 @@ QUnit.module('minify underscore'); (function() { - var source = fs.readFileSync(path.join(__dirname, '..', 'vendor', 'underscore', 'underscore.js'), 'utf8'), - start = _.once(QUnit.start); - asyncTest('`node minify underscore.js`', function() { + var source = fs.readFileSync(path.join(__dirname, '..', 'vendor', 'underscore', 'underscore.js'), 'utf8'), + start = _.once(QUnit.start); + minify(source, { 'silent': true, 'workingName': 'underscore.min', @@ -742,9 +745,9 @@ QUnit.module('mobile build'); (function() { - var start = _.after(2, _.once(QUnit.start)); - asyncTest('`lodash mobile`', function() { + var start = _.after(2, _.once(QUnit.start)); + build(['-s', 'mobile'], function(source, filepath) { var basename = path.basename(filepath, '.js'), context = createContext(); @@ -811,9 +814,9 @@ ); commands.forEach(function(command) { - var start = _.after(2, _.once(QUnit.start)); - asyncTest('`lodash ' + command +'`', function() { + var start = _.after(2, _.once(QUnit.start)); + build(['--silent'].concat(command.split(' ')), function(source, filepath) { var methodNames, basename = path.basename(filepath, '.js'), From 30666aa11141d03949e509a54803e4c81d4b10bb Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 27 Sep 2012 20:53:49 -0700 Subject: [PATCH 52/82] Update vendor. Former-commit-id: 9f433cc31e3c70dddba332346c7d053539f54ab5 --- vendor/underscore/test/arrays.js | 2 -- vendor/underscore/test/collections.js | 31 +++++---------------------- vendor/underscore/underscore-min.js | 16 +++----------- vendor/underscore/underscore.js | 22 ++++--------------- 4 files changed, 12 insertions(+), 59 deletions(-) diff --git a/vendor/underscore/test/arrays.js b/vendor/underscore/test/arrays.js index 008766a723..57da88fe55 100644 --- a/vendor/underscore/test/arrays.js +++ b/vendor/underscore/test/arrays.js @@ -144,7 +144,6 @@ $(document).ready(function() { equal(_.indexOf(numbers, 2), 1, 'can compute indexOf, even without the native function'); var result = (function(){ return _.indexOf(arguments, 2); })(1, 2, 3); equal(result, 1, 'works on an arguments object'); - equal(_.indexOf(null, 2), -1, 'handles nulls properly'); var numbers = [10, 20, 30, 40, 50], num = 35; var index = _.indexOf(numbers, num, true); @@ -170,7 +169,6 @@ $(document).ready(function() { equal(_.lastIndexOf(numbers, 0), 8, 'lastIndexOf the other element'); var result = (function(){ return _.lastIndexOf(arguments, 1); })(1, 0, 1, 0, 0, 1, 0, 0, 0); equal(result, 5, 'works on an arguments object'); - equal(_.indexOf(null, 2), -1, 'handles nulls properly'); numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3]; index = _.lastIndexOf(numbers, 2, 2); diff --git a/vendor/underscore/test/collections.js b/vendor/underscore/test/collections.js index b1eb11999c..095ace1d31 100644 --- a/vendor/underscore/test/collections.js +++ b/vendor/underscore/test/collections.js @@ -25,10 +25,6 @@ $(document).ready(function() { answer = null; _.each([1, 2, 3], function(num, index, arr){ if (_.include(arr, num)) answer = true; }); ok(answer, 'can reference the original collection from inside the iterator'); - - answers = 0; - _.each(null, function(){ ++answers; }); - equal(answers, 0, 'handles a null properly'); }); test('map', function() { @@ -54,9 +50,6 @@ $(document).ready(function() { var ids = _.map(document.images, function(n){ return n.id; }); ok(ids[0] == 'chart_image', 'can use collection methods on HTMLCollections'); - - var ifnull = _.map(null, function(){}); - ok(_.isArray(ifnull) && ifnull.length === 0, 'handles a null properly'); }); test('reduce', function() { @@ -76,15 +69,6 @@ $(document).ready(function() { var sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num; }); equal(sum, 6, 'default initial value'); - var ifnull; - try { - _.reduce(null, function(){}); - } catch (ex) { - ifnull = ex; - } - ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly'); - - ok(_.reduce(null, function(){}, 138) === 138, 'handles a null (with initial value) properly'); equal(_.reduce([], function(){}, undefined), undefined, 'undefined can be passed as a special case'); raises(function() { _.reduce([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value'); }); @@ -99,19 +83,9 @@ $(document).ready(function() { var list = _.foldr(["foo", "bar", "baz"], function(memo, str){ return memo + str; }); equal(list, 'bazbarfoo', 'default initial value'); - var ifnull; - try { - _.reduceRight(null, function(){}); - } catch (ex) { - ifnull = ex; - } - ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly'); - var sum = _.reduceRight({a: 1, b: 2, c: 3}, function(sum, num){ return sum + num; }); equal(sum, 6, 'default initial value on object'); - ok(_.reduceRight(null, function(){}, 138) === 138, 'handles a null (with initial value) properly'); - equal(_.reduceRight([], function(){}, undefined), undefined, 'undefined can be passed as a special case'); raises(function() { _.reduceRight([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value'); @@ -336,6 +310,8 @@ $(document).ready(function() { equal(grouped.constructor.length, 1); equal(grouped.hasOwnProperty.length, 2); + var array = [{}]; + _.groupBy(array, function(value, index, obj){ ok(obj === array); }); }); test('countBy', function() { @@ -357,6 +333,9 @@ $(document).ready(function() { }); equal(grouped.constructor, 1); equal(grouped.hasOwnProperty, 2); + + var array = [{}]; + _.countBy(array, function(value, index, obj){ ok(obj === array); }); }); test('sortedIndex', function() { diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index bf9741db45..8ec052be49 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -1,15 +1,5 @@ -// Underscore.js 1.3.3 -// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. -// Underscore may be freely distributed under the MIT license. -// Portions of Underscore are inspired or borrowed from Prototype, -// Oliver Steele's Functional, and John Resig's Micro-Templating. -// For all details and documentation: -// http://documentcloud.github.com/underscore -// Underscore.js 1.3.3 +// Underscore.js 1.4.0 +// http://underscorejs.org // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. // Underscore may be freely distributed under the MIT license. -// Portions of Underscore are inspired or borrowed from Prototype, -// Oliver Steele's Functional, and John Resig's Micro-Templating. -// For all details and documentation: -// http://documentcloud.github.com/underscore -(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.3.3";var N=T.each=T.forEach=function(e,t,r){if(e==null)return;if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i2;e==null&&(e=[]);if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return e==null?r:m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return e==null?r:(N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r)},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return e==null?i:g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return e==null?i:y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return e==null?n:b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;or||n===void 0)return 1;if(n>>1;n.call(r,e[u])=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r":">",'"':""","'":"'","/":"/"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file +(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.4.0";var N=T.each=T.forEach=function(e,t,r){if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i2;if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;or||n===void 0)return 1;if(n>>1;n.call(r,e[u])=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r":">",'"':""","'":"'","/":"/"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index dc1cf676ac..a3d378aa3b 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -1,10 +1,7 @@ -// Underscore.js 1.3.3 +// Underscore.js 1.4.0 +// http://underscorejs.org // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. // Underscore may be freely distributed under the MIT license. -// Portions of Underscore are inspired or borrowed from Prototype, -// Oliver Steele's Functional, and John Resig's Micro-Templating. -// For all details and documentation: -// http://documentcloud.github.com/underscore (function() { @@ -68,7 +65,7 @@ } // Current version. - _.VERSION = '1.3.3'; + _.VERSION = '1.4.0'; // Collection Functions // -------------------- @@ -77,7 +74,6 @@ // Handles objects with the built-in `forEach`, arrays, and raw objects. // Delegates to **ECMAScript 5**'s native `forEach` if available. var each = _.each = _.forEach = function(obj, iterator, context) { - if (obj == null) return; if (nativeForEach && obj.forEach === nativeForEach) { obj.forEach(iterator, context); } else if (obj.length === +obj.length) { @@ -97,7 +93,6 @@ // Delegates to **ECMAScript 5**'s native `map` if available. _.map = _.collect = function(obj, iterator, context) { var results = []; - if (obj == null) return results; if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); each(obj, function(value, index, list) { results[results.length] = iterator.call(context, value, index, list); @@ -109,7 +104,6 @@ // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { var initial = arguments.length > 2; - if (obj == null) obj = []; if (nativeReduce && obj.reduce === nativeReduce) { if (context) iterator = _.bind(iterator, context); return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); @@ -130,7 +124,6 @@ // Delegates to **ECMAScript 5**'s native `reduceRight` if available. _.reduceRight = _.foldr = function(obj, iterator, memo, context) { var initial = arguments.length > 2; - if (obj == null) obj = []; if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { if (context) iterator = _.bind(iterator, context); return arguments.length > 2 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); @@ -170,7 +163,6 @@ // Aliased as `select`. _.filter = _.select = function(obj, iterator, context) { var results = []; - if (obj == null) return results; if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); each(obj, function(value, index, list) { if (iterator.call(context, value, index, list)) results[results.length] = value; @@ -181,7 +173,6 @@ // Return all the elements for which a truth test fails. _.reject = function(obj, iterator, context) { var results = []; - if (obj == null) return results; each(obj, function(value, index, list) { if (!iterator.call(context, value, index, list)) results[results.length] = value; }); @@ -194,7 +185,6 @@ _.every = _.all = function(obj, iterator, context) { iterator || (iterator = _.identity); var result = true; - if (obj == null) return result; if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context); each(obj, function(value, index, list) { if (!(result = result && iterator.call(context, value, index, list))) return breaker; @@ -208,7 +198,6 @@ var any = _.some = _.any = function(obj, iterator, context) { iterator || (iterator = _.identity); var result = false; - if (obj == null) return result; if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); each(obj, function(value, index, list) { if (result || (result = iterator.call(context, value, index, list))) return breaker; @@ -220,7 +209,6 @@ // Aliased as `include`. _.contains = _.include = function(obj, target) { var found = false; - if (obj == null) return found; if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; found = any(obj, function(value) { return value === target; @@ -326,7 +314,7 @@ var result = {}; var iterator = lookupIterator(value); each(obj, function(value, index) { - var key = iterator.call(context, value, index); + var key = iterator.call(context, value, index, obj); behavior(result, key, value); }); return result; @@ -512,7 +500,6 @@ // If the array is large and already in sort order, pass `true` // for **isSorted** to use binary search. _.indexOf = function(array, item, isSorted) { - if (array == null) return -1; var i = 0, l = array.length; if (isSorted) { if (typeof isSorted == 'number') { @@ -529,7 +516,6 @@ // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. _.lastIndexOf = function(array, item, fromIndex) { - if (array == null) return -1; if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item, fromIndex); var i = (fromIndex != null ? fromIndex : array.length); while (i--) if (array[i] === item) return i; From 7036ed5e2fef3727f6705a6789bfc8f7c53d8a8c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 28 Sep 2012 00:46:57 -0700 Subject: [PATCH 53/82] Remove falsey checks and reduce file size. Former-commit-id: 5263a0beaffe2a987eb65fd3631ea4aff8d9f000 --- build.js | 23 ++-- build/post-compile.js | 4 +- build/pre-compile.js | 1 - lodash.js | 245 ++++++++++++------------------------------ test/test.js | 39 +------ 5 files changed, 80 insertions(+), 232 deletions(-) diff --git a/build.js b/build.js index 1e629becac..673baa92ee 100755 --- a/build.js +++ b/build.js @@ -118,10 +118,10 @@ 'lastIndexOf': [], 'lateBind': ['isFunction'], 'map': ['identity'], - 'max': [], + 'max': ['identity'], 'memoize': [], 'merge': ['isArray', 'isPlainObject'], - 'min': [], + 'min': ['identity'], 'mixin': ['forEach', 'functions'], 'noConflict': [], 'object': [], @@ -142,7 +142,7 @@ 'size': ['keys'], 'some': ['identity'], 'sortBy': [], - 'sortedIndex': ['bind'], + 'sortedIndex': ['bind', 'identity'], 'tap': ['mixin'], 'template': ['escape'], 'throttle': [], @@ -167,7 +167,6 @@ 'arrayBranch', 'beforeLoop', 'bottom', - 'exit', 'firstArg', 'hasDontEnumBug', 'inLoop', @@ -243,7 +242,7 @@ 'partial' ])); - /** List of ways to export the `LoDash` function */ + /** List of ways to export the `lodash` function */ var exportsAll = [ 'amd', 'commonjs', @@ -362,7 +361,7 @@ ' lodash plus=... Comma separated method/category names to add to those included in the build', ' lodash category=... Comma separated categories of methods to include in the build (case-insensitive)', ' (i.e. “arrays”, “chaining”, “collections”, “functions”, “objects”, and “utilities”)', - ' lodash exports=... Comma separated names of ways to export the `LoDash` function', + ' lodash exports=... Comma separated names of ways to export the `lodash` function', ' (i.e. “amd”, “commonjs”, “global”, “node”, and “none”)', ' lodash iife=... Code to replace the immediately-invoked function expression that wraps Lo-Dash', ' (e.g. `lodash iife="!function(window,undefined){%output%}(this)"`)', @@ -911,7 +910,7 @@ // constructed using the "use strict" directive var isStrict = options.indexOf('strict') > -1; - // used to specify the ways to export the `LoDash` function + // used to specify the ways to export the `lodash` function var exportsOptions = options.reduce(function(result, value) { return /exports/.test(value) ? optionToArray(value).sort() : result; }, isUnderscore @@ -1324,12 +1323,10 @@ source = removeIsFunctionFallback(source); } if (isRemoved(source, 'mixin')) { - // remove `LoDash` constructor - source = removeFunction(source, 'LoDash'); - // remove `LoDash` calls - source = source.replace(/(?:new +LoDash(?!\()|(?:new +)?LoDash\([^)]*\));?/g, ''); - // remove `LoDash.prototype` additions - source = source.replace(/(?:\s*\/\/.*)*\s*LoDash.prototype *=[\s\S]+?\/\*-+\*\//, ''); + // remove `lodash` calls + source = source.replace(/(?:new +lodash(?!\()|(?:new +)?lodash\([^)]*\));?/g, ''); + // remove `lodash.prototype` additions + source = source.replace(/(?:\s*\/\/.*)*\s*mixin\(lodash\)[\s\S]+?\/\*-+\*\//, ''); // remove `hasObjectSpliceBug` assignment source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasObjectSpliceBug;|.+?hasObjectSpliceBug *=.+/g, ''); } diff --git a/build/post-compile.js b/build/post-compile.js index 6639c3979a..37358a6f99 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -10,10 +10,10 @@ 'lodash': '/*!\n' + ' Lo-Dash @VERSION lodash.com/license\n' + - ' Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE\n' + + ' Underscore.js 1.4.0 underscorejs.org/LICENSE\n' + '*/', 'underscore': - '/*! Underscore.js @VERSION github.com/documentcloud/underscore/blob/master/LICENSE */' + '/*! Underscore.js @VERSION underscorejs.org/LICENSE */' }; /*--------------------------------------------------------------------------*/ diff --git a/build/pre-compile.js b/build/pre-compile.js index 6cca03bf01..032ea865e0 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -80,7 +80,6 @@ 'arrayBranch', 'beforeLoop', 'bottom', - 'exit', 'firstArg', 'hasDontEnumBug', 'inLoop', diff --git a/lodash.js b/lodash.js index 9d5fa0392c..f49bededb1 100644 --- a/lodash.js +++ b/lodash.js @@ -1,8 +1,8 @@ /*! * Lo-Dash v0.7.0 - * Copyright 2012 John-David Dalton - * Based on Underscore.js 1.3.3, copyright 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. - * + * (c) 2012 John-David Dalton + * Based on Underscore.js 1.4.0 + * (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. * Available under MIT license */ ;(function(window, undefined) { @@ -259,26 +259,18 @@ * * @name _ * @constructor - * @param {Mixed} value The value to wrap in a `LoDash` instance. - * @returns {Object} Returns a `LoDash` instance. + * @param {Mixed} value The value to wrap in a `lodash` instance. + * @returns {Object} Returns a `lodash` instance. */ function lodash(value) { - // allow invoking `lodash` without the `new` operator - return new LoDash(value); - } - - /** - * Creates a `LoDash` instance that wraps a value to allow chaining. - * - * @private - * @constructor - * @param {Mixed} value The value to wrap. - */ - function LoDash(value) { // exit early if already wrapped if (value && value.__wrapped__) { return value; } + // allow invoking `lodash` without the `new` operator + if (!(this instanceof lodash)) { + return new lodash(value); + } this.__wrapped__ = value; } @@ -347,9 +339,7 @@ 'var index, value, iteratee = <%= firstArg %>, ' + // assign the `result` variable an initial value 'result<% if (init) { %> = <%= init %><% } %>;\n' + - // add code to exit early or do so if the first argument is falsey - '<%= exit %>;\n' + - // add code after the exit snippet but before the iteration branches + // add code before the iteration branches '<%= top %>;\n' + // the following branch is for iterating arrays and array-like objects @@ -465,8 +455,7 @@ 'top': 'if (!callback) {\n' + ' callback = identity\n' + - '}\n' + - 'else if (thisArg !== undefined) {\n' + + '} else if (thisArg !== undefined) {\n' + ' callback = bindCallback(callback, thisArg)\n' + '}', 'inLoop': 'if (callback(value, index, collection) === false) return result' @@ -526,7 +515,6 @@ /** Reusable iterator options for `invoke`, `map`, `pluck`, and `sortBy` */ var mapIteratorOptions = { 'init': '', - 'exit': 'if (!collection) return []', 'beforeLoop': { 'array': 'result = Array(length)', 'object': 'result = ' + (isKeysFast ? 'Array(length)' : '[]') @@ -712,11 +700,7 @@ * * init - A string to specify the initial value of the `result` variable. * - * exit - A string of code to use in place of the default exit-early check - * of `if (!arguments[0]) return result`. - * - * top - A string of code to execute after the exit-early check but before - * the iteration branches. + * top - A string of code to execute before the iteration branches. * * beforeLoop - A string or object containing an "array" or "object" property * of code to execute before the array or object loops. @@ -739,8 +723,6 @@ // merge options into a template data object var data = { 'bottom': '', - 'exit': '', - 'init': '', 'top': '', 'arrayBranch': { 'beforeLoop': '' }, 'objectBranch': { 'beforeLoop': '' } @@ -765,10 +747,12 @@ // set additional template `data` values var args = data.args, firstArg = /^[^,]+/.exec(args)[0], + init = data.init, useStrict = data.useStrict; data.firstArg = firstArg; data.hasDontEnumBug = hasDontEnumBug; + data.init = init == null ? firstArg : init; data.isKeysFast = isKeysFast; data.noArgsEnum = noArgsEnum; data.shadowed = shadowed; @@ -778,9 +762,6 @@ if (data.noCharByIndex == null) { data.noCharByIndex = noCharByIndex; } - if (!data.exit) { - data.exit = 'if (!' + firstArg + ') return result'; - } if (firstArg != 'collection' || !data.arrayBranch.inLoop) { data.arrayBranch = null; } @@ -788,7 +769,7 @@ var factory = Function( 'arrayLikeClasses, ArrayProto, bind, bindCallback, compareAscending, concat, ' + 'forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, ' + - 'isPlainObject, noop, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, ' + + 'isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, ' + 'propertyCallback, slice, stringClass, toString, undefined', 'var callee = function(' + args + ') {\n' + iteratorTemplate(data) + '\n};\n' + 'return callee' @@ -797,7 +778,7 @@ return factory( arrayLikeClasses, ArrayProto, bind, bindCallback, compareAscending, concat, forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, - isPlainObject, noop, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, + isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, propertyCallback, slice, stringClass, toString ); } @@ -825,15 +806,6 @@ return htmlEscapes[match]; } - /** - * A no-operation function. - * - * @private - */ - function noop() { - // no operation performed - } - /** * Creates a function that returns the `property` value of the given `object`. * @@ -1268,7 +1240,7 @@ * // => true */ function has(object, property) { - return object ? hasOwnProperty.call(object, property) : false; + return hasOwnProperty.call(object, property); } /** @@ -1366,6 +1338,7 @@ 'args': 'value', 'init': 'true', 'top': + 'if (!value) return result;\n' + 'var className = toString.call(value),\n' + ' length = value.length;\n' + 'if (arrayLikeClasses[className]' + @@ -1411,7 +1384,7 @@ // treat `+0` vs. `-0` as not equal return a !== 0 || (1 / a == 1 / b); } - // unwrap any LoDash wrapped values + // unwrap any `lodash` wrapped values if (objectTypes[typeof a] || objectTypes[typeof b]) { a = a.__wrapped__ || a; b = b.__wrapped__ || b; @@ -1732,9 +1705,7 @@ if (type == 'function' && propertyIsEnumerable.call(object, 'prototype')) { return shimKeys(object); } - return object && objectTypes[type] - ? nativeKeys(object) - : []; + return nativeKeys(object); }; /** @@ -1771,16 +1742,11 @@ var merge = createIterator(extendIteratorOptions, { 'args': 'object, source, indicator', 'top': - 'var argsLength, isArr, stackA, stackB,\n' + - ' args = arguments, argsIndex = 0;\n' + - 'if (indicator == noop) {\n' + - ' argsLength = 2;\n' + - ' stackA = args[3];\n' + - ' stackB = args[4]\n' + + 'var isArr, args = arguments, argsIndex = 0;\n' + + 'if (indicator == compareAscending) {\n' + + ' var argsLength = 2, stackA = args[3], stackB = args[4]\n' + '} else {\n' + - ' argsLength = args.length;\n' + - ' stackA = [];\n' + - ' stackB = []\n' + + ' var argsLength = args.length, stackA = [], stackB = []\n' + '}\n' + 'while (++argsIndex < argsLength) {\n' + ' if (iteratee = args[argsIndex]) {', @@ -1798,7 +1764,7 @@ ' ? (isArray(value) ? value : [])\n' + ' : (isPlainObject(value) ? value : {})\n' + ' );\n' + - ' result[index] = callee(value, source, noop, stackA, stackB)\n' + + ' result[index] = callee(value, source, compareAscending, stackA, stackB)\n' + ' }\n' + '} else if (source != null) {\n' + ' result[index] = source\n' + @@ -2243,9 +2209,6 @@ * // => [4, 5, 2, 3, 0, 1] */ function reduceRight(collection, callback, accumulator, thisArg) { - if (!collection) { - return accumulator; - } var iteratee = collection, length = collection.length, noaccum = arguments.length < 3; @@ -2465,12 +2428,9 @@ * // => [1, 2, 3] */ function compact(array) { - var result = []; - if (!array) { - return result; - } var index = -1, - length = array.length; + length = array.length, + result = []; while (++index < length) { if (array[index]) { @@ -2497,14 +2457,11 @@ * // => [1, 3, 4] */ function difference(array) { - var result = []; - if (!array) { - return result; - } var index = -1, length = array.length, flattened = concat.apply(ArrayProto, arguments), - contains = cachedContains(flattened, length); + contains = cachedContains(flattened, length), + result = []; while (++index < length) { if (!contains(array[index])) { @@ -2534,9 +2491,7 @@ * // => 5 */ function first(array, n, guard) { - if (array) { - return (n == null || guard) ? array[0] : slice.call(array, 0, n); - } + return (n == null || guard) ? array[0] : slice.call(array, 0, n); } /** @@ -2558,13 +2513,10 @@ * // => [1, 2, 3, [[4]]]; */ function flatten(array, shallow) { - var result = []; - if (!array) { - return result; - } var value, index = -1, - length = array.length; + length = array.length, + result = []; while (++index < length) { value = array[index]; @@ -2604,9 +2556,6 @@ * // => 2 */ function indexOf(array, value, fromIndex) { - if (!array) { - return -1; - } var index = -1, length = array.length; @@ -2644,9 +2593,6 @@ * // => [3, 2] */ function initial(array, n, guard) { - if (!array) { - return []; - } return slice.call(array, 0, -((n == null || guard) ? 1 : n)); } @@ -2666,15 +2612,12 @@ * // => [1, 2] */ function intersection(array) { - var result = []; - if (!array) { - return result; - } var value, argsLength = arguments.length, cache = [], index = -1, - length = array.length; + length = array.length, + result = []; array: while (++index < length) { value = array[index]; @@ -2709,10 +2652,8 @@ * // => 1 */ function last(array, n, guard) { - if (array) { - var length = array.length; - return (n == null || guard) ? array[length - 1] : slice.call(array, -n || length); - } + var length = array.length; + return (n == null || guard) ? array[length - 1] : slice.call(array, -n || length); } /** @@ -2735,9 +2676,6 @@ * // => 1 */ function lastIndexOf(array, value, fromIndex) { - if (!array) { - return -1; - } var index = array.length; if (fromIndex && typeof fromIndex == 'number') { index = (fromIndex < 0 ? nativeMax(0, index + fromIndex) : nativeMin(fromIndex, index - 1)) + 1; @@ -2786,14 +2724,8 @@ length = array.length; if (!callback) { - while (++index < length) { - if (array[index] > result) { - result = array[index]; - } - } - return result; - } - if (thisArg !== undefined) { + callback = identity; + } else if (thisArg !== undefined) { callback = bindCallback(callback, thisArg); } while (++index < length) { @@ -2836,14 +2768,8 @@ length = array.length; if (!callback) { - while (++index < length) { - if (array[index] < result) { - result = array[index]; - } - } - return result; - } - if (thisArg !== undefined) { + callback = identity; + } else if (thisArg !== undefined) { callback = bindCallback(callback, thisArg); } while (++index < length) { @@ -2874,9 +2800,6 @@ * // => { 'moe': 30, 'larry': 40, 'curly': 50 } */ function object(keys, values) { - if (!keys) { - return {}; - } var index = -1, length = keys.length, result = {}; @@ -2960,9 +2883,6 @@ * // => [2, 1] */ function rest(array, n, guard) { - if (!array) { - return []; - } return slice.call(array, (n == null || guard) ? 1 : n); } @@ -2981,9 +2901,6 @@ * // => [4, 1, 6, 3, 5, 2] */ function shuffle(array) { - if (!array) { - return []; - } var rand, index = -1, length = array.length, @@ -3033,29 +2950,21 @@ * // => 2 */ function sortedIndex(array, value, callback, thisArg) { - if (!array) { - return 0; - } var mid, low = 0, high = array.length; - if (callback) { - if (typeof callback != 'function') { - callback = propertyCallback(callback); - } else if (thisArg !== undefined) { - callback = bind(callback, thisArg); - } - value = callback(value); - while (low < high) { - mid = (low + high) >>> 1; - callback(array[mid]) < value ? low = mid + 1 : high = mid; - } - } else { - while (low < high) { - mid = (low + high) >>> 1; - array[mid] < value ? low = mid + 1 : high = mid; - } + if (!callback) { + callback = identity; + } else if (typeof callback != 'function') { + callback = propertyCallback(callback); + } else if (thisArg !== undefined) { + callback = bind(callback, thisArg); + } + value = callback(value); + while (low < high) { + mid = (low + high) >>> 1; + callback(array[mid]) < value ? low = mid + 1 : high = mid; } return low; } @@ -3120,13 +3029,10 @@ * // => [1, 2, 3] */ function uniq(array, isSorted, callback, thisArg) { - var result = []; - if (!array) { - return result; - } var computed, index = -1, length = array.length, + result = [], seen = []; // juggle arguments @@ -3169,13 +3075,10 @@ * // => [2, 3, 4] */ function without(array) { - var result = []; - if (!array) { - return result; - } var index = -1, length = array.length, - contains = cachedContains(arguments, 1, 20); + contains = cachedContains(arguments, 1, 20), + result = []; while (++index < length) { if (!contains(array[index])) { @@ -3202,9 +3105,6 @@ * // => [['moe', 30, true], ['larry', 40, false], ['curly', 50, false]] */ function zip(array) { - if (!array) { - return []; - } var index = -1, length = max(pluck(arguments, 'length')), result = Array(length); @@ -3303,7 +3203,6 @@ 'useHas': false, 'useStrict': false, 'args': 'object', - 'init': 'object', 'top': 'var funcs = arguments,\n' + ' length = funcs.length;\n' + @@ -3704,14 +3603,14 @@ forEach(functions(object), function(methodName) { var func = lodash[methodName] = object[methodName]; - LoDash.prototype[methodName] = function() { + lodash.prototype[methodName] = function() { var args = [this.__wrapped__]; if (arguments.length) { push.apply(args, arguments); } var result = func.apply(lodash, args); if (this.__chain__) { - result = new LoDash(result); + result = new lodash(result); result.__chain__ = true; } return result; @@ -3872,7 +3771,6 @@ // and Laura Doktorova's doT.js // https://github.com/olado/doT options || (options = {}); - text += ''; var isEvaluating, result, @@ -3990,14 +3888,8 @@ var index = -1, result = Array(n); - if (thisArg !== undefined) { - while (++index < n) { - result[index] = callback.call(thisArg, index); - } - } else { - while (++index < n) { - result[index] = callback(index); - } + while (++index < n) { + result[index] = callback.call(thisArg, index); } return result; } @@ -4065,7 +3957,7 @@ * // => 'moe is 40' */ function chain(value) { - value = new LoDash(value); + value = new lodash(value); value.__chain__ = true; return value; } @@ -4261,22 +4153,19 @@ /*--------------------------------------------------------------------------*/ - // assign private `LoDash` constructor's prototype - LoDash.prototype = lodash.prototype; - - // add all static functions to `LoDash.prototype` + // add all static functions to `lodash.prototype` mixin(lodash); - // add `LoDash.prototype.chain` after calling `mixin()` to avoid overwriting + // add `lodash.prototype.chain` after calling `mixin()` to avoid overwriting // it with the wrapped `lodash.chain` - LoDash.prototype.chain = wrapperChain; - LoDash.prototype.value = wrapperValue; + lodash.prototype.chain = wrapperChain; + lodash.prototype.value = wrapperValue; // add all mutator Array functions to the wrapper. forEach(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { var func = ArrayProto[methodName]; - LoDash.prototype[methodName] = function() { + lodash.prototype[methodName] = function() { var value = this.__wrapped__; func.apply(value, arguments); @@ -4286,7 +4175,7 @@ delete value[0]; } if (this.__chain__) { - value = new LoDash(value); + value = new lodash(value); value.__chain__ = true; } return value; @@ -4297,12 +4186,12 @@ forEach(['concat', 'join', 'slice'], function(methodName) { var func = ArrayProto[methodName]; - LoDash.prototype[methodName] = function() { + lodash.prototype[methodName] = function() { var value = this.__wrapped__, result = func.apply(value, arguments); if (this.__chain__) { - result = new LoDash(result); + result = new lodash(result); result.__chain__ = true; } return result; diff --git a/test/test.js b/test/test.js index 0cbafaacdb..e99f876955 100644 --- a/test/test.js +++ b/test/test.js @@ -394,7 +394,7 @@ } else { func(object, { 'a': 1 }); } - } catch(e) { + } catch(e) {console.log(e); pass = false; } ok(pass); @@ -1696,43 +1696,6 @@ QUnit.module('lodash methods'); (function() { - test('should allow falsey arguments', function() { - var funcs = _.without.apply(_, [_.functions(_)].concat([ - '_', - '_iteratorTemplate', - '_shimKeys', - 'after', - 'bind', - 'bindAll', - 'compose', - 'debounce', - 'defer', - 'delay', - 'functions', - 'memoize', - 'once', - 'partial', - 'tap', - 'throttle', - 'wrap' - ])); - - _.each(funcs, function(methodName) { - var func = _[methodName], - pass = true; - - _.each(falsey, function(value, index) { - try { - index ? func(value) : func(); - } catch(e) { - pass = false; - } - }); - - ok(pass, '_.' + methodName + ' allows falsey arguments'); - }); - }); - test('should handle `null` `thisArg` arguments', function() { var thisArg, array = ['a'], From 383b92b20784b5b0b6300f7741205c06afb5da57 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 28 Sep 2012 02:14:59 -0700 Subject: [PATCH 54/82] Update build.js, test-build.js and rebuild docs. Former-commit-id: 385c6b4cb127ad8089622416758021556e413a0a --- build.js | 14 +-- doc/README.md | 210 ++++++++++++++++++++++----------------------- lodash.min.js | 74 ++++++++-------- test/test-build.js | 11 ++- 4 files changed, 152 insertions(+), 157 deletions(-) diff --git a/build.js b/build.js index 673baa92ee..2b7173a0f3 100755 --- a/build.js +++ b/build.js @@ -1094,15 +1094,6 @@ source = buildTemplate(templatePattern, templateSettings); } else { - // simplify template snippets by removing unnecessary brackets - source = source.replace( - RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *([,\\n])", 'g'), "$1'$2" - ); - - source = source.replace( - RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *\\+", 'g'), "$1;\\n'+" - ); - // remove methods from the build allMethods.forEach(function(otherName) { if (!_.contains(buildMethods, otherName)) { @@ -1271,7 +1262,7 @@ source = source.match(/\/\*![\s\S]+?\*\/\n/) + iife.slice(0, index) + - source.replace(/^[^(]+?\(function[^{]+?{|}\(this\)\)[;\s]*$/g, '') + + source.replace(/^[\s\S]+?\(function[^{]+?{|}\(this\)\)[;\s]*$/g, '') + iife.slice(index + token.length); } }()); @@ -1323,8 +1314,6 @@ source = removeIsFunctionFallback(source); } if (isRemoved(source, 'mixin')) { - // remove `lodash` calls - source = source.replace(/(?:new +lodash(?!\()|(?:new +)?lodash\([^)]*\));?/g, ''); // remove `lodash.prototype` additions source = source.replace(/(?:\s*\/\/.*)*\s*mixin\(lodash\)[\s\S]+?\/\*-+\*\//, ''); // remove `hasObjectSpliceBug` assignment @@ -1384,6 +1373,7 @@ } if (isRemoved(source, 'createIterator', 'keys')) { source = removeVar(source, 'nativeKeys'); + source = removeKeysOptimization(source); } if (!source.match(/var (?:hasDontEnumBug|hasObjectSpliceBug|iteratesOwnLast|noArgsEnum)\b/g)) { // remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, and `noArgsEnum` assignment diff --git a/doc/README.md b/doc/README.md index b9da3a7b07..09cde4a4cc 100644 --- a/doc/README.md +++ b/doc/README.md @@ -161,10 +161,10 @@ The `lodash` function. #### Arguments -1. `value` *(Mixed)*: The value to wrap in a `LoDash` instance. +1. `value` *(Mixed)*: The value to wrap in a `lodash` instance. #### Returns -*(Object)*: Returns a `LoDash` instance. +*(Object)*: Returns a `lodash` instance. * * * @@ -174,7 +174,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4130 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4034 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -186,7 +186,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3227 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3139 "View in source") [Ⓣ][1] Creates a function that is restricted to executing only after it is called `n` times. @@ -214,7 +214,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3260 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3172 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. @@ -245,7 +245,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3290 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3202 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -276,7 +276,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4055 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3959 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -310,7 +310,7 @@ var youngest = _.chain(stooges) ### `_.clone(value, deep)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1053 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1035 "View in source") [Ⓣ][1] Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned. @@ -349,7 +349,7 @@ shallow[0] === stooges[0]; ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2457 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2430 "View in source") [Ⓣ][1] Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -373,7 +373,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3328 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3239 "View in source") [Ⓣ][1] Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -400,7 +400,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1930 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1906 "View in source") [Ⓣ][1] Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -434,7 +434,7 @@ _.contains('curly', 'ur'); ### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1966 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1942 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -466,7 +466,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3361 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3272 "View in source") [Ⓣ][1] Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -492,7 +492,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1146 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1128 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -518,7 +518,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3426 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3337 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -543,7 +543,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3406 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3317 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -570,7 +570,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2489 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2459 "View in source") [Ⓣ][1] Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -595,7 +595,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3645 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3556 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -619,7 +619,7 @@ _.escape('Moe, Larry & Curly'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1987 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1963 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -648,7 +648,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1166 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1148 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -673,7 +673,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2007 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1983 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -702,7 +702,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2029 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2005 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -731,7 +731,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2526 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2493 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -759,7 +759,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2550 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2515 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -787,7 +787,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2056 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2032 "View in source") [Ⓣ][1] Iterates over a `collection`, 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`. @@ -819,7 +819,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1196 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1178 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, 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`. @@ -855,7 +855,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1220 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1202 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, 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`. @@ -883,7 +883,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1237 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1219 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -910,7 +910,7 @@ _.functions(_); ### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2084 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2060 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -942,7 +942,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1260 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1242 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -967,7 +967,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3665 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3576 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -992,7 +992,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2596 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2558 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1024,7 +1024,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2636 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2595 "View in source") [Ⓣ][1] Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. @@ -1049,7 +1049,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2658 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2614 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -1073,7 +1073,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invert(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1277 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1259 "View in source") [Ⓣ][1] Creates an object composed of the inverted keys and values of the given `object`. @@ -1097,7 +1097,7 @@ _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2112 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2088 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`, returning an array of the results of each invoked method. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1126,7 +1126,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L869 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L851 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1153,7 +1153,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L895 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L877 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1180,7 +1180,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1296 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1278 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1204,7 +1204,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1313 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1295 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1228,7 +1228,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1330 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1312 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1252,7 +1252,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1355 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1337 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1282,7 +1282,7 @@ _.isEmpty(''); ### `_.isEqual(a, b)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1394 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1377 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1313,7 +1313,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1551 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1534 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1343,7 +1343,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L912 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L894 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1367,7 +1367,7 @@ _.isFunction(_); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1609 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1592 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1400,7 +1400,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1632 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1615 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1427,7 +1427,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1649 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1632 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1451,7 +1451,7 @@ _.isNumber(8.4 * 5); ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1575 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1558 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -1481,7 +1481,7 @@ _.isObject(1); ### `_.isPlainObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L946 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L928 "View in source") [Ⓣ][1] Checks if a given `value` is an object created by the `Object` constructor. @@ -1516,7 +1516,7 @@ _.isPlainObject({ 'name': 'moe', 'age': 40 }); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1666 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1649 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1540,7 +1540,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1683 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1666 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1564,7 +1564,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1701 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1684 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1588,7 +1588,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1718 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1701 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of `object`. @@ -1612,7 +1612,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2701 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2654 "View in source") [Ⓣ][1] Gets the last element of the `array`. Pass `n` to return the last `n` elements of the `array`. @@ -1637,7 +1637,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2727 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2678 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1666,7 +1666,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.lateBind(object, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3463 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3374 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method @@ -1707,7 +1707,7 @@ func(); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2147 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2123 "View in source") [Ⓣ][1] Creates an array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1739,7 +1739,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2767 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2715 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1771,7 +1771,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3485 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3396 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1797,7 +1797,7 @@ var fibonacci = _.memoize(function(n) { ### `_.merge(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1761 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1742 "View in source") [Ⓣ][1] Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -1832,7 +1832,7 @@ _.merge(stooges, ages); ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2817 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2759 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1858,7 +1858,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3691 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3602 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1888,7 +1888,7 @@ _('curly').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3722 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3633 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1908,7 +1908,7 @@ var lodash = _.noConflict(); ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2866 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2802 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. @@ -1933,7 +1933,7 @@ _.object(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1823 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1799 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -1964,7 +1964,7 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3511 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3422 "View in source") [Ⓣ][1] Creates a function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1990,7 +1990,7 @@ initialize(); ### `_.pairs(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1839 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1815 "View in source") [Ⓣ][1] Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. @@ -2014,7 +2014,7 @@ _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3546 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3457 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `bind`, except it does **not** alter the `this` binding. @@ -2041,7 +2041,7 @@ hi('moe'); ### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1870 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1846 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, picking the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -2072,7 +2072,7 @@ _.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2170 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2146 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -2103,7 +2103,7 @@ _.pluck(stooges, 'name'); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3745 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3656 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -2131,7 +2131,7 @@ _.random(5); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2913 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2846 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -2169,7 +2169,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2198 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2174 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -2199,7 +2199,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2235 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2211 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -2230,7 +2230,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2275 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2248 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -2256,7 +2256,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2952 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2885 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2284,13 +2284,13 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3784 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3695 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. #### Arguments 1. `object` *(Object)*: The object to inspect. -2. `property` *(String)*: The property to get the result of. +2. `property` *(String)*: The property to get the value of. #### Returns *(Mixed)*: Returns the resolved value. @@ -2319,7 +2319,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2973 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2903 "View in source") [Ⓣ][1] Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2343,7 +2343,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2299 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2272 "View in source") [Ⓣ][1] Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. @@ -2373,7 +2373,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2327 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2300 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2402,7 +2402,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2357 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2330 "View in source") [Ⓣ][1] Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2434,7 +2434,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3025 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2952 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. @@ -2475,7 +2475,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4082 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3986 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2505,7 +2505,7 @@ _.chain([1, 2, 3, 200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3857 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3768 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: In the development build `_.template` utilizes sourceURLs for easier debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. See http://developer.chrome.com/trunk/extensions/sandboxingEval.html @@ -2570,7 +2570,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3568 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3479 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2595,7 +2595,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3976 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3886 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -2627,7 +2627,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2393 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2366 "View in source") [Ⓣ][1] Converts the `collection`, to an array. @@ -2651,7 +2651,7 @@ Converts the `collection`, to an array. ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4007 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3911 "View in source") [Ⓣ][1] Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -2675,7 +2675,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3066 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2987 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -2699,7 +2699,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3110 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3031 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -2738,7 +2738,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4025 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3929 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2762,7 +2762,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1900 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1876 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2786,7 +2786,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2427 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2400 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. @@ -2817,7 +2817,7 @@ _.where(stooges, { 'age': 40 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3159 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3077 "View in source") [Ⓣ][1] Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2842,7 +2842,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3619 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3530 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2871,7 +2871,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3192 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3107 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2902,7 +2902,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4100 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4004 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2923,7 +2923,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4117 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4021 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -2951,7 +2951,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L294 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L286 "View in source") [Ⓣ][1] *(Object)*: By default, the template delimiters used by Lo-Dash are similar to those in embedded Ruby *(ERB)*. Change the following template settings to use alternative delimiters. @@ -2963,7 +2963,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.escape` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L303 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L295 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to be HTML-escaped. @@ -2975,7 +2975,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.evaluate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L312 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L304 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect code to be evaluated. @@ -2987,7 +2987,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.interpolate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L321 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L313 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to inject. @@ -2999,7 +2999,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.variable` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L330 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L322 "View in source") [Ⓣ][1] *(String)*: Used to reference the data object in the template text. diff --git a/lodash.min.js b/lodash.min.js index 19f9831ee5..7407e2791b 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -1,41 +1,39 @@ /*! Lo-Dash 0.7.0 lodash.com/license - Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE + Underscore.js 1.4.0 underscorejs.org/LICENSE */ -; -(function(s,v){var j=!0,m=null,o=!1;function c(a){return new t(a)}function t(a){if(a&&a.__wrapped__)return a;this.__wrapped__=a}function N(a,b){return function(d,l,c){return a.call(b,d,l,c)}}function X(a,b,d){b||(b=0);var l=a.length,c=l-b>=(d||Za),e=c?{}:a;if(c)for(var i=b-1;++ib||a===v)return 1;if(ad;d++)b+="j='"+e.p[d]+"';if(", -"constructor"==e.p[d]&&(b+="!(g&&g.prototype===k)&&"),b+="h.call(k,j)){B=k[j];"+e.m.i+"}"}if(e.c||e.n)b+="}"}b+=e.e+";return u";return Function("E,F,G,c,J,f,K,h,i,N,P,R,T,U,X,Y,Z,m,r,dd,w,x,z,A","var H=function("+a+"){"+b+"};return H")(u,A,aa,N,$a,ba,O,q,ca,C,y,da,x,ea,Z,H,z,E,ya,za,n,B,k)}function bb(a){return"\\"+cb[a]}function db(a){return eb[a]}function Z(){}function za(a){return function(b){return b[a]}}function fb(a){return gb[a]}function y(a){return k.call(a)==fa}function x(a){return"function"== -typeof a}function Aa(a){var b=o;if(!(a&&"object"==typeof a)||y(a))return b;var d=a.constructor;if((!Ba||!("function"!=typeof a.toString&&"string"==typeof(a+"")))&&(!x(d)||d instanceof d)){if(Ca)return O(a,function(a,d,e){b=!q.call(e,d);return o}),b===o;O(a,function(a,d){b=d});return b===o||q.call(a,b)}return b}function ga(a,b,d,l,c){if(a==m)return a;d&&(b=o);if(d=z[typeof a]){var e=k.call(a);if(!w[e]||P&&y(a))return a;var i=e==Q,d=i||(e==H?ea(a):d)}if(!d||!b)return d?i?n.call(a):Da({},a):a;d=a.constructor; -switch(e){case J:return new d(a==j);case K:return new d(+a);case F:case B:return new d(a);case L:return d(a.source,hb.exec(a))}l||(l=[]);c||(c=[]);for(e=l.length;e--;)if(l[e]==a)return c[e];var h=i?d(e=a.length):{};l.push(a);c.push(h);if(i)for(i=-1;++i++f;)if(p=wa[f],q.call(a,p)&&(!q.call(b,p)||!R(a[p],b[p],d,c)))return o;return j}function Fa(a,b,d,c){if(!a)return d;var f=a,e=a.length,i=3>arguments.length;if(e!==+e)var h=ha(a),e=h.length;else xa&&k.call(a)==B&&(f=a.split(""));I(a,function(a,g,k){g=h?h[--e]:--e;d=i?(i=o,f[g]):b.call(c,d,f[g],g,k)});return d} -function ia(a,b,d){if(a)return b==m||d?a[0]:n.call(a,0,b)}function Ga(a,b){var d=[];if(!a)return d;for(var c,f=-1,e=a.length;++fd?ka(0,f+d):d)-1;else return c=Ha(a,b),a[c]===b?c:-1;for(;++cf&&(f=a[e]);return f}for(d!==v&&(b=N(b, -d));++ec&&(c=d,f=a[e]);return f}function la(a,b,d){return!a?[]:n.call(a,b==m||d?1:b)}function Ha(a,b,d,c){if(!a)return 0;var f=0,e=a.length;if(d){"function"!=typeof d?d=za(b):c!==v&&(d=aa(d,c));for(b=d(b);f>>1,d(a[c])>>1,a[c]C(h,c))h.push(c), -f.push(a[e]);return f}function aa(a,b){return Ka||G&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,lb=/&(?:amp|lt|gt|quot|#x27);/g,mb=/\b__p\+='';/g,nb=/\b(__p\+=)''\+/g,ob=/(__e\(.*?\)|\b__t\))\+'';/g,hb=/\w*$/,pb=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,oa=RegExp("^"+(M.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),pa=/($^)/,qb=/[&<>"']/g,rb=/['\n\r\t\u2028\u2029\\]/g,wa="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "), -ba=A.concat,q=M.hasOwnProperty,ja=A.push,ya=M.propertyIsEnumerable,n=A.slice,k=M.toString,G=oa.test(G=n.bind)&&G,Ma=Math.floor,qa=oa.test(qa=Array.isArray)&&qa,sb=s.isFinite,E=oa.test(E=Object.keys)&&E,ka=Math.max,tb=Math.min,Na=Math.random,fa="[object Arguments]",Q="[object Array]",J="[object Boolean]",K="[object Date]",F="[object Number]",H="[object Object]",L="[object RegExp]",B="[object String]",ub=s.clearTimeout,S=s.setTimeout,$,Oa,Ca,va=j;(function(){function a(){this.x=1}var b={"0":1,length:1}, -d=[];a.prototype={valueOf:1,y:1};for(var c in new a)d.push(c);for(c in arguments)va=!c;$=4>(d+"").length;Ca="x"!=d[0];Oa=(d.splice.call(b,0,1),b[0])})(1);var P=!y(arguments),vb="x"!=n.call("x")[0],xa="xx"!="x"[0]+Object("x")[0];try{var Ba=("[object Object]",k.call(s.document||0)==H)}catch(Kb){}var Ka=G&&/\n|Opera/.test(G+k.call(s.opera)),D=E&&/^.+$|true/.test(E+!!s.attachEvent),ab=!Ka,u={};u[J]=u[K]=u["[object Function]"]=u[F]=u[H]=u[L]=o;u[fa]=u[Q]=u[B]=j;var w={};w[fa]=w["[object Function]"]=o;w[Q]= -w[J]=w[K]=w[F]=w[H]=w[L]=w[B]=j;var eb={"&":"&","<":"<",">":">",'"':""","'":"'"},gb={"&":"&","<":"<",">":">",""":'"',"'":"'"},z={"boolean":o,"function":j,object:j,number:o,string:o,undefined:o,unknown:j},cb={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"};c.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var r={a:"e,d,y",j:"e",q:"if(!d)d=i;else if(y!==A)d=c(d,y)", -i:"if(d(B,j,e)===false)return u"},ra={j:"{}",q:"if(typeof d!='function'){d=dd(B,d)}else if(y!==A)d=c(d,y)",i:"var q=d(B,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},sa={j:"true",i:"if(!d(B,j,e))return!u"},T={r:o,s:o,a:"n",j:"n",q:"for(var a=1,b=arguments.length;a-1"},i:"if(B===jj)return true"}),Db=g(r,ra),Ua=g(r,sa),Va=g(r,U),Wa=g(r,V,{j:"",i:"if(d(B,j,e))return B"}),I=g(r,V),Eb=g(r,ra,{i:"var q=d(B,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(B)"}),Fb=g(W,{a:"e,V",q:"var D=w.call(arguments,2),S=typeof V=='function'",i:{b:"u[j]=(S?V:B[V]).apply(B,D)",l:"u"+(D?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),Xa=g(r,W),ta=g(W,{a:"e,cc",i:{b:"u[j]=B[cc]",l:"u"+(D?"[o]=":".push")+"(B[cc])"}}),ua=g({a:"e,d,C,y", -j:"C",q:"var W=arguments.length<3;if(y!==A)d=c(d,y)",d:{b:"if(W)u=k[++j]"},i:{b:"u=d(u,B,j,e)",l:"u=W?(W=false,B):d(u,B,j,e)"}}),Gb=g(r,U,{i:"!"+U.i}),Ya=g(r,sa,{j:"false",i:sa.i.replace("!","")}),Hb=g(r,ra,W,{i:{b:"u[j]={a:d(B,j,e),b:j,c:B}",l:"u"+(D?"[o]=":".push")+"({a:d(B,j,e),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--)u[l]=u[l].c"}),Ib=g(U,{a:"e,bb",q:"var t=[];K(bb,function(B,q){t.push(q)});var ee=t.length",i:"for(var q,aa=true,s=0;s1){for(var j=1;ja?b():function(){if(1>--a)return b.apply(this,arguments)}};c.bind=aa;c.bindAll=Jb;c.chain=function(a){a=new t(a);a.__chain__=j;return a};c.clone=ga;c.compact=function(a){var b=[];if(!a)return b;for(var d=-1,c=a.length;++dC(b,d)){for(var h=1;hd?ka(0,c+d):tb(d,c-1))+1);c--;)if(a[c]===b)return c;return-1};c.lateBind= -function(a,b){return Y(b,a,n.call(arguments,2))};c.map=Xa;c.max=Ia;c.memoize=function(a,b){var d={};return function(){var c=b?b.apply(this,arguments):arguments[0];return q.call(d,c)?d[c]:d[c]=a.apply(this,arguments)}};c.merge=zb;c.min=function(a,b,d){var c=Infinity,f=c;if(!a)return f;var e=-1,i=a.length;if(!b){for(;++e=n?(h=k,f= -a.apply(e,g)):i||(i=S(c,n));return f}};c.times=function(a,b,c){var a=+a||0,g=-1,f=Array(a);if(c!==v)for(;++gC(g,b[a])&&g.push(b[a]);return g};c.uniq=Ja;c.uniqueId=function(a){var b= -ib++;return a?a+b:b};c.values=Sa;c.where=Ib;c.without=function(a){var b=[];if(!a)return b;for(var c=-1,g=a.length,f=X(arguments,1,20);++c=(n||H),s=i?{}:e;if(i)for(var o=t-1;++on||e===t)return 1;if(en;n++)t+="j='"+f.o[n]+"';if(","constructor"== +f.o[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){B=k[j];"+f.l.h+"}"}if(f.c||f.m)t+="}"}return t+=f.e+";return u",Function("E,F,G,c,J,f,K,h,i,N,P,R,T,U,Y,Z,m,r,dd,w,x,z,A","var H=function("+e+"){"+t+"};return H")(Mt,_,L,o,a,K,Gt,Q,A,x,v,Vt,m,$t,dt,Ht,st,Y,p,Z,mt,et)}function c(e){return"\\"+Bt[e]}function h(e){return Dt[e]}function p(e){return function(t){return t[e]}}function d(e){return Pt[e]}function v(e){return et.call(e)==ft}function m(e){return"function"==typeof e}function g(e){var t= +i;if(!e||"object"!=typeof e||v(e))return t;var n=e.constructor;return(!Ct||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!m(n)||n instanceof n)?Et?(Gt(e,function(e,n,r){return t=!Q.call(r,n),i}),t===i):(Gt(e,function(e,n){t=n}),t===i||Q.call(e,t)):t}function y(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=Ht[typeof e]){var a=et.call(e);if(!_t[a]||xt&&v(e))return e;var f=a==lt,s=f||(a==dt?$t(e):s)}if(!s||!t)return s?f?Z.call(e):Qt({},e):e;s=e.constructor;switch(a){case ct:return new s(e==n +);case ht:return new s(+e);case pt:case mt:return new s(e);case vt:return s(e.source,U.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=J[u],Q.call(e,c)&&(!Q.call(t,c)||!b(e[c],t[c],s,o)))return i;return n}function w(e,t,n,r){var s=e,o=e.length,u=3>arguments.length;if(o!==+o)var a=nn(e),o=a.length;else Nt&&et.call(e)==mt&&(s=e.split(""));return dn(e,function(e,f,l){f=a?a[--o]:--o,n=u?(u=i,s[f]):t.call(r,n,s[f],f,l)}),n}function E(e,t +,n){return t==r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n,r=-1,i=e.length,s=[];++rn?ot(0,i+n):n)-1}for(;++ri&&(i=r,s=e[u]);return s}function N(e,t,n){return Z.call(e,t==r||n?1:t)}function C +(e,n,r,i){var s=0,o=e.length;r?"function"!=typeof r?r=p(r):i!==t&&(r=L(r,i)):r=A;for(n=r(n);s>>1,r(e[i])x(l,s))l.push(s),f.push(e[u]);return f}function L(e,t){return Lt||tt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,F=/&(?:amp|lt|gt|quot|#x27);/g,I=/\b__p\+='';/g,q=/\b(__p\+=)''\+/g +,R=/(__e\(.*?\)|\b__t\))\+'';/g,U=/\w*$/,z=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,W=RegExp("^"+(D.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),X=/($^)/,V=/[&<>"']/g,$=/['\n\r\t\u2028\u2029\\]/g,J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),K=_.concat,Q=D.hasOwnProperty,G=_.push,Y=D.propertyIsEnumerable,Z=_.slice,et=D.toString,tt=W.test(tt=Z.bind)&&tt,nt=Math.floor,rt=W.test(rt=Array +.isArray)&&rt,it=e.isFinite,st=W.test(st=Object.keys)&&st,ot=Math.max,ut=Math.min,at=Math.random,ft="[object Arguments]",lt="[object Array]",ct="[object Boolean]",ht="[object Date]",pt="[object Number]",dt="[object Object]",vt="[object RegExp]",mt="[object String]",gt=e.clearTimeout,yt=e.setTimeout,bt,wt,Et,St=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in arguments)St=!r;bt=4>(n+"").length,Et="x"!=n[0],wt=(n.splice.call +(t,0,1),t[0])})(1);var xt=!v(arguments),Tt="x"!=Z.call("x")[0],Nt="xx"!="x"[0]+Object("x")[0];try{var Ct=("[object Object]",et.call(e.document||0)==dt)}catch(kt){}var Lt=tt&&/\n|Opera/.test(tt+et.call(e.opera)),At=st&&/^.+$|true/.test(st+!!e.attachEvent),Ot=!Lt,Mt={};Mt[ct]=Mt[ht]=Mt["[object Function]"]=Mt[pt]=Mt[dt]=Mt[vt]=i,Mt[ft]=Mt[lt]=Mt[mt]=n;var _t={};_t[ft]=_t["[object Function]"]=i,_t[lt]=_t[ct]=_t[ht]=_t[pt]=_t[dt]=_t[vt]=_t[mt]=n;var Dt={"&":"&","<":"<",">":">",'"':""","'" +:"'"},Pt={"&":"&","<":"<",">":">",""":'"',"'":"'"},Ht={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Bt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var jt={a:"e,d,y",i:"e",p:"if(!d){d=i}else if(y!==A){d=c(d,y)}",h:"if(d(B,j,e)===false)return u"},Ft={i:"{}",p:"if(typeof d!='function'){d=dd(d)}else if(y!==A){d=c(d,y)}" +,h:"var q=d(B,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},It={i:"true",h:"if(!d(B,j,e))return!u"},qt={q:i,r:i,a:"n",i:"n",p:"for(var a=1,b=arguments.length;a-1"},h:"if(B===jj)return true"}),ln=l(jt,Ft),cn=l(jt,It),hn=l(jt,Rt),pn=l(jt,Ut,{i:"",h:"if(d(B,j,e))return B"}),dn=l(jt,Ut),vn=l(jt,Ft,{h:"var q=d(B,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(B)" +}),mn=l(Wt,{a:"e,V",p:"var D=w.call(arguments,2),S=typeof V=='function'",h:{b:"u[j]=(S?V:B[V]).apply(B,D)",k:"u"+(At?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),gn=l(jt,Wt),yn=l(Wt,{a:"e,cc",h:{b:"u[j]=B[cc]",k:"u"+(At?"[o]=":".push")+"(B[cc])"}}),bn=l({a:"e,d,C,y",i:"C",p:"var W=arguments.length<3;if(y!==A)d=c(d,y)",d:{b:"if(W)u=k[++j]"},h:{b:"u=d(u,B,j,e)",k:"u=W?(W=false,B):d(u,B,j,e)"}}),wn=l(jt,Rt,{h:"!"+Rt.h}),En=l(jt,It,{i:"false",h:It.h.replace("!","")}),Sn=l(jt,Ft,Wt,{h:{b:"u[j]={a:d(B,j,e),b:j,c:B}" +,k:"u"+(At?"[o]=":".push")+"({a:d(B,j,e),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--){u[l]=u[l].c}"}),xn=l(Rt,{a:"e,bb",p:"var t=[];K(bb,function(B,q){t.push(q)});var ee=t.length",h:"for(var q,aa=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply +(this,arguments)}},s.bind=L,s.bindAll=Tn,s.chain=function(e){return e=new s(e),e.__chain__=n,e},s.clone=y,s.compact=function(e){for(var t=-1,n=e.length,r=[];++tx(o,t)){for(var a=1;an?ot(0,r+n):ut(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return f(t,e,Z.call(arguments,2))},s.map=gn,s.max=T,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Q.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=rn,s.min=function(e,n,r){var i=Infinity,s=i;if(!e)return s +;var u=-1,a=e.length;for(n?r!==t&&(n=o(n,r)):n=A;++u=f?(a=r,s=e.apply(o,i)):u||(u=yt(n,f)),s}},s.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rx(r,t[e])&&r.push(t[e]);return r},s.uniq=k,s.uniqueId=function(e){var t=P++;return e?e+t:t},s.values=an,s.where=xn,s.without=function(e){for(var t=-1,n=e.length,r=u(arguments,1,20),i=[];++t Date: Fri, 28 Sep 2012 07:56:53 -0700 Subject: [PATCH 55/82] Reduce file size further. Former-commit-id: 009540db12d86f0fb79ccd493b61c4fa2cdd9b1f --- doc/README.md | 104 +++++++++++++++++++++++++------------------------- lodash.js | 35 +++++------------ lodash.min.js | 38 +++++++++--------- 3 files changed, 80 insertions(+), 97 deletions(-) diff --git a/doc/README.md b/doc/README.md index 09cde4a4cc..8437a06ce2 100644 --- a/doc/README.md +++ b/doc/README.md @@ -174,7 +174,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4034 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4017 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -186,7 +186,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3139 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3125 "View in source") [Ⓣ][1] Creates a function that is restricted to executing only after it is called `n` times. @@ -214,7 +214,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3172 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3158 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. @@ -245,7 +245,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3202 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3188 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -276,7 +276,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3959 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3942 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -349,7 +349,7 @@ shallow[0] === stooges[0]; ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2430 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2424 "View in source") [Ⓣ][1] Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -373,7 +373,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3239 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3225 "View in source") [Ⓣ][1] Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -466,7 +466,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3272 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3258 "View in source") [Ⓣ][1] Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -518,7 +518,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3337 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3323 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -543,7 +543,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3317 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3303 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -570,7 +570,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2459 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2453 "View in source") [Ⓣ][1] Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -595,7 +595,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3556 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3542 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -731,7 +731,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2493 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2487 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -759,7 +759,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2515 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2509 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -967,7 +967,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3576 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3562 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -992,7 +992,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2558 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2552 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1024,7 +1024,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2595 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2589 "View in source") [Ⓣ][1] Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. @@ -1049,7 +1049,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2614 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2608 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -1612,7 +1612,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2654 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2648 "View in source") [Ⓣ][1] Gets the last element of the `array`. Pass `n` to return the last `n` elements of the `array`. @@ -1637,7 +1637,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2678 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2672 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1666,7 +1666,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.lateBind(object, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3374 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3360 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method @@ -1739,7 +1739,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2715 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2709 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1771,7 +1771,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3396 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3382 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1832,7 +1832,7 @@ _.merge(stooges, ages); ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2759 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2749 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1858,7 +1858,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3602 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3588 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1888,7 +1888,7 @@ _('curly').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3633 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3619 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1908,7 +1908,7 @@ var lodash = _.noConflict(); ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2802 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2788 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. @@ -1964,7 +1964,7 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3422 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3408 "View in source") [Ⓣ][1] Creates a function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -2014,7 +2014,7 @@ _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3457 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3443 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `bind`, except it does **not** alter the `this` binding. @@ -2103,7 +2103,7 @@ _.pluck(stooges, 'name'); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3656 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3642 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -2131,7 +2131,7 @@ _.random(5); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2846 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2832 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -2256,7 +2256,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2885 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2871 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2284,7 +2284,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3695 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3681 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2319,7 +2319,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2903 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2889 "View in source") [Ⓣ][1] Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2373,7 +2373,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2300 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2297 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2402,7 +2402,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2330 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2327 "View in source") [Ⓣ][1] Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2434,7 +2434,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2952 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2938 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. @@ -2475,7 +2475,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3986 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3969 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2505,7 +2505,7 @@ _.chain([1, 2, 3, 200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3768 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3751 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: In the development build `_.template` utilizes sourceURLs for easier debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. See http://developer.chrome.com/trunk/extensions/sandboxingEval.html @@ -2570,7 +2570,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3479 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3465 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2595,7 +2595,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3886 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3869 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -2627,7 +2627,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2366 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2363 "View in source") [Ⓣ][1] Converts the `collection`, to an array. @@ -2651,7 +2651,7 @@ Converts the `collection`, to an array. ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3911 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3894 "View in source") [Ⓣ][1] Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -2675,7 +2675,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2987 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2973 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -2699,7 +2699,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3031 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3017 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -2738,7 +2738,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3929 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3912 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2786,7 +2786,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2400 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2394 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. @@ -2817,7 +2817,7 @@ _.where(stooges, { 'age': 40 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3077 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3063 "View in source") [Ⓣ][1] Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2842,7 +2842,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3530 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3516 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2871,7 +2871,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3107 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3093 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2902,7 +2902,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4004 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3987 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2923,7 +2923,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4021 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4004 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.js b/lodash.js index f49bededb1..2ec7223a56 100644 --- a/lodash.js +++ b/lodash.js @@ -2270,10 +2270,7 @@ * // => 5 */ function size(collection) { - if (!collection) { - return 0; - } - var length = collection.length; + var length = collection ? collection.length : 0; return length === +length ? length : keys(collection).length; } @@ -2364,10 +2361,7 @@ * // => [2, 3, 4] */ function toArray(collection) { - if (!collection) { - return []; - } - var length = collection.length; + var length = collection ? collection.length : 0; if (length === +length) { return (noArraySliceOnStrings ? toString.call(collection) == stringClass : typeof collection == 'string') ? collection.split('') @@ -2713,15 +2707,11 @@ * // => { 'name': 'curly', 'age': 60 }; */ function max(array, callback, thisArg) { - var computed = -Infinity, - result = computed; - - if (!array) { - return result; - } var current, + result, + computed = -Infinity, index = -1, - length = array.length; + length = array ? array.length : 0; if (!callback) { callback = identity; @@ -2757,15 +2747,11 @@ * // => 2 */ function min(array, callback, thisArg) { - var computed = Infinity, - result = computed; - - if (!array) { - return result; - } var current, + result, + computed = Infinity, index = -1, - length = array.length; + length = array ? array.length : 0; if (!callback) { callback = identity; @@ -3695,10 +3681,7 @@ function result(object, property) { // based on Backbone's private `getValue` function // https://github.com/documentcloud/backbone/blob/0.9.2/backbone.js#L1419-1424 - if (!object) { - return null; - } - var value = object[property]; + var value = object ? object[property] : null; return isFunction(value) ? object[property]() : value; } diff --git a/lodash.min.js b/lodash.min.js index 7407e2791b..82cb65baf1 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -11,16 +11,16 @@ i;if(!e||"object"!=typeof e||v(e))return t;var n=e.constructor;return(!Ct||"func );case ht:return new s(+e);case pt:case mt:return new s(e);case vt:return s(e.source,U.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=J[u],Q.call(e,c)&&(!Q.call(t,c)||!b(e[c],t[c],s,o)))return i;return n}function w(e,t,n,r){var s=e,o=e.length,u=3>arguments.length;if(o!==+o)var a=nn(e),o=a.length;else Nt&&et.call(e)==mt&&(s=e.split(""));return dn(e,function(e,f,l){f=a?a[--o]:--o,n=u?(u=i,s[f]):t.call(r,n,s[f],f,l)}),n}function E(e,t -,n){return t==r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n,r=-1,i=e.length,s=[];++rn?ot(0,i+n):n)-1}for(;++ri&&(i=r,s=e[u]);return s}function N(e,t,n){return Z.call(e,t==r||n?1:t)}function C -(e,n,r,i){var s=0,o=e.length;r?"function"!=typeof r?r=p(r):i!==t&&(r=L(r,i)):r=A;for(n=r(n);s>>1,r(e[i])x(l,s))l.push(s),f.push(e[u]);return f}function L(e,t){return Lt||tt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,F=/&(?:amp|lt|gt|quot|#x27);/g,I=/\b__p\+='';/g,q=/\b(__p\+=)''\+/g -,R=/(__e\(.*?\)|\b__t\))\+'';/g,U=/\w*$/,z=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,W=RegExp("^"+(D.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),X=/($^)/,V=/[&<>"']/g,$=/['\n\r\t\u2028\u2029\\]/g,J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),K=_.concat,Q=D.hasOwnProperty,G=_.push,Y=D.propertyIsEnumerable,Z=_.slice,et=D.toString,tt=W.test(tt=Z.bind)&&tt,nt=Math.floor,rt=W.test(rt=Array -.isArray)&&rt,it=e.isFinite,st=W.test(st=Object.keys)&&st,ot=Math.max,ut=Math.min,at=Math.random,ft="[object Arguments]",lt="[object Array]",ct="[object Boolean]",ht="[object Date]",pt="[object Number]",dt="[object Object]",vt="[object RegExp]",mt="[object String]",gt=e.clearTimeout,yt=e.setTimeout,bt,wt,Et,St=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in arguments)St=!r;bt=4>(n+"").length,Et="x"!=n[0],wt=(n.splice.call -(t,0,1),t[0])})(1);var xt=!v(arguments),Tt="x"!=Z.call("x")[0],Nt="xx"!="x"[0]+Object("x")[0];try{var Ct=("[object Object]",et.call(e.document||0)==dt)}catch(kt){}var Lt=tt&&/\n|Opera/.test(tt+et.call(e.opera)),At=st&&/^.+$|true/.test(st+!!e.attachEvent),Ot=!Lt,Mt={};Mt[ct]=Mt[ht]=Mt["[object Function]"]=Mt[pt]=Mt[dt]=Mt[vt]=i,Mt[ft]=Mt[lt]=Mt[mt]=n;var _t={};_t[ft]=_t["[object Function]"]=i,_t[lt]=_t[ct]=_t[ht]=_t[pt]=_t[dt]=_t[vt]=_t[mt]=n;var Dt={"&":"&","<":"<",">":">",'"':""","'" -:"'"},Pt={"&":"&","<":"<",">":">",""":'"',"'":"'"},Ht={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Bt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var jt={a:"e,d,y",i:"e",p:"if(!d){d=i}else if(y!==A){d=c(d,y)}",h:"if(d(B,j,e)===false)return u"},Ft={i:"{}",p:"if(typeof d!='function'){d=dd(d)}else if(y!==A){d=c(d,y)}" -,h:"var q=d(B,j,e);(h.call(u,q)?u[q]++:u[q]=1)"},It={i:"true",h:"if(!d(B,j,e))return!u"},qt={q:i,r:i,a:"n",i:"n",p:"for(var a=1,b=arguments.length;an?ot(0,i+n):n)-1}for(;++rs&&(s=r,i=e[u]);return i}function N(e,t,n){return Z.call(e,t==r||n?1:t)}function C(e,n,r,i +){var s=0,o=e.length;r?"function"!=typeof r?r=p(r):i!==t&&(r=L(r,i)):r=A;for(n=r(n);s>>1,r(e[i])x(l,s))l.push(s),f.push(e[u]);return f}function L(e,t){return Lt||tt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,F=/&(?:amp|lt|gt|quot|#x27);/g,I=/\b__p\+='';/g,q=/\b(__p\+=)''\+/g,R=/(__e\(.*?\)|\b__t\))\+'';/g +,U=/\w*$/,z=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,W=RegExp("^"+(D.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),X=/($^)/,V=/[&<>"']/g,$=/['\n\r\t\u2028\u2029\\]/g,J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),K=_.concat,Q=D.hasOwnProperty,G=_.push,Y=D.propertyIsEnumerable,Z=_.slice,et=D.toString,tt=W.test(tt=Z.bind)&&tt,nt=Math.floor,rt=W.test(rt=Array.isArray)&&rt,it=e.isFinite,st= +W.test(st=Object.keys)&&st,ot=Math.max,ut=Math.min,at=Math.random,ft="[object Arguments]",lt="[object Array]",ct="[object Boolean]",ht="[object Date]",pt="[object Number]",dt="[object Object]",vt="[object RegExp]",mt="[object String]",gt=e.clearTimeout,yt=e.setTimeout,bt,wt,Et,St=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in arguments)St=!r;bt=4>(n+"").length,Et="x"!=n[0],wt=(n.splice.call(t,0,1),t[0])})(1);var xt=!v(arguments +),Tt="x"!=Z.call("x")[0],Nt="xx"!="x"[0]+Object("x")[0];try{var Ct=("[object Object]",et.call(e.document||0)==dt)}catch(kt){}var Lt=tt&&/\n|Opera/.test(tt+et.call(e.opera)),At=st&&/^.+$|true/.test(st+!!e.attachEvent),Ot=!Lt,Mt={};Mt[ct]=Mt[ht]=Mt["[object Function]"]=Mt[pt]=Mt[dt]=Mt[vt]=i,Mt[ft]=Mt[lt]=Mt[mt]=n;var _t={};_t[ft]=_t["[object Function]"]=i,_t[lt]=_t[ct]=_t[ht]=_t[pt]=_t[dt]=_t[vt]=_t[mt]=n;var Dt={"&":"&","<":"<",">":">",'"':""","'":"'"},Pt={"&":"&","<":"<" +,">":">",""":'"',"'":"'"},Ht={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Bt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var jt={a:"e,d,y",i:"e",p:"if(!d){d=i}else if(y!==A){d=c(d,y)}",h:"if(d(B,j,e)===false)return u"},Ft={i:"{}",p:"if(typeof d!='function'){d=dd(d)}else if(y!==A){d=c(d,y)}",h:"var q=d(B,j,e);(h.call(u,q)?u[q]++:u[q]=1)" +},It={i:"true",h:"if(!d(B,j,e))return!u"},qt={q:i,r:i,a:"n",i:"n",p:"for(var a=1,b=arguments.length;a-1"},h:"if(B===jj)return true"}),ln=l(jt,Ft),cn=l(jt,It),hn=l(jt,Rt),pn=l(jt,Ut,{i:"",h:"if(d(B,j,e))return B"}),dn=l(jt,Ut),vn=l(jt,Ft,{h:"var q=d(B,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(B)" }),mn=l(Wt,{a:"e,V",p:"var D=w.call(arguments,2),S=typeof V=='function'",h:{b:"u[j]=(S?V:B[V]).apply(B,D)",k:"u"+(At?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),gn=l(jt,Wt),yn=l(Wt,{a:"e,cc",h:{b:"u[j]=B[cc]",k:"u"+(At?"[o]=":".push")+"(B[cc])"}}),bn=l({a:"e,d,C,y",i:"C",p:"var W=arguments.length<3;if(y!==A)d=c(d,y)",d:{b:"if(W)u=k[++j]"},h:{b:"u=d(u,B,j,e)",k:"u=W?(W=false,B):d(u,B,j,e)"}}),wn=l(jt,Rt,{h:"!"+Rt.h}),En=l(jt,It,{i:"false",h:It.h.replace("!","")}),Sn=l(jt,Ft,Wt,{h:{b:"u[j]={a:d(B,j,e),b:j,c:B}" ,k:"u"+(At?"[o]=":".push")+"({a:d(B,j,e),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--){u[l]=u[l].c}"}),xn=l(Rt,{a:"e,bb",p:"var t=[];K(bb,function(B,q){t.push(q)});var ee=t.length",h:"for(var q,aa=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply @@ -28,12 +28,12 @@ h:"if(T(B))u.push(j)",e:"u.sort()"}),en=l({a:"n",i:"{}",h:"u[B]=j"}),tn=l({a:"B" e.apply(u,s)),o}},s.defaults=Kt,s.defer=function(e){var n=Z.call(arguments,1);return yt(function(){return e.apply(t,n)},1)},s.delay=function(e,n){var r=Z.call(arguments,2);return yt(function(){return e.apply(t,r)},n)},s.difference=function(e){for(var t=-1,n=e.length,r=K.apply(_,arguments),r=u(r,n),i=[];++tx(o,t)){for(var a=1;an?ot(0,r+n):ut(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return f(t,e,Z.call(arguments,2))},s.map=gn,s.max=T,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Q.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=rn,s.min=function(e,n,r){var i=Infinity,s=i;if(!e)return s -;var u=-1,a=e.length;for(n?r!==t&&(n=o(n,r)):n=A;++u=f?(a=r,s=e.apply(o,i)):u||(u=yt(n,f)),s}},s.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rx(r,t[e])&&r.push(t[e]);return r},s.uniq=k,s.uniqueId=function(e){var t=P++;return e?e+t:t},s.values=an,s.where=xn,s.without=function(e){for(var t=-1,n=e.length,r=u(arguments,1,20),i=[];++tn?ot(0,r+n):ut(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return f(t,e,Z.call(arguments,2))},s.map=gn,s.max=T,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Q.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=rn,s.min=function(e,n,r){var i,s=Infinity,u=-1,a=e?e.length +:0;for(n?r!==t&&(n=o(n,r)):n=A;++u=f?(a=r,s=e.apply(o,i)):u||(u=yt(n,f)),s}},s.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rx(r,t[e])&&r.push(t[e]);return r +},s.uniq=k,s.uniqueId=function(e){var t=P++;return e?e+t:t},s.values=an,s.where=xn,s.without=function(e){for(var t=-1,n=e.length,r=u(arguments,1,20),i=[];++t Date: Sat, 29 Sep 2012 00:17:27 -0700 Subject: [PATCH 56/82] Fix perf.js. Former-commit-id: 4eef40ddbcb851aca3a87813a17dc329f9ecb071 --- perf/perf.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/perf/perf.js b/perf/perf.js index 399548cb95..bf8212b7ad 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -835,13 +835,13 @@ ); suites.push( - Benchmark.Suite('`_.intersection` iterating 50 elements') + Benchmark.Suite('`_.intersection` iterating 50 and 75 elements') .add('Lo-Dash', { - 'fn': 'lodash.intersection(fiftyValues, fiftyValues2)', + 'fn': 'lodash.intersection(fiftyValues, seventyFiveValues2)', 'teardown': 'function multiArrays(){}' }) .add('Underscore', { - 'fn': '_.intersection(fiftyValues, fiftyValues2)', + 'fn': '_.intersection(fiftyValues, seventyFiveValues2)', 'teardown': 'function multiArrays(){}' }) ); @@ -1511,13 +1511,13 @@ ); suites.push( - Benchmark.Suite('`_.without` iterating an array of 50 elements') + Benchmark.Suite('`_.without` iterating an array of 75 and 50 elements') .add('Lo-Dash', { - 'fn': 'lodash.without.apply(lodash, [fiftyValues].concat(fiftyValues2));', + 'fn': 'lodash.without.apply(lodash, [seventyFiveValues2].concat(fiftyValues));', 'teardown': 'function multiArrays(){}' }) .add('Underscore', { - 'fn': '_.without.apply(_, [fiftyValues].concat(fiftyValues2));', + 'fn': '_.without.apply(_, [seventyFiveValues2].concat(fiftyValues));', 'teardown': 'function multiArrays(){}' }) ); From 40cf5c99ef7197b06b794e7f5f907373eb30ac2a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 29 Sep 2012 03:13:45 -0700 Subject: [PATCH 57/82] Update reduce repeated code. Former-commit-id: 3412cde47a136dab5c241c67d1c29f2e676c38d1 --- build.js | 2 +- build/pre-compile.js | 4 +- doc/README.md | 267 ++++++++++++++++++++++--------------------- lodash.js | 187 ++++++++++++++---------------- lodash.min.js | 66 +++++------ 5 files changed, 254 insertions(+), 272 deletions(-) diff --git a/build.js b/build.js index 2b7173a0f3..2a8873bc44 100755 --- a/build.js +++ b/build.js @@ -142,7 +142,7 @@ 'size': ['keys'], 'some': ['identity'], 'sortBy': [], - 'sortedIndex': ['bind', 'identity'], + 'sortedIndex': ['identity'], 'tap': ['mixin'], 'template': ['escape'], 'throttle': [], diff --git a/build/pre-compile.js b/build/pre-compile.js index 032ea865e0..f2bcffd9c7 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -9,10 +9,10 @@ var compiledVars = [ 'argsIndex', 'argsLength', - 'bindCallback', 'callback', 'collection', 'concat', + 'createCallback', 'ctor', 'hasOwnProperty', 'identity', @@ -64,7 +64,6 @@ 'pass', 'properties', 'property', - 'propertyCallback', 'propsLength', 'source', 'stackA', @@ -105,7 +104,6 @@ var propWhitelist = [ '_', '__chain__', - '__proto__', '__wrapped__', 'after', 'all', diff --git a/doc/README.md b/doc/README.md index 8437a06ce2..9f71d8bcd3 100644 --- a/doc/README.md +++ b/doc/README.md @@ -100,7 +100,7 @@ * [`_.size`](#_sizecollection) * [`_.some`](#_somecollection--callbackidentity-thisarg) * [`_.sortBy`](#_sortbycollection-callbackproperty--thisarg) -* [`_.sortedIndex`](#_sortedindexarray-value--callbackidentity-thisarg) +* [`_.sortedIndex`](#_sortedindexarray-value--callbackidentityproperty-thisarg) * [`_.tail`](#_restarray--n) * [`_.take`](#_firstarray--n) * [`_.tap`](#_tapvalue-interceptor) @@ -156,7 +156,7 @@ ### `_(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L265 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L266 "View in source") [Ⓣ][1] The `lodash` function. @@ -174,7 +174,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4017 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3998 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -186,7 +186,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3125 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3106 "View in source") [Ⓣ][1] Creates a function that is restricted to executing only after it is called `n` times. @@ -214,7 +214,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3158 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3139 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. @@ -245,7 +245,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3188 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3169 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -276,7 +276,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3942 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3923 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -310,7 +310,7 @@ var youngest = _.chain(stooges) ### `_.clone(value, deep)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1035 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1029 "View in source") [Ⓣ][1] Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned. @@ -349,7 +349,7 @@ shallow[0] === stooges[0]; ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2424 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2418 "View in source") [Ⓣ][1] Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -373,7 +373,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3225 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3206 "View in source") [Ⓣ][1] Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -400,7 +400,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1906 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1900 "View in source") [Ⓣ][1] Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -434,14 +434,14 @@ _.contains('curly', 'ur'); ### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1942 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1936 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `callback|property` *(Function|String)*: The function called per iteration or property name to count by. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Object)*: Returns the composed aggregate object. @@ -466,7 +466,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3258 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3239 "View in source") [Ⓣ][1] Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -492,7 +492,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1128 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1122 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -518,7 +518,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3323 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3304 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -543,7 +543,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3303 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3284 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -570,7 +570,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2453 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2447 "View in source") [Ⓣ][1] Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -595,7 +595,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3542 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3523 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -619,7 +619,7 @@ _.escape('Moe, Larry & Curly'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1963 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1957 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -629,7 +629,7 @@ Checks if the `callback` returns a truthy value for **all** elements of a `colle #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `[callback=identity]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Boolean)*: Returns `true` if all elements pass the callback check, else `false`. @@ -648,7 +648,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1148 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1142 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -673,7 +673,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1983 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1977 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -683,7 +683,7 @@ Examines each element in a `collection`, returning an array of all elements the #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `[callback=identity]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Array)*: Returns a new array of elements that passed the callback check. @@ -702,7 +702,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2005 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1999 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -712,7 +712,7 @@ Examines each element in a `collection`, returning the first one the `callback` #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `callback` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Mixed)*: Returns the element that passed the callback check, else `undefined`. @@ -731,7 +731,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2487 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2481 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -759,7 +759,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2509 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2503 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -787,7 +787,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2032 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2026 "View in source") [Ⓣ][1] Iterates over a `collection`, 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`. @@ -797,7 +797,7 @@ Iterates over a `collection`, executing the `callback` for each element in the ` #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `callback` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Array, Object, String)*: Returns `collection`. @@ -819,14 +819,14 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1178 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1172 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, 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`. #### Arguments 1. `object` *(Object)*: The object to iterate over. 2. `callback` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Object)*: Returns `object`. @@ -855,14 +855,14 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1202 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1196 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, 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`. #### Arguments 1. `object` *(Object)*: The object to iterate over. 2. `callback` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Object)*: Returns `object`. @@ -883,7 +883,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1219 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1213 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -910,14 +910,14 @@ _.functions(_); ### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2060 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2054 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `callback|property` *(Function|String)*: The function called per iteration or property name to group by. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Object)*: Returns the composed aggregate object. @@ -942,7 +942,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1242 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1236 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -967,7 +967,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3562 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3543 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -992,7 +992,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2552 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2546 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1024,7 +1024,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2589 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2583 "View in source") [Ⓣ][1] Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. @@ -1049,7 +1049,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2608 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2602 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -1073,7 +1073,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invert(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1259 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1253 "View in source") [Ⓣ][1] Creates an object composed of the inverted keys and values of the given `object`. @@ -1097,7 +1097,7 @@ _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2088 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2082 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`, returning an array of the results of each invoked method. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1126,7 +1126,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L851 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L845 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1153,7 +1153,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L877 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L871 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1180,7 +1180,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1278 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1272 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1204,7 +1204,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1295 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1289 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1228,7 +1228,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1312 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1306 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1252,7 +1252,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1337 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1331 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1282,7 +1282,7 @@ _.isEmpty(''); ### `_.isEqual(a, b)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1377 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1371 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1313,7 +1313,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1534 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1528 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1343,7 +1343,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L894 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L888 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1367,7 +1367,7 @@ _.isFunction(_); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1592 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1586 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1400,7 +1400,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1615 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1609 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1427,7 +1427,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1632 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1626 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1451,7 +1451,7 @@ _.isNumber(8.4 * 5); ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1558 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1552 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -1481,7 +1481,7 @@ _.isObject(1); ### `_.isPlainObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L928 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L922 "View in source") [Ⓣ][1] Checks if a given `value` is an object created by the `Object` constructor. @@ -1516,7 +1516,7 @@ _.isPlainObject({ 'name': 'moe', 'age': 40 }); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1649 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1643 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1540,7 +1540,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1666 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1660 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1564,7 +1564,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1684 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1678 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1588,7 +1588,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1701 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1695 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of `object`. @@ -1612,7 +1612,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2648 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2642 "View in source") [Ⓣ][1] Gets the last element of the `array`. Pass `n` to return the last `n` elements of the `array`. @@ -1637,7 +1637,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2672 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2666 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1666,7 +1666,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.lateBind(object, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3360 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3341 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method @@ -1707,7 +1707,7 @@ func(); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2123 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2117 "View in source") [Ⓣ][1] Creates an array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1717,7 +1717,7 @@ Creates an array of values by running each element in the `collection` through a #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `[callback=identity]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Array)*: Returns a new array of the results of each `callback` execution. @@ -1739,14 +1739,14 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2709 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2703 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. #### Arguments 1. `array` *(Array)*: The array to iterate over. 2. `[callback]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Mixed)*: Returns the maximum value. @@ -1771,7 +1771,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3382 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3363 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1797,7 +1797,7 @@ var fibonacci = _.memoize(function(n) { ### `_.merge(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1742 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1736 "View in source") [Ⓣ][1] Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -1832,14 +1832,14 @@ _.merge(stooges, ages); ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2749 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2739 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. #### Arguments 1. `array` *(Array)*: The array to iterate over. 2. `[callback]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Mixed)*: Returns the minimum value. @@ -1858,7 +1858,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3588 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3569 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1888,7 +1888,7 @@ _('curly').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3619 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3600 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1908,7 +1908,7 @@ var lodash = _.noConflict(); ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2788 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2774 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. @@ -1933,14 +1933,14 @@ _.object(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1799 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1793 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. #### Arguments 1. `object` *(Object)*: The source object. 2. `callback|[prop1, prop2, ...]` *(Function|String)*: The properties to omit or the function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Object)*: Returns an object without the omitted properties. @@ -1964,7 +1964,7 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3408 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3389 "View in source") [Ⓣ][1] Creates a function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1990,7 +1990,7 @@ initialize(); ### `_.pairs(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1815 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1809 "View in source") [Ⓣ][1] Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. @@ -2014,7 +2014,7 @@ _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3443 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3424 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `bind`, except it does **not** alter the `this` binding. @@ -2041,14 +2041,14 @@ hi('moe'); ### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1846 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1840 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, picking the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. #### Arguments 1. `object` *(Object)*: The source object. 2. `callback|[prop1, prop2, ...]` *(Function|String)*: The properties to pick or the function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Object)*: Returns an object composed of the picked properties. @@ -2072,7 +2072,7 @@ _.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2146 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2140 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -2103,7 +2103,7 @@ _.pluck(stooges, 'name'); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3642 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3623 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -2131,7 +2131,7 @@ _.random(5); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2832 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2818 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -2169,7 +2169,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2174 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2168 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -2180,7 +2180,7 @@ Boils down a `collection` to a single value. The initial state of the reduction 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `callback` *(Function)*: The function called per iteration. 3. `[accumulator]` *(Mixed)*: Initial value of the accumulator. -4. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Mixed)*: Returns the accumulated value. @@ -2199,7 +2199,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2211 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2205 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -2210,7 +2210,7 @@ The right-associative version of `_.reduce`. 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `callback` *(Function)*: The function called per iteration. 3. `[accumulator]` *(Mixed)*: Initial value of the accumulator. -4. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Mixed)*: Returns the accumulated value. @@ -2230,14 +2230,14 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2248 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2242 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `[callback=identity]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Array)*: Returns a new array of elements that did **not** pass the callback check. @@ -2256,7 +2256,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2871 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2857 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2284,7 +2284,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3681 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3662 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2319,7 +2319,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2889 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2875 "View in source") [Ⓣ][1] Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2343,7 +2343,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2272 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2266 "View in source") [Ⓣ][1] Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. @@ -2373,7 +2373,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2297 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2291 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2383,7 +2383,7 @@ Checks if the `callback` returns a truthy value for **any** element of a `collec #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `[callback=identity]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Boolean)*: Returns `true` if any element passes the callback check, else `false`. @@ -2402,14 +2402,14 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2327 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2321 "View in source") [Ⓣ][1] Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `callback|property` *(Function|String)*: The function called per iteration or property name to sort by. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Array)*: Returns a new array of sorted elements. @@ -2433,35 +2433,38 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); -### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2938 "View in source") [Ⓣ][1] +### `_.sortedIndex(array, value [, callback=identity|property, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2929 "View in source") [Ⓣ][1] -Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. +Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. The `callback` argument may also be the name of a property to order by. #### Arguments 1. `array` *(Array)*: The array to iterate over. 2. `value` *(Mixed)*: The value to evaluate. -3. `[callback=identity]` *(Function)*: The function called per iteration. -4. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[callback=identity|property]` *(Function|String)*: The function called per iteration or property name to order by. +4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Number)*: Returns the index at which the value should be inserted into `array`. #### Example ```js -_.sortedIndex([20, 30, 40], 35); +_.sortedIndex([20, 30, 50], 40); +// => 2 + +_.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); // => 2 var dict = { - 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'thirty-five': 35, 'fourty': 40 } + 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } }; -_.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { +_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { return dict.wordToNumber[word]; }); // => 2 -_.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { +_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { return this.wordToNumber[word]; }, dict); // => 2 @@ -2475,7 +2478,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3969 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3950 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2505,7 +2508,7 @@ _.chain([1, 2, 3, 200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3751 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3732 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: In the development build `_.template` utilizes sourceURLs for easier debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. See http://developer.chrome.com/trunk/extensions/sandboxingEval.html @@ -2570,7 +2573,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3465 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3446 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2595,14 +2598,14 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3869 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3850 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. #### Arguments 1. `n` *(Number)*: The number of times to execute the callback. 2. `callback` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Array)*: Returns a new array of the results of each `callback` execution. @@ -2627,7 +2630,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2363 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2357 "View in source") [Ⓣ][1] Converts the `collection`, to an array. @@ -2651,7 +2654,7 @@ Converts the `collection`, to an array. ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3894 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3875 "View in source") [Ⓣ][1] Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -2675,7 +2678,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2973 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2958 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -2699,7 +2702,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3017 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3002 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -2710,7 +2713,7 @@ Creates a duplicate-value-free version of the `array` using strict equality for 1. `array` *(Array)*: The array to process. 2. `[isSorted=false]` *(Boolean)*: A flag to indicate that the `array` is already sorted. 3. `[callback=identity]` *(Function)*: The function called per iteration. -4. `[thisArg]` *(Mixed)*: The `this` binding for the callback. +4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns *(Array)*: Returns a duplicate-value-free array. @@ -2738,7 +2741,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3912 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3893 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2762,7 +2765,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1876 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1870 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2786,7 +2789,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2394 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2388 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. @@ -2817,7 +2820,7 @@ _.where(stooges, { 'age': 40 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3063 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3044 "View in source") [Ⓣ][1] Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2842,7 +2845,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3516 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3497 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2871,7 +2874,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3093 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3074 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2902,7 +2905,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3987 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3968 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2923,7 +2926,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4004 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3985 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -2951,7 +2954,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L286 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L287 "View in source") [Ⓣ][1] *(Object)*: By default, the template delimiters used by Lo-Dash are similar to those in embedded Ruby *(ERB)*. Change the following template settings to use alternative delimiters. @@ -2963,7 +2966,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.escape` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L295 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L296 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to be HTML-escaped. @@ -2975,7 +2978,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.evaluate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L304 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L305 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect code to be evaluated. @@ -2987,7 +2990,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.interpolate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L313 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L314 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to inject. @@ -2999,7 +3002,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.variable` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L322 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L323 "View in source") [Ⓣ][1] *(String)*: Used to reference the data object in the template text. diff --git a/lodash.js b/lodash.js index 2ec7223a56..0d7003cf3f 100644 --- a/lodash.js +++ b/lodash.js @@ -81,6 +81,7 @@ /* Native method shortcuts for methods with the same name as other `lodash` methods */ var nativeBind = reNative.test(nativeBind = slice.bind) && nativeBind, nativeFloor = Math.floor, + nativeGetPrototypeOf = reNative.test(nativeGetPrototypeOf = Object.getPrototypeOf) && nativeGetPrototypeOf, nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray, nativeIsFinite = window.isFinite, nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys, @@ -452,24 +453,14 @@ var baseIteratorOptions = { 'args': 'collection, callback, thisArg', 'init': 'collection', - 'top': - 'if (!callback) {\n' + - ' callback = identity\n' + - '} else if (thisArg !== undefined) {\n' + - ' callback = bindCallback(callback, thisArg)\n' + - '}', + 'top': 'callback = createCallback(callback, thisArg)', 'inLoop': 'if (callback(value, index, collection) === false) return result' }; /** Reusable iterator options for `countBy`, `groupBy`, and `sortBy` */ var countByIteratorOptions = { 'init': '{}', - 'top': - 'if (typeof callback != \'function\') {\n' + - ' callback = propertyCallback(callback)\n' + - '} else if (thisArg !== undefined) {\n' + - ' callback = bindCallback(callback, thisArg)\n' + - '}', + 'top': 'callback = createCallback(callback, thisArg)', 'inLoop': 'var prop = callback(value, index, collection);\n' + '(hasOwnProperty.call(result, prop) ? result[prop]++ : result[prop] = 1)' @@ -502,7 +493,7 @@ /** Reusable iterator options for `find`, `forEach`, `forIn`, and `forOwn` */ var forEachIteratorOptions = { - 'top': 'if (thisArg !== undefined) callback = bindCallback(callback, thisArg)' + 'top': 'callback = createCallback(callback, thisArg)' }; /** Reusable iterator options for `forIn` and `forOwn` */ @@ -532,11 +523,8 @@ 'init': '{}', 'top': 'var isFunc = typeof callback == \'function\';\n' + - 'if (!isFunc) {\n' + - ' var props = concat.apply(ArrayProto, arguments)\n' + - '} else if (thisArg !== undefined) {\n' + - ' callback = bindCallback(callback, thisArg)\n' + - '}', + 'callback = createCallback(callback, thisArg);\n' + + 'if (!isFunc) var props = concat.apply(ArrayProto, arguments)', 'inLoop': 'if (isFunc\n' + ' ? !callback(value, index, object)\n' + @@ -546,21 +534,6 @@ /*--------------------------------------------------------------------------*/ - /** - * Creates a bound iterator function that, when called, invokes `func` with - * the `this` binding of `thisArg` and the arguments (value, index, object). - * - * @private - * @param {Function} func The function to bind. - * @param {Mixed} [thisArg] The `this` binding of `func`. - * @returns {Function} Returns the new bound function. - */ - function bindCallback(func, thisArg) { - return function(value, index, object) { - return func.call(thisArg, value, index, object); - }; - } - /** * Creates a function optimized for searching large arrays for a given `value`, * starting at `fromIndex`, using strict equality for comparisons, i.e. `===`. @@ -681,6 +654,31 @@ return bound; } + /** + * Produces an iteration callback bound to an optional `thisArg`. If `func` is + * a property name, the callback will return the property value for a given element. + * + * @private + * @param {Function|String} [func=identity|property] The function called per + * iteration or property name to query. + * @param {Mixed} [thisArg] The `this` binding of `callback`. + * @returns {Function} Returns a callback function. + */ + function createCallback(func, thisArg) { + if (!func) { + return identity; + } else if (typeof func != 'function') { + return function(object) { + return object[func]; + } + } else if (thisArg !== undefined) { + return function(value, index, object) { + return func.call(thisArg, value, index, object); + }; + } + return func; + } + /** * Creates compiled iteration functions. The iteration function will be created * to iterate over only objects if the first argument of `options.args` is @@ -767,19 +765,19 @@ } // create the function factory var factory = Function( - 'arrayLikeClasses, ArrayProto, bind, bindCallback, compareAscending, concat, ' + + 'arrayLikeClasses, ArrayProto, bind, compareAscending, concat, createCallback, ' + 'forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, ' + 'isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, ' + - 'propertyCallback, slice, stringClass, toString, undefined', + 'slice, stringClass, toString, undefined', 'var callee = function(' + args + ') {\n' + iteratorTemplate(data) + '\n};\n' + 'return callee' ); // return the compiled function return factory( - arrayLikeClasses, ArrayProto, bind, bindCallback, compareAscending, concat, + arrayLikeClasses, ArrayProto, bind, compareAscending, concat, createCallback, forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, - propertyCallback, slice, stringClass, toString + slice, stringClass, toString ); } @@ -807,16 +805,12 @@ } /** - * Creates a function that returns the `property` value of the given `object`. + * A no-operation function. * * @private - * @param {String} property The property to get the value of. - * @returns {Function} Returns the new function. */ - function propertyCallback(property) { - return function(object) { - return object[property]; - }; + function noop() { + // no operation performed } /** @@ -925,15 +919,15 @@ * _.isPlainObject({ 'name': 'moe', 'age': 40 }); * // => true */ - var isPlainObject = objectTypes.__proto__ != ObjectProto ? isPlainFallback : function(value) { - if (!value) { + var isPlainObject = !nativeGetPrototypeOf ? isPlainFallback : function(value) { + if (!(value && typeof value == 'object')) { return false; } var valueOf = value.valueOf, - objProto = typeof valueOf == 'function' && (objProto = valueOf.__proto__) && objProto.__proto__; + objProto = typeof valueOf == 'function' && (objProto = nativeGetPrototypeOf(valueOf)) && nativeGetPrototypeOf(objProto); return objProto - ? value == objProto || (value.__proto__ == objProto && !isArguments(value)) + ? value == objProto || (nativeGetPrototypeOf(value) == objProto && !isArguments(value)) : isPlainFallback(value); }; @@ -1158,7 +1152,7 @@ * @category Objects * @param {Object} object The object to iterate over. * @param {Function} callback The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns `object`. * @example * @@ -1190,7 +1184,7 @@ * @category Objects * @param {Object} object The object to iterate over. * @param {Function} callback The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns `object`. * @example * @@ -1784,7 +1778,7 @@ * @param {Object} object The source object. * @param {Function|String} callback|[prop1, prop2, ...] The properties to omit * or the function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns an object without the omitted properties. * @example * @@ -1831,7 +1825,7 @@ * @param {Object} object The source object. * @param {Function|String} callback|[prop1, prop2, ...] The properties to pick * or the function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns an object composed of the picked properties. * @example * @@ -1854,7 +1848,7 @@ ' if (prop in object) result[prop] = object[prop]\n' + ' }\n' + '} else {\n' + - ' if (thisArg !== undefined) callback = bindCallback(callback, thisArg)', + ' callback = createCallback(callback, thisArg)', 'inLoop': 'if (callback(value, index, object)) result[index] = value', 'bottom': '}' @@ -1926,7 +1920,7 @@ * @param {Array|Object|String} collection The collection to iterate over. * @param {Function|String} callback|property The function called per iteration * or property name to count by. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns the composed aggregate object. * @example * @@ -1952,7 +1946,7 @@ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Function} [callback=identity] The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Boolean} Returns `true` if all elements pass the callback check, * else `false`. * @example @@ -1973,7 +1967,7 @@ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Function} [callback=identity] The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of elements that passed the callback check. * @example * @@ -1994,7 +1988,7 @@ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Function} callback The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the element that passed the callback check, * else `undefined`. * @example @@ -2019,7 +2013,7 @@ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Function} callback The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array|Object|String} Returns `collection`. * @example * @@ -2044,7 +2038,7 @@ * @param {Array|Object|String} collection The collection to iterate over. * @param {Function|String} callback|property The function called per iteration * or property name to group by. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns the composed aggregate object. * @example * @@ -2110,7 +2104,7 @@ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Function} [callback=identity] The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of the results of each `callback` execution. * @example * @@ -2164,7 +2158,7 @@ * @param {Array|Object|String} collection The collection to iterate over. * @param {Function} callback The function called per iteration. * @param {Mixed} [accumulator] Initial value of the accumulator. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the accumulated value. * @example * @@ -2176,7 +2170,7 @@ 'init': 'accumulator', 'top': 'var noaccum = arguments.length < 3;\n' + - 'if (thisArg !== undefined) callback = bindCallback(callback, thisArg)', + 'callback = createCallback(callback, thisArg)', 'beforeLoop': { 'array': 'if (noaccum) result = iteratee[++index]' }, @@ -2200,7 +2194,7 @@ * @param {Array|Object|String} collection The collection to iterate over. * @param {Function} callback The function called per iteration. * @param {Mixed} [accumulator] Initial value of the accumulator. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the accumulated value. * @example * @@ -2237,7 +2231,7 @@ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Function} [callback=identity] The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of elements that did **not** pass the * callback check. * @example @@ -2286,7 +2280,7 @@ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Function} [callback=identity] The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Boolean} Returns `true` if any element passes the callback check, * else `false`. * @example @@ -2311,7 +2305,7 @@ * @param {Array|Object|String} collection The collection to iterate over. * @param {Function|String} callback|property The function called per iteration * or property name to sort by. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of sorted elements. * @example * @@ -2693,7 +2687,7 @@ * @category Arrays * @param {Array} array The array to iterate over. * @param {Function} [callback] The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the maximum value. * @example * @@ -2708,16 +2702,12 @@ */ function max(array, callback, thisArg) { var current, - result, computed = -Infinity, index = -1, - length = array ? array.length : 0; + length = array ? array.length : 0, + result = computed; - if (!callback) { - callback = identity; - } else if (thisArg !== undefined) { - callback = bindCallback(callback, thisArg); - } + callback = createCallback(callback, thisArg); while (++index < length) { current = callback(array[index], index, array); if (current > computed) { @@ -2739,7 +2729,7 @@ * @category Arrays * @param {Array} array The array to iterate over. * @param {Function} [callback] The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the minimum value. * @example * @@ -2748,16 +2738,12 @@ */ function min(array, callback, thisArg) { var current, - result, computed = Infinity, index = -1, - length = array ? array.length : 0; + length = array ? array.length : 0, + result = computed; - if (!callback) { - callback = identity; - } else if (thisArg !== undefined) { - callback = bindCallback(callback, thisArg); - } + callback = createCallback(callback, thisArg); while (++index < length) { current = callback(array[index], index, array); if (current < computed) { @@ -2905,32 +2891,37 @@ * should be inserted into `array` in order to maintain the sort order of the * sorted `array`. If `callback` is passed, it will be executed for `value` and * each element in `array` to compute their sort ranking. The `callback` is - * bound to `thisArg` and invoked with one argument; (value). + * bound to `thisArg` and invoked with one argument; (value). The `callback` + * argument may also be the name of a property to order by. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to iterate over. * @param {Mixed} value The value to evaluate. - * @param {Function} [callback=identity] The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Function|String} [callback=identity|property] The function called + * per iteration or property name to order by. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Number} Returns the index at which the value should be inserted * into `array`. * @example * - * _.sortedIndex([20, 30, 40], 35); + * _.sortedIndex([20, 30, 50], 40); + * // => 2 + * + * _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); * // => 2 * * var dict = { - * 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'thirty-five': 35, 'fourty': 40 } + * 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } * }; * - * _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { + * _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { * return dict.wordToNumber[word]; * }); * // => 2 * - * _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { + * _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { * return this.wordToNumber[word]; * }, dict); * // => 2 @@ -2940,13 +2931,7 @@ low = 0, high = array.length; - if (!callback) { - callback = identity; - } else if (typeof callback != 'function') { - callback = propertyCallback(callback); - } else if (thisArg !== undefined) { - callback = bind(callback, thisArg); - } + callback = createCallback(callback, thisArg); value = callback(value); while (low < high) { mid = (low + high) >>> 1; @@ -2998,7 +2983,7 @@ * @param {Array} array The array to process. * @param {Boolean} [isSorted=false] A flag to indicate that the `array` is already sorted. * @param {Function} [callback=identity] The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a duplicate-value-free array. * @example * @@ -3027,11 +3012,7 @@ callback = isSorted; isSorted = false; } - if (!callback) { - callback = identity; - } else if (thisArg !== undefined) { - callback = bindCallback(callback, thisArg); - } + callback = createCallback(callback, thisArg); while (++index < length) { computed = callback(array[index], index, array); if (isSorted @@ -3853,7 +3834,7 @@ * @category Utilities * @param {Number} n The number of times to execute the callback. * @param {Function} callback The function called per iteration. - * @param {Mixed} [thisArg] The `this` binding for the callback. + * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of the results of each `callback` execution. * @example * diff --git a/lodash.min.js b/lodash.min.js index 82cb65baf1..cf4f0f4461 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -2,38 +2,38 @@ Lo-Dash 0.7.0 lodash.com/license Underscore.js 1.4.0 underscorejs.org/LICENSE */ -;(function(e,t){function s(e){if(e&&e.__wrapped__)return e;if(!(this instanceof s))return new s(e);this.__wrapped__=e}function o(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function u(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||H),s=i?{}:e;if(i)for(var o=t-1;++on||e===t)return 1;if(en;n++)t+="j='"+f.o[n]+"';if(","constructor"== -f.o[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){B=k[j];"+f.l.h+"}"}if(f.c||f.m)t+="}"}return t+=f.e+";return u",Function("E,F,G,c,J,f,K,h,i,N,P,R,T,U,Y,Z,m,r,dd,w,x,z,A","var H=function("+e+"){"+t+"};return H")(Mt,_,L,o,a,K,Gt,Q,A,x,v,Vt,m,$t,dt,Ht,st,Y,p,Z,mt,et)}function c(e){return"\\"+Bt[e]}function h(e){return Dt[e]}function p(e){return function(t){return t[e]}}function d(e){return Pt[e]}function v(e){return et.call(e)==ft}function m(e){return"function"==typeof e}function g(e){var t= -i;if(!e||"object"!=typeof e||v(e))return t;var n=e.constructor;return(!Ct||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!m(n)||n instanceof n)?Et?(Gt(e,function(e,n,r){return t=!Q.call(r,n),i}),t===i):(Gt(e,function(e,n){t=n}),t===i||Q.call(e,t)):t}function y(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=Ht[typeof e]){var a=et.call(e);if(!_t[a]||xt&&v(e))return e;var f=a==lt,s=f||(a==dt?$t(e):s)}if(!s||!t)return s?f?Z.call(e):Qt({},e):e;s=e.constructor;switch(a){case ct:return new s(e==n -);case ht:return new s(+e);case pt:case mt:return new s(e);case vt:return s(e.source,U.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=J[u],Q.call(e,c)&&(!Q.call(t,c)||!b(e[c],t[c],s,o)))return i;return n}function w(e,t,n,r){var s=e,o=e.length,u=3>arguments.length;if(o!==+o)var a=nn(e),o=a.length;else Nt&&et.call(e)==mt&&(s=e.split(""));return dn(e,function(e,f,l){f=a?a[--o]:--o,n=u?(u=i,s[f]):t.call(r,n,s[f],f,l)}),n}function E(e,t -,n){return t==r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n,r=-1,i=e.length,s=[];++rn?ot(0,i+n):n)-1}for(;++rs&&(s=r,i=e[u]);return i}function N(e,t,n){return Z.call(e,t==r||n?1:t)}function C(e,n,r,i -){var s=0,o=e.length;r?"function"!=typeof r?r=p(r):i!==t&&(r=L(r,i)):r=A;for(n=r(n);s>>1,r(e[i])x(l,s))l.push(s),f.push(e[u]);return f}function L(e,t){return Lt||tt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,F=/&(?:amp|lt|gt|quot|#x27);/g,I=/\b__p\+='';/g,q=/\b(__p\+=)''\+/g,R=/(__e\(.*?\)|\b__t\))\+'';/g -,U=/\w*$/,z=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,W=RegExp("^"+(D.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),X=/($^)/,V=/[&<>"']/g,$=/['\n\r\t\u2028\u2029\\]/g,J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),K=_.concat,Q=D.hasOwnProperty,G=_.push,Y=D.propertyIsEnumerable,Z=_.slice,et=D.toString,tt=W.test(tt=Z.bind)&&tt,nt=Math.floor,rt=W.test(rt=Array.isArray)&&rt,it=e.isFinite,st= -W.test(st=Object.keys)&&st,ot=Math.max,ut=Math.min,at=Math.random,ft="[object Arguments]",lt="[object Array]",ct="[object Boolean]",ht="[object Date]",pt="[object Number]",dt="[object Object]",vt="[object RegExp]",mt="[object String]",gt=e.clearTimeout,yt=e.setTimeout,bt,wt,Et,St=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in arguments)St=!r;bt=4>(n+"").length,Et="x"!=n[0],wt=(n.splice.call(t,0,1),t[0])})(1);var xt=!v(arguments -),Tt="x"!=Z.call("x")[0],Nt="xx"!="x"[0]+Object("x")[0];try{var Ct=("[object Object]",et.call(e.document||0)==dt)}catch(kt){}var Lt=tt&&/\n|Opera/.test(tt+et.call(e.opera)),At=st&&/^.+$|true/.test(st+!!e.attachEvent),Ot=!Lt,Mt={};Mt[ct]=Mt[ht]=Mt["[object Function]"]=Mt[pt]=Mt[dt]=Mt[vt]=i,Mt[ft]=Mt[lt]=Mt[mt]=n;var _t={};_t[ft]=_t["[object Function]"]=i,_t[lt]=_t[ct]=_t[ht]=_t[pt]=_t[dt]=_t[vt]=_t[mt]=n;var Dt={"&":"&","<":"<",">":">",'"':""","'":"'"},Pt={"&":"&","<":"<" -,">":">",""":'"',"'":"'"},Ht={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Bt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var jt={a:"e,d,y",i:"e",p:"if(!d){d=i}else if(y!==A){d=c(d,y)}",h:"if(d(B,j,e)===false)return u"},Ft={i:"{}",p:"if(typeof d!='function'){d=dd(d)}else if(y!==A){d=c(d,y)}",h:"var q=d(B,j,e);(h.call(u,q)?u[q]++:u[q]=1)" -},It={i:"true",h:"if(!d(B,j,e))return!u"},qt={q:i,r:i,a:"n",i:"n",p:"for(var a=1,b=arguments.length;a-1"},h:"if(B===jj)return true"}),ln=l(jt,Ft),cn=l(jt,It),hn=l(jt,Rt),pn=l(jt,Ut,{i:"",h:"if(d(B,j,e))return B"}),dn=l(jt,Ut),vn=l(jt,Ft,{h:"var q=d(B,j,e);(h.call(u,q)?u[q]:u[q]=[]).push(B)" -}),mn=l(Wt,{a:"e,V",p:"var D=w.call(arguments,2),S=typeof V=='function'",h:{b:"u[j]=(S?V:B[V]).apply(B,D)",k:"u"+(At?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),gn=l(jt,Wt),yn=l(Wt,{a:"e,cc",h:{b:"u[j]=B[cc]",k:"u"+(At?"[o]=":".push")+"(B[cc])"}}),bn=l({a:"e,d,C,y",i:"C",p:"var W=arguments.length<3;if(y!==A)d=c(d,y)",d:{b:"if(W)u=k[++j]"},h:{b:"u=d(u,B,j,e)",k:"u=W?(W=false,B):d(u,B,j,e)"}}),wn=l(jt,Rt,{h:"!"+Rt.h}),En=l(jt,It,{i:"false",h:It.h.replace("!","")}),Sn=l(jt,Ft,Wt,{h:{b:"u[j]={a:d(B,j,e),b:j,c:B}" -,k:"u"+(At?"[o]=":".push")+"({a:d(B,j,e),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--){u[l]=u[l].c}"}),xn=l(Rt,{a:"e,bb",p:"var t=[];K(bb,function(B,q){t.push(q)});var ee=t.length",h:"for(var q,aa=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply -(this,arguments)}},s.bind=L,s.bindAll=Tn,s.chain=function(e){return e=new s(e),e.__chain__=n,e},s.clone=y,s.compact=function(e){for(var t=-1,n=e.length,r=[];++tx(o,t)){for(var a=1;an?ot(0,r+n):ut(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return f(t,e,Z.call(arguments,2))},s.map=gn,s.max=T,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Q.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=rn,s.min=function(e,n,r){var i,s=Infinity,u=-1,a=e?e.length -:0;for(n?r!==t&&(n=o(n,r)):n=A;++u=(n||H),s=i?{}:e;if(i)for(var o=t-1;++on||e===t)return 1;if(en;n++)t+="j='"+a.o[n]+"';if(" +,"constructor"==a.o[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){B=k[j];"+a.l.h+"}"}if(a.c||a.m)t+="}"}return t+=a.e+";return u",Function("E,F,G,J,e,f,K,h,i,N,P,R,T,U,Y,Z,m,r,w,x,z,A","var H=function("+e+"){"+t+"};return H")(_t,_,L,u,K,f,Yt,Q,A,x,v,$t,m,Jt,vt,Bt,ot,Y,Z,gt,et)}function c(e){return"\\"+jt[e]}function h(e){return Pt[e]}function p(){}function d(e){return Ht[e]}function v(e){return et.call(e)==lt}function m(e){return"function"==typeof e}function g(e){var t=i;if(!e||"object"!=typeof +e||v(e))return t;var n=e.constructor;return(!kt||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!m(n)||n instanceof n)?St?(Yt(e,function(e,n,r){return t=!Q.call(r,n),i}),t===i):(Yt(e,function(e,n){t=n}),t===i||Q.call(e,t)):t}function y(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=Bt[typeof e]){var a=et.call(e);if(!Dt[a]||Tt&&v(e))return e;var f=a==ct,s=f||(a==vt?Jt(e):s)}if(!s||!t)return s?f?Z.call(e):Gt({},e):e;s=e.constructor;switch(a){case ht:return new s(e==n);case pt:return new s(+e) +;case dt:case gt:return new s(e);case mt:return s(e.source,U.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f++u;)if(c=J[u],Q.call(e,c)&&(!Q.call(t,c)||!b(e[c],t[c],s,o)))return i;return n}function w(e,t,n,r){var s=e,o=e.length,u=3>arguments.length;if(o!==+o)var a=rn(e),o=a.length;else Ct&&et.call(e)==gt&&(s=e.split(""));return vn(e,function(e,f,l){f=a?a[--o]:--o,n=u?(u=i,s[f]):t.call(r,n,s[f],f,l)}),n}function E(e,t,n){return t==r||n?e[0 +]:Z.call(e,0,t)}function S(e,t){for(var n,r=-1,i=e.length,s=[];++rn?ut(0,i+n):n)-1}for(;++rr&&(r=n,o=e[i]);return o}function N(e,t,n){return Z.call(e,t==r||n?1:t)}function C(e,t,n,r){for(var i=0,s=e.length,n=f(n,r),t= +n(t);i>>1,n(e[r])x(a,r))a.push(r),u.push(e[s]);return u}function L(e,t){return At||tt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,F=/&(?:amp|lt|gt|quot|#x27);/g,I=/\b__p\+='';/g,q=/\b(__p\+=)''\+/g,R=/(__e\(.*?\)|\b__t\))\+'';/g,U=/\w*$/,z=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,W=RegExp("^"+(D +.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),X=/($^)/,V=/[&<>"']/g,$=/['\n\r\t\u2028\u2029\\]/g,J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),K=_.concat,Q=D.hasOwnProperty,G=_.push,Y=D.propertyIsEnumerable,Z=_.slice,et=D.toString,tt=W.test(tt=Z.bind)&&tt,nt=Math.floor,rt=W.test(rt=Object.getPrototypeOf)&&rt,it=W.test(it=Array.isArray)&&it,st=e.isFinite,ot=W.test(ot=Object.keys)&&ot, +ut=Math.max,at=Math.min,ft=Math.random,lt="[object Arguments]",ct="[object Array]",ht="[object Boolean]",pt="[object Date]",dt="[object Number]",vt="[object Object]",mt="[object RegExp]",gt="[object String]",yt=e.clearTimeout,bt=e.setTimeout,wt,Et,St,xt=n;(function(){function e(){this.x=1}var t={0:1,length:1},n=[];e.prototype={valueOf:1,y:1};for(var r in new e)n.push(r);for(r in arguments)xt=!r;wt=4>(n+"").length,St="x"!=n[0],Et=(n.splice.call(t,0,1),t[0])})(1);var Tt=!v(arguments),Nt="x"!=Z.call("x" +)[0],Ct="xx"!="x"[0]+Object("x")[0];try{var kt=("[object Object]",et.call(e.document||0)==vt)}catch(Lt){}var At=tt&&/\n|Opera/.test(tt+et.call(e.opera)),Ot=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Mt=!At,_t={};_t[ht]=_t[pt]=_t["[object Function]"]=_t[dt]=_t[vt]=_t[mt]=i,_t[lt]=_t[ct]=_t[gt]=n;var Dt={};Dt[lt]=Dt["[object Function]"]=i,Dt[ct]=Dt[ht]=Dt[pt]=Dt[dt]=Dt[vt]=Dt[mt]=Dt[gt]=n;var Pt={"&":"&","<":"<",">":">",'"':""","'":"'"},Ht={"&":"&","<":"<",">":">",""" +:'"',"'":"'"},Bt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Ft={a:"d,c,y",i:"d",p:"c=f(c,y)",h:"if(c(B,j,d)===false)return u"},It={i:"{}",p:"c=f(c,y)",h:"var q=c(B,j,d);(h.call(u,q)?u[q]++:u[q]=1)"},qt={i:"true",h:"if(!c(B,j,d))return!u"},Rt={q:i,r:i,a:"n", +i:"n",p:"for(var a=1,b=arguments.length;a-1"},h:"if(B===ii)return true"}),cn=l(Ft,It),hn=l(Ft,qt),pn=l(Ft,Ut),dn=l(Ft,zt,{i:"",h:"if(c(B,j,d))return B"}),vn=l(Ft,zt),mn=l(Ft,It,{h:"var q=c(B,j,d);(h.call(u,q)?u[q]:u[q]=[]).push(B)" +}),gn=l(Xt,{a:"d,V",p:"var D=w.call(arguments,2),S=typeof V=='function'",h:{b:"u[j]=(S?V:B[V]).apply(B,D)",k:"u"+(Ot?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),yn=l(Ft,Xt),bn=l(Xt,{a:"d,cc",h:{b:"u[j]=B[cc]",k:"u"+(Ot?"[o]=":".push")+"(B[cc])"}}),wn=l({a:"d,c,C,y",i:"C",p:"var W=arguments.length<3;c=f(c,y)",d:{b:"if(W)u=k[++j]"},h:{b:"u=c(u,B,j,d)",k:"u=W?(W=false,B):c(u,B,j,d)"}}),En=l(Ft,Ut,{h:"!"+Ut.h}),Sn=l(Ft,qt,{i:"false",h:qt.h.replace("!","")}),xn=l(Ft,It,Xt,{h:{b:"u[j]={a:c(B,j,d),b:j,c:B}" +,k:"u"+(Ot?"[o]=":".push")+"({a:c(B,j,d),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--){u[l]=u[l].c}"}),Tn=l(Ut,{a:"d,bb",p:"var t=[];K(bb,function(B,q){t.push(q)});var dd=t.length",h:"for(var q,aa=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply +(this,arguments)}},s.bind=L,s.bindAll=Nn,s.chain=function(e){return e=new s(e),e.__chain__=n,e},s.clone=y,s.compact=function(e){for(var t=-1,n=e.length,r=[];++tx(u,t)){for(var a=1;an?ut(0,r+n):at(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return a(t,e,Z.call(arguments,2))},s.map=yn,s.max=T,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Q.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=sn,s.min=function(e,t,n){for(var r=Infinity,i=-1,s=e?e. +length:0,o=r,t=f(t,n);++i=f?(a=r,s=e.apply(o,i)):u||(u=yt(n,f)),s}},s.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rx(r,t[e])&&r.push(t[e]);return r -},s.uniq=k,s.uniqueId=function(e){var t=P++;return e?e+t:t},s.values=an,s.where=xn,s.without=function(e){for(var t=-1,n=e.length,r=u(arguments,1,20),i=[];++t=f?(a=r,s=e.apply(o,i)):u||(u=bt(n,f)),s}},s.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rx(r,t[e])&&r.push(t[e]);return r +},s.uniq=k,s.uniqueId=function(e){var t=P++;return e?e+t:t},s.values=fn,s.where=Tn,s.without=function(e){for(var t=-1,n=e.length,r=o(arguments,1,20),i=[];++t Date: Sat, 29 Sep 2012 03:14:03 -0700 Subject: [PATCH 58/82] Update vendors. Former-commit-id: 31e8de8842ed9ea020f54ca06cdb87b1478e3b08 --- vendor/backbone/backbone.js | 1 + vendor/underscore/test/arrays.js | 5 ++++- vendor/underscore/underscore-min.js | 2 +- vendor/underscore/underscore.js | 9 ++++++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/vendor/backbone/backbone.js b/vendor/backbone/backbone.js index 5fc0fe6e33..418fc7d207 100644 --- a/vendor/backbone/backbone.js +++ b/vendor/backbone/backbone.js @@ -926,6 +926,7 @@ // Simple proxy to `Backbone.history` to save a fragment into the history. navigate: function(fragment, options) { Backbone.history.navigate(fragment, options); + return this; }, // Bind all defined routes to `Backbone.history`. We have to reverse the diff --git a/vendor/underscore/test/arrays.js b/vendor/underscore/test/arrays.js index 57da88fe55..1ab33d8f7a 100644 --- a/vendor/underscore/test/arrays.js +++ b/vendor/underscore/test/arrays.js @@ -163,7 +163,10 @@ $(document).ready(function() { }); test("lastIndexOf", function() { - var numbers = [1, 0, 1, 0, 0, 1, 0, 0, 0]; + var numbers = [1, 0, 1]; + equal(_.lastIndexOf(numbers, 1), 2); + + numbers = [1, 0, 1, 0, 0, 1, 0, 0, 0]; numbers.lastIndexOf = null; equal(_.lastIndexOf(numbers, 1), 5, 'can compute lastIndexOf, even without the native function'); equal(_.lastIndexOf(numbers, 0), 8, 'lastIndexOf the other element'); diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index 8ec052be49..6889f810c9 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -2,4 +2,4 @@ // http://underscorejs.org // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. // Underscore may be freely distributed under the MIT license. -(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.4.0";var N=T.each=T.forEach=function(e,t,r){if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i2;if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;or||n===void 0)return 1;if(n>>1;n.call(r,e[u])=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r":">",'"':""","'":"'","/":"/"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file +(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.4.0";var N=T.each=T.forEach=function(e,t,r){if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i2;if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;or||n===void 0)return 1;if(n>>1;n.call(r,e[u])=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r":">",'"':""","'":"'","/":"/"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index a3d378aa3b..013dcadbed 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -515,9 +515,12 @@ }; // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. - _.lastIndexOf = function(array, item, fromIndex) { - if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item, fromIndex); - var i = (fromIndex != null ? fromIndex : array.length); + _.lastIndexOf = function(array, item, from) { + var hasIndex = from != null; + if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) { + return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item); + } + var i = (hasIndex ? from : array.length); while (i--) if (array[i] === item) return i; return -1; }; From 6a9efd8ac6acb965c26572b7aa73a695b1cfb5a3 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 29 Sep 2012 03:41:00 -0700 Subject: [PATCH 59/82] Ensure build tests pass. Former-commit-id: 9b91f0d884fe96dce1df34a6c0b659619276b83e --- build.js | 7 +++++-- build/pre-compile.js | 2 +- lodash.js | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/build.js b/build.js index 2a8873bc44..774bc36339 100755 --- a/build.js +++ b/build.js @@ -1031,7 +1031,7 @@ } } if (isLegacy) { - _.each(['isBindFast', 'isKeysFast', 'isStrictFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'], function(varName) { + _.each(['isBindFast', 'isKeysFast', 'isStrictFast', 'nativeBind', 'nativeGetPrototypeOf', 'nativeIsArray', 'nativeKeys'], function(varName) { source = replaceVar(source, varName, 'false'); }); @@ -1334,6 +1334,9 @@ if (isRemoved(source, 'isArray')) { source = removeVar(source, 'nativeIsArray'); } + if (isRemoved(source, 'isPlainObject')) { + source = removeVar(source, 'nativeGetPrototypeOf'); + } if (isRemoved(source, 'keys')) { source = removeFunction(source, 'shimKeys'); } @@ -1359,7 +1362,7 @@ source = removeVar(source, 'isStrictFast'); source = removeVar(source, 'nativeBind'); } - if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) { + if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'isPlainObject', 'keys')) { source = removeVar(source, 'reNative'); } if (isRemoved(source, 'createIterator', 'isEmpty', 'isEqual')) { diff --git a/build/pre-compile.js b/build/pre-compile.js index f2bcffd9c7..879e9149a9 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -274,7 +274,7 @@ // remove whitespace from string literals source = source.replace(/'(?:(?=(\\?))\1.)*?'/g, function(string) { // avoids removing the '\n' of the `stringEscapes` object - return string.replace(/\[object |delete |else if|function | in |return\s+[\w']|throw |typeof |use strict|var |@ |'\\n'|\\\\n|\\n|\s+/g, function(match) { + return string.replace(/\[object |delete |else if|else var |function | in |return\s+[\w']|throw |typeof |use strict|var |@ |'\\n'|\\\\n|\\n|\s+/g, function(match) { return match == false || match == '\\n' ? '' : match; }); }); diff --git a/lodash.js b/lodash.js index 0d7003cf3f..e1468cb091 100644 --- a/lodash.js +++ b/lodash.js @@ -523,8 +523,8 @@ 'init': '{}', 'top': 'var isFunc = typeof callback == \'function\';\n' + - 'callback = createCallback(callback, thisArg);\n' + - 'if (!isFunc) var props = concat.apply(ArrayProto, arguments)', + 'if (isFunc) callback = createCallback(callback, thisArg);\n' + + 'else var props = concat.apply(ArrayProto, arguments)', 'inLoop': 'if (isFunc\n' + ' ? !callback(value, index, object)\n' + From f31598f9160aa077aa56676395b93f443f766a4e Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 29 Sep 2012 03:48:15 -0700 Subject: [PATCH 60/82] Update README.md and rebuild minified file. Former-commit-id: 0b37eebda0d1a82d0bb62cf2ba6e5b190e176547 --- README.md | 6 ++---- lodash.min.js | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0d24d173e8..db6b7cd87b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Lo-Dash v0.7.0 -A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) for Underscore.js, from the devs behind [jsPerf.com](http://jsperf.com), delivering [performance](http://lodash.com/benchmarks), [bug fixes](https://github.com/bestiejs/lodash#resolved-underscorejs-issues), and [additional features](https://github.com/bestiejs/lodash#features). +A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) for Underscore.js, from the devs behind [jsPerf.com](http://jsperf.com), delivering [performance](http://lodash.com/benchmarks), [bug fixes](https://github.com/bestiejs/lodash#resolved-underscorejs-issues), and [additional features](http://lodash.com/#features). Lo-Dash’s performance is gained by avoiding slower native methods, instead opting for simplified non-ES5 compliant methods optimized for common usage, and by leveraging function compilation to reduce the number of overall function calls. @@ -56,7 +56,7 @@ For more information check out these screencasts over Lo-Dash: ## Support -Lo-Dash has been tested in at least Chrome 5-21, Firefox 1-15, IE 6-9, Opera 9.25-12, Safari 3-6, Node.js 0.4.8-0.8.8, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC5. +Lo-Dash has been tested in at least Chrome 5-21, Firefox 1-15, IE 6-9, Opera 9.25-12, Safari 3-6, Node.js 0.4.8-0.8.9, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC5. ## Custom builds @@ -194,7 +194,6 @@ require({ ## Resolved Underscore.js issues * Allow iteration of objects with a `length` property [[#148](https://github.com/documentcloud/underscore/issues/148), [#154](https://github.com/documentcloud/underscore/issues/154), [#252](https://github.com/documentcloud/underscore/issues/252), [#448](https://github.com/documentcloud/underscore/issues/448), [#659](https://github.com/documentcloud/underscore/issues/659), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L543-549)] - * Ensure *“Arrays”*, *“Collections”*, and *“Objects”* methods don’t error when passed falsey arguments [[#650](https://github.com/documentcloud/underscore/pull/650), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L1719-1754)] * Ensure *“Collections”* methods allow string `collection` arguments [[#247](https://github.com/documentcloud/underscore/issues/247), [#276](https://github.com/documentcloud/underscore/issues/276), [#561](https://github.com/documentcloud/underscore/pull/561), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L503-520)] * Fix cross-browser object iteration bugs [[#60](https://github.com/documentcloud/underscore/issues/60), [#376](https://github.com/documentcloud/underscore/issues/376), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L554-579)] * Methods should work on pages with incorrectly shimmed native methods [[#7](https://github.com/documentcloud/underscore/issues/7), [#742](https://github.com/documentcloud/underscore/issues/742), [test](https://github.com/bestiejs/lodash/blob/v0.8.0/test/test.js#L134-140)] @@ -262,7 +261,6 @@ require({ * `_.sortedIndex` * `_.template` * `_.throttle` - * `_.times` * `_.toArray` * `_.union` * `_.uniq`, `_.unique` diff --git a/lodash.min.js b/lodash.min.js index cf4f0f4461..1f405860b1 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -18,8 +18,8 @@ n(t);i>>1,n(e[r])(n+"").length,St="x"!=n[0],Et=(n.splice.call(t,0,1),t[0])})(1);var Tt=!v(arguments),Nt="x"!=Z.call("x" )[0],Ct="xx"!="x"[0]+Object("x")[0];try{var kt=("[object Object]",et.call(e.document||0)==vt)}catch(Lt){}var At=tt&&/\n|Opera/.test(tt+et.call(e.opera)),Ot=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Mt=!At,_t={};_t[ht]=_t[pt]=_t["[object Function]"]=_t[dt]=_t[vt]=_t[mt]=i,_t[lt]=_t[ct]=_t[gt]=n;var Dt={};Dt[lt]=Dt["[object Function]"]=i,Dt[ct]=Dt[ht]=Dt[pt]=Dt[dt]=Dt[vt]=Dt[mt]=Dt[gt]=n;var Pt={"&":"&","<":"<",">":">",'"':""","'":"'"},Ht={"&":"&","<":"<",">":">",""" :'"',"'":"'"},Bt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Ft={a:"d,c,y",i:"d",p:"c=f(c,y)",h:"if(c(B,j,d)===false)return u"},It={i:"{}",p:"c=f(c,y)",h:"var q=c(B,j,d);(h.call(u,q)?u[q]++:u[q]=1)"},qt={i:"true",h:"if(!c(B,j,d))return!u"},Rt={q:i,r:i,a:"n", -i:"n",p:"for(var a=1,b=arguments.length;a-1"},h:"if(B===ii)return true"}),cn=l(Ft,It),hn=l(Ft,qt),pn=l(Ft,Ut),dn=l(Ft,zt,{i:"",h:"if(c(B,j,d))return B"}),vn=l(Ft,zt),mn=l(Ft,It,{h:"var q=c(B,j,d);(h.call(u,q)?u[q]:u[q]=[]).push(B)" }),gn=l(Xt,{a:"d,V",p:"var D=w.call(arguments,2),S=typeof V=='function'",h:{b:"u[j]=(S?V:B[V]).apply(B,D)",k:"u"+(Ot?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),yn=l(Ft,Xt),bn=l(Xt,{a:"d,cc",h:{b:"u[j]=B[cc]",k:"u"+(Ot?"[o]=":".push")+"(B[cc])"}}),wn=l({a:"d,c,C,y",i:"C",p:"var W=arguments.length<3;c=f(c,y)",d:{b:"if(W)u=k[++j]"},h:{b:"u=c(u,B,j,d)",k:"u=W?(W=false,B):c(u,B,j,d)"}}),En=l(Ft,Ut,{h:"!"+Ut.h}),Sn=l(Ft,qt,{i:"false",h:qt.h.replace("!","")}),xn=l(Ft,It,Xt,{h:{b:"u[j]={a:c(B,j,d),b:j,c:B}" From 82bc52b909cd4707d530c8ba2d9a2e690cc0b2b9 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 29 Sep 2012 12:04:40 -0700 Subject: [PATCH 61/82] Reduce underscore build size. Former-commit-id: 207d4ab49063483245dc951d4646413d6d4a1903 --- build.js | 16 +++++++++++++++- build/pre-compile.js | 2 +- lodash.js | 17 ++++++++--------- test/test-build.js | 18 +++++++++++++----- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/build.js b/build.js index 774bc36339..9728c96469 100755 --- a/build.js +++ b/build.js @@ -630,7 +630,7 @@ return source; } // remove function - source = source.replace(matchFunction(source, funcName), ''); + source = source.replace(snippet, ''); // grab the method assignments snippet snippet = getMethodAssignments(source); @@ -1054,6 +1054,11 @@ // replace `arrayLikeClasses` in `_.isEqual` source = source.replace(/(?: *\/\/.*\n)*( +)var isArr *= *arrayLikeClasses[^}]+}/, '$1var isArr = isArray(a);'); + // remove "exit early" feature from `_.each` + source = source.replace(/( )+var baseIteratorOptions *=[\s\S]+?\n\1.+?;/, function(match) { + return match.replace(/if *\(callback[^']+/, 'callback(value, index, collection)'); + }); + // remove `deep` clone functionality source = source.replace(/( +)function clone[\s\S]+?\n\1}/, [ ' function clone(value) {', @@ -1094,6 +1099,15 @@ source = buildTemplate(templatePattern, templateSettings); } else { + // simplify template snippets by removing unnecessary brackets + source = source.replace( + RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *([,\\n])", 'g'), "$1'$2" + ); + + source = source.replace( + RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *\\+", 'g'), "$1;\\n'+" + ); + // remove methods from the build allMethods.forEach(function(otherName) { if (!_.contains(buildMethods, otherName)) { diff --git a/build/pre-compile.js b/build/pre-compile.js index 879e9149a9..dfe28763ca 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -274,7 +274,7 @@ // remove whitespace from string literals source = source.replace(/'(?:(?=(\\?))\1.)*?'/g, function(string) { // avoids removing the '\n' of the `stringEscapes` object - return string.replace(/\[object |delete |else if|else var |function | in |return\s+[\w']|throw |typeof |use strict|var |@ |'\\n'|\\\\n|\\n|\s+/g, function(match) { + return string.replace(/\[object |delete |else |function | in |return\s+[\w']|throw |typeof |use strict|var |@ |'\\n'|\\\\n|\\n|\s+/g, function(match) { return match == false || match == '\\n' ? '' : match; }); }); diff --git a/lodash.js b/lodash.js index e1468cb091..f8c337329b 100644 --- a/lodash.js +++ b/lodash.js @@ -667,11 +667,13 @@ function createCallback(func, thisArg) { if (!func) { return identity; - } else if (typeof func != 'function') { + } + if (typeof func != 'function') { return function(object) { return object[func]; - } - } else if (thisArg !== undefined) { + }; + } + if (thisArg !== undefined) { return function(value, index, object) { return func.call(thisArg, value, index, object); }; @@ -1693,13 +1695,10 @@ * // => ['one', 'two', 'three'] (order is not guaranteed) */ var keys = !nativeKeys ? shimKeys : function(object) { - var type = typeof object; - // avoid iterating over the `prototype` property - if (type == 'function' && propertyIsEnumerable.call(object, 'prototype')) { - return shimKeys(object); - } - return nativeKeys(object); + return typeof object == 'function' && propertyIsEnumerable.call(object, 'prototype') + ? shimKeys(object) + : nativeKeys(object); }; /** diff --git a/test/test-build.js b/test/test-build.js index 14109d2766..2f536af713 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -436,7 +436,7 @@ console.log(e); pass = false; } - equal(pass, true, methodName + ': ' + message); + equal(pass, true, '_.' + methodName + ': ' + message); } /*--------------------------------------------------------------------------*/ @@ -545,17 +545,25 @@ var start = _.after(2, _.once(QUnit.start)); build(['-s', 'underscore'], function(source, filepath) { - var array = [{ 'a': 1 }], + var last, + array = [{ 'value': 1 }, { 'value': 2 }], basename = path.basename(filepath, '.js'), context = createContext(); vm.runInContext(source, context); var lodash = context._; + lodash.each(array, function(value) { + last = value; + return false; + }); + + equal(last.value, 2, '_.each: ' + basename); + var object = { 'fn': lodash.bind(function(x) { return this.x + x; }, { 'x': 1 }, 1) }; - equal(object.fn(), 2, 'bind: ' + basename); + equal(object.fn(), 2, '_.bind: ' + basename); - ok(lodash.clone(array, true)[0] === array[0], 'clone: ' + basename); + ok(lodash.clone(array, true)[0] === array[0], '_.clone: ' + basename); start(); }); }); @@ -570,7 +578,7 @@ vm.runInContext(source, context); var lodash = context._; - equal(lodash.partial(_.identity, 2)(), 2, 'partial: ' + basename); + equal(lodash.partial(_.identity, 2)(), 2, '_.partial: ' + basename); start(); }); }); From d993a62263c33f3147b102d27ec6a0594477d3ea Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 29 Sep 2012 14:36:23 -0700 Subject: [PATCH 62/82] Use `invert` to assign `htmlUnescapes`. Former-commit-id: 20f9f29d622643e2f59bbc4a57fd2456c09ef49e --- build.js | 21 +++-- doc/README.md | 206 +++++++++++++++++++++++++------------------------- lodash.js | 82 ++++++++++---------- lodash.min.js | 36 ++++----- 4 files changed, 172 insertions(+), 173 deletions(-) diff --git a/build.js b/build.js index 9728c96469..3d38dbad82 100755 --- a/build.js +++ b/build.js @@ -768,18 +768,20 @@ */ function replaceVar(source, varName, varValue) { // replace a variable that's not part of a declaration list - source = source.replace(RegExp( + var result = source.replace(RegExp( '(( +)var ' + varName + ' *= *)' + '(?:.+?;|(?:Function\\(.+?|.*?[^,])\\n[\\s\\S]+?\\n\\2.+?;)\\n' ), '$1' + varValue + ';\n'); - // replace a varaible at the start or middle of a declaration list - source = source.replace(RegExp('((?:var|\\n) +' + varName + ' *=).+?,'), '$1 ' + varValue + ','); - - // replace a variable at the end of a variable declaration list - source = source.replace(RegExp('(,\\s*' + varName + ' *=).+?;'), '$1 ' + varValue + ';'); - - return source; + if (source == result) { + // replace a varaible at the start or middle of a declaration list + result = source.replace(RegExp('((?:var|\\n) +' + varName + ' *=).+?,'), '$1 ' + varValue + ','); + } + if (source == result) { + // replace a variable at the end of a variable declaration list + result = source.replace(RegExp('(,\\s*' + varName + ' *=).+?;'), '$1 ' + varValue + ';'); + } + return result; } /** @@ -1321,6 +1323,9 @@ } else { // modify/remove references to removed methods/variables + if (isRemoved(source, 'invert')) { + source = replaceVar(source, 'htmlUnescapes', "{'&':'&','<':'<','>':'>','"':'\"',''':\"'\"}"); + } if (isRemoved(source, 'isArguments')) { source = replaceVar(source, 'noArgsClass', 'false'); } diff --git a/doc/README.md b/doc/README.md index 9f71d8bcd3..b442d5fea0 100644 --- a/doc/README.md +++ b/doc/README.md @@ -156,7 +156,7 @@ ### `_(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L266 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L241 "View in source") [Ⓣ][1] The `lodash` function. @@ -174,7 +174,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3998 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3991 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -186,7 +186,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3106 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3099 "View in source") [Ⓣ][1] Creates a function that is restricted to executing only after it is called `n` times. @@ -214,7 +214,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3139 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3132 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. @@ -245,7 +245,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3169 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3162 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -276,7 +276,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3923 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3916 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -310,7 +310,7 @@ var youngest = _.chain(stooges) ### `_.clone(value, deep)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1029 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1044 "View in source") [Ⓣ][1] Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned. @@ -349,7 +349,7 @@ shallow[0] === stooges[0]; ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2418 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2411 "View in source") [Ⓣ][1] Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -373,7 +373,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3206 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3199 "View in source") [Ⓣ][1] Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -400,7 +400,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1900 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1893 "View in source") [Ⓣ][1] Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -434,7 +434,7 @@ _.contains('curly', 'ur'); ### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1936 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1929 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -466,7 +466,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3239 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3232 "View in source") [Ⓣ][1] Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -492,7 +492,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1122 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1137 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -518,7 +518,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3304 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3297 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -543,7 +543,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3284 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3277 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -570,7 +570,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2447 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2440 "View in source") [Ⓣ][1] Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -595,7 +595,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3523 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3516 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -619,7 +619,7 @@ _.escape('Moe, Larry & Curly'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1957 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1950 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -648,7 +648,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1142 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1157 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -673,7 +673,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1977 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1970 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -702,7 +702,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1999 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1992 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -731,7 +731,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2481 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2474 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -759,7 +759,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2503 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2496 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -787,7 +787,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2026 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2019 "View in source") [Ⓣ][1] Iterates over a `collection`, 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`. @@ -819,7 +819,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1172 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1187 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, 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`. @@ -855,7 +855,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1196 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1211 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, 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`. @@ -883,7 +883,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1213 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1228 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -910,7 +910,7 @@ _.functions(_); ### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2054 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2047 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -942,7 +942,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1236 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1251 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -967,7 +967,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3543 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3536 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -992,7 +992,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2546 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2539 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1024,7 +1024,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2583 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2576 "View in source") [Ⓣ][1] Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. @@ -1049,7 +1049,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2602 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2595 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -1073,7 +1073,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invert(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1253 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L819 "View in source") [Ⓣ][1] Creates an object composed of the inverted keys and values of the given `object`. @@ -1097,7 +1097,7 @@ _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2082 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2075 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`, returning an array of the results of each invoked method. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1126,7 +1126,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L845 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L841 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1153,7 +1153,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L871 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L867 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1180,7 +1180,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1272 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1268 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1204,7 +1204,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1289 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1285 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1228,7 +1228,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1306 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1302 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1252,7 +1252,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1331 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1327 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1282,7 +1282,7 @@ _.isEmpty(''); ### `_.isEqual(a, b)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1371 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1367 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1313,7 +1313,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1528 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1524 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1343,7 +1343,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L888 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L884 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1367,7 +1367,7 @@ _.isFunction(_); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1586 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1582 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1400,7 +1400,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1609 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1605 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1427,7 +1427,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1626 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1622 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1451,7 +1451,7 @@ _.isNumber(8.4 * 5); ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1552 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1548 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -1481,7 +1481,7 @@ _.isObject(1); ### `_.isPlainObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L922 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L918 "View in source") [Ⓣ][1] Checks if a given `value` is an object created by the `Object` constructor. @@ -1516,7 +1516,7 @@ _.isPlainObject({ 'name': 'moe', 'age': 40 }); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1643 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1639 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1540,7 +1540,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1660 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1656 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1564,7 +1564,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1678 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1674 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1588,7 +1588,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1695 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1691 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of `object`. @@ -1612,7 +1612,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2642 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2635 "View in source") [Ⓣ][1] Gets the last element of the `array`. Pass `n` to return the last `n` elements of the `array`. @@ -1637,7 +1637,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2666 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2659 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1666,7 +1666,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.lateBind(object, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3341 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3334 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method @@ -1707,7 +1707,7 @@ func(); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2117 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2110 "View in source") [Ⓣ][1] Creates an array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1739,7 +1739,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2703 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2696 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1771,7 +1771,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3363 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3356 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1797,7 +1797,7 @@ var fibonacci = _.memoize(function(n) { ### `_.merge(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1736 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1729 "View in source") [Ⓣ][1] Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -1832,7 +1832,7 @@ _.merge(stooges, ages); ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2739 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2732 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -1858,7 +1858,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3569 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3562 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1888,7 +1888,7 @@ _('curly').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3600 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3593 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1908,7 +1908,7 @@ var lodash = _.noConflict(); ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2774 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2767 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. @@ -1933,7 +1933,7 @@ _.object(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1793 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1786 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -1964,7 +1964,7 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3389 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3382 "View in source") [Ⓣ][1] Creates a function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1990,7 +1990,7 @@ initialize(); ### `_.pairs(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1809 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1802 "View in source") [Ⓣ][1] Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. @@ -2014,7 +2014,7 @@ _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3424 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3417 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `bind`, except it does **not** alter the `this` binding. @@ -2041,7 +2041,7 @@ hi('moe'); ### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1840 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1833 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, picking the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -2072,7 +2072,7 @@ _.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2140 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2133 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -2103,7 +2103,7 @@ _.pluck(stooges, 'name'); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3623 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3616 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -2131,7 +2131,7 @@ _.random(5); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2818 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2811 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -2169,7 +2169,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2168 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2161 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -2199,7 +2199,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2205 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2198 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -2230,7 +2230,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2242 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2235 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -2256,7 +2256,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2857 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2850 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2284,7 +2284,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3662 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3655 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2319,7 +2319,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2875 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2868 "View in source") [Ⓣ][1] Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2343,7 +2343,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2266 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2259 "View in source") [Ⓣ][1] Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. @@ -2373,7 +2373,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2291 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2284 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2402,7 +2402,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2321 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2314 "View in source") [Ⓣ][1] Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2434,7 +2434,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity|property, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2929 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2922 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. The `callback` argument may also be the name of a property to order by. @@ -2478,7 +2478,7 @@ _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3950 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3943 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2508,7 +2508,7 @@ _.chain([1, 2, 3, 200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3732 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3725 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: In the development build `_.template` utilizes sourceURLs for easier debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. See http://developer.chrome.com/trunk/extensions/sandboxingEval.html @@ -2573,7 +2573,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3446 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3439 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2598,7 +2598,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3850 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3843 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -2630,7 +2630,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2357 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2350 "View in source") [Ⓣ][1] Converts the `collection`, to an array. @@ -2654,7 +2654,7 @@ Converts the `collection`, to an array. ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3875 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3868 "View in source") [Ⓣ][1] Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -2678,7 +2678,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2958 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2951 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -2702,7 +2702,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3002 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2995 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -2741,7 +2741,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3893 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3886 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2765,7 +2765,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1870 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1863 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2789,7 +2789,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2388 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2381 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. @@ -2820,7 +2820,7 @@ _.where(stooges, { 'age': 40 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3044 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3037 "View in source") [Ⓣ][1] Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2845,7 +2845,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3497 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3490 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2874,7 +2874,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3074 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3067 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2905,7 +2905,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3968 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3961 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2926,7 +2926,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3985 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3978 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -2954,7 +2954,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L287 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L262 "View in source") [Ⓣ][1] *(Object)*: By default, the template delimiters used by Lo-Dash are similar to those in embedded Ruby *(ERB)*. Change the following template settings to use alternative delimiters. @@ -2966,7 +2966,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.escape` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L296 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L271 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to be HTML-escaped. @@ -2978,7 +2978,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.evaluate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L305 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L280 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect code to be evaluated. @@ -2990,7 +2990,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.interpolate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L314 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L289 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to inject. @@ -3002,7 +3002,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.variable` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L323 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L298 "View in source") [Ⓣ][1] *(String)*: Used to reference the data object in the template text. diff --git a/lodash.js b/lodash.js index f8c337329b..6ef37f9494 100644 --- a/lodash.js +++ b/lodash.js @@ -206,31 +206,6 @@ cloneableClasses[numberClass] = cloneableClasses[objectClass] = cloneableClasses[regexpClass] = cloneableClasses[stringClass] = true; - /** - * Used to convert characters to HTML entities: - * - * Though the `>` character is escaped for symmetry, characters like `>` and `/` - * don't require escaping in HTML and have no special meaning unless they're part - * of a tag or an unquoted attribute value. - * http://mathiasbynens.be/notes/ambiguous-ampersands (under "semi-related fun fact") - */ - var htmlEscapes = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; - - /** Used to convert HTML entities to characters */ - var htmlUnescapes = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - ''': "'" - }; - /** Used to determine if values are of the language type Object */ var objectTypes = { 'boolean': false, @@ -828,6 +803,25 @@ /*--------------------------------------------------------------------------*/ + /** + * Creates an object composed of the inverted keys and values of the given `object`. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The object to invert. + * @returns {Object} Returns the created inverted object. + * @example + * + * _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); + * // => { 'Moe': 'first', 'Larry': 'second', 'Curly': 'third' } (order is not guaranteed) + */ + var invert = createIterator({ + 'args': 'object', + 'init': '{}', + 'inLoop': 'result[value] = index' + }); + /** * Checks if `value` is an `arguments` object. * @@ -990,6 +984,25 @@ 'inLoop': 'result.push(index)' }); + /** + * Used to convert characters to HTML entities: + * + * Though the `>` character is escaped for symmetry, characters like `>` and `/` + * don't require escaping in HTML and have no special meaning unless they're part + * of a tag or an unquoted attribute value. + * http://mathiasbynens.be/notes/ambiguous-ampersands (under "semi-related fun fact") + */ + var htmlEscapes = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + + /** Used to convert HTML entities to characters */ + var htmlUnescapes = invert(htmlEscapes); + /*--------------------------------------------------------------------------*/ /** @@ -1239,25 +1252,6 @@ return hasOwnProperty.call(object, property); } - /** - * Creates an object composed of the inverted keys and values of the given `object`. - * - * @static - * @memberOf _ - * @category Objects - * @param {Object} object The object to invert. - * @returns {Object} Returns the created inverted object. - * @example - * - * _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); - * // => { 'Moe': 'first', 'Larry': 'second', 'Curly': 'third' } (order is not guaranteed) - */ - var invert = createIterator({ - 'args': 'object', - 'init': '{}', - 'inLoop': 'result[value] = index' - }); - /** * Checks if `value` is a boolean (`true` or `false`) value. * diff --git a/lodash.min.js b/lodash.min.js index 1f405860b1..3b4a3d77e4 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -4,8 +4,8 @@ */ ;(function(e,t){function s(e){if(e&&e.__wrapped__)return e;if(!(this instanceof s))return new s(e);this.__wrapped__=e}function o(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||H),s=i?{}:e;if(i)for(var o=t-1;++on||e===t)return 1;if(en;n++)t+="j='"+a.o[n]+"';if(" +n&&(n={b:n,k:n}),a.c[t]=n.b||"",a.l[t]=n.k||""):a[t]=n;e=a.a,t=/^[^,]+/.exec(e)[0],n=a.i,s=a.r,a.f=t,a.g=wt,a.i=n==r?t:n,a.j=Ot,a.m=xt,a.o=J,a.q=a.q!==i,a.r=s==r?Mt:s,a.n==r&&(a.n=Ct);if("d"!=t||!a.c.h)a.c=r;t="",a.r&&(t+="'use strict';"),t+="var j,B,k="+a.f+",u",a.i&&(t+="="+a.i),t+=";"+a.p+";",a.c&&(t+="var l=k.length;j=-1;",a.l&&(t+="if(l===+l){"),a.n&&(t+="if(z.call(k)==x){k=k.split('')}"),t+=a.c.d+";while(++jn;n++)t+="j='"+a.o[n]+"';if(" ,"constructor"==a.o[n]&&(t+="!(g&&g.prototype===k)&&"),t+="h.call(k,j)){B=k[j];"+a.l.h+"}"}if(a.c||a.m)t+="}"}return t+=a.e+";return u",Function("E,F,G,J,e,f,K,h,i,N,P,R,T,U,Y,Z,m,r,w,x,z,A","var H=function("+e+"){"+t+"};return H")(_t,_,L,u,K,f,Yt,Q,A,x,v,$t,m,Jt,vt,Bt,ot,Y,Z,gt,et)}function c(e){return"\\"+jt[e]}function h(e){return Pt[e]}function p(){}function d(e){return Ht[e]}function v(e){return et.call(e)==lt}function m(e){return"function"==typeof e}function g(e){var t=i;if(!e||"object"!=typeof e||v(e))return t;var n=e.constructor;return(!kt||"function"==typeof e.toString||"string"!=typeof (e+""))&&(!m(n)||n instanceof n)?St?(Yt(e,function(e,n,r){return t=!Q.call(r,n),i}),t===i):(Yt(e,function(e,n){t=n}),t===i||Q.call(e,t)):t}function y(e,t,s,o,u){if(e==r)return e;s&&(t=i);if(s=Bt[typeof e]){var a=et.call(e);if(!Dt[a]||Tt&&v(e))return e;var f=a==ct,s=f||(a==vt?Jt(e):s)}if(!s||!t)return s?f?Z.call(e):Gt({},e):e;s=e.constructor;switch(a){case ht:return new s(e==n);case pt:return new s(+e) ;case dt:case gt:return new s(e);case mt:return s(e.source,U.exec(e))}o||(o=[]),u||(u=[]);for(a=o.length;a--;)if(o[a]==e)return u[a];var l=f?s(a=e.length):{};o.push(e),u.push(l);if(f)for(f=-1;++f/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Ft={a:"d,c,y",i:"d",p:"c=f(c,y)",h:"if(c(B,j,d)===false)return u"},It={i:"{}",p:"c=f(c,y)",h:"var q=c(B,j,d);(h.call(u,q)?u[q]++:u[q]=1)"},qt={i:"true",h:"if(!c(B,j,d))return!u"},Rt={q:i,r:i,a:"n", i:"n",p:"for(var a=1,b=arguments.length;a-1"},h:"if(B===ii)return true"}),cn=l(Ft,It),hn=l(Ft,qt),pn=l(Ft,Ut),dn=l(Ft,zt,{i:"",h:"if(c(B,j,d))return B"}),vn=l(Ft,zt),mn=l(Ft,It,{h:"var q=c(B,j,d);(h.call(u,q)?u[q]:u[q]=[]).push(B)" +(Tt?"||P(B)":"")+"||(I==Y&&l===+l&&T(B.splice)))return!l",h:{k:"return false"}}),rn=ot?function(e){return"function"==typeof e&&Y.call(e,"prototype")?Kt(e):ot(e)}:Kt,sn=l(Rt,{a:"n,ee,O",p:"var Q,D=arguments,a=0;if(O==J){var b=2,ff=D[3],gg=D[4]}else var b=D.length,ff=[],gg=[];while(++a-1"},h:"if(B===ii)return true"}),cn=l(Ft,It),hn=l(Ft,qt),pn=l(Ft,Ut),dn=l(Ft,zt,{i:"",h:"if(c(B,j,d))return B"}),vn=l(Ft,zt),mn=l(Ft,It,{h:"var q=c(B,j,d);(h.call(u,q)?u[q]:u[q]=[]).push(B)" }),gn=l(Xt,{a:"d,V",p:"var D=w.call(arguments,2),S=typeof V=='function'",h:{b:"u[j]=(S?V:B[V]).apply(B,D)",k:"u"+(Ot?"[o]=":".push")+"((S?V:B[V]).apply(B,D))"}}),yn=l(Ft,Xt),bn=l(Xt,{a:"d,cc",h:{b:"u[j]=B[cc]",k:"u"+(Ot?"[o]=":".push")+"(B[cc])"}}),wn=l({a:"d,c,C,y",i:"C",p:"var W=arguments.length<3;c=f(c,y)",d:{b:"if(W)u=k[++j]"},h:{b:"u=c(u,B,j,d)",k:"u=W?(W=false,B):c(u,B,j,d)"}}),En=l(Ft,Ut,{h:"!"+Ut.h}),Sn=l(Ft,qt,{i:"false",h:qt.h.replace("!","")}),xn=l(Ft,It,Xt,{h:{b:"u[j]={a:c(B,j,d),b:j,c:B}" -,k:"u"+(Ot?"[o]=":".push")+"({a:c(B,j,d),b:j,c:B})"},e:"u.sort(J);l=u.length;while(l--){u[l]=u[l].c}"}),Tn=l(Ut,{a:"d,bb",p:"var t=[];K(bb,function(B,q){t.push(q)});var dd=t.length",h:"for(var q,aa=true,s=0;s1){for(var j=1;je?t():function(){if(1>--e)return t.apply -(this,arguments)}},s.bind=L,s.bindAll=Nn,s.chain=function(e){return e=new s(e),e.__chain__=n,e},s.clone=y,s.compact=function(e){for(var t=-1,n=e.length,r=[];++tx(u,t)){for(var a=1;an?ut(0,r+n):at(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return a(t,e,Z.call(arguments,2))},s.map=yn,s.max=T,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Q.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=sn,s.min=function(e,t,n){for(var r=Infinity,i=-1,s=e?e. -length:0,o=r,t=f(t,n);++i=f?(a=r,s=e.apply(o,i)):u||(u=bt(n,f)),s}},s.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rx(r,t[e])&&r.push(t[e]);return r -},s.uniq=k,s.uniqueId=function(e){var t=P++;return e?e+t:t},s.values=fn,s.where=Tn,s.without=function(e){for(var t=-1,n=e.length,r=o(arguments,1,20),i=[];++t1){for(var j=1;je?t():function(){if(1>--e)return t.apply(this +,arguments)}},s.bind=L,s.bindAll=Nn,s.chain=function(e){return e=new s(e),e.__chain__=n,e},s.clone=y,s.compact=function(e){for(var t=-1,n=e.length,r=[];++tx(u,t)){for(var a=1;an?ut(0,r+n):at(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.lateBind=function(e,t){return a(t,e,Z.call(arguments,2))},s.map=yn,s.max=T,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Q.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=sn,s.min=function(e,t,n){for(var r=Infinity,i=-1,s=e?e.length:0,o= +r,t=f(t,n);++i=f?(a=r,s=e.apply(o,i)):u||(u=bt(n,f)),s}},s.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rx(r,t[e])&&r.push(t[e]);return r},s.uniq=k,s.uniqueId= +function(e){var t=P++;return e?e+t:t},s.values=fn,s.where=Tn,s.without=function(e){for(var t=-1,n=e.length,r=o(arguments,1,20),i=[];++t Date: Sat, 29 Sep 2012 15:31:47 -0700 Subject: [PATCH 63/82] Remove component.json and add index.js. Former-commit-id: 16718a8ee6c4b6c834fe96feb58404311b82e3a0 --- component.json | 30 ------------------------------ index.js | 1 + 2 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 component.json create mode 100755 index.js diff --git a/component.json b/component.json deleted file mode 100644 index 58181b8045..0000000000 --- a/component.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "lodash", - "version": "0.7.0", - "description": "A drop-in replacement for Underscore.js delivering performance, bug fixes, and additional features.", - "homepage": "http://lodash.com", - "main": [ - "./lodash.js", - "./lodash.min.js" - ], - "keywords": [ - "browser", - "client", - "functional", - "performance", - "server", - "speed", - "util" - ], - "licenses": [ - { - "type": "MIT", - "url": "http://lodash.com/license" - } - ], - "author": { - "name": "John-David Dalton", - "email": "john.david.dalton@gmail.com", - "web": "http://allyoucanleet.com/" - } -} diff --git a/index.js b/index.js new file mode 100755 index 0000000000..5d063e21f3 --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +module.exports = require('./lodash'); \ No newline at end of file From 56ad6af5b227a89deaff07c0328ccf3d2bea9273 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 29 Sep 2012 15:49:17 -0700 Subject: [PATCH 64/82] Add travis integration. Former-commit-id: 293478e5175ff94dab92bc340034d8d83e3e4773 --- .travis.yml | 4 ++++ README.md | 1 + vendor/benchmark.js/README.md | 1 + 3 files changed, 6 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..811124587a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - 0.6 + - 0.8 \ No newline at end of file diff --git a/README.md b/README.md index db6b7cd87b..f19ff4b930 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Lo-Dash v0.7.0 +[![build status](https://secure.travis-ci.org/bestiejs/lodash.png)](http://travis-ci.org/bestiejs/lodash) A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) for Underscore.js, from the devs behind [jsPerf.com](http://jsperf.com), delivering [performance](http://lodash.com/benchmarks), [bug fixes](https://github.com/bestiejs/lodash#resolved-underscorejs-issues), and [additional features](http://lodash.com/#features). diff --git a/vendor/benchmark.js/README.md b/vendor/benchmark.js/README.md index 2f7a1326ad..fcbab4ebda 100644 --- a/vendor/benchmark.js/README.md +++ b/vendor/benchmark.js/README.md @@ -1,4 +1,5 @@ # Benchmark.js v1.0.0 +[![build status](https://secure.travis-ci.org/bestiejs/benchmark.js.png)](http://travis-ci.org/bestiejs/benchmark.js) A [robust](http://calendar.perfplanet.com/2010/bulletproof-javascript-benchmarks/ "Bulletproof JavaScript benchmarks") benchmarking library that works on nearly all JavaScript platforms1, supports high-resolution timers, and returns statistically significant results. As seen on [jsPerf](http://jsperf.com/). From bc0b92428383481d32fb49d1bca03d418a3bb5bf Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 29 Sep 2012 16:42:13 -0700 Subject: [PATCH 65/82] Reorganize tests. Former-commit-id: 5293cdc1206af20824e8aec86b892afd4badf639 --- test/test.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/test/test.js b/test/test.js index e99f876955..bef79e4603 100644 --- a/test/test.js +++ b/test/test.js @@ -378,11 +378,12 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('strict mode checks'); + _.each(['bindAll', 'defaults', 'extend'], function(methodName) { var func = _[methodName]; - QUnit.module('lodash.' + methodName + ' strict mode checks'); - test('should not throw strict mode errors', function() { + test('lodash.' + methodName + ' should not throw strict mode errors', function() { var object = { 'a': null, 'b': function(){} }, pass = true; @@ -517,17 +518,18 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('object iteration bugs'); + _.each(['forEach', 'forIn', 'forOwn'], function(methodName) { var func = _[methodName]; - QUnit.module('lodash.' + methodName + ' iteration bugs'); - test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() { + test('lodash.' + methodName + ' fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() { var keys = []; func(shadowed, function(value, key) { keys.push(key); }); deepEqual(keys.sort(), shadowedKeys); }); - test('skips the prototype property of functions (test in Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1)', function() { + test('lodash.' + methodName + ' skips the prototype property of functions (test in Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1)', function() { function Foo() {} Foo.prototype.a = 1; @@ -544,11 +546,14 @@ }); }); + /*--------------------------------------------------------------------------*/ + + QUnit.module('exit early'); + _.each(['forEach', 'forIn', 'forOwn'], function(methodName) { var func = _[methodName]; - QUnit.module('lodash.' + methodName + ' can exit early'); - test('can exit early when iterating arrays', function() { + test('lodash.' + methodName + ' can exit early when iterating arrays', function() { var array = [1, 2, 3], values = []; @@ -556,7 +561,7 @@ deepEqual(values, [1]); }); - test('can exit early when iterating objects', function() { + test('lodash.' + methodName + ' can exit early when iterating objects', function() { var object = { 'a': 1, 'b': 2, 'c': 3 }, values = []; @@ -798,6 +803,8 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('isType checks'); + _.each([ 'isArguments', 'isArray', @@ -817,9 +824,8 @@ 'isUndefined' ], function(methodName) { var func = _[methodName]; - QUnit.module('lodash.' + methodName + ' result'); - test('should return a boolean', function() { + test('lodash.' + methodName + ' should return a boolean', function() { var expected = 'boolean'; equal(typeof func(arguments), expected); From d2f7a035b3a50057ea4acc22f7a75a909416bfe4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 29 Sep 2012 17:20:51 -0700 Subject: [PATCH 66/82] Add test-build.js to `npm test`. Former-commit-id: c915ba8401c1c1b11aa69d155cebe2a0a81eb2d1 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e23dd4d2ee..6b9dd29e91 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.7.0", "description": "A drop-in replacement for Underscore.js delivering performance, bug fixes, and additional features.", "homepage": "http://lodash.com", - "main": "lodash", + "main": "./lodash", "keywords": [ "browser", "client", @@ -43,10 +43,10 @@ "rhino" ], "jam": { - "main": "./lodash.min.js" + "main": "./lodash.js" }, "scripts": { "build": "node build", - "test": "node test/test" + "test": "node test/test;node test/test-build" } } From 65ab5fdb346bc67ac13dfdfb95c28f2b7c992850 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 29 Sep 2012 19:31:05 -0700 Subject: [PATCH 67/82] Ensured failed tests trigger travis fails. Former-commit-id: d513b5b1bae77ab1f4aa9e98ec3622e143048def --- package.json | 2 +- vendor/qunit-clib/qunit-clib.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6b9dd29e91..1bf39aaf4b 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,6 @@ }, "scripts": { "build": "node build", - "test": "node test/test;node test/test-build" + "test": "node test/test && node test/test-build" } } diff --git a/vendor/qunit-clib/qunit-clib.js b/vendor/qunit-clib/qunit-clib.js index e487c03e72..e3edde6bef 100644 --- a/vendor/qunit-clib/qunit-clib.js +++ b/vendor/qunit-clib/qunit-clib.js @@ -171,7 +171,7 @@ // exit out of Node.js try { - process.exit(); + process.exit(details.failed); } catch(e) { } } From 463b5c6e490ad9e4bf3c36cc12c5a1a235db72db Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 30 Sep 2012 00:57:09 -0700 Subject: [PATCH 68/82] Tweak build option internals and add test template files. Former-commit-id: ed5ec6ed7886a066c8c727de19dc0fe6548a276d --- build.js | 21 ++++++++++---------- build/minify.js | 46 ++++++++++++++++++++++++++++++------------- build/post-compile.js | 9 ++++++--- build/pre-compile.js | 21 +++++++++++++++----- test/template/a.jst | 3 +++ test/template/b.jst | 1 + test/template/c.tpl | 1 + 7 files changed, 70 insertions(+), 32 deletions(-) create mode 100644 test/template/a.jst create mode 100644 test/template/b.jst create mode 100644 test/template/c.tpl diff --git a/build.js b/build.js index 3d38dbad82..8bfd4b24db 100755 --- a/build.js +++ b/build.js @@ -258,12 +258,12 @@ * each template file's basename. * * @private - * @param {String} pattern The file path pattern. - * @param {Object} options The options object. + * @param {String} [pattern='/*.jst'] The file path pattern. + * @param {Object} [options=_.templateSettings] The options object. * @returns {String} Returns the compiled source. */ function buildTemplate(pattern, options) { - pattern || (pattern = './*.jst'); + pattern || (pattern = path.join(cwd, '*.jst')); options || (options = _.templateSettings); var directory = path.dirname(pattern); @@ -289,9 +289,9 @@ ); fs.readdirSync(directory).forEach(function(filename) { - var filepath = path.join(directory, filename); + var filePath = path.join(directory, filename); if (pattern.test(filename)) { - var text = fs.readFileSync(filepath, 'utf8'), + var text = fs.readFileSync(filePath, 'utf8'), precompiled = getFunctionSource(_.template(text, null, options)), prop = filename.replace(/\..*$/, ''); @@ -809,9 +809,9 @@ /** * Creates a debug and minified build, executing the `callback` for each. - * The `callback` is invoked with 2 arguments; (filepath, source) + * The `callback` is invoked with 2 arguments; (filePath, source) * - * @param {Array} options The build options array. + * @param {Array} [options=[]] The build options array. * @param {Function} callback The function called per build. */ function build(options, callback) { @@ -1429,7 +1429,8 @@ if (!isDebug) { workingName += '.min'; minify(source, { - 'silent': isSilent, + 'isSilent': isSilent, + 'isTemplate': isTemplate, 'workingName': workingName, 'onComplete': function(source) { // correct overly aggressive Closure Compiler minification @@ -1458,8 +1459,8 @@ } else { // or invoked directly - build(process.argv, function(source, filepath) { - filepath && fs.writeFileSync(filepath, source, 'utf8'); + build(process.argv, function(source, filePath) { + filePath && fs.writeFileSync(filePath, source, 'utf8'); }); } }()); diff --git a/build/minify.js b/build/minify.js index b04571a965..bba7047e99 100755 --- a/build/minify.js +++ b/build/minify.js @@ -9,7 +9,7 @@ spawn = require('child_process').spawn; /** The directory that is the base of the repository */ - var basePath = path.join(__dirname, '../'); + var basePath = fs.realpathSync(path.join(__dirname, '../')); /** The directory where the Closure Compiler is located */ var closurePath = path.join(basePath, 'vendor', 'closure-compiler', 'compiler.jar'); @@ -18,9 +18,9 @@ var distPath = path.join(basePath, 'dist'); /** Load other modules */ - var preprocess = require(path.join(__dirname, 'pre-compile')), - postprocess = require(path.join(__dirname, 'post-compile')), - uglifyJS = require(path.join(basePath, 'vendor', 'uglifyjs', 'uglify-js')); + var preprocess = require('./pre-compile'), + postprocess = require('./post-compile'), + uglifyJS = require('../vendor/uglifyjs/uglify-js'); /** Closure Compiler command-line options */ var closureOptions = [ @@ -50,14 +50,22 @@ options = source; var filePath = options[options.length - 1], dirPath = path.dirname(filePath), - workingName = path.basename(filePath, '.js') + '.min', - outputPath = path.join(dirPath, workingName + '.js'), - isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -1; + isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -1, + isTemplate = options.indexOf('-t') > -1 || options.indexOf('--template') > -1, + workingName = path.basename(filePath, '.js') + '.min'; + workingName = options.reduce(function(result, value, index) { + return /-wn|--working-name/.test(value) + ? options[index + 1] + : result; + }, workingName); + + var outputPath = path.join(dirPath, workingName + '.js'); source = fs.readFileSync(filePath, 'utf8'); + options = { - 'silent': isSilent, - 'workingName': workingName, + 'isSilent': isSilent, + 'isTemplate': isTemplate, 'onComplete': function(source) { fs.writeFileSync(outputPath, source, 'utf8'); } @@ -71,8 +79,8 @@ * * @private * @constructor - * @param {String} source The source to minify. - * @param {Object} options The options object containing `onComplete`, + * @param {String} [source=''] The source to minify. + * @param {Object} [options={}] The options object containing `onComplete`, * `silent`, and `workingName`. */ function Minify(source, options) { @@ -94,11 +102,12 @@ this.compiled = {}; this.hybrid = {}; this.uglified = {}; - this.isSilent = !!options.silent; + this.isSilent = !!options.isSilent; + this.isTemplate = !!options.isTemplate; this.onComplete = options.onComplete || function() {}; this.workingName = options.workingName || 'temp'; - source = preprocess(source); + source = preprocess(source, options); this.source = source; // begin the minification process @@ -117,10 +126,19 @@ * @param {Function} callback The function to call once the process completes. */ function closureCompile(source, message, callback) { + var options = closureOptions.slice(); + + // use simple optimizations when minifying template files + if (this.isTemplate) { + options = options.map(function(value) { + return value.replace(/^(compilation_level)=.+$/, '$1=SIMPLE_OPTIMIZATIONS'); + }); + } + // the standard error stream, standard output stream, and Closure Compiler process var error = '', output = '', - compiler = spawn('java', ['-jar', closurePath].concat(closureOptions)); + compiler = spawn('java', ['-jar', closurePath].concat(options)); // juggle arguments if (typeof message == 'function') { diff --git a/build/post-compile.js b/build/post-compile.js index 37358a6f99..dc40ac2db5 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -56,13 +56,16 @@ // expose `postprocess` if (module != require.main) { module.exports = postprocess; - } else { + } + else { // read the Lo-Dash source file from the first argument if the script // was invoked directly (e.g. `node post-compile.js source.js`) and write to // the same file (function() { - var source = fs.readFileSync(process.argv[2], 'utf8'); - fs.writeFileSync(process.argv[2], postprocess(source), 'utf8'); + var filePath = process.argv[2], + source = fs.readFileSync(filePath, 'utf8'); + + fs.writeFileSync(filePath, postprocess(source), 'utf8'); }()); } }()); diff --git a/build/pre-compile.js b/build/pre-compile.js index dfe28763ca..d990f0e3f8 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -246,15 +246,22 @@ * Pre-process a given Lo-Dash `source`, preparing it for minification. * * @param {String} source The source to process. + * @param {Object} [options={}] The options object. * @returns {String} Returns the processed source. */ - function preprocess(source) { - // remove copyright to add later in post-compile.js - source = source.replace(/\/\*![\s\S]+?\*\//, ''); + function preprocess(source, options) { + options || (options = {}); // remove unrecognized JSDoc tags so Closure Compiler won't complain source = source.replace(/@(?:alias|category)\b.*/g, ''); + if (options.isTemplate) { + return source; + } + + // remove copyright to add later in post-compile.js + source = source.replace(/\/\*![\s\S]+?\*\//, ''); + // add brackets to whitelisted properties so Closure Compiler won't mung them // http://code.google.com/closure/compiler/docs/api-tutorial3.html#export source = source.replace(RegExp('\\.(' + propWhitelist.join('|') + ')\\b', 'g'), "['$1']"); @@ -439,8 +446,12 @@ // was invoked directly (e.g. `node pre-compile.js source.js`) and write to // the same file (function() { - var source = fs.readFileSync(process.argv[2], 'utf8'); - fs.writeFileSync(process.argv[2], preprocess(source), 'utf8'); + var options = process.argv, + filePath = options[options.length - 1], + isTemplate = options.indexOf('-t') > -1 || options.indexOf('--template') > -1, + source = fs.readFileSync(filePath, 'utf8'); + + fs.writeFileSync(filePath, preprocess(source, { 'isTemplate': isTemplate }), 'utf8'); }()); } }()); diff --git a/test/template/a.jst b/test/template/a.jst new file mode 100644 index 0000000000..a2a8b6e003 --- /dev/null +++ b/test/template/a.jst @@ -0,0 +1,3 @@ +
    +<% _.forEach(people, function(name) { %>
  • <%= name %>
  • <% }); %> +
\ No newline at end of file diff --git a/test/template/b.jst b/test/template/b.jst new file mode 100644 index 0000000000..cad081d19f --- /dev/null +++ b/test/template/b.jst @@ -0,0 +1 @@ +<% print("Hello " + epithet); %>. \ No newline at end of file diff --git a/test/template/c.tpl b/test/template/c.tpl new file mode 100644 index 0000000000..c7a43bc1fd --- /dev/null +++ b/test/template/c.tpl @@ -0,0 +1 @@ +Hello {{ name }}! \ No newline at end of file From de821e55ae48de984e79b6654ca227af1ec6f411 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 30 Sep 2012 01:03:43 -0700 Subject: [PATCH 69/82] Add `template` and `settings` build options unit tests and tweak `_.template` docs. Former-commit-id: c814799c82e5a1dde60e5eda4dda5cb192d437f9 --- doc/README.md | 6 +-- lodash.js | 6 +-- lodash.min.js | 36 ++++++++-------- test/test-build.js | 102 +++++++++++++++++++++++++++++++++------------ 4 files changed, 100 insertions(+), 50 deletions(-) diff --git a/doc/README.md b/doc/README.md index b442d5fea0..41a04589ae 100644 --- a/doc/README.md +++ b/doc/README.md @@ -2527,7 +2527,7 @@ var compiled = _.template('hello: <%= name %>'); compiled({ 'name': 'moe' }); // => 'hello: moe' -var list = '<% _.forEach(people, function(name) { %>
  • <%= name %>
  • <% }); %>'; +var list = '<% _.forEach(people, function(name) { %>
  • <%= name %>
  • <% }); %>'; _.template(list, { 'people': ['moe', 'larry', 'curly'] }); // => '
  • moe
  • larry
  • curly
  • ' @@ -2536,12 +2536,12 @@ _.template('<%- value %>', { 'value': '