From 754b1de5979de8a89776237c808d38334d8dfbc2 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 21 May 2012 11:32:43 -0400 Subject: [PATCH] Cleanup and prep for v0.2.0. Former-commit-id: 27fb5b6ce649bedae9ba8127278322a037075e41 --- README.md | 42 +++++++++++++++++++++++++++++++++++------- lodash.js | 27 +++++++++++++++++++-------- lodash.min.js | 24 ++++++++++++++---------- 3 files changed, 68 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 320ee8240..fb1c306c0 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # Lo-Dash v0.1.0 -A drop-in replacement for [Underscore.js](https://github.com/documentcloud/underscore/) that delivers up to [8x performance improvements](http://jsperf.com/lodash-underscore#chart=bar), [bug fixes](https://github.com/bestiejs/lodash/blob/master/test/test.js#L88), and additional features. +Lo-Dash, from the devs behind [jsPerf.com](http://jsperf.com), is a drop-in replacement for Underscore.js that delivers [performance improvements](http://jsperf.com/lodash-underscore#filterby=family), [additional features](https://github.com/bestiejs/lodash/wiki/The-Low-Down#wiki-features), and works on nearly all JavaScript platforms1. -## Screencast +## Screencasts -For more information check out [this screencast](http://dl.dropbox.com/u/513327/allyoucanleet/post/20/file/screencast.mp4) over Lo-Dash. +For more information check out the series of screencasts over Lo-Dash: + * [Introducing Lo-Dash](http://dl.dropbox.com/u/513327/allyoucanleet/post/20/file/screencast.mp4) + * [Compiling and custom builds]() ## BestieJS @@ -12,7 +14,7 @@ Lo-Dash is part of the BestieJS *"Best in Class"* module collection. This means ## Documentation -The documentation for Lo-Dash can be viewed here: [/doc/README.md](https://github.com/bestiejs/lodash/blob/master/doc/README.md#readme) +The documentation for Lo-Dash can be viewed here: Underscore's [documentation](http://documentcloud.github.com/underscore/) may also be used. @@ -20,11 +22,32 @@ For a list of upcoming features, check out our [roadmap](https://github.com/best ## So What's The Secret? -Lo-Dash's performance is gained by avoiding 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. +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. -## What else? +## Any New Features? -Lo-Dash comes with AMD loader support baked in, chainable `_.each`, and will [soon address](https://github.com/bestiejs/lodash/wiki/Roadmap) cross-browser object iteration issues. +Lo-Dash comes with AMD loader support, chainable `_.each`, lazy `_.bind`, [and more](https://github.com/bestiejs/lodash/wiki/The-Low-Down#wiki-features)... + +## Custom builds + +Creating custom builds to keep your utility belt lightweight is easy. +We handle all the method dependency and alias mapping for you. + +Custom builds may be created in two ways: + + 1. Use the`include` argument to pass the names of the methods to include in the build. +~~~ bash +node build include=each,filter,map,noConflict +node build include="each, filter, map, noConflict" +~~~ + + 2. Use the `exclude` argument to pass the names of the methods to exclude from the build. +~~~ bash +node build exclude=isNaN,union,zip +node build exclude="isNaN, union, zip" +~~~ + +Custom builds are saved to `lodash.custom.js` and `lodash.custom.min.js`. ## Installation and usage @@ -92,6 +115,11 @@ git submodule update --init Feel free to fork and send pull requests if you see improvements! +## Footnotes + + 1. Lo-Dash has been tested in at least Chrome 5-19, Firefox 1.5-12, IE 6-9, Opera 9.25-11.64, Safari 3.0.4-5.1.3, Node.js 0.4.8-0.6.18, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC3. + + ## Author * [John-David Dalton](http://allyoucanleet.com/) diff --git a/lodash.js b/lodash.js index 7c5909153..825cb7b58 100644 --- a/lodash.js +++ b/lodash.js @@ -635,11 +635,11 @@ * @returns {Array|Object} Returns the `collection`. * @example * - * _.forEach([1, 2, 3], function(num) { alert(num); }); - * // => alerts each number in turn... + * _([1, 2, 3]).forEach(function(num) { alert(num); }).join(','); + * // => alerts each number in turn and returns "1,2,3" * * _.forEach({ 'one': 1, 'two': 2, 'three': 3}, function(num) { alert(num); }); - * // => alerts each number in turn... + * // => alerts each number in turn */ var forEach = createIterator(baseIteratorOptions, { 'top': 'if (thisArg) callback = bind(callback, thisArg)' @@ -851,7 +851,7 @@ }); /** - * Gets the number of values in the `collection`. + * Gets the number of values in the `collection` or the `length` of a string value. * * @static * @memberOf _ @@ -860,8 +860,14 @@ * @returns {Number} Returns the number of values in the collection. * @example * + * _.size([1, 2]); + * // => 2 + * * _.size({ 'one': 1, 'two': 2, 'three': 3 }); * // => 3 + * + * _.size('curly'); + * // => 5 */ function size(collection) { var className = toString.call(collection); @@ -889,6 +895,9 @@ * * _.sortBy([1, 2, 3, 4, 5, 6], function(num) { return Math.sin(num); }); * // => [5, 4, 6, 3, 1, 2] + * + * _.sortBy([1, 2, 3, 4, 5, 6], function(num) { return this.sin(num); }, Math); + * // => [5, 4, 6, 3, 1, 2] */ function sortBy(collection, callback, thisArg) { if (toString.call(callback) != funcClass) { @@ -1828,7 +1837,8 @@ * 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. + * instead of the trailing, edge of the `wait` timeout. Subsequent calls to + * the debounced function will return the result of the last `func` call. * * @static * @memberOf _ @@ -2012,7 +2022,8 @@ * 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, `func` will also be called on the trailing edge - * of the `wait` timeout. + * of the `wait` timeout. Subsequent calls to the throttled function will + * return the result of the last `func` call. * * @static * @memberOf _ @@ -2699,7 +2710,7 @@ */ function escape(string) { // the `>` character doesn't require escaping in HTML and has no special - // meaning unless it's part of an open tag + // meaning unless it's part of a tag or an unquoted attribute value // http://mathiasbynens.be/notes/ambiguous-ampersands (semi-related fun fact) return (string + '') .replace(/&/g, '&') @@ -3199,7 +3210,7 @@ lodash.take = first; lodash.unique = uniq; - // add pseudo private template used and removed in the build process + // add pseudo private template used and removed during the build process lodash._iteratorTemplate = iteratorTemplate; /*--------------------------------------------------------------------------*/ diff --git a/lodash.min.js b/lodash.min.js index 69ab31ede..4367b2aa8 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -1,12 +1,16 @@ -"use strict";var n=!0,o=null,r=!1;(function(u,m){function R(a){return"[object Arguments]"==h.call(a)}function c(a){return new p(a)}function p(a){if(a&&a._wrapped)return a;this._wrapped=a}function j(){for(var a,b,d,k=-1,c=arguments.length,f={e:"",f:"",k:"",q:"",c:{m:"++ow(e,a[b])&&c.push(a[b]);return c},c.escape=function(a){re ,k=Function("_","return "+a)(c),b?k(b):(k.source=a,k)},c.throttle=function(a,b){function d(){i=new Date,g=m,a.apply(f,c)}var c,e,f,g,i=0;return function(){var h=new Date,j=b-(h-i);return c=arguments,f=this,0>=j?(i=h,e=a.apply(f,c)):g||(g=P(d,j)),e}},c.times=function(a,b,d){d&&(b=v(b,d));for(d=0;dw(b,d[a])&&b.push(d[a]);return b},c.uniq=ka,c.uniqueId=function(a){var b=Aa++;return a?a+b:b},c.values=ra,c.without=function(a){for(var b=l.call(arguments,1),d=-1,c=a.length,e=[];++dw(b,a[d])&&e.push(a[d]);return e},c.wrap=function(a,b){return function(){var c=[a];return arguments.length&&E.apply(c,arguments),b.apply(this,c)}},c.zip=function(){for(var a=-1,b=ia(Q(arguments,"length")),c=Array(b);++a