From 4a6e17b214d2adc2dbc8d02348d4e8e36cb40aee Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 4 Oct 2012 18:15:45 -0700 Subject: [PATCH 01/26] Reduce lodash builds and cleanup README.md. Former-commit-id: 3c6bbc236a35687c843a8cb27c29f71ed89d0ab0 --- README.md | 2 +- doc/README.md | 194 +++++++++++++++++++-------------------- lodash.js | 29 +++--- lodash.min.js | 20 ++-- lodash.underscore.min.js | 8 +- 5 files changed, 123 insertions(+), 130 deletions(-) diff --git a/README.md b/README.md index 60f099ae64..79a50a9be4 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ require({ * `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L267-276)] * `_.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.1/test/test.js#L955-977)] * `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L465-468)] - * `_.forEach` should allow exiting iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L553-570)] + * `_.forEach` should allow exiting iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L553-571)] * `_.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.1/test/test.js#L712-717)] * `_.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.1/test/test.js#L772-784)] * `_.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.1/test/test.js#L865-867)] diff --git a/doc/README.md b/doc/README.md index af2222c9ea..26337495c3 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#L4002 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3995 "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#L3108 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3101 "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#L3141 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3134 "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#L3171 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3164 "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#L3927 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3920 "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#L1039 "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#L2413 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2409 "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#L3208 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3201 "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#L1892 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1888 "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#L1928 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1924 "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#L3241 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3234 "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#L1132 "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#L3306 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3299 "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#L3286 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3279 "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#L2442 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2438 "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#L3526 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3519 "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#L1949 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1945 "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#L1152 "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#L1969 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1965 "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#L1991 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1987 "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#L2480 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2476 "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#L2504 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2500 "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#L2018 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2014 "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#L1182 "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#L1206 "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#L1223 "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#L2046 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2042 "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#L1246 "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#L3546 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3539 "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#L2547 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2542 "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#L2582 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2577 "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#L2603 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2598 "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#L814 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L810 "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#L2074 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2070 "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#L836 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L832 "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#L862 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L858 "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#L1263 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1259 "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#L1280 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1276 "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#L1297 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1293 "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#L1322 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1318 "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#L1361 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1357 "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#L1518 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1514 "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#L879 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L875 "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#L1576 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1572 "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#L1599 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1595 "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#L1616 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1612 "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#L1542 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1538 "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#L913 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L909 "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#L1633 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1629 "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#L1650 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1646 "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#L1668 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1664 "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#L1685 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1681 "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#L2637 "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#L2668 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2663 "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#L3344 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3337 "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 differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. @@ -1707,7 +1707,7 @@ func(); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2109 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2105 "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#L2705 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2700 "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#L3366 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3359 "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#L1728 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1724 "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#L2741 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2735 "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#L3572 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3565 "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#L3603 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3596 "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#L2776 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2769 "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#L1785 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1781 "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#L3392 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3385 "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#L1801 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1797 "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#L3427 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3420 "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#L1832 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1828 "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#L2132 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2128 "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#L3626 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3619 "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#L2820 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2813 "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#L2160 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2156 "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#L2197 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2193 "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#L2234 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2230 "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#L2859 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2852 "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#L3665 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3658 "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#L2879 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2872 "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#L2258 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2254 "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#L2283 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2279 "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#L2313 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2309 "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#L2932 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2925 "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#L3954 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3947 "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#L3735 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3728 "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#L3449 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3442 "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#L3854 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3847 "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#L2349 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2345 "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#L3879 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3872 "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#L2960 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2953 "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#L3004 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2997 "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#L3897 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3890 "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#L1862 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1858 "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#L2383 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2379 "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#L3045 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3038 "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#L3500 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3493 "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#L3076 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3069 "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#L3972 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3965 "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#L3989 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3982 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.js b/lodash.js index 76108074f8..50cbcfc654 100644 --- a/lodash.js +++ b/lodash.js @@ -531,13 +531,11 @@ if (isLarge) { // init value cache - var key, - index = fromIndex - 1; - + var index = fromIndex - 1; while (++index < length) { // manually coerce `value` to string because `hasOwnProperty`, in some // older versions of Firefox, coerces objects incorrectly - key = array[index] + ''; + var key = array[index] + ''; (hasOwnProperty.call(cache, key) ? cache[key] : (cache[key] = [])).push(array[index]); } } @@ -666,11 +664,9 @@ * @private * @param {Object} [options1, options2, ...] The compile options objects. * - * useHas - A boolean to specify whether or not to use `hasOwnProperty` checks - * in the object loop. + * useHas - A boolean to specify using `hasOwnProperty` checks in the object loop. * - * useStrict - A boolean to specify whether or not to include the ES5 - * "use strict" directive. + * useStrict - A boolean to specify including the "use strict" directive. * * args - A string of comma separated arguments the iteration function will accept. * @@ -2502,13 +2498,12 @@ * // => [1, 2, 3, [[4]]]; */ function flatten(array, shallow) { - var value, - index = -1, + var index = -1, length = array ? array.length : 0, result = []; while (++index < length) { - value = array[index]; + var value = array[index]; // recursively flatten arrays (susceptible to call stack limits) if (isArray(value)) { @@ -2703,15 +2698,14 @@ * // => { 'name': 'curly', 'age': 60 }; */ function max(array, callback, thisArg) { - var current, - computed = -Infinity, + var computed = -Infinity, index = -1, length = array ? array.length : 0, result = computed; callback = createCallback(callback, thisArg); while (++index < length) { - current = callback(array[index], index, array); + var current = callback(array[index], index, array); if (current > computed) { computed = current; result = array[index]; @@ -2739,15 +2733,14 @@ * // => 2 */ function min(array, callback, thisArg) { - var current, - computed = Infinity, + var computed = Infinity, index = -1, length = array ? array.length : 0, result = computed; callback = createCallback(callback, thisArg); while (++index < length) { - current = callback(array[index], index, array); + var current = callback(array[index], index, array); if (current < computed) { computed = current; result = array[index]; @@ -3737,7 +3730,7 @@ // http://ejohn.org/blog/javascript-micro-templating/ // and Laura Doktorova's doT.js // https://github.com/olado/doT - text += ''; + text || (text = ''); options || (options = {}); var isEvaluating, diff --git a/lodash.min.js b/lodash.min.js index a817335872..addd209f61 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -2,7 +2,7 @@ Lo-Dash 0.8.1 lodash.com/license Underscore.js 1.4.1 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,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(e=(n||H),s=i?{}:e;if(i)for(n=t-1;++nn||e===t)return 1;if(es;s++)t+="i='"+i.o[s]+"';if(" @@ -11,9 +11,9 @@ e||v(e))return t;var n=e.constructor;return(!kt||"function"==typeof e.toString|| ;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?e.length:0,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){if(e)return t== -r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n,r=-1,i=e?e.length:0,s=[];++rn?ut(0,i+n):n||0)-1;else if(n)return r=C(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function N(e,t,n){return e?Z.call(e,t==r||n?1:t):[]}function C(e,t,n,r){for(var i=0 -,s=e?e.length:i,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 +r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?ut(0,i+n):n||0)-1;else if(n)return r=C(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function N(e,t,n){return e?Z.call(e,t==r||n?1:t):[]}function C(e,t,n,r){for( +var i=0,s=e?e.length:i,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={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Ht={"\\":"\\","'":"'" @@ -31,9 +31,9 @@ s.isDate=function(e){return et.call(e)==pt},s.isElement=function(e){return e?1== e){return e===t},s.keys=rn,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:Z.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){var r=e?e.length:0;for("number"==typeof n&&(r=(0>n?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?e.length:0,r=o(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?e.length:0,r=o(arguments,1,20),i=[];++targuments.length;if(s!==+s)var u=Mt(e),s=u.length;return f(e,function( -a,f,l){f=u?u[--s]:--s,n=o?(o=i,e[f]):t.call(r,n,e[f],f,l)}),n}function _(e,t,n){if(e)return t==r||n?e[0]:ot.call(e,0,t)}function D(e,t){for(var n,r=-1,i=e?e.length:0,s=[];++rn?dt(0,i+n):n||0)-1;else if(n)return r=j(e,t),e[r]===t?r:-1;for(;++rr&&(r= -n,o=e[i]);return o}function B(e,t,n){return e?ot.call(e,t==r||n?1:t):[]}function j(e,t,n,r){for(var i=0,s=e?e.length:i,n=x(n,r),t=n(t);i>>1,n(e[r])P(a,r))a.push(r),u.push(e[s]);return u}function I(e,t){return Nt||at&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,J=/&(?:amp|lt|gt|quot|#x27);/g,K=/\b__p\+='';/g +a,f,l){f=u?u[--s]:--s,n=o?(o=i,e[f]):t.call(r,n,e[f],f,l)}),n}function _(e,t,n){if(e)return t==r||n?e[0]:ot.call(e,0,t)}function D(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?dt(0,i+n):n||0)-1;else if(n)return r=j(e,t),e[r]===t?r:-1;for(;++rr&& +(r=n,o=e[i]);return o}function B(e,t,n){return e?ot.call(e,t==r||n?1:t):[]}function j(e,t,n,r){for(var i=0,s=e?e.length:i,n=x(n,r),t=n(t);i>>1,n(e[r])P(a,r))a.push(r),u.push(e[s]);return u}function I(e,t){return Nt||at&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,J=/&(?:amp|lt|gt|quot|#x27);/g,K=/\b__p\+='';/g ,Q=/\b(__p\+=)''\+/g,G=/(__e\(.*?\)|\b__t\))\+'';/g,Y=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,Z=RegExp("^"+(W.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),et=/($^)/,tt=/[&<>"']/g,nt=/['\n\r\t\u2028\u2029\\]/g,rt=z.concat,it=W.hasOwnProperty,st=z.push,ot=z.slice,ut=W.toString,at=Z.test(at=ot.bind)&&at,ft=Math.floor,lt=Z.test(lt=Object.getPrototypeOf)&<,ct=Z.test(ct=Array.isArray)&&ct,ht=e.isFinite,pt=Z.test(pt=Object.keys)&&pt,dt=Math.max,vt=Math .min,mt=Math.random,gt="[object Boolean]",yt="[object Date]",bt="[object Number]",wt="[object Object]",Et="[object RegExp]",St="[object String]",xt=e.clearTimeout,Tt=e.setTimeout,Nt=at&&/\n|Opera/.test(at+ut.call(e.opera)),Ct={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},kt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};w.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"" },w.isArguments=function(e){return"[object Arguments]"==ut.call(e)},w.isArguments(arguments)||(w.isArguments=function(e){return e?it.call(e,"callee"):i});var Lt=ct||function(e){return"[object Array]"==ut.call(e)};L(/x/)&&(L=function(e){return"[object Function]"==ut.call(e)});var W=lt?function(e){if(!e||"object"!=typeof e)return i;var t=e.valueOf,n="function"==typeof t&&(n=lt(t))&<(n);return n?e==n||lt(e)==n&&!isArguments(e):A(e)}:A,At={"&":"&","<":"<",">":">",'"':""","'":"'" @@ -27,7 +27,7 @@ r||n?e[i-1]:ot.call(e,-t||i)}},w.lastIndexOf=function(e,t,n){var r=e?e.length:0; ._=V,this},w.object=function(e,t){for(var n=-1,r=e?e.length:0,i={};++nP(a,r))o[r]=i;return o},w.once=function(e){var t,s=i;return function(){return s?t:(s=n,t=e.apply(this,arguments),e=r,t)}},w.pairs=function(e){var t,n,r=[];if(!e)return r;for(t in e)it.call(e,t)&&(n=e[t],r.push([t,n]));return r },w.pick=function(e,t,n){var r,i,s=e,o={};if(!e)return o;if("function"!=typeof t){var s=rt.apply(z,arguments),u=s.length;for(r=1;r=f?(a=r,s=e.apply(o,i)):u||(u=Tt(n,f)),s}},w.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rP(r,t[e])&&r.push(t[e]);return r},w.uniq=F,w.uniqueId=function(e){var t=X++;return e?e+t:t},w.values=d,w.where=function(e,t){var r,i,s=[];if(!e)return s;var o=[];m(t,function(e,t){o.push(t)});var u=o.length,a=e.length;r=-1;if(a===+a)for(;++r Date: Sat, 6 Oct 2012 13:56:09 -0700 Subject: [PATCH 02/26] Simplify `createIterator`. Former-commit-id: 0530a9db49488900843c6312cc0d30b1dc641120 --- build.js | 2 +- lodash.js | 28 +++++++---------- lodash.min.js | 68 ++++++++++++++++++++-------------------- lodash.underscore.min.js | 54 +++++++++++++++---------------- 4 files changed, 73 insertions(+), 79 deletions(-) diff --git a/build.js b/build.js index 211805b937..a9e6094796 100755 --- a/build.js +++ b/build.js @@ -1318,7 +1318,7 @@ .replace(/__p *\+= *' *';/g, '') .replace(/(__p *\+= *)' *' *\+/g, '$1') .replace(/(\{) *;|; *(\})/g, '$1$2') - .replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '$1'); + .replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '($1)'); // remove the with-statement snippet = snippet.replace(/ *with *\(.+?\) *{/, '\n').replace(/}([^}]*}[^}]*$)/, '$1'); diff --git a/lodash.js b/lodash.js index 50cbcfc654..6f0f8054cc 100644 --- a/lodash.js +++ b/lodash.js @@ -314,7 +314,7 @@ // the `iteratee` may be reassigned by the `top` snippet 'var index, value, iteratee = <%= firstArg %>, ' + // assign the `result` variable an initial value - 'result<% if (init) { %> = <%= init %><% } %>;\n' + + 'result = <%= init || firstArg %>;\n' + // exit early if the first argument is falsey 'if (!<%= firstArg %>) return result;\n' + // add code before the iteration branches @@ -686,13 +686,10 @@ * @returns {Function} Returns the compiled function. */ function createIterator() { - var index = -1, - length = arguments.length; - - // merge options into a template data object var data = { 'bottom': '', 'hasDontEnumBug': hasDontEnumBug, + 'init': '', 'isKeysFast': isKeysFast, 'noArgsEnum': noArgsEnum, 'noCharByIndex': noCharByIndex, @@ -704,8 +701,11 @@ 'objectBranch': {} }; - while (++index < length) { - var object = arguments[index]; + var object, + index = -1; + + // merge options into a template data object + while (object = arguments[++index]) { for (var prop in object) { var value = object[prop]; // keep this regexp explicit for the build pre-process @@ -721,14 +721,8 @@ } } // set additional template `data` values - var args = data.args, - firstArg = /^[^,]+/.exec(args)[0], - init = data.init; - - data.firstArg = firstArg; - data.init = init == null ? firstArg : init; - - if (firstArg != 'collection' || !data.arrayBranch.inLoop) { + var args = data.args; + if ((data.firstArg = /^[^,]+/.exec(args)[0]) != 'collection' || !data.arrayBranch.inLoop) { data.arrayBranch = null; } // create the function factory @@ -1742,7 +1736,7 @@ ' result[index] = stackB[stackLength]\n' + ' } else {\n' + ' stackA.push(source);\n' + - ' stackB.push(value = (value = result[index]) && isArr\n' + + ' stackB.push(value = (value = result[index], isArr)\n' + ' ? (isArray(value) ? value : [])\n' + ' : (isPlainObject(value) ? value : {})\n' + ' );\n' + @@ -1985,7 +1979,7 @@ * // => 2 */ var find = createIterator(baseIteratorOptions, forEachIteratorOptions, { - 'init': false, + 'init': 'undefined', 'inLoop': 'if (callback(value, index, collection)) return value' }); diff --git a/lodash.min.js b/lodash.min.js index addd209f61..8aa7d249ec 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -3,37 +3,37 @@ Underscore.js 1.4.1 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,n){t||(t=0);var r=e.length,i=r-t>=(n||H),s=i?{}:e;if(i)for(n=t-1;++nn||e===t)return 1;if(es;s++)t+="i='"+i.o[s]+"';if(" -,"constructor"==i.o[s]&&(t+="!(g&&g.prototype===j)&&"),t+="h.call(j,i)){A=j[i];"+i.l.h+"}"}if(i.c||i.m)t+="}"}return t+=i.e+";return t",Function("D,E,F,I,e,f,J,h,M,O,Q,S,T,X,Y,l,q,v,w,y,z","var G=function("+e+"){"+t+"};return G")(_t,_,L,u,K,f,Zt,Q,x,v,Vt,m,$t,vt,Pt,ot,Y,Z,gt,et)}function c(e){return"\\"+Ht[e]}function h(e){return Kt[e]}function p(){}function d(e){return Qt[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?(Zt(e,function(e,n,r){return t=!Q.call(r,n),i}),t===i):(Zt(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=Pt[typeof e]){var a=et.call(e);if(!Dt[a]||Tt&&v(e))return e;var f=a==ct,s=f||(a==vt?$t(e):s)}if(!s||!t)return s?f?Z.call(e):Yt({},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?e.length:0,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){if(e)return t== -r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?ut(0,i+n):n||0)-1;else if(n)return r=C(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function N(e,t,n){return e?Z.call(e,t==r||n?1:t):[]}function C(e,t,n,r){for( -var i=0,s=e?e.length:i,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={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Ht={"\\":"\\","'":"'" -,"\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 Bt={a:"d,c,x",i:"d",p:"c=f(c,x)",h:"if(c(A,i,d)===false)return t"},jt={i:"{}",p:"c=f(c,x)",h:"var p=c(A,i,d);(h.call(t,p)?t[p]++:t[p]=1)"},Ft={i:"true",h:"if(!c(A,i,d))return!t"},It={q:i,r:i,a:"m",i:"m",p:"for(var a=1,b=arguments.length;a":">",'"':""","'":"'"},Qt=Xt(Kt),Gt=l(It,{h:"if(t[i]==null)"+It.h}),Yt=l(It),Zt=l(Bt,Rt,Ut,{q:i}),en=l(Bt,Rt,Ut),tn=l({q:i,a:"m",i:"[]",h:"if(S(A))t.push(i)",e:"t.sort()"}),nn=l({a:"A",i:"true",p:"var H=y.call(A),k=A.length;if(D[H]"+(Tt?"||O(A)":"")+"||(H==X&&k===+k&&S(A.splice)))return!k" -,h:{k:"return false"}}),rn=ot?function(e){var t=typeof e;return"function"==t&&Y.call(e,"prototype")?Jt(e):e&&Pt[t]?ot(e):[]}:Jt,sn=l(It,{a:"m,dd,N",p:"var P,C=arguments,a=0;if(N==I){var b=2,ee=C[3],ff=C[4]}else var b=C.length,ee=[],ff=[];while(++a-1"},h:"if(A===hh)return true"}),cn=l(Bt,jt),hn=l(Bt,Ft),pn=l(Bt,qt),dn=l(Bt,Rt,{i:i,h:"if(c(A,i,d))return A"}),vn=l(Bt,Rt),mn=l(Bt,jt,{h:"var p=c(A,i,d);(h.call(t,p)?t[p]:t[p]=[]).push(A)" -}),gn=l(zt,{a:"d,U",p:"var C=v.call(arguments,2),R=typeof U=='function'",h:{b:"t[i]=(R?U:A[U]).apply(A,C)",k:"t"+(Ot?"[n]=":".push")+"((R?U:A[U]).apply(A,C))"}}),yn=l(Bt,zt),bn=l(zt,{a:"d,bb",h:{b:"t[i]=A[bb]",k:"t"+(Ot?"[n]=":".push")+"(A[bb])"}}),wn=l({a:"d,c,B,x",i:"B",p:"var V=arguments.length<3;c=f(c,x)",d:{b:"if(V)t=j[++i]"},h:{b:"t=c(t,A,i,d)",k:"t=V?(V=false,A):c(t,A,i,d)"}}),En=l(Bt,qt,{h:"!"+qt.h}),Sn=l(Bt,Ft,{i:"false",h:Ft.h.replace("!","")}),xn=l(Bt,jt,zt,{h:{b:"t[i]={a:c(A,i,d),b:i,c:A}" -,k:"t"+(Ot?"[n]=":".push")+"({a:c(A,i,d),b:i,c:A})"},e:"t.sort(I);k=t.length;while(k--)t[k]=t[k].c"}),Tn=l(qt,{a:"d,aa",p:"var s=[];J(aa,function(A,p){s.push(p)});var cc=s.length",h:"for(var p,Z=true,r=0;r1){for(var i=1;ie?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?e.length:0,r=[];++tx(s,u)){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?e.length:0,r=o(arguments,1,20),i=[];++ts;s++)i+="i='"+e.o[s]+"';if(","constructor"==e.o[s]&&(i+="!(g&&g.prototype===j)&&"),i+="h.call(j,i)){A=j[i];"+ +e.l.h+"}"}if(e.c||e.m)i+="}"}return i+=e.e+";return t",Function("D,E,F,I,e,f,J,h,M,O,Q,S,T,X,Y,l,q,v,w,y,z","var G=function("+t+"){"+i+"};return G")(_t,_,L,u,K,f,Zt,Q,x,v,Vt,m,$t,vt,Pt,ot,Y,Z,gt,et)}function c(e){return"\\"+Ht[e]}function h(e){return Kt[e]}function p(){}function d(e){return Qt[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?(Zt(e,function(e,n,r){return t=!Q.call(r,n),i}),t===i):(Zt(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=Pt[typeof e]){var a=et.call(e);if(!Dt[a]||Tt&&v(e))return e;var f=a==ct,s=f||(a==vt?$t(e):s)}if(!s||!t)return s?f?Z.call(e):Yt({},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?e.length:0,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){if(e)return t==r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?ut(0,i+n):n||0)-1;else if(n)return r=C(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function N(e,t,n){return e?Z.call(e,t==r||n?1:t):[]}function C(e,t,n,r){for(var i=0,s=e?e.length:i,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={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Ht={"\\":"\\","'":"'","\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 Bt={a:"d,c,x",i:"d",p:"c=f(c,x)",h:"if(c(A,i,d)===false)return t"},jt={i:"{}",p:"c=f(c,x)",h:"var p=c(A,i,d);(h.call(t,p)?t[p]++:t[p]=1)"},Ft={i:"true",h:"if(!c(A,i,d))return!t"},It={q:i,r:i,a:"m",i:"m",p:"for(var a=1,b=arguments.length;a":">",'"':""","'":"'"},Qt=Xt(Kt),Gt=l(It,{h:"if(t[i]==null)"+It.h}),Yt=l(It),Zt=l(Bt,Rt,Ut,{q:i}),en=l(Bt,Rt,Ut),tn=l({q:i,a:"m",i:"[]",h:"if(S(A))t.push(i)",e:"t.sort()"}),nn=l({a:"A",i:"true",p:"var H=y.call(A),k=A.length;if(D[H]"+(Tt?"||O(A)":"")+"||(H==X&&k===+k&&S(A.splice)))return!k",h:{k:"return false"}}),rn=ot?function(e){var t=typeof e;return"function"==t&&Y.call(e,"prototype")?Jt(e):e&&Pt[t]?ot +(e):[]}:Jt,sn=l(It,{a:"m,dd,N",p:"var P,C=arguments,a=0;if(N==I){var b=2,ee=C[3],ff=C[4]}else var b=C.length,ee=[],ff=[];while(++a-1"},h:"if(A===hh)return true"}),cn=l(Bt,jt),hn=l(Bt,Ft),pn=l(Bt,qt),dn=l(Bt,Rt,{i:"z",h:"if(c(A,i,d))return A"}),vn=l(Bt,Rt),mn=l(Bt,jt,{h:"var p=c(A,i,d);(h.call(t,p)?t[p]:t[p]=[]).push(A)"}),gn=l(zt,{a:"d,U",p:"var C=v.call(arguments,2),R=typeof U=='function'",h:{b:"t[i]=(R?U:A[U]).apply(A,C)",k:"t"+(Ot?"[n]=":".push")+"((R?U:A[U]).apply(A,C))"}}),yn=l(Bt,zt +),bn=l(zt,{a:"d,bb",h:{b:"t[i]=A[bb]",k:"t"+(Ot?"[n]=":".push")+"(A[bb])"}}),wn=l({a:"d,c,B,x",i:"B",p:"var V=arguments.length<3;c=f(c,x)",d:{b:"if(V)t=j[++i]"},h:{b:"t=c(t,A,i,d)",k:"t=V?(V=false,A):c(t,A,i,d)"}}),En=l(Bt,qt,{h:"!"+qt.h}),Sn=l(Bt,Ft,{i:"false",h:Ft.h.replace("!","")}),xn=l(Bt,jt,zt,{h:{b:"t[i]={a:c(A,i,d),b:i,c:A}",k:"t"+(Ot?"[n]=":".push")+"({a:c(A,i,d),b:i,c:A})"},e:"t.sort(I);k=t.length;while(k--)t[k]=t[k].c"}),Tn=l(qt,{a:"d,aa",p:"var s=[];J(aa,function(A,p){s.push(p)});var cc=s.length" +,h:"for(var p,Z=true,r=0;r1){for(var i=1;ie?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?e.length:0,r=[];++tx(s,u)){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?e.length:0,r=o(arguments,1,20),i=[];++targuments.length,t=x(t,r),f=e.length;s=-1;if(f===+f)for(a&&(u=e[++s]);++sn||e===t)return 1;if(earguments.length;if(s!==+s)var u=Mt(e),s=u.length;return f(e,function( -a,f,l){f=u?u[--s]:--s,n=o?(o=i,e[f]):t.call(r,n,e[f],f,l)}),n}function _(e,t,n){if(e)return t==r||n?e[0]:ot.call(e,0,t)}function D(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?dt(0,i+n):n||0)-1;else if(n)return r=j(e,t),e[r]===t?r:-1;for(;++rr&& -(r=n,o=e[i]);return o}function B(e,t,n){return e?ot.call(e,t==r||n?1:t):[]}function j(e,t,n,r){for(var i=0,s=e?e.length:i,n=x(n,r),t=n(t);i>>1,n(e[r])P(a,r))a.push(r),u.push(e[s]);return u}function I(e,t){return Nt||at&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,J=/&(?:amp|lt|gt|quot|#x27);/g,K=/\b__p\+='';/g -,Q=/\b(__p\+=)''\+/g,G=/(__e\(.*?\)|\b__t\))\+'';/g,Y=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,Z=RegExp("^"+(W.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),et=/($^)/,tt=/[&<>"']/g,nt=/['\n\r\t\u2028\u2029\\]/g,rt=z.concat,it=W.hasOwnProperty,st=z.push,ot=z.slice,ut=W.toString,at=Z.test(at=ot.bind)&&at,ft=Math.floor,lt=Z.test(lt=Object.getPrototypeOf)&<,ct=Z.test(ct=Array.isArray)&&ct,ht=e.isFinite,pt=Z.test(pt=Object.keys)&&pt,dt=Math.max,vt=Math -.min,mt=Math.random,gt="[object Boolean]",yt="[object Date]",bt="[object Number]",wt="[object Object]",Et="[object RegExp]",St="[object String]",xt=e.clearTimeout,Tt=e.setTimeout,Nt=at&&/\n|Opera/.test(at+ut.call(e.opera)),Ct={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},kt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};w.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"" -},w.isArguments=function(e){return"[object Arguments]"==ut.call(e)},w.isArguments(arguments)||(w.isArguments=function(e){return e?it.call(e,"callee"):i});var Lt=ct||function(e){return"[object Array]"==ut.call(e)};L(/x/)&&(L=function(e){return"[object Function]"==ut.call(e)});var W=lt?function(e){if(!e||"object"!=typeof e)return i;var t=e.valueOf,n="function"==typeof t&&(n=lt(t))&<(n);return n?e==n||lt(e)==n&&!isArguments(e):A(e)}:A,At={"&":"&","<":"<",">":">",'"':""","'":"'" -},Ot=b(At),Mt=pt?function(e){return e&&Ct[typeof e]?pt(e):[]}:y;w.VERSION="0.8.1",w.after=function(e,t){return 1>e?t():function(){if(1>--e)return t.apply(this,arguments)}},w.bind=I,w.bindAll=function(e){var t,n,r=e,i=e;if(!e)return i;n=arguments;var s=n.length;if(1P(r,s,n)&&i.push(s)}return i},w.escape=function(e){return e==r?"":(e+"").replace(tt,N)},w.every=h,w.extend=g,w.filter=c,w.find=l,w.first=_,w.flatten=D,w.forEach=f,w.forIn=m,w.forOwn=function(e,t,n){var r;if(!e)return e;t=x(t,n);for(r in e)it.call(e,r)&&(n=e[r],t(n,r,e));return e},w.functions=v,w.groupBy=function(e,t,n){var r,i={};if(!e)return i;var t=x(t,n),s=e.length,n=-1;if(s===+s)for(;++nP(i,s)){for(var o=1;oP(arguments[o],s))continue e;i.push(s)}}return i},w.invert=b,w.invoke=function(e,t){var n,r,i=e,s;if(!e)return s;var o=ot.call(arguments -,2),u="function"==typeof t,a=i.length;n=-1;if(a===+a)for(s=Array(a);++nn?dt(0,r+n):vt(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},w.map=a,w.max=H,w.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return it.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},w.min=function(e,t,n){for(var r=Infinity,i=-1,s=e?e.length:0,o=r,t=x(t,n);++iP(a,r))o[r]=i;return o},w.once=function(e){var t,s=i;return function(){return s?t:(s=n,t=e.apply(this,arguments),e=r,t)}},w.pairs=function(e){var t,n,r=[];if(!e)return r;for(t in e)it.call(e,t)&&(n=e[t],r.push([t,n]));return r -},w.pick=function(e,t,n){var r,i,s=e,o={};if(!e)return o;if("function"!=typeof t){var s=rt.apply(z,arguments),u=s.length;for(r=1;rarguments.length,t=x(t,r),f=e.length;s=-1;if(f===+f)for(a&&(u=e[++s]);++sn||e===t)return 1;if( +earguments.length;if(s!==+s)var u=Mt(e),s=u +.length;return f(e,function(a,f,l){f=u?u[--s]:--s,n=o?(o=i,e[f]):t.call(r,n,e[f],f,l)}),n}function _(e,t,n){if(e)return t==r||n?e[0]:ot.call(e,0,t)}function D(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?dt(0,i+n):n||0)-1;else if(n)return r=j(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function B(e,t,n){return e?ot.call(e,t==r||n?1:t):[]}function j(e,t,n,r){for(var i=0,s=e?e.length:i,n=x(n,r),t=n(t);i>>1,n(e[r])P(a,r))a.push(r),u.push(e[s]);return u}function I(e,t){return Nt||at&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,J=/&(?:amp|lt|gt|quot|#x27);/g +,K=/\b__p\+='';/g,Q=/\b(__p\+=)''\+/g,G=/(__e\(.*?\)|\b__t\))\+'';/g,Y=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,Z=RegExp("^"+(W.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),et=/($^)/,tt=/[&<>"']/g,nt=/['\n\r\t\u2028\u2029\\]/g,rt=z.concat,it=W.hasOwnProperty,st=z.push,ot=z.slice,ut=W.toString,at=Z.test(at=ot.bind)&&at,ft=Math.floor,lt=Z.test(lt=Object.getPrototypeOf)&<,ct=Z.test(ct=Array.isArray)&&ct,ht=e.isFinite,pt=Z.test(pt=Object.keys)&&pt, +dt=Math.max,vt=Math.min,mt=Math.random,gt="[object Boolean]",yt="[object Date]",bt="[object Number]",wt="[object Object]",Et="[object RegExp]",St="[object String]",xt=e.clearTimeout,Tt=e.setTimeout,Nt=at&&/\n|Opera/.test(at+ut.call(e.opera)),Ct={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},kt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};w.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g +,variable:""},w.isArguments=function(e){return"[object Arguments]"==ut.call(e)},w.isArguments(arguments)||(w.isArguments=function(e){return e?it.call(e,"callee"):i});var Lt=ct||function(e){return"[object Array]"==ut.call(e)};L(/x/)&&(L=function(e){return"[object Function]"==ut.call(e)});var W=lt?function(e){if(!e||"object"!=typeof e)return i;var t=e.valueOf,n="function"==typeof t&&(n=lt(t))&<(n);return n?e==n||lt(e)==n&&!isArguments(e):A(e)}:A,At={"&":"&","<":"<",">":">",'"':""","'" +:"'"},Ot=b(At),Mt=pt?function(e){return e&&Ct[typeof e]?pt(e):[]}:y;w.VERSION="0.8.1",w.after=function(e,t){return 1>e?t():function(){if(1>--e)return t.apply(this,arguments)}},w.bind=I,w.bindAll=function(e){var t,n,r=e,i=e;if(!e)return i;n=arguments;var s=n.length;if(1P(r,s,n)&&i.push(s)}return i},w.escape=function(e){return e==r?"":(e+"").replace(tt,N)},w.every=h,w.extend=g,w.filter=c,w.find=l,w.first=_,w.flatten=D,w.forEach=f,w.forIn=m,w.forOwn=function(e,t,n){var r;if(!e)return e;t=x(t,n);for(r in e)it.call(e,r)&&(n=e[r],t(n,r,e));return e},w.functions=v,w.groupBy=function(e,t,n){var r,i={};if(!e)return i;var t=x(t,n),s=e.length,n=-1;if(s===+s)for(;++nP(i,s)){for(var o=1;oP(arguments[o],s))continue e;i.push(s)}}return i},w.invert=b,w.invoke=function(e,t){var n,r,i=e,s=e;if(!e)return s; +var o=ot.call(arguments,2),u="function"==typeof t,a=i.length;n=-1;if(a===+a)for(s=Array(a);++nn?dt(0,r+n):vt(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},w.map=a,w.max=H,w.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return it.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},w.min=function(e,t,n){for(var r=Infinity,i=-1,s=e?e.length:0,o=r,t=x(t,n);++iP(a,r))o[r]=i;return o},w.once=function(e){var t,s=i;return function(){return s?t:(s=n,t=e.apply(this,arguments),e=r,t)}},w.pairs=function(e){var t,n,r=[];if(!e)return r;for(t in e)it.call(e,t)&&(n=e[ +t],r.push([t,n]));return r},w.pick=function(e,t,n){var r,i,s=e,o={};if(!e)return o;if("function"!=typeof t){var s=rt.apply(z,arguments),u=s.length;for(r=1;r=f?(a=r,s=e.apply(o,i)):u||(u=Tt(n,f)),s}},w.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rP(r,t[e])&&r.push(t[e]);return r},w.uniq=F,w.uniqueId=function(e){var t=X++;return e?e+t:t},w.values=d,w.where=function(e,t){var r,i,s=[];if(!e)return s;var o=[];m(t,function(e,t){o.push(t)});var u=o.length,a=e.length;r=-1;if(a===+a)for(;++rP(arguments,i,1)&&r.push(i)}return r},w.wrap=function(e,t){return function(){var n=[e];return arguments.length&&st.apply(n,arguments),t.apply(this,n)}},w.zip=function(e){for(var t=-1,n=e?H(u(arguments,"length")):0,r=Array(n);++t Date: Sat, 6 Oct 2012 15:45:19 -0700 Subject: [PATCH 03/26] Add `_.isPlainObject` to the list of features in README.md. [ci skip] Former-commit-id: ec81cdc9e7fef775871cc1c4a497e4d17e7716aa --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 79a50a9be4..dba3f8eeca 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ For more information check out these screencasts over Lo-Dash: * [_.forEach](http://lodash.com/docs#forEach) is chainable and supports exiting iteration early * [_.forIn](http://lodash.com/docs#forIn) for iterating over an object’s own and inherited properties * [_.forOwn](http://lodash.com/docs#forOwn) for iterating over an object’s own properties + * [_.isPlainObject](http://lodash.com/docs#isPlainObject) checks if values are created by the `Object` constructor * [_.lateBind](http://lodash.com/docs#lateBind) for late binding * [_.merge](http://lodash.com/docs#merge) for a *“deep”* [_.extend](http://lodash.com/docs#extend) * [_.partial](http://lodash.com/docs#partial) for partial application without `this` binding From 13295999871e899c07fd2bcd4096ce756d93a935 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 6 Oct 2012 17:32:18 -0700 Subject: [PATCH 04/26] Simplify how deep `_.clone` handles booleans. Former-commit-id: adf1d03677336131da2f62bd2fb6e2900c9889a4 --- lodash.js | 4 +--- lodash.min.js | 14 +++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lodash.js b/lodash.js index 6f0f8054cc..167692e3bf 100644 --- a/lodash.js +++ b/lodash.js @@ -720,7 +720,7 @@ } } } - // set additional template `data` values + // set additional template `data` properties var args = data.args; if ((data.firstArg = /^[^,]+/.exec(args)[0]) != 'collection' || !data.arrayBranch.inLoop) { data.arrayBranch = null; @@ -1055,8 +1055,6 @@ var ctor = value.constructor; switch (className) { case boolClass: - return new ctor(value == true); - case dateClass: return new ctor(+value); diff --git a/lodash.min.js b/lodash.min.js index 8aa7d249ec..ae8b41feb3 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -7,13 +7,13 @@ o&&(o={b:o,k:o}),e.c[s]=o.b,e.l[s]=o.k):e[s]=o}t=e.a;if("d"!=(e.f=/^[^,]+/.exec(t)[0])||!e.c.h)e.c=r;i="",e.r&&(i+="'use strict';"),i+="var i,A,j="+e.f+",t="+(e.i||e.f)+";if(!"+e.f+")return t;"+e.p+";",e.c&&(i+="var k=j.length;i=-1;",e.l&&(i+="if(k===+k){"),e.n&&(i+="if(y.call(j)==w){j=j.split('')}"),i+=e.c.d+";while(++is;s++)i+="i='"+e.o[s]+"';if(","constructor"==e.o[s]&&(i+="!(g&&g.prototype===j)&&"),i+="h.call(j,i)){A=j[i];"+ e.l.h+"}"}if(e.c||e.m)i+="}"}return i+=e.e+";return t",Function("D,E,F,I,e,f,J,h,M,O,Q,S,T,X,Y,l,q,v,w,y,z","var G=function("+t+"){"+i+"};return G")(_t,_,L,u,K,f,Zt,Q,x,v,Vt,m,$t,vt,Pt,ot,Y,Z,gt,et)}function c(e){return"\\"+Ht[e]}function h(e){return Kt[e]}function p(){}function d(e){return Qt[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?(Zt(e,function(e,n,r){return t=!Q.call(r,n),i}),t===i):(Zt(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=Pt[typeof e]){var a=et.call(e);if(!Dt[a]||Tt&&v(e))return e;var f=a==ct,s=f||(a==vt?$t(e):s)}if(!s||!t)return s?f?Z.call(e):Yt({},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?e.length:0,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){if(e)return t==r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?ut(0,i+n):n||0)-1;else if(n)return r=C(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function N(e,t,n){return e?Z.call(e,t==r||n?1:t):[]}function C(e,t,n,r){for(var i=0,s=e?e.length:i,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 +(e+""))&&(!m(n)||n instanceof n)?St?(Zt(e,function(e,n,r){return t=!Q.call(r,n),i}),t===i):(Zt(e,function(e,n){t=n}),t===i||Q.call(e,t)):t}function y(e,t,n,s,o){if(e==r)return e;n&&(t=i);if(n=Pt[typeof e]){var u=et.call(e);if(!Dt[u]||Tt&&v(e))return e;var a=u==ct,n=a||(u==vt?$t(e):n)}if(!n||!t)return n?a?Z.call(e):Yt({},e):e;n=e.constructor;switch(u){case ht:case pt:return new n(+e);case dt:case gt:return new n(e);case mt:return n(e.source,U.exec(e))}s||(s=[]),o||(o=[]);for(u=s.length;u--;)if(s[u +]==e)return o[u];var f=a?n(u=e.length):{};s.push(e),o.push(f);if(a)for(a=-1;++a++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?e.length:0,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){if(e)return t==r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?ut(0,i+n):n||0)-1;else if(n)return r=C(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function N(e,t,n){return e?Z.call(e,t==r||n?1:t):[]}function C(e,t,n,r){for(var i=0,s=e?e.length:i,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={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Ht={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate From b3d68893df1af8291e1ae0da264b24f5558fb801 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 6 Oct 2012 18:09:49 -0700 Subject: [PATCH 05/26] Reduce deep `_.clone` array iteration and add `_.each` dependency. Former-commit-id: 3cb599d294a693974483b892748e6f60186d0c50 --- build.js | 2 +- lodash.js | 18 +++++----------- lodash.min.js | 58 +++++++++++++++++++++++++-------------------------- 3 files changed, 35 insertions(+), 43 deletions(-) diff --git a/build.js b/build.js index a9e6094796..8b147e2503 100755 --- a/build.js +++ b/build.js @@ -67,7 +67,7 @@ 'bind': ['isFunction'], 'bindAll': ['bind', 'isFunction'], 'chain': ['mixin'], - 'clone': ['extend', 'forOwn', 'isArguments', 'isPlainObject'], + 'clone': ['extend', 'forEach', 'forOwn', 'isArguments', 'isPlainObject'], 'compact': [], 'compose': [], 'contains': [], diff --git a/lodash.js b/lodash.js index 167692e3bf..1667b55e2b 100644 --- a/lodash.js +++ b/lodash.js @@ -1065,7 +1065,6 @@ case regexpClass: return ctor(value.source, reFlags.exec(value)); } - // check for circular references and return corresponding clone stackA || (stackA = []); stackB || (stackB = []); @@ -1076,9 +1075,8 @@ return stackB[length]; } } - // init cloned object - var result = isArr ? ctor(length = value.length) : {}; + var result = isArr ? ctor(value.length) : {}; // add the source value to the stack of traversed objects // and associate it with its clone @@ -1086,16 +1084,10 @@ 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, stackA, stackB); - } - } else { - forOwn(value, function(objValue, key) { - result[key] = clone(objValue, deep, null, stackA, stackB); - }); - } + (isArr ? forEach : forOwn)(value, function(objValue, key) { + result[key] = clone(objValue, deep, null, stackA, stackB); + }); + return result; } diff --git a/lodash.min.js b/lodash.min.js index ae8b41feb3..e6df07de96 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -8,32 +8,32 @@ o&&(o={b:o,k:o}),e.c[s]=o.b,e.l[s]=o.k):e[s]=o}t=e.a;if("d"!=(e.f=/^[^,]+/.exec( );if(e.j&&e.q)i+="var n=-1,o=Y[typeof j]?l(j):[],k=o.length;"+e.l.d+";while(++ns;s++)i+="i='"+e.o[s]+"';if(","constructor"==e.o[s]&&(i+="!(g&&g.prototype===j)&&"),i+="h.call(j,i)){A=j[i];"+ e.l.h+"}"}if(e.c||e.m)i+="}"}return i+=e.e+";return t",Function("D,E,F,I,e,f,J,h,M,O,Q,S,T,X,Y,l,q,v,w,y,z","var G=function("+t+"){"+i+"};return G")(_t,_,L,u,K,f,Zt,Q,x,v,Vt,m,$t,vt,Pt,ot,Y,Z,gt,et)}function c(e){return"\\"+Ht[e]}function h(e){return Kt[e]}function p(){}function d(e){return Qt[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?(Zt(e,function(e,n,r){return t=!Q.call(r,n),i}),t===i):(Zt(e,function(e,n){t=n}),t===i||Q.call(e,t)):t}function y(e,t,n,s,o){if(e==r)return e;n&&(t=i);if(n=Pt[typeof e]){var u=et.call(e);if(!Dt[u]||Tt&&v(e))return e;var a=u==ct,n=a||(u==vt?$t(e):n)}if(!n||!t)return n?a?Z.call(e):Yt({},e):e;n=e.constructor;switch(u){case ht:case pt:return new n(+e);case dt:case gt:return new n(e);case mt:return n(e.source,U.exec(e))}s||(s=[]),o||(o=[]);for(u=s.length;u--;)if(s[u -]==e)return o[u];var f=a?n(u=e.length):{};s.push(e),o.push(f);if(a)for(a=-1;++a++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?e.length:0,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){if(e)return t==r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?ut(0,i+n):n||0)-1;else if(n)return r=C(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function N(e,t,n){return e?Z.call(e,t==r||n?1:t):[]}function C(e,t,n,r){for(var i=0,s=e?e.length:i,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={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Ht={"\\":"\\","'":"'","\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 Bt={a:"d,c,x",i:"d",p:"c=f(c,x)",h:"if(c(A,i,d)===false)return t"},jt={i:"{}",p:"c=f(c,x)",h:"var p=c(A,i,d);(h.call(t,p)?t[p]++:t[p]=1)"},Ft={i:"true",h:"if(!c(A,i,d))return!t"},It={q:i,r:i,a:"m",i:"m",p:"for(var a=1,b=arguments.length;a":">",'"':""","'":"'"},Qt=Xt(Kt),Gt=l(It,{h:"if(t[i]==null)"+It.h}),Yt=l(It),Zt=l(Bt,Rt,Ut,{q:i}),en=l(Bt,Rt,Ut),tn=l({q:i,a:"m",i:"[]",h:"if(S(A))t.push(i)",e:"t.sort()"}),nn=l({a:"A",i:"true",p:"var H=y.call(A),k=A.length;if(D[H]"+(Tt?"||O(A)":"")+"||(H==X&&k===+k&&S(A.splice)))return!k",h:{k:"return false"}}),rn=ot?function(e){var t=typeof e;return"function"==t&&Y.call(e,"prototype")?Jt(e):e&&Pt[t]?ot -(e):[]}:Jt,sn=l(It,{a:"m,dd,N",p:"var P,C=arguments,a=0;if(N==I){var b=2,ee=C[3],ff=C[4]}else var b=C.length,ee=[],ff=[];while(++a-1"},h:"if(A===hh)return true"}),cn=l(Bt,jt),hn=l(Bt,Ft),pn=l(Bt,qt),dn=l(Bt,Rt,{i:"z",h:"if(c(A,i,d))return A"}),vn=l(Bt,Rt),mn=l(Bt,jt,{h:"var p=c(A,i,d);(h.call(t,p)?t[p]:t[p]=[]).push(A)"}),gn=l(zt,{a:"d,U",p:"var C=v.call(arguments,2),R=typeof U=='function'",h:{b:"t[i]=(R?U:A[U]).apply(A,C)",k:"t"+(Ot?"[n]=":".push")+"((R?U:A[U]).apply(A,C))"}}),yn=l(Bt,zt -),bn=l(zt,{a:"d,bb",h:{b:"t[i]=A[bb]",k:"t"+(Ot?"[n]=":".push")+"(A[bb])"}}),wn=l({a:"d,c,B,x",i:"B",p:"var V=arguments.length<3;c=f(c,x)",d:{b:"if(V)t=j[++i]"},h:{b:"t=c(t,A,i,d)",k:"t=V?(V=false,A):c(t,A,i,d)"}}),En=l(Bt,qt,{h:"!"+qt.h}),Sn=l(Bt,Ft,{i:"false",h:Ft.h.replace("!","")}),xn=l(Bt,jt,zt,{h:{b:"t[i]={a:c(A,i,d),b:i,c:A}",k:"t"+(Ot?"[n]=":".push")+"({a:c(A,i,d),b:i,c:A})"},e:"t.sort(I);k=t.length;while(k--)t[k]=t[k].c"}),Tn=l(qt,{a:"d,aa",p:"var s=[];J(aa,function(A,p){s.push(p)});var cc=s.length" -,h:"for(var p,Z=true,r=0;r1){for(var i=1;ie?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?e.length:0,r=[];++tx(s,u)){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?e.length:0,r=o(arguments,1,20),i=[];++t++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?e.length:0,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){if(e)return t==r||n?e[0]:Z.call(e,0,t)}function S(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?ut(0,i+n):n||0)-1;else if(n)return r=C(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function N(e,t,n){return e?Z.call(e,t==r||n?1:t):[]}function C(e,t,n,r){for(var i=0,s=e?e.length:i,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={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Ht={"\\":"\\","'":"'","\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 Bt={a:"d,c,x",i:"d",p:"c=f(c,x)",h:"if(c(A,i,d)===false)return t"},jt={i +:"{}",p:"c=f(c,x)",h:"var p=c(A,i,d);(h.call(t,p)?t[p]++:t[p]=1)"},Ft={i:"true",h:"if(!c(A,i,d))return!t"},It={q:i,r:i,a:"m",i:"m",p:"for(var a=1,b=arguments.length;a":">",'"':""","'":"'"},Qt=Xt(Kt),Gt=l(It,{ +h:"if(t[i]==null)"+It.h}),Yt=l(It),Zt=l(Bt,Rt,Ut,{q:i}),en=l(Bt,Rt,Ut),tn=l({q:i,a:"m",i:"[]",h:"if(S(A))t.push(i)",e:"t.sort()"}),nn=l({a:"A",i:"true",p:"var H=y.call(A),k=A.length;if(D[H]"+(Tt?"||O(A)":"")+"||(H==X&&k===+k&&S(A.splice)))return!k",h:{k:"return false"}}),rn=ot?function(e){var t=typeof e;return"function"==t&&Y.call(e,"prototype")?Jt(e):e&&Pt[t]?ot(e):[]}:Jt,sn=l(It,{a:"m,dd,N",p:"var P,C=arguments,a=0;if(N==I){var b=2,ee=C[3],ff=C[4]}else var b=C.length,ee=[],ff=[];while(++a-1"},h:"if(A===hh)return true"}),cn=l(Bt,jt),hn=l(Bt,Ft),pn=l(Bt,qt),dn=l(Bt,Rt,{i:"z",h:"if(c(A,i,d))return A"}),vn=l(Bt,Rt),mn=l(Bt,jt,{h:"var p=c(A,i,d);(h.call(t,p)?t[p]:t[p]=[]).push(A)"}),gn=l(zt,{a:"d,U",p:"var C=v.call(arguments,2),R=typeof U=='function'",h:{b:"t[i]=(R?U:A[U]).apply(A,C)",k:"t"+(Ot?"[n]=":".push")+"((R?U:A[U]).apply(A,C))"}}),yn=l(Bt,zt),bn=l(zt,{a:"d,bb",h:{b:"t[i]=A[bb]",k:"t"+(Ot?"[n]=":".push")+"(A[bb])" +}}),wn=l({a:"d,c,B,x",i:"B",p:"var V=arguments.length<3;c=f(c,x)",d:{b:"if(V)t=j[++i]"},h:{b:"t=c(t,A,i,d)",k:"t=V?(V=false,A):c(t,A,i,d)"}}),En=l(Bt,qt,{h:"!"+qt.h}),Sn=l(Bt,Ft,{i:"false",h:Ft.h.replace("!","")}),xn=l(Bt,jt,zt,{h:{b:"t[i]={a:c(A,i,d),b:i,c:A}",k:"t"+(Ot?"[n]=":".push")+"({a:c(A,i,d),b:i,c:A})"},e:"t.sort(I);k=t.length;while(k--)t[k]=t[k].c"}),Tn=l(qt,{a:"d,aa",p:"var s=[];J(aa,function(A,p){s.push(p)});var cc=s.length",h:"for(var p,Z=true,r=0;r1){for(var i=1;ie?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?e.length:0,r=[];++tx(s,u)){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?e.length:0,r=o(arguments,1,20),i=[];++t Date: Sat, 6 Oct 2012 20:56:42 -0700 Subject: [PATCH 06/26] Update Backbone/Underscore vendor folders. Former-commit-id: 3317d501fe535d91eefab8a5dcb3a88a791e20ac --- vendor/backbone/backbone.js | 4 ++-- vendor/backbone/test/view.js | 11 ++++++++--- vendor/underscore/test/arrays.js | 2 ++ vendor/underscore/test/collections.js | 26 ++++++++++++++++++++++++++ vendor/underscore/underscore-min.js | 4 ++-- vendor/underscore/underscore.js | 15 +++++++++++++-- 6 files changed, 53 insertions(+), 9 deletions(-) diff --git a/vendor/backbone/backbone.js b/vendor/backbone/backbone.js index 3457b0f4fd..d8e31b3524 100644 --- a/vendor/backbone/backbone.js +++ b/vendor/backbone/backbone.js @@ -1234,8 +1234,8 @@ // memory leaks. dispose: function() { this.undelegateEvents(); - if (this.model) this.model.off(null, null, this); - if (this.collection) this.collection.off(null, null, this); + if (this.model && this.model.off) this.model.off(null, null, this); + if (this.collection && this.collection.off) this.collection.off(null, null, this); return this; }, diff --git a/vendor/backbone/test/view.js b/vendor/backbone/test/view.js index d2741a7449..1de5c20e40 100644 --- a/vendor/backbone/test/view.js +++ b/vendor/backbone/test/view.js @@ -286,11 +286,11 @@ $(document).ready(function() { test("dispose", 0, function() { var View = Backbone.View.extend({ events: { - click: function() { ok(false); } + click: function() { fail(); } }, initialize: function() { - this.model.on('all x', function(){ ok(false); }, this); - this.collection.on('all x', function(){ ok(false); }, this); + this.model.on('all x', function(){ fail(); }, this); + this.collection.on('all x', function(){ fail(); }, this); } }); @@ -305,6 +305,11 @@ $(document).ready(function() { view.$el.click(); }); + test("dispose with non Backbone objects", 0, function() { + var view = new Backbone.View({model: {}, collection: {}}); + view.dispose(); + }); + test("view#remove calls dispose.", 1, function() { var view = new Backbone.View(); diff --git a/vendor/underscore/test/arrays.js b/vendor/underscore/test/arrays.js index 1ab33d8f7a..a757ced67f 100644 --- a/vendor/underscore/test/arrays.js +++ b/vendor/underscore/test/arrays.js @@ -144,6 +144,7 @@ $(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); @@ -172,6 +173,7 @@ $(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 095ace1d31..efc5723d40 100644 --- a/vendor/underscore/test/collections.js +++ b/vendor/underscore/test/collections.js @@ -25,6 +25,10 @@ $(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() { @@ -50,6 +54,9 @@ $(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() { @@ -69,6 +76,15 @@ $(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'); }); @@ -83,9 +99,19 @@ $(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'); diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index e617fe8719..ad3a39ad82 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -1,5 +1,5 @@ -// Underscore.js 1.4.1 +// Underscore.js 1.4.2 // 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.1";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.2";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 2ab97e9024..1ebe2671b9 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -1,4 +1,4 @@ -// Underscore.js 1.4.1 +// Underscore.js 1.4.2 // http://underscorejs.org // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. // Underscore may be freely distributed under the MIT license. @@ -65,7 +65,7 @@ } // Current version. - _.VERSION = '1.4.1'; + _.VERSION = '1.4.2'; // Collection Functions // -------------------- @@ -74,6 +74,7 @@ // 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) { @@ -93,6 +94,7 @@ // 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); @@ -104,6 +106,7 @@ // 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); @@ -124,6 +127,7 @@ // 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); @@ -163,6 +167,7 @@ // 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; @@ -173,6 +178,7 @@ // 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; }); @@ -185,6 +191,7 @@ _.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; @@ -198,6 +205,7 @@ 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; @@ -209,6 +217,7 @@ // 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; @@ -500,6 +509,7 @@ // 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') { @@ -516,6 +526,7 @@ // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. _.lastIndexOf = function(array, item, from) { + if (array == null) return -1; var hasIndex = from != null; if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) { return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item); From c33825a904bdef40091070afdb04c30ceec08413 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 6 Oct 2012 20:58:21 -0700 Subject: [PATCH 07/26] Reduce Underscore build and update Underscore version number. Former-commit-id: fd631cd5525fa287c2af493bfe4a93668678977d --- build.js | 8 ++++- build/post-compile.js | 2 +- lodash.js | 10 +++--- lodash.min.js | 4 +-- lodash.underscore.min.js | 66 ++++++++++++++++++++-------------------- 5 files changed, 47 insertions(+), 43 deletions(-) diff --git a/build.js b/build.js index 8b147e2503..810b4e864a 100755 --- a/build.js +++ b/build.js @@ -1256,8 +1256,14 @@ }); if (isUnderscore) { + // remove compiled template cleanup from `_.template` + source = source.replace(/(?:\s*\/\/.*)*\n *source *=.+?isEvaluating.+?reEmptyStringLeading[\s\S]+?\);/, ''); + source = removeVar(source, 'reEmptyStringLeading'); + source = removeVar(source, 'reEmptyStringMiddle'); + source = removeVar(source, 'reEmptyStringTrailing'); + + // replace `isArguments` and its fallback (function() { - // replace `isArguments` and its fallback var snippet = matchFunction(source, 'isArguments') .replace(/function isArguments/, 'lodash.isArguments = function'); diff --git a/build/post-compile.js b/build/post-compile.js index 99429b9ecc..5d616c77b5 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -10,7 +10,7 @@ 'lodash': '/*!\n' + ' Lo-Dash @VERSION lodash.com/license\n' + - ' Underscore.js 1.4.1 underscorejs.org/LICENSE\n' + + ' Underscore.js 1.4.2 underscorejs.org/LICENSE\n' + '*/', 'underscore': '/*! Underscore.js @VERSION underscorejs.org/LICENSE */' diff --git a/lodash.js b/lodash.js index 1667b55e2b..bdf2c170c4 100644 --- a/lodash.js +++ b/lodash.js @@ -1,7 +1,7 @@ /*! * Lo-Dash v0.8.1 * (c) 2012 John-David Dalton - * Based on Underscore.js 1.4.1 + * Based on Underscore.js 1.4.2 * (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. * Available under MIT license */ @@ -1204,7 +1204,7 @@ 'useHas': false, 'args': 'object', 'init': '[]', - 'inLoop': 'if (isFunction(value)) result.push(index)', + 'inLoop': 'isFunction(value) && result.push(index)', 'bottom': 'result.sort()' }); @@ -1671,7 +1671,7 @@ } return object && objectTypes[type] ? nativeKeys(object) - : []; + : []; }; /** @@ -3159,9 +3159,7 @@ ' return result\n' + '}', 'inLoop': - 'if (isFunction(value)) {\n' + - ' result[index] = bind(value, result)\n' + - '}' + 'if (isFunction(value)) result[index] = bind(value, result)' }); /** diff --git a/lodash.min.js b/lodash.min.js index e6df07de96..bcaee1192e 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -1,6 +1,6 @@ /*! Lo-Dash 0.8.1 lodash.com/license - Underscore.js 1.4.1 underscorejs.org/LICENSE + Underscore.js 1.4.2 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,n){t||(t=0);var r=e.length,i=r-t>=(n||H),s=i?{}:e;if(i)for(n=t-1;++nn||e===t)return 1;if(e/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Bt={a:"d,c,x",i:"d",p:"c=f(c,x)",h:"if(c(A,i,d)===false)return t"},jt={i :"{}",p:"c=f(c,x)",h:"var p=c(A,i,d);(h.call(t,p)?t[p]++:t[p]=1)"},Ft={i:"true",h:"if(!c(A,i,d))return!t"},It={q:i,r:i,a:"m",i:"m",p:"for(var a=1,b=arguments.length;a":">",'"':""","'":"'"},Qt=Xt(Kt),Gt=l(It,{ -h:"if(t[i]==null)"+It.h}),Yt=l(It),Zt=l(Bt,Rt,Ut,{q:i}),en=l(Bt,Rt,Ut),tn=l({q:i,a:"m",i:"[]",h:"if(S(A))t.push(i)",e:"t.sort()"}),nn=l({a:"A",i:"true",p:"var H=y.call(A),k=A.length;if(D[H]"+(Tt?"||O(A)":"")+"||(H==X&&k===+k&&S(A.splice)))return!k",h:{k:"return false"}}),rn=ot?function(e){var t=typeof e;return"function"==t&&Y.call(e,"prototype")?Jt(e):e&&Pt[t]?ot(e):[]}:Jt,sn=l(It,{a:"m,dd,N",p:"var P,C=arguments,a=0;if(N==I){var b=2,ee=C[3],ff=C[4]}else var b=C.length,ee=[],ff=[];while(++a-1"},h:"if(A===hh)return true"}),cn=l(Bt,jt),hn=l(Bt,Ft),pn=l(Bt,qt),dn=l(Bt,Rt,{i:"z",h:"if(c(A,i,d))return A"}),vn=l(Bt,Rt),mn=l(Bt,jt,{h:"var p=c(A,i,d);(h.call(t,p)?t[p]:t[p]=[]).push(A)"}),gn=l(zt,{a:"d,U",p:"var C=v.call(arguments,2),R=typeof U=='function'",h:{b:"t[i]=(R?U:A[U]).apply(A,C)",k:"t"+(Ot?"[n]=":".push")+"((R?U:A[U]).apply(A,C))"}}),yn=l(Bt,zt),bn=l(zt,{a:"d,bb",h:{b:"t[i]=A[bb]",k:"t"+(Ot?"[n]=":".push")+"(A[bb])" }}),wn=l({a:"d,c,B,x",i:"B",p:"var V=arguments.length<3;c=f(c,x)",d:{b:"if(V)t=j[++i]"},h:{b:"t=c(t,A,i,d)",k:"t=V?(V=false,A):c(t,A,i,d)"}}),En=l(Bt,qt,{h:"!"+qt.h}),Sn=l(Bt,Ft,{i:"false",h:Ft.h.replace("!","")}),xn=l(Bt,jt,zt,{h:{b:"t[i]={a:c(A,i,d),b:i,c:A}",k:"t"+(Ot?"[n]=":".push")+"({a:c(A,i,d),b:i,c:A})"},e:"t.sort(I);k=t.length;while(k--)t[k]=t[k].c"}),Tn=l(qt,{a:"d,aa",p:"var s=[];J(aa,function(A,p){s.push(p)});var cc=s.length",h:"for(var p,Z=true,r=0;rarguments.length,t=x(t,r),f=e.length;s=-1;if(f===+f)for(a&&(u=e[++s]);++sn||e===t)return 1;if( -earguments.length;if(s!==+s)var u=Mt(e),s=u -.length;return f(e,function(a,f,l){f=u?u[--s]:--s,n=o?(o=i,e[f]):t.call(r,n,e[f],f,l)}),n}function _(e,t,n){if(e)return t==r||n?e[0]:ot.call(e,0,t)}function D(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?dt(0,i+n):n||0)-1;else if(n)return r=j(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function B(e,t,n){return e?ot.call(e,t==r||n?1:t):[]}function j(e,t,n,r){for(var i=0,s=e?e.length:i,n=x(n,r),t=n(t);i>>1,n(e[r])P(a,r))a.push(r),u.push(e[s]);return u}function I(e,t){return Nt||at&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,J=/&(?:amp|lt|gt|quot|#x27);/g -,K=/\b__p\+='';/g,Q=/\b(__p\+=)''\+/g,G=/(__e\(.*?\)|\b__t\))\+'';/g,Y=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,Z=RegExp("^"+(W.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),et=/($^)/,tt=/[&<>"']/g,nt=/['\n\r\t\u2028\u2029\\]/g,rt=z.concat,it=W.hasOwnProperty,st=z.push,ot=z.slice,ut=W.toString,at=Z.test(at=ot.bind)&&at,ft=Math.floor,lt=Z.test(lt=Object.getPrototypeOf)&<,ct=Z.test(ct=Array.isArray)&&ct,ht=e.isFinite,pt=Z.test(pt=Object.keys)&&pt, -dt=Math.max,vt=Math.min,mt=Math.random,gt="[object Boolean]",yt="[object Date]",bt="[object Number]",wt="[object Object]",Et="[object RegExp]",St="[object String]",xt=e.clearTimeout,Tt=e.setTimeout,Nt=at&&/\n|Opera/.test(at+ut.call(e.opera)),Ct={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},kt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};w.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g -,variable:""},w.isArguments=function(e){return"[object Arguments]"==ut.call(e)},w.isArguments(arguments)||(w.isArguments=function(e){return e?it.call(e,"callee"):i});var Lt=ct||function(e){return"[object Array]"==ut.call(e)};L(/x/)&&(L=function(e){return"[object Function]"==ut.call(e)});var W=lt?function(e){if(!e||"object"!=typeof e)return i;var t=e.valueOf,n="function"==typeof t&&(n=lt(t))&<(n);return n?e==n||lt(e)==n&&!isArguments(e):A(e)}:A,At={"&":"&","<":"<",">":">",'"':""","'" -:"'"},Ot=b(At),Mt=pt?function(e){return e&&Ct[typeof e]?pt(e):[]}:y;w.VERSION="0.8.1",w.after=function(e,t){return 1>e?t():function(){if(1>--e)return t.apply(this,arguments)}},w.bind=I,w.bindAll=function(e){var t,n,r=e,i=e;if(!e)return i;n=arguments;var s=n.length;if(1P(r,s,n)&&i.push(s)}return i},w.escape=function(e){return e==r?"":(e+"").replace(tt,N)},w.every=h,w.extend=g,w.filter=c,w.find=l,w.first=_,w.flatten=D,w.forEach=f,w.forIn=m,w.forOwn=function(e,t,n){var r;if(!e)return e;t=x(t,n);for(r in e)it.call(e,r)&&(n=e[r],t(n,r,e));return e},w.functions=v,w.groupBy=function(e,t,n){var r,i={};if(!e)return i;var t=x(t,n),s=e.length,n=-1;if(s===+s)for(;++nP(i,s)){for(var o=1;oP(arguments[o],s))continue e;i.push(s)}}return i},w.invert=b,w.invoke=function(e,t){var n,r,i=e,s=e;if(!e)return s; -var o=ot.call(arguments,2),u="function"==typeof t,a=i.length;n=-1;if(a===+a)for(s=Array(a);++nn?dt(0,r+n):vt(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},w.map=a,w.max=H,w.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return it.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},w.min=function(e,t,n){for(var r=Infinity,i=-1,s=e?e.length:0,o=r,t=x(t,n);++iP(a,r))o[r]=i;return o},w.once=function(e){var t,s=i;return function(){return s?t:(s=n,t=e.apply(this,arguments),e=r,t)}},w.pairs=function(e){var t,n,r=[];if(!e)return r;for(t in e)it.call(e,t)&&(n=e[ -t],r.push([t,n]));return r},w.pick=function(e,t,n){var r,i,s=e,o={};if(!e)return o;if("function"!=typeof t){var s=rt.apply(z,arguments),u=s.length;for(r=1;r=f?(a=r,s=e.apply(o,i)):u||(u=Tt(n,f)),s}},w.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rP(r,t[e])&&r.push(t[e]);return r},w.uniq=F,w.uniqueId=function(e){var t=X++;return e?e+t:t},w.values=d,w.where=function(e,t){var r,i,s=[];if(!e)return s;var o=[];m(t,function(e,t){o.push(t)});var u=o.length,a=e.length;r=-1;if(a===+a)for(;++rP(arguments,i,1)&&r.push(i)}return r},w.wrap=function(e,t){return function(){var n=[e];return arguments.length&&st.apply(n,arguments),t.apply(this,n)}},w.zip=function(e){for(var t=-1,n=e?H(u(arguments,"length")):0,r=Array(n);++targuments.length,t=x(t,r),f=e.length;s=-1;if(f===+f)for(a&&(u=e[++s]);++sn||e===t)return 1;if( +earguments.length;if(s!==+s)var u=Lt(e),s=u +.length;return f(e,function(a,f,l){f=u?u[--s]:--s,n=o?(o=i,e[f]):t.call(r,n,e[f],f,l)}),n}function _(e,t,n){if(e)return t==r||n?e[0]:rt.call(e,0,t)}function D(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?ct(0,i+n):n||0)-1;else if(n)return r=j(e,t),e[r]===t?r:-1;for(;++rr&&(r=n,o=e[i]);return o}function B(e,t,n){return e?rt.call(e,t==r||n?1:t):[]}function j(e,t,n,r){for(var i=0,s=e?e.length:i,n=x(n,r),t=n(t);i>>1,n(e[r])P(a,r))a.push(r),u.push(e[s]);return u}function I(e,t){return St||st&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,J=/&(?:amp|lt|gt|quot|#x27);/g +,K=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,Q=RegExp("^"+(W.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),G=/($^)/,Y=/[&<>"']/g,Z=/['\n\r\t\u2028\u2029\\]/g,et=z.concat,tt=W.hasOwnProperty,nt=z.push,rt=z.slice,it=W.toString,st=Q.test(st=rt.bind)&&st,ot=Math.floor,ut=Q.test(ut=Object.getPrototypeOf)&&ut,at=Q.test(at=Array.isArray)&&at,ft=e.isFinite,lt=Q.test(lt=Object.keys)&<,ct=Math.max,ht=Math.min,pt=Math.random,dt="[object Boolean]",vt="[object Date]" +,mt="[object Number]",gt="[object Object]",yt="[object RegExp]",bt="[object String]",wt=e.clearTimeout,Et=e.setTimeout,St=st&&/\n|Opera/.test(st+it.call(e.opera)),xt={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Tt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};w.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},w.isArguments=function(e){return"[object Arguments]"==it. +call(e)},w.isArguments(arguments)||(w.isArguments=function(e){return e?tt.call(e,"callee"):i});var Nt=at||function(e){return"[object Array]"==it.call(e)};L(/x/)&&(L=function(e){return"[object Function]"==it.call(e)});var W=ut?function(e){if(!e||"object"!=typeof e)return i;var t=e.valueOf,n="function"==typeof t&&(n=ut(t))&&ut(n);return n?e==n||ut(e)==n&&!isArguments(e):A(e)}:A,Ct={"&":"&","<":"<",">":">",'"':""","'":"'"},kt=b(Ct),Lt=lt?function(e){return e&&xt[typeof e]?lt(e):[ +]}:y;w.VERSION="0.8.1",w.after=function(e,t){return 1>e?t():function(){if(1>--e)return t.apply(this,arguments)}},w.bind=I,w.bindAll=function(e){var t,n,r=e,i=e;if(!e)return i;n=arguments;var s=n.length;if(1P(r, +s,n)&&i.push(s)}return i},w.escape=function(e){return e==r?"":(e+"").replace(Y,N)},w.every=h,w.extend=g,w.filter=c,w.find=l,w.first=_,w.flatten=D,w.forEach=f,w.forIn=m,w.forOwn=function(e,t,n){var r;if(!e)return e;t=x(t,n);for(r in e)tt.call(e,r)&&(n=e[r],t(n,r,e));return e},w.functions=v,w.groupBy=function(e,t,n){var r,i={};if(!e)return i;var t=x(t,n),s=e.length,n=-1;if(s===+s)for(;++nP(i,s)){for(var o=1;oP(arguments[o],s))continue e;i.push(s)}}return i},w.invert=b,w.invoke=function(e,t){var n,r,i=e,s=e;if(!e)return s;var o=rt.call(arguments,2),u="function"==typeof t,a=i.length;n=-1;if( +a===+a)for(s=Array(a);++nn?ct(0,r+n):ht(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},w.map=a,w.max=H,w.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return tt.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},w.min=function(e,t,n){for(var r=Infinity,i=-1,s=e?e.length:0,o=r,t=x(t,n);++iP(a,r))o[r]=i;return o},w.once=function(e){var t,s=i;return function(){return s?t:(s=n,t=e.apply(this,arguments),e=r,t)}},w.pairs=function(e){var t,n,r=[];if(!e)return r;for(t in e)tt.call(e,t)&&(n=e[t],r.push([t,n]));return r},w.pick=function(e,t,n){var r,i,s=e,o={};if(! +e)return o;if("function"!=typeof t){var s=et.apply(z,arguments),u=s.length;for(r=1;r=f?(a=r,s=e.apply(o,i)):u||(u=Et(n,f)),s}},w.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rP(r,t[e])&&r.push(t[e]);return r},w.uniq=F,w.uniqueId=function(e){var t=X++;return e?e+t:t},w.values=d,w.where=function(e,t){var r,i,s=[];if(!e)return s;var o=[];m(t,function(e,t){o.push(t)});var u=o.length,a=e.length;r=-1;if(a===+a)for(;++rP(arguments,i,1)&&r.push(i)}return r},w.wrap=function(e,t){return function(){var n=[e];return arguments.length&&nt.apply(n,arguments),t.apply(this,n)}},w.zip=function(e){for(var t=-1,n=e?H(u(arguments,"length")):0,r=Array(n);++t Date: Sat, 6 Oct 2012 21:11:52 -0700 Subject: [PATCH 08/26] Update `_.map` to return an empty array when falsey values are passed. Former-commit-id: 2f091fbeb140cbc0b8f3bd2df7a449a06239be0b --- build.js | 2 +- lodash.js | 2 +- lodash.min.js | 2 +- lodash.underscore.min.js | 32 ++++++++++++++++---------------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/build.js b/build.js index 810b4e864a..f7a38dd3dc 100755 --- a/build.js +++ b/build.js @@ -1256,7 +1256,7 @@ }); if (isUnderscore) { - // remove compiled template cleanup from `_.template` + // remove "compiled template cleanup" from `_.template` source = source.replace(/(?:\s*\/\/.*)*\n *source *=.+?isEvaluating.+?reEmptyStringLeading[\s\S]+?\);/, ''); source = removeVar(source, 'reEmptyStringLeading'); source = removeVar(source, 'reEmptyStringMiddle'); diff --git a/lodash.js b/lodash.js index bdf2c170c4..35a2f458de 100644 --- a/lodash.js +++ b/lodash.js @@ -482,7 +482,7 @@ /** Reusable iterator options for `invoke`, `map`, `pluck`, and `sortBy` */ var mapIteratorOptions = { - 'init': false, + 'init': 'collection || []', 'beforeLoop': { 'array': 'result = Array(length)', 'object': 'result = ' + (isKeysFast ? 'Array(length)' : '[]') diff --git a/lodash.min.js b/lodash.min.js index bcaee1192e..699d25bca9 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -17,7 +17,7 @@ global==global.global&&(e=global),exports),_=Array.prototype,D=Object.prototype, .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={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},Ht={"\\":"\\","'":"'","\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 Bt={a:"d,c,x",i:"d",p:"c=f(c,x)",h:"if(c(A,i,d)===false)return t"},jt={i -:"{}",p:"c=f(c,x)",h:"var p=c(A,i,d);(h.call(t,p)?t[p]++:t[p]=1)"},Ft={i:"true",h:"if(!c(A,i,d))return!t"},It={q:i,r:i,a:"m",i:"m",p:"for(var a=1,b=arguments.length;a":">",'"':""","'":"'"},Qt=Xt(Kt),Gt=l(It,{ h:"if(t[i]==null)"+It.h}),Yt=l(It),Zt=l(Bt,Rt,Ut,{q:i}),en=l(Bt,Rt,Ut),tn=l({q:i,a:"m",i:"[]",h:"S(A)&&t.push(i)",e:"t.sort()"}),nn=l({a:"A",i:"true",p:"var H=y.call(A),k=A.length;if(D[H]"+(Tt?"||O(A)":"")+"||(H==X&&k===+k&&S(A.splice)))return!k",h:{k:"return false"}}),rn=ot?function(e){var t=typeof e;return"function"==t&&Y.call(e,"prototype")?Jt(e):e&&Pt[t]?ot(e):[]}:Jt,sn=l(It,{a:"m,dd,N",p:"var P,C=arguments,a=0;if(N==I){var b=2,ee=C[3],ff=C[4]}else var b=C.length,ee=[],ff=[];while(++aarguments.length,t=x(t,r),f=e.length;s=-1;if(f===+f)for(a&&(u=e[++s]);++sn||e===t)return 1;if( -earguments.length,t=x(t,r),f=e.length;s=-1;if(f===+f)for(a&&(u=e[++s]);++sn||e===t)return 1 +;if(earguments.length;if(s!==+s)var u=Lt(e),s=u .length;return f(e,function(a,f,l){f=u?u[--s]:--s,n=o?(o=i,e[f]):t.call(r,n,e[f],f,l)}),n}function _(e,t,n){if(e)return t==r||n?e[0]:rt.call(e,0,t)}function D(e,t){for(var n=-1,r=e?e.length:0,i=[];++nn?ct(0,i+n):n||0)-1;else if(n)return r=j(e,t),e[r]===t?r:-1;for(;++rP(r, s,n)&&i.push(s)}return i},w.escape=function(e){return e==r?"":(e+"").replace(Y,N)},w.every=h,w.extend=g,w.filter=c,w.find=l,w.first=_,w.flatten=D,w.forEach=f,w.forIn=m,w.forOwn=function(e,t,n){var r;if(!e)return e;t=x(t,n);for(r in e)tt.call(e,r)&&(n=e[r],t(n,r,e));return e},w.functions=v,w.groupBy=function(e,t,n){var r,i={};if(!e)return i;var t=x(t,n),s=e.length,n=-1;if(s===+s)for(;++nP(i,s)){for(var o=1;oP(arguments[o],s))continue e;i.push(s)}}return i},w.invert=b,w.invoke=function(e,t){var n,r,i=e,s=e;if(!e)return s;var o=rt.call(arguments,2),u="function"==typeof t,a=i.length;n=-1;if( -a===+a)for(s=Array(a);++nn?ct(0,r+n):ht(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},w.map=a,w.max=H,w.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return tt.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},w.min=function(e,t,n){for(var r=Infinity,i=-1,s=e?e.length:0,o=r,t=x(t,n);++iP(a,r))o[r]=i;return o},w.once=function(e){var t,s=i;return function(){return s?t:(s=n,t=e.apply(this,arguments),e=r,t)}},w.pairs=function(e){var t,n,r=[];if(!e)return r;for(t in e)tt.call(e,t)&&(n=e[t],r.push([t,n]));return r},w.pick=function(e,t,n){var r,i,s=e,o={};if(! -e)return o;if("function"!=typeof t){var s=et.apply(z,arguments),u=s.length;for(r=1;r=f?(a=r,s=e.apply(o,i)):u||(u=Et(n,f)),s}},w.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rP(i,s)){for(var o=1;oP(arguments[o],s))continue e;i.push(s)}}return i},w.invert=b,w.invoke=function(e,t){var n,r,i=e,s=e||[];if(!e)return s;var o=rt.call(arguments,2),u="function"==typeof t,a=i.length;n=-1 +;if(a===+a)for(s=Array(a);++nn?ct(0,r+n):ht(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},w.map=a,w.max=H,w.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return tt.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},w.min=function(e,t,n){for(var r=Infinity,i=-1,s=e?e.length:0,o=r,t=x(t,n);++iP(a,r))o[r]=i;return o},w.once=function(e){var t,s=i;return function(){return s?t:(s=n,t=e.apply(this,arguments),e=r,t)}},w.pairs=function(e){var t,n,r=[];if(!e)return r;for(t in e)tt.call(e,t)&&(n=e[t],r.push([t,n]));return r},w.pick=function(e,t,n){var r,i,s=e,o= +{};if(!e)return o;if("function"!=typeof t){var s=et.apply(z,arguments),u=s.length;for(r=1;r=f?(a=r,s=e.apply(o,i)):u||(u=Et(n,f)),s}},w.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rP(r,t[e])&&r.push(t[e]);return r},w.uniq=F,w.uniqueId=function(e){var t=X++;return e?e+t:t},w.values=d,w.where=function(e,t){var r,i,s=[];if(!e)return s;var o=[];m(t,function(e,t){o.push(t)});var u=o.length,a=e.length;r=-1;if(a===+a)for(;++rP(arguments,i,1)&&r.push(i)}return r},w.wrap=function(e,t){return function(){var n=[e];return arguments.length&&nt.apply(n,arguments),t.apply(this,n)}},w.zip=function(e){for(var t=-1,n=e?H(u(arguments,"length")):0,r=Array(n);++t Date: Sat, 6 Oct 2012 22:31:08 -0700 Subject: [PATCH 09/26] Update DocDown and Underscore. Former-commit-id: 7744ef274a9d8b47975dc9f3e3283bd778bc5403 --- vendor/docdown/src/DocDown/Alias.php | 11 ++++++++++ vendor/docdown/src/DocDown/Entry.php | 19 +++++++++++++++++ vendor/docdown/src/DocDown/Generator.php | 27 ++++++++++++++++++------ vendor/underscore/test/arrays.js | 6 ++++++ vendor/underscore/test/collections.js | 2 ++ vendor/underscore/underscore-min.js | 2 +- vendor/underscore/underscore.js | 4 ++++ 7 files changed, 63 insertions(+), 8 deletions(-) diff --git a/vendor/docdown/src/DocDown/Alias.php b/vendor/docdown/src/DocDown/Alias.php index 1f9521e1b6..6a873c0af7 100644 --- a/vendor/docdown/src/DocDown/Alias.php +++ b/vendor/docdown/src/DocDown/Alias.php @@ -26,6 +26,7 @@ public function __construct($name, $owner) { $this->owner = $owner; $this->_name = $name; $this->_call = $owner->getCall(); + $this->_category = $owner->getCategory(); $this->_desc = $owner->getDesc(); $this->_example = $owner->getExample(); $this->_lineNumber = $owner->getLineNumber(); @@ -65,6 +66,16 @@ public function getCall() { return $this->_call; } + /** + * Extracts the owner entry's `category` data. + * + * @memberOf Alias + * @returns {String} The owner entry's `category` data. + */ + public function getCategory() { + return $this->_category; + } + /** * Extracts the owner entry's description. * diff --git a/vendor/docdown/src/DocDown/Entry.php b/vendor/docdown/src/DocDown/Entry.php index 887241bf05..c61f9e8529 100644 --- a/vendor/docdown/src/DocDown/Entry.php +++ b/vendor/docdown/src/DocDown/Entry.php @@ -152,6 +152,25 @@ public function getCall() { return $this->_call; } + /** + * Extracts the entry's `category` data. + * + * @memberOf Entry + * @returns {String} The entry's `category` data. + */ + public function getCategory() { + if (isset($this->_category)) { + return $this->_category; + } + + preg_match('#\* *@category\s+([^\n]+)#', $this->entry, $result); + if (count($result)) { + $result = trim(preg_replace('/(?:^|\n)\s*\* ?/', ' ', $result[1])); + } + $this->_category = $result; + return $result; + } + /** * Extracts the entry's description. * diff --git a/vendor/docdown/src/DocDown/Generator.php b/vendor/docdown/src/DocDown/Generator.php index 4273306202..e9ca1c27ac 100644 --- a/vendor/docdown/src/DocDown/Generator.php +++ b/vendor/docdown/src/DocDown/Generator.php @@ -204,6 +204,7 @@ private function getSeparator( $entry ) { */ public function generate() { $api = array(); + $categories = array(); $compiling = false; $openTag = "\n\n"; $closeTag = "\n\n"; @@ -223,14 +224,26 @@ public function generate() { foreach ($members as $member) { // create api category arrays - if (!isset($api[$member]) && $member) { + if ($member && !isset($api[$member])) { // create temporary entry to be replaced later - $api[$member] = new Entry('', '', $entry->lang); + $api[$member] = new stdClass; $api[$member]->static = array(); $api[$member]->plugin = array(); } - // append entry to api category + // track categories + $category = $entry->getCategory(); + if ($category) { + if (!isset($categories[$category])) { + $categories[$category] = array(); + } + $categories[$category][] = $entry; + foreach ($entry->getAliases() as $alias) { + $categories[$category][] = $alias; + } + } + + // append entry to api member if (!$member || $entry->isCtor() || ($entry->getType() == 'Object' && !preg_match('/[=:]\s*(?:null|undefined)\s*[,;]?$/', $entry->entry))) { @@ -268,19 +281,19 @@ public function generate() { function sortCompare($a, $b) { $score = array( 'a' => 0, 'b' => 0); foreach (array( 'a' => $a, 'b' => $b) as $key => $value) { - // capitalized keys that represent constructor properties are last + // capitalized properties are last if (preg_match('/[#.][A-Z]/', $value)) { $score[$key] = 0; } - // lowercase keys with prototype properties are next to last + // lowercase prototype properties are next to last else if (preg_match('/#[a-z]/', $value)) { $score[$key] = 1; } - // lowercase keys with static properties next to first + // lowercase static properties next to first else if (preg_match('/\.[a-z]/', $value)) { $score[$key] = 2; } - // lowercase keys with no properties are first + // root properties are first else if (preg_match('/^[^#.]+$/', $value)) { $score[$key] = 3; } diff --git a/vendor/underscore/test/arrays.js b/vendor/underscore/test/arrays.js index a757ced67f..32252a3f59 100644 --- a/vendor/underscore/test/arrays.js +++ b/vendor/underscore/test/arrays.js @@ -14,6 +14,8 @@ $(document).ready(function() { equal(result.join(','), '1,1', 'works well with _.map'); result = (function() { return _.take([1,2,3], 2); })(); equal(result.join(','), '1,2', 'aliased as take'); + + equal(_.first(null), undefined, 'handles nulls'); }); test("rest", function() { @@ -47,6 +49,8 @@ $(document).ready(function() { equal(result, 4, 'works on an arguments object'); result = _.map([[1,2,3],[1,2,3]], _.last); equal(result.join(','), '3,3', 'works well with _.map'); + + equal(_.last(null), undefined, 'handles nulls'); }); test("compact", function() { @@ -136,6 +140,8 @@ $(document).ready(function() { var stooges = {moe: 30, larry: 40, curly: 50}; ok(_.isEqual(_.object(_.pairs(stooges)), stooges), 'an object converted to pairs and back to an object'); + + ok(_.isEqual(_.object(null), {}), 'handles nulls'); }); test("indexOf", function() { diff --git a/vendor/underscore/test/collections.js b/vendor/underscore/test/collections.js index efc5723d40..7dce44ba51 100644 --- a/vendor/underscore/test/collections.js +++ b/vendor/underscore/test/collections.js @@ -411,6 +411,8 @@ $(document).ready(function() { equal(func(1, 2, 3, 4), 4, 'can test the size of the arguments object'); equal(_.size('hello'), 5, 'can compute the size of a string'); + + equal(_.size(null), 0, 'handles nulls'); }); }); diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index ad3a39ad82..0bdee410ca 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.2";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.2";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 1ebe2671b9..43b4e407dd 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -369,6 +369,7 @@ // Return the number of elements in an object. _.size = function(obj) { + if (obj == null) return 0; return (obj.length === +obj.length) ? obj.length : _.keys(obj).length; }; @@ -379,6 +380,7 @@ // values in the array. Aliased as `head` and `take`. The **guard** check // allows it to work with `_.map`. _.first = _.head = _.take = function(array, n, guard) { + if (array == null) return void 0; return (n != null) && !guard ? slice.call(array, 0, n) : array[0]; }; @@ -393,6 +395,7 @@ // Get the last element of an array. Passing **n** will return the last N // values in the array. The **guard** check allows it to work with `_.map`. _.last = function(array, n, guard) { + if (array == null) return void 0; if ((n != null) && !guard) { return slice.call(array, Math.max(array.length - n, 0)); } else { @@ -491,6 +494,7 @@ // pairs, or two parallel arrays of the same length -- one of keys, and one of // the corresponding values. _.object = function(list, values) { + if (list == null) return {}; var result = {}; for (var i = 0, l = list.length; i < l; i++) { if (values) { From 1104b28bc1ced111ce65e2f32ae9a744eb868e0c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 6 Oct 2012 23:38:25 -0700 Subject: [PATCH 10/26] Update README.md to remove fixed Underscore issue. Former-commit-id: 16fc177c33c2f2522fd9080c0974091ef8e97850 --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index dba3f8eeca..83d7e878f3 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,6 @@ require({ * Add AMD loader support [[#431](https://github.com/documentcloud/underscore/pull/431), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L118-140)] * Allow iteration of objects with a `length` property [[#799](https://github.com/documentcloud/underscore/pull/799), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L510-516)] - * Ensure *“Arrays”*, *“Collections”*, and *“Objects”* methods don’t error when passed falsey arguments [[#650](https://github.com/documentcloud/underscore/pull/650), [#803](https://github.com/documentcloud/underscore/issues/803), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L1729-1764)] * 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.1/test/test.js#L470-487)] * 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.1/test/test.js#L526-546)] * 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.1/test/test.js#L142-148)] From 8f7d5dcb4d2d148a7c8682a49f868ca769718374 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 6 Oct 2012 23:39:41 -0700 Subject: [PATCH 11/26] Reduce lodash file size. Former-commit-id: c6c309cbbc5f93bffb852726e831ba9f90c332a0 --- lodash.js | 10 ++++++---- lodash.min.js | 6 +++--- lodash.underscore.min.js | 16 ++++++++-------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lodash.js b/lodash.js index 35a2f458de..f5c91c982d 100644 --- a/lodash.js +++ b/lodash.js @@ -2756,10 +2756,11 @@ result = {}; while (++index < length) { + var key = keys[index]; if (values) { - result[keys[index]] = values[index]; + result[key] = values[index]; } else { - result[keys[index][0]] = keys[index][1]; + result[key[0]] = key[1]; } } return result; @@ -2941,8 +2942,9 @@ result = []; while (++index < length) { - if (indexOf(result, flattened[index]) < 0) { - result.push(flattened[index]); + var value = flattened[index]; + if (indexOf(result, value) < 0) { + result.push(value); } } return result; diff --git a/lodash.min.js b/lodash.min.js index 699d25bca9..2d781cfae9 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -28,12 +28,12 @@ e.length;n--;)t=[e[n].apply(this,t)];return t[0]}},s.contains=ln,s.countBy=cn,s. var n=-1,r=e.length,i=K.apply(_,arguments),i=o(i,r);++nx(s,u)){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?e.length:0,r=o(arguments,1,20),i=[];++tx(r,i)&&r.push(i)}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?e.length:0,r=o(arguments,1,20),i=[];++tn?ct(0,r+n):ht(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},w.map=a,w.max=H,w.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return tt.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},w.min=function(e,t,n){for(var r=Infinity,i=-1,s=e?e.length:0,o=r,t=x(t,n);++iP(a,r))o[r]=i;return o},w.once=function(e){var t,s=i;return function(){return s?t:(s=n,t=e.apply(this,arguments),e=r,t)}},w.pairs=function(e){var t,n,r=[];if(!e)return r;for(t in e)tt.call(e,t)&&(n=e[t],r.push([t,n]));return r},w.pick=function(e,t,n){var r,i,s=e,o= -{};if(!e)return o;if("function"!=typeof t){var s=et.apply(z,arguments),u=s.length;for(r=1;rP(a,r))o[r]=i;return o},w.once=function(e){var t,s=i;return function(){return s?t:(s=n,t=e.apply(this,arguments),e=r,t)}},w.pairs=function(e){var t,n,r=[];if(!e)return r;for(t in e)tt.call(e,t)&&(n=e[t],r.push([t,n]));return r},w.pick=function(e,t,n){var r,i,s=e +,o={};if(!e)return o;if("function"!=typeof t){var s=et.apply(z,arguments),u=s.length;for(r=1;r=f?(a=r,s=e.apply(o,i)):u||(u=Et(n,f)),s}},w.times=function(e,t,n){for(var e=+e||0,r=-1,i=Array(e);++rP(r,t[e])&&r.push(t[e]);return r},w.uniq=F,w.uniqueId=function(e){var t=X++;return e?e+t:t},w.values=d,w.where=function(e,t){var r,i,s=[];if(!e)return s;var o=[];m(t,function(e,t){o.push(t)});var u=o.length,a=e.length;r=-1;if(a===+a)for(;++rP(arguments,i,1)&&r.push(i)}return r},w.wrap=function(e,t){return function(){var n=[e];return arguments.length&&nt.apply(n,arguments),t.apply(this,n)}},w.zip=function(e){for(var t=-1,n=e?H(u(arguments,"length")):0,r=Array(n);++tP(r,i)&&r.push(i)}return r},w.uniq=F,w.uniqueId=function(e){var t=X++;return e?e+t:t},w.values=d,w.where=function(e,t){var r,i,s=[];if(!e)return s;var o=[];m(t,function(e,t){o.push(t)});var u=o.length,a=e.length;r=-1;if(a===+a)for(;++rP(arguments,i,1)&&r.push(i)}return r},w.wrap=function(e,t){return function(){var n=[e];return arguments.length&&nt.apply(n,arguments),t.apply(this,n)}},w.zip=function(e){for(var t=-1,n=e?H(u(arguments,"length")):0,r=Array(n);++t Date: Sun, 7 Oct 2012 02:19:16 -0700 Subject: [PATCH 12/26] Organize docs by category. [closes #84] Former-commit-id: f4ebda7c32a0ce9c5a86cdb0fd1e689f76557e42 --- doc/README.md | 2480 +++++++++++----------- doc/parse.php | 5 +- lodash.js | 1 + vendor/docdown/docdown.php | 2 +- vendor/docdown/src/DocDown/Alias.php | 2 +- vendor/docdown/src/DocDown/Entry.php | 2 + vendor/docdown/src/DocDown/Generator.php | 335 +-- 7 files changed, 1491 insertions(+), 1336 deletions(-) diff --git a/doc/README.md b/doc/README.md index 26337495c3..c377cbc84e 100644 --- a/doc/README.md +++ b/doc/README.md @@ -5,53 +5,114 @@ -## `_` +## `Arrays` +* [`_.compact`](#_compactarray) +* [`_.difference`](#_differencearray--array1-array2-) +* [`_.drop`](#_restarray--n) +* [`_.first`](#_firstarray--n) +* [`_.flatten`](#_flattenarray-shallow) +* [`_.head`](#_firstarray--n) +* [`_.indexOf`](#_indexofarray-value--fromindex0) +* [`_.initial`](#_initialarray--n) +* [`_.intersection`](#_intersectionarray1-array2-) +* [`_.last`](#_lastarray--n) +* [`_.lastIndexOf`](#_lastindexofarray-value--fromindexarraylength-1) +* [`_.max`](#_maxarray--callback-thisarg) +* [`_.min`](#_minarray--callback-thisarg) +* [`_.object`](#_objectkeys--values) +* [`_.range`](#_rangestart0-end--step1) +* [`_.rest`](#_restarray--n) +* [`_.shuffle`](#_shufflearray) +* [`_.sortedIndex`](#_sortedindexarray-value--callbackidentityproperty-thisarg) +* [`_.tail`](#_restarray--n) +* [`_.take`](#_firstarray--n) +* [`_.union`](#_unionarray1-array2-) +* [`_.uniq`](#_uniqarray--issortedfalse-callbackidentity-thisarg) +* [`_.unique`](#_uniqarray--issortedfalse-callbackidentity-thisarg) +* [`_.without`](#_withoutarray--value1-value2-) +* [`_.zip`](#_ziparray1-array2-) + + + + + + +## `Chaining` * [`_`](#_value) -* [`_.VERSION`](#_version) -* [`_.after`](#_aftern-func) +* [`_.chain`](#_chainvalue) +* [`_.tap`](#_tapvalue-interceptor) +* [`_.prototype.chain`](#_prototypechain) +* [`_.prototype.value`](#_prototypevalue) + + + + + + +## `Collections` * [`_.all`](#_everycollection--callbackidentity-thisarg) * [`_.any`](#_somecollection--callbackidentity-thisarg) -* [`_.bind`](#_bindfunc--thisarg-arg1-arg2-) -* [`_.bindAll`](#_bindallobject--methodname1-methodname2-) -* [`_.chain`](#_chainvalue) -* [`_.clone`](#_clonevalue-deep) * [`_.collect`](#_mapcollection--callbackidentity-thisarg) -* [`_.compact`](#_compactarray) -* [`_.compose`](#_composefunc1-func2-) * [`_.contains`](#_containscollection-target) * [`_.countBy`](#_countbycollection-callbackproperty--thisarg) -* [`_.debounce`](#_debouncefunc-wait-immediate) -* [`_.defaults`](#_defaultsobject--default1-default2-) -* [`_.defer`](#_deferfunc--arg1-arg2-) -* [`_.delay`](#_delayfunc-wait--arg1-arg2-) * [`_.detect`](#_findcollection-callback--thisarg) -* [`_.difference`](#_differencearray--array1-array2-) -* [`_.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) -* [`_.flatten`](#_flattenarray-shallow) * [`_.foldl`](#_reducecollection-callback--accumulator-thisarg) * [`_.foldr`](#_reducerightcollection-callback--accumulator-thisarg) * [`_.forEach`](#_foreachcollection-callback--thisarg) +* [`_.groupBy`](#_groupbycollection-callbackproperty--thisarg) +* [`_.include`](#_containscollection-target) +* [`_.inject`](#_reducecollection-callback--accumulator-thisarg) +* [`_.invoke`](#_invokecollection-methodname--arg1-arg2-) +* [`_.map`](#_mapcollection--callbackidentity-thisarg) +* [`_.pluck`](#_pluckcollection-property) +* [`_.reduce`](#_reducecollection-callback--accumulator-thisarg) +* [`_.reduceRight`](#_reducerightcollection-callback--accumulator-thisarg) +* [`_.reject`](#_rejectcollection--callbackidentity-thisarg) +* [`_.select`](#_filtercollection--callbackidentity-thisarg) +* [`_.size`](#_sizecollection) +* [`_.some`](#_somecollection--callbackidentity-thisarg) +* [`_.sortBy`](#_sortbycollection-callbackproperty--thisarg) +* [`_.toArray`](#_toarraycollection) +* [`_.where`](#_wherecollection-properties) + + + + + + +## `Functions` +* [`_.after`](#_aftern-func) +* [`_.bind`](#_bindfunc--thisarg-arg1-arg2-) +* [`_.bindAll`](#_bindallobject--methodname1-methodname2-) +* [`_.compose`](#_composefunc1-func2-) +* [`_.debounce`](#_debouncefunc-wait-immediate) +* [`_.defer`](#_deferfunc--arg1-arg2-) +* [`_.delay`](#_delayfunc-wait--arg1-arg2-) +* [`_.lateBind`](#_latebindobject-methodname--arg1-arg2-) +* [`_.memoize`](#_memoizefunc--resolver) +* [`_.once`](#_oncefunc) +* [`_.partial`](#_partialfunc--arg1-arg2-) +* [`_.throttle`](#_throttlefunc-wait) +* [`_.wrap`](#_wrapvalue-wrapper) + + + + + + +## `Objects` +* [`_.clone`](#_clonevalue-deep) +* [`_.defaults`](#_defaultsobject--default1-default2-) +* [`_.extend`](#_extendobject--source1-source2-) * [`_.forIn`](#_forinobject-callback--thisarg) * [`_.forOwn`](#_forownobject-callback--thisarg) * [`_.functions`](#_functionsobject) -* [`_.groupBy`](#_groupbycollection-callbackproperty--thisarg) * [`_.has`](#_hasobject-property) -* [`_.head`](#_firstarray--n) -* [`_.identity`](#_identityvalue) -* [`_.include`](#_containscollection-target) -* [`_.indexOf`](#_indexofarray-value--fromindex0) -* [`_.initial`](#_initialarray--n) -* [`_.inject`](#_reducecollection-callback--accumulator-thisarg) -* [`_.intersection`](#_intersectionarray1-array2-) * [`_.invert`](#_invertobject) -* [`_.invoke`](#_invokecollection-methodname--arg1-arg2-) * [`_.isArguments`](#_isargumentsvalue) * [`_.isArray`](#_isarrayvalue) * [`_.isBoolean`](#_isbooleanvalue) @@ -70,70 +131,37 @@ * [`_.isString`](#_isstringvalue) * [`_.isUndefined`](#_isundefinedvalue) * [`_.keys`](#_keysobject) -* [`_.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-) * [`_.methods`](#_functionsobject) -* [`_.min`](#_minarray--callback-thisarg) -* [`_.mixin`](#_mixinobject) -* [`_.noConflict`](#_noconflict) -* [`_.object`](#_objectkeys--values) * [`_.omit`](#_omitobject-callback-prop1-prop2--thisarg) -* [`_.once`](#_oncefunc) * [`_.pairs`](#_pairsobject) -* [`_.partial`](#_partialfunc--arg1-arg2-) * [`_.pick`](#_pickobject-callback-prop1-prop2--thisarg) -* [`_.pluck`](#_pluckcollection-property) -* [`_.random`](#_randommin0-max1) -* [`_.range`](#_rangestart0-end--step1) -* [`_.reduce`](#_reducecollection-callback--accumulator-thisarg) -* [`_.reduceRight`](#_reducerightcollection-callback--accumulator-thisarg) -* [`_.reject`](#_rejectcollection--callbackidentity-thisarg) -* [`_.rest`](#_restarray--n) -* [`_.result`](#_resultobject-property) -* [`_.select`](#_filtercollection--callbackidentity-thisarg) -* [`_.shuffle`](#_shufflearray) -* [`_.size`](#_sizecollection) -* [`_.some`](#_somecollection--callbackidentity-thisarg) -* [`_.sortBy`](#_sortbycollection-callbackproperty--thisarg) -* [`_.sortedIndex`](#_sortedindexarray-value--callbackidentityproperty-thisarg) -* [`_.tail`](#_restarray--n) -* [`_.take`](#_firstarray--n) -* [`_.tap`](#_tapvalue-interceptor) -* [`_.template`](#_templatetext-data-options) -* [`_.throttle`](#_throttlefunc-wait) -* [`_.times`](#_timesn-callback--thisarg) -* [`_.toArray`](#_toarraycollection) -* [`_.unescape`](#_unescapestring) -* [`_.union`](#_unionarray1-array2-) -* [`_.uniq`](#_uniqarray--issortedfalse-callbackidentity-thisarg) -* [`_.unique`](#_uniqarray--issortedfalse-callbackidentity-thisarg) -* [`_.uniqueId`](#_uniqueidprefix) * [`_.values`](#_valuesobject) -* [`_.where`](#_wherecollection-properties) -* [`_.without`](#_withoutarray--value1-value2-) -* [`_.wrap`](#_wrapvalue-wrapper) -* [`_.zip`](#_ziparray1-array2-) -## `_.prototype` -* [`_.prototype.chain`](#_prototypechain) -* [`_.prototype.value`](#_prototypevalue) +## `Utilities` +* [`_.escape`](#_escapestring) +* [`_.identity`](#_identityvalue) +* [`_.mixin`](#_mixinobject) +* [`_.noConflict`](#_noconflict) +* [`_.random`](#_randommin0-max1) +* [`_.result`](#_resultobject-property) +* [`_.template`](#_templatetext-data-options) +* [`_.times`](#_timesn-callback--thisarg) +* [`_.unescape`](#_unescapestring) +* [`_.uniqueId`](#_uniqueidprefix) -## `_.templateSettings` +## `Properties` +* [`_.VERSION`](#_version) * [`_.templateSettings`](#_templatesettings) * [`_.templateSettings.escape`](#_templatesettingsescape) * [`_.templateSettings.evaluate`](#_templatesettingsevaluate) @@ -151,32 +179,26 @@ -## `_` +## `“Arrays” Methods` -### `_(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L241 "View in source") [Ⓣ][1] +### `_.compact(array)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2394 "View in source") [Ⓣ][1] -The `lodash` function. +Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. #### Arguments -1. `value` *(Mixed)*: The value to wrap in a `lodash` instance. +1. `array` *(Array)*: The array to compact. #### Returns -*(Object)*: Returns a `lodash` instance. - -* * * - - - - - - -### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3995 "View in source") [Ⓣ][1] +*(Array)*: Returns a new filtered array. -*(String)*: The semantic version number. +#### Example +```js +_.compact([0, 1, false, 2, '', 3]); +// => [1, 2, 3] +``` * * * @@ -185,25 +207,22 @@ The `lodash` function. -### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3101 "View in source") [Ⓣ][1] +### `_.difference(array [, array1, array2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2423 "View in source") [Ⓣ][1] -Creates a function that is restricted to executing only after it is called `n` times. +Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. #### Arguments -1. `n` *(Number)*: The number of times the function must be called before it is executed. -2. `func` *(Function)*: The function to restrict. +1. `array` *(Array)*: The array to process. +2. `[array1, array2, ...]` *(Array)*: Arrays to check. #### Returns -*(Function)*: Returns the new restricted function. +*(Array)*: Returns a new array of `array` elements not present in the other arrays. #### Example ```js -var renderNotes = _.after(notes.length, render); -_.forEach(notes, function(note) { - note.asyncSave({ 'success': renderNotes }); -}); -// `renderNotes` is run once, after all notes have saved +_.difference([1, 2, 3, 4, 5], [5, 2, 10]); +// => [1, 3, 4] ``` * * * @@ -213,28 +232,25 @@ _.forEach(notes, function(note) { -### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3134 "View in source") [Ⓣ][1] +### `_.first(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2461 "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. +Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. + +#### Aliases +*head, take* #### Arguments -1. `func` *(Function)*: The function to bind. -2. `[thisArg]` *(Mixed)*: The `this` binding of `func`. -3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. +1. `array` *(Array)*: The array to query. +2. `[n]` *(Number)*: The number of elements to return. #### Returns -*(Function)*: Returns the new bound function. +*(Mixed)*: Returns the first element or an array of the first `n` elements of `array`. #### Example ```js -var func = function(greeting) { - return greeting + ' ' + this.name; -}; - -func = _.bind(func, { 'name': 'moe' }, 'hi'); -func(); -// => 'hi moe' +_.first([5, 4, 3, 2, 1]); +// => 5 ``` * * * @@ -244,28 +260,25 @@ func(); -### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3164 "View in source") [Ⓣ][1] +### `_.flatten(array, shallow)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2485 "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. +Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. #### Arguments -1. `object` *(Object)*: The object to bind and assign the bound methods to. -2. `[methodName1, methodName2, ...]` *(String)*: Method names on the object to bind. +1. `array` *(Array)*: The array to compact. +2. `shallow` *(Boolean)*: A flag to indicate only flattening a single level. #### Returns -*(Object)*: Returns `object`. +*(Array)*: Returns a new flattened array. #### Example ```js -var buttonView = { - 'label': 'lodash', - 'onClick': function() { alert('clicked: ' + this.label); } -}; +_.flatten([1, [2], [3, [[4]]]]); +// => [1, 2, 3, 4]; -_.bindAll(buttonView); -jQuery('#lodash_button').on('click', buttonView.onClick); -// => When the button is clicked, `this.label` will have the correct value +_.flatten([1, [2], [3, [[4]]]], true); +// => [1, 2, 3, [[4]]]; ``` * * * @@ -275,31 +288,29 @@ jQuery('#lodash_button').on('click', buttonView.onClick); -### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3920 "View in source") [Ⓣ][1] +### `_.indexOf(array, value [, fromIndex=0])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2527 "View in source") [Ⓣ][1] -Wraps the value in a `lodash` wrapper object. +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. #### Arguments -1. `value` *(Mixed)*: The value to wrap. +1. `array` *(Array)*: The array to search. +2. `value` *(Mixed)*: The value to search for. +3. `[fromIndex=0]` *(Boolean|Number)*: The index to start searching from or `true` to perform a binary search on a sorted `array`. #### Returns -*(Object)*: Returns the wrapper object. +*(Number)*: Returns the index of the matched value or `-1`. #### Example ```js -var stooges = [ - { 'name': 'moe', 'age': 40 }, - { 'name': 'larry', 'age': 50 }, - { 'name': 'curly', 'age': 60 } -]; +_.indexOf([1, 2, 3, 1, 2, 3], 2); +// => 1 -var youngest = _.chain(stooges) - .sortBy(function(stooge) { return stooge.age; }) - .map(function(stooge) { return stooge.name + ' is ' + stooge.age; }) - .first() - .value(); -// => 'moe is 40' +_.indexOf([1, 2, 3, 1, 2, 3], 2, 3); +// => 4 + +_.indexOf([1, 1, 2, 2, 3, 3], 2, true); +// => 2 ``` * * * @@ -309,36 +320,22 @@ var youngest = _.chain(stooges) -### `_.clone(value, deep)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1035 "View in source") [Ⓣ][1] +### `_.initial(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2562 "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. +Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. #### Arguments -1. `value` *(Mixed)*: The value to clone. -2. `deep` *(Boolean)*: A flag to indicate a deep clone. +1. `array` *(Array)*: The array to query. +2. `[n]` *(Number)*: The number of elements to return. #### Returns -*(Mixed)*: Returns the cloned `value`. +*(Array)*: Returns all but the last element or `n` elements of `array`. #### Example ```js -var stooges = [ - { 'name': 'moe', 'age': 40 }, - { 'name': 'larry', 'age': 50 }, - { 'name': 'curly', 'age': 60 } -]; - -_.clone({ 'name': 'moe' }); -// => { 'name': 'moe' } - -var shallow = _.clone(stooges); -shallow[0] === stooges[0]; -// => true - -var deep = _.clone(stooges, true); -shallow[0] === stooges[0]; -// => false +_.initial([3, 2, 1]); +// => [3, 2] ``` * * * @@ -348,21 +345,21 @@ shallow[0] === stooges[0]; -### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2409 "View in source") [Ⓣ][1] +### `_.intersection([array1, array2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2583 "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. +Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. #### Arguments -1. `array` *(Array)*: The array to compact. +1. `[array1, array2, ...]` *(Array)*: Arrays to process. #### Returns -*(Array)*: Returns a new filtered array. +*(Array)*: Returns a new array of unique elements, in order, that are present in **all** of the arrays. #### Example ```js -_.compact([0, 1, false, 2, '', 3]); -// => [1, 2, 3] +_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); +// => [1, 2] ``` * * * @@ -372,24 +369,22 @@ _.compact([0, 1, false, 2, '', 3]); -### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3201 "View in source") [Ⓣ][1] +### `_.last(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2622 "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()))`. +Gets the last element of the `array`. Pass `n` to return the last `n` elements of the `array`. #### Arguments -1. `[func1, func2, ...]` *(Function)*: Functions to compose. +1. `array` *(Array)*: The array to query. +2. `[n]` *(Number)*: The number of elements to return. #### Returns -*(Function)*: Returns the new composed function. +*(Mixed)*: Returns the last element or an array of the last `n` elements of `array`. #### Example ```js -var greet = function(name) { return 'hi: ' + name; }; -var exclaim = function(statement) { return statement + '!'; }; -var welcome = _.compose(exclaim, greet); -welcome('moe'); -// => 'hi: moe!' +_.last([3, 2, 1]); +// => 1 ``` * * * @@ -399,31 +394,26 @@ welcome('moe'); -### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1888 "View in source") [Ⓣ][1] - -Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. +### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2648 "View in source") [Ⓣ][1] -#### Aliases -*include* +Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `target` *(Mixed)*: The value to check for. +1. `array` *(Array)*: The array to search. +2. `value` *(Mixed)*: The value to search for. +3. `[fromIndex=array.length-1]` *(Number)*: The index to start searching from. #### Returns -*(Boolean)*: Returns `true` if the `target` element is found, else `false`. +*(Number)*: Returns the index of the matched value or `-1`. #### Example ```js -_.contains([1, 2, 3], 3); -// => true - -_.contains({ 'name': 'moe', 'age': 40 }, 'moe'); -// => true +_.lastIndexOf([1, 2, 3, 1, 2, 3], 2); +// => 4 -_.contains('curly', 'ur'); -// => true +_.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); +// => 1 ``` * * * @@ -433,29 +423,29 @@ _.contains('curly', 'ur'); -### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1924 "View in source") [Ⓣ][1] +### `_.max(array [, callback, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2685 "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')*. +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. `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. +1. `array` *(Array)*: The array to iterate over. +2. `[callback]` *(Function)*: The function called per iteration. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Object)*: Returns the composed aggregate object. +*(Mixed)*: Returns the maximum value. #### Example ```js -_.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); -// => { '4': 1, '6': 2 } - -_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); -// => { '4': 1, '6': 2 } +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; -_.countBy(['one', 'two', 'three'], 'length'); -// => { '3': 2, '5': 1 } +_.max(stooges, function(stooge) { return stooge.age; }); +// => { 'name': 'curly', 'age': 60 }; ``` * * * @@ -465,23 +455,23 @@ _.countBy(['one', 'two', 'three'], 'length'); -### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3234 "View in source") [Ⓣ][1] +### `_.min(array [, callback, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2720 "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. +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. `func` *(Function)*: The function to debounce. -2. `wait` *(Number)*: The number of milliseconds to delay. -3. `immediate` *(Boolean)*: A flag to indicate execution is on the leading edge of the timeout. +1. `array` *(Array)*: The array to iterate over. +2. `[callback]` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Function)*: Returns the new debounced function. +*(Mixed)*: Returns the minimum value. #### Example ```js -var lazyLayout = _.debounce(calculateLayout, 300); -jQuery(window).on('resize', lazyLayout); +_.min([10, 5, 100, 2, 1000]); +// => 2 ``` * * * @@ -491,23 +481,22 @@ jQuery(window).on('resize', lazyLayout); -### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1128 "View in source") [Ⓣ][1] +### `_.object(keys [, values=[]])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2754 "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. +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`. #### Arguments -1. `object` *(Object)*: The destination object. -2. `[default1, default2, ...]` *(Object)*: The default objects. +1. `keys` *(Array)*: The array of keys. +2. `[values=[]]` *(Array)*: The array of values. #### Returns -*(Object)*: Returns the destination object. +*(Object)*: Returns an object composed of the given keys and corresponding values. #### Example ```js -var iceCream = { 'flavor': 'chocolate' }; -_.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); -// => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' } +_.object(['moe', 'larry', 'curly'], [30, 40, 50]); +// => { 'moe': 30, 'larry': 40, 'curly': 50 } ``` * * * @@ -517,22 +506,35 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); -### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3299 "View in source") [Ⓣ][1] +### `_.range([start=0], end [, step=1])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2799 "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. +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. #### Arguments -1. `func` *(Function)*: The function to defer. -2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the function with. +1. `[start=0]` *(Number)*: The start of the range. +2. `end` *(Number)*: The end of the range. +3. `[step=1]` *(Number)*: The value to increment or descrement by. #### Returns -*(Number)*: Returns the `setTimeout` timeout id. +*(Array)*: Returns a new range array. #### Example ```js -_.defer(function() { alert('deferred'); }); -// returns from the function before `alert` is called +_.range(10); +// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + +_.range(1, 11); +// => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + +_.range(0, 30, 5); +// => [0, 5, 10, 15, 20, 25] + +_.range(0, -10, -1); +// => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] + +_.range(0); +// => [] ``` * * * @@ -542,24 +544,25 @@ _.defer(function() { alert('deferred'); }); -### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3279 "View in source") [Ⓣ][1] +### `_.rest(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2838 "View in source") [Ⓣ][1] -Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. +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. + +#### Aliases +*drop, tail* #### Arguments -1. `func` *(Function)*: The function to delay. -2. `wait` *(Number)*: The number of milliseconds to delay execution. -3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the function with. +1. `array` *(Array)*: The array to query. +2. `[n]` *(Number)*: The number of elements to return. #### Returns -*(Number)*: Returns the `setTimeout` timeout id. +*(Array)*: Returns all but the first value or `n` values of `array`. #### Example ```js -var log = _.bind(console.log, console); -_.delay(log, 1000, 'logged later'); -// => 'logged later' (Appears after one second.) +_.rest([3, 2, 1]); +// => [2, 1] ``` * * * @@ -569,22 +572,21 @@ _.delay(log, 1000, 'logged later'); -### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2438 "View in source") [Ⓣ][1] +### `_.shuffle(array)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2858 "View in source") [Ⓣ][1] -Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. +Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. #### Arguments -1. `array` *(Array)*: The array to process. -2. `[array1, array2, ...]` *(Array)*: Arrays to check. +1. `array` *(Array)*: The array to shuffle. #### Returns -*(Array)*: Returns a new array of `array` elements not present in the other arrays. +*(Array)*: Returns a new shuffled array. #### Example ```js -_.difference([1, 2, 3, 4, 5], [5, 2, 10]); -// => [1, 3, 4] +_.shuffle([1, 2, 3, 4, 5, 6]); +// => [4, 1, 6, 3, 5, 2] ``` * * * @@ -594,21 +596,41 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); -### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3519 "View in source") [Ⓣ][1] +### `_.sortedIndex(array, value [, callback=identity|property, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2911 "View in source") [Ⓣ][1] -Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. +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. `string` *(String)*: The string to escape. +1. `array` *(Array)*: The array to iterate over. +2. `value` *(Mixed)*: The value to evaluate. +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 -*(String)*: Returns the escaped string. +*(Number)*: Returns the index at which the value should be inserted into `array`. #### Example ```js -_.escape('Moe, Larry & Curly'); -// => "Moe, Larry & Curly" +_.sortedIndex([20, 30, 50], 40); +// => 2 + +_.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); +// => 2 + +var dict = { + 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } +}; + +_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { + return dict.wordToNumber[word]; +}); +// => 2 + +_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { + return this.wordToNumber[word]; +}, dict); +// => 2 ``` * * * @@ -618,26 +640,21 @@ _.escape('Moe, Larry & Curly'); -### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1945 "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)*. +### `_.union([array1, array2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2939 "View in source") [Ⓣ][1] -#### Aliases -*all* +Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. #### 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 of `callback`. +1. `[array1, array2, ...]` *(Array)*: Arrays to process. #### Returns -*(Boolean)*: Returns `true` if all elements pass the callback check, else `false`. +*(Array)*: Returns a new array of unique values, in order, that are present in one or more of the arrays. #### Example ```js -_.every([true, 1, null, 'yes'], Boolean); -// => false +_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); +// => [1, 2, 3, 101, 10] ``` * * * @@ -647,22 +664,36 @@ _.every([true, 1, null, 'yes'], Boolean); -### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1148 "View in source") [Ⓣ][1] +### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2984 "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. +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)*. + +#### Aliases +*unique* #### Arguments -1. `object` *(Object)*: The destination object. -2. `[source1, source2, ...]` *(Object)*: The source objects. +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 of `callback`. #### Returns -*(Object)*: Returns the destination object. +*(Array)*: Returns a duplicate-value-free array. #### Example ```js -_.extend({ 'name': 'moe' }, { 'age': 40 }); -// => { 'name': 'moe', 'age': 40 } +_.uniq([1, 2, 1, 3, 1]); +// => [1, 2, 3] + +_.uniq([1, 1, 2, 2, 3], true); +// => [1, 2, 3] + +_.uniq([1, 2, 1.5, 3, 2.5], function(num) { return Math.floor(num); }); +// => [1, 2, 3] + +_.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); +// => [1, 2, 3] ``` * * * @@ -672,26 +703,22 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); -### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1965 "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)*. +### `_.without(array [, value1, value2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3025 "View in source") [Ⓣ][1] -#### Aliases -*select* +Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. #### 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 of `callback`. +1. `array` *(Array)*: The array to filter. +2. `[value1, value2, ...]` *(Mixed)*: Values to remove. #### Returns -*(Array)*: Returns a new array of elements that passed the callback check. +*(Array)*: Returns a new filtered array. #### Example ```js -var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -// => [2, 4, 6] +_.without([1, 2, 1, 0, 3, 1, 4], 0, 1); +// => [2, 3, 4] ``` * * * @@ -701,26 +728,21 @@ 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#L1987 "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)*. +### `_.zip([array1, array2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3056 "View in source") [Ⓣ][1] -#### Aliases -*detect* +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. #### 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 of `callback`. +1. `[array1, array2, ...]` *(Array)*: Arrays to process. #### Returns -*(Mixed)*: Returns the element that passed the callback check, else `undefined`. +*(Array)*: Returns a new array of grouped elements. #### Example ```js -var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -// => 2 +_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); +// => [['moe', 30, true], ['larry', 40, false], ['curly', 50, false]] ``` * * * @@ -728,28 +750,25 @@ 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#L2476 "View in source") [Ⓣ][1] +## `“Chaining” Methods` -Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. + -#### Aliases -*head, take* +### `_(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L242 "View in source") [Ⓣ][1] + +The `lodash` function. #### Arguments -1. `array` *(Array)*: The array to query. -2. `[n]` *(Number)*: The number of elements to return. +1. `value` *(Mixed)*: The value to wrap in a `lodash` instance. #### Returns -*(Mixed)*: Returns the first element or an array of the first `n` elements of `array`. - -#### Example -```js -_.first([5, 4, 3, 2, 1]); -// => 5 -``` +*(Object)*: Returns a `lodash` instance. * * * @@ -758,25 +777,31 @@ _.first([5, 4, 3, 2, 1]); -### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2500 "View in source") [Ⓣ][1] +### `_.chain(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3905 "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. +Wraps the value in a `lodash` wrapper object. #### Arguments -1. `array` *(Array)*: The array to compact. -2. `shallow` *(Boolean)*: A flag to indicate only flattening a single level. +1. `value` *(Mixed)*: The value to wrap. #### Returns -*(Array)*: Returns a new flattened array. +*(Object)*: Returns the wrapper object. #### Example ```js -_.flatten([1, [2], [3, [[4]]]]); -// => [1, 2, 3, 4]; +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; -_.flatten([1, [2], [3, [[4]]]], true); -// => [1, 2, 3, [[4]]]; +var youngest = _.chain(stooges) + .sortBy(function(stooge) { return stooge.age; }) + .map(function(stooge) { return stooge.name + ' is ' + stooge.age; }) + .first() + .value(); +// => 'moe is 40' ``` * * * @@ -786,29 +811,27 @@ _.flatten([1, [2], [3, [[4]]]], true); -### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2014 "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`. +### `_.tap(value, interceptor)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3932 "View in source") [Ⓣ][1] -#### Aliases -*each* +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. #### 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 of `callback`. +1. `value` *(Mixed)*: The value to pass to `interceptor`. +2. `interceptor` *(Function)*: The function to invoke. #### Returns -*(Array, Object, String)*: Returns `collection`. +*(Mixed)*: Returns `value`. #### Example ```js -_([1, 2, 3]).forEach(alert).join(','); -// => alerts each number and returns '1,2,3' - -_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); -// => alerts each number (order is not guaranteed) +_.chain([1, 2, 3, 200]) + .filter(function(num) { return num % 2 == 0; }) + .tap(alert) + .map(function(num) { return num * num }) + .value(); +// => // [2, 200] (alerted) +// => [4, 40000] ``` * * * @@ -818,33 +841,18 @@ _.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] - -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`. +### `_.prototype.chain()` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3950 "View in source") [Ⓣ][1] -#### Arguments -1. `object` *(Object)*: The object to iterate over. -2. `callback` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +Enables method chaining on the wrapper object. #### Returns -*(Object)*: Returns `object`. +*(Mixed)*: Returns the wrapper object. #### Example ```js -function Dog(name) { - this.name = name; -} - -Dog.prototype.bark = function() { - alert('Woof, woof!'); -}; - -_.forIn(new Dog('Dagny'), function(value, key) { - alert(key); -}); -// => alerts 'name' and 'bark' (order is not guaranteed) +_([1, 2, 3]).value(); +// => [1, 2, 3] ``` * * * @@ -854,25 +862,18 @@ _.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] - -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`. +### `_.prototype.value()` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3967 "View in source") [Ⓣ][1] -#### Arguments -1. `object` *(Object)*: The object to iterate over. -2. `callback` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +Extracts the wrapped value. #### Returns -*(Object)*: Returns `object`. +*(Mixed)*: Returns the wrapped value. #### Example ```js -_.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { - alert(key); -}); -// => alerts '0', '1', and 'length' (order is not guaranteed) +_([1, 2, 3]).value(); +// => [1, 2, 3] ``` * * * @@ -880,26 +881,40 @@ _.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] +## `“Collections” Methods` -Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. + + +### `_.contains(collection, target)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1873 "View in source") [Ⓣ][1] + +Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. #### Aliases -*methods* +*include* #### Arguments -1. `object` *(Object)*: The object to inspect. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `target` *(Mixed)*: The value to check for. #### Returns -*(Array)*: Returns a new array of property names that have function values. +*(Boolean)*: Returns `true` if the `target` element is found, else `false`. #### Example ```js -_.functions(_); -// => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...] +_.contains([1, 2, 3], 3); +// => true + +_.contains({ 'name': 'moe', 'age': 40 }, 'moe'); +// => true + +_.contains('curly', 'ur'); +// => true ``` * * * @@ -909,14 +924,14 @@ _.functions(_); -### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2042 "View in source") [Ⓣ][1] +### `_.countBy(collection, callback|property [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1909 "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')*. +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 group by. +2. `callback|property` *(Function|String)*: The function called per iteration or property name to count by. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -924,14 +939,14 @@ Creates an object composed of keys returned from running each element of `collec #### Example ```js -_.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); }); -// => { '4': [4.2], '6': [6.1, 6.4] } +_.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); +// => { '4': 1, '6': 2 } -_.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); -// => { '4': [4.2], '6': [6.1, 6.4] } +_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); +// => { '4': 1, '6': 2 } -_.groupBy(['one', 'two', 'three'], 'length'); -// => { '3': ['one', 'two'], '5': ['three'] } +_.countBy(['one', 'two', 'three'], 'length'); +// => { '3': 2, '5': 1 } ``` * * * @@ -941,22 +956,26 @@ _.groupBy(['one', 'two', 'three'], 'length'); -### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1242 "View in source") [Ⓣ][1] +### `_.every(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1930 "View in source") [Ⓣ][1] -Checks if the specified object `property` exists and is a direct property, instead of an inherited property. +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)*. + +#### Aliases +*all* #### Arguments -1. `object` *(Object)*: The object to check. -2. `property` *(String)*: The property to check for. +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 of `callback`. #### Returns -*(Boolean)*: Returns `true` if key is a direct property, else `false`. +*(Boolean)*: Returns `true` if all elements pass the callback check, else `false`. #### Example ```js -_.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); -// => true +_.every([true, 1, null, 'yes'], Boolean); +// => false ``` * * * @@ -966,22 +985,26 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); -### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3539 "View in source") [Ⓣ][1] +### `_.filter(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1950 "View in source") [Ⓣ][1] -This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. +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)*. + +#### Aliases +*select* #### Arguments -1. `value` *(Mixed)*: Any value. +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 of `callback`. #### Returns -*(Mixed)*: Returns `value`. +*(Array)*: Returns a new array of elements that passed the callback check. #### Example ```js -var moe = { 'name': 'moe' }; -moe === _.identity(moe); -// => true +var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +// => [2, 4, 6] ``` * * * @@ -991,28 +1014,25 @@ moe === _.identity(moe); -### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2542 "View in source") [Ⓣ][1] +### `_.find(collection, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1972 "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. +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)*. + +#### Aliases +*detect* #### Arguments -1. `array` *(Array)*: The array to search. -2. `value` *(Mixed)*: The value to search for. -3. `[fromIndex=0]` *(Boolean|Number)*: The index to start searching from or `true` to perform a binary search on a sorted `array`. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `callback` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Number)*: Returns the index of the matched value or `-1`. +*(Mixed)*: Returns the element that passed the callback check, else `undefined`. #### Example ```js -_.indexOf([1, 2, 3, 1, 2, 3], 2); -// => 1 - -_.indexOf([1, 2, 3, 1, 2, 3], 2, 3); -// => 4 - -_.indexOf([1, 1, 2, 2, 3, 3], 2, true); +var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); // => 2 ``` @@ -1023,22 +1043,29 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); -### `_.initial(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2577 "View in source") [Ⓣ][1] +### `_.forEach(collection, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1999 "View in source") [Ⓣ][1] -Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. +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`. + +#### Aliases +*each* #### Arguments -1. `array` *(Array)*: The array to query. -2. `[n]` *(Number)*: The number of elements to return. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `callback` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Array)*: Returns all but the last element or `n` elements of `array`. +*(Array, Object, String)*: Returns `collection`. #### Example ```js -_.initial([3, 2, 1]); -// => [3, 2] +_([1, 2, 3]).forEach(alert).join(','); +// => alerts each number and returns '1,2,3' + +_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); +// => alerts each number (order is not guaranteed) ``` * * * @@ -1048,21 +1075,29 @@ _.initial([3, 2, 1]); -### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2598 "View in source") [Ⓣ][1] +### `_.groupBy(collection, callback|property [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2027 "View in source") [Ⓣ][1] -Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. +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. `[array1, array2, ...]` *(Array)*: Arrays to process. +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 of `callback`. #### Returns -*(Array)*: Returns a new array of unique elements, in order, that are present in **all** of the arrays. +*(Object)*: Returns the composed aggregate object. #### Example ```js -_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); -// => [1, 2] +_.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); }); +// => { '4': [4.2], '6': [6.1, 6.4] } + +_.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); +// => { '4': [4.2], '6': [6.1, 6.4] } + +_.groupBy(['one', 'two', 'three'], 'length'); +// => { '3': ['one', 'two'], '5': ['three'] } ``` * * * @@ -1072,21 +1107,26 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); -### `_.invert(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L810 "View in source") [Ⓣ][1] +### `_.invoke(collection, methodName [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2055 "View in source") [Ⓣ][1] -Creates an object composed of the inverted keys and values of the given `object`. +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`. #### Arguments -1. `object` *(Object)*: The object to invert. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `methodName` *(Function|String)*: The name of the method to invoke or the function invoked per iteration. +3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the method with. #### Returns -*(Object)*: Returns the created inverted object. +*(Array)*: Returns a new array of the results of each invoked method. #### Example ```js -_.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); -// => { 'Moe': 'first', 'Larry': 'second', 'Curly': 'third' } (order is not guaranteed) +_.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); +// => [[1, 5, 7], [1, 2, 3]] + +_.invoke([123, 456], String.prototype.split, ''); +// => [['1', '2', '3'], ['4', '5', '6']] ``` * * * @@ -1096,26 +1136,29 @@ _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); -### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2070 "View in source") [Ⓣ][1] +### `_.map(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2090 "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`. +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)*. + +#### Aliases +*collect* #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `methodName` *(Function|String)*: The name of the method to invoke or the function invoked per iteration. -3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the method with. +2. `[callback=identity]` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Array)*: Returns a new array of the results of each invoked method. +*(Array)*: Returns a new array of the results of each `callback` execution. #### Example ```js -_.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); -// => [[1, 5, 7], [1, 2, 3]] +_.map([1, 2, 3], function(num) { return num * 3; }); +// => [3, 6, 9] -_.invoke([123, 456], String.prototype.split, ''); -// => [['1', '2', '3'], ['4', '5', '6']] +_.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); +// => [3, 6, 9] (order is not guaranteed) ``` * * * @@ -1125,24 +1168,28 @@ _.invoke([123, 456], String.prototype.split, ''); -### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L832 "View in source") [Ⓣ][1] +### `_.pluck(collection, property)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2113 "View in source") [Ⓣ][1] -Checks if `value` is an `arguments` object. +Retrieves the value of a specified property from all elements in the `collection`. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `property` *(String)*: The property to pluck. #### Returns -*(Boolean)*: Returns `true` if the `value` is an `arguments` object, else `false`. +*(Array)*: Returns a new array of property values. #### Example ```js -(function() { return _.isArguments(arguments); })(1, 2, 3); -// => true +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; -_.isArguments([1, 2, 3]); -// => false +_.pluck(stooges, 'name'); +// => ['moe', 'larry', 'curly'] ``` * * * @@ -1152,24 +1199,27 @@ _.isArguments([1, 2, 3]); -### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L858 "View in source") [Ⓣ][1] +### `_.reduce(collection, callback [, accumulator, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2141 "View in source") [Ⓣ][1] -Checks if `value` is an array. +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)*. + +#### Aliases +*foldl, inject* #### Arguments -1. `value` *(Mixed)*: The value to check. +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 of `callback`. #### Returns -*(Boolean)*: Returns `true` if the `value` is an array, else `false`. +*(Mixed)*: Returns the accumulated value. #### Example ```js -(function() { return _.isArray(arguments); })(); -// => false - -_.isArray([1, 2, 3]); -// => true +var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); +// => 6 ``` * * * @@ -1179,21 +1229,28 @@ _.isArray([1, 2, 3]); -### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1259 "View in source") [Ⓣ][1] +### `_.reduceRight(collection, callback [, accumulator, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2178 "View in source") [Ⓣ][1] -Checks if `value` is a boolean *(`true` or `false`)* value. +The right-associative version of `_.reduce`. + +#### Aliases +*foldr* #### Arguments -1. `value` *(Mixed)*: The value to check. +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 of `callback`. #### Returns -*(Boolean)*: Returns `true` if the `value` is a boolean value, else `false`. +*(Mixed)*: Returns the accumulated value. #### Example ```js -_.isBoolean(null); -// => false +var list = [[0, 1], [2, 3], [4, 5]]; +var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); +// => [4, 5, 2, 3, 0, 1] ``` * * * @@ -1203,21 +1260,23 @@ _.isBoolean(null); -### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1276 "View in source") [Ⓣ][1] +### `_.reject(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2215 "View in source") [Ⓣ][1] -Checks if `value` is a date. +The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. #### Arguments -1. `value` *(Mixed)*: The value to check. +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 of `callback`. #### Returns -*(Boolean)*: Returns `true` if the `value` is a date, else `false`. +*(Array)*: Returns a new array of elements that did **not** pass the callback check. #### Example ```js -_.isDate(new Date); -// => true +var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +// => [1, 3, 5] ``` * * * @@ -1227,21 +1286,27 @@ _.isDate(new Date); -### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1293 "View in source") [Ⓣ][1] +### `_.size(collection)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2239 "View in source") [Ⓣ][1] -Checks if `value` is a DOM element. +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. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `collection` *(Array|Object|String)*: The collection to inspect. #### Returns -*(Boolean)*: Returns `true` if the `value` is a DOM element, else `false`. +*(Number)*: Returns `collection.length` or number of own enumerable properties. + +#### Example +```js +_.size([1, 2]); +// => 2 + +_.size({ 'one': 1, 'two': 2, 'three': 3 }); +// => 3 -#### Example -```js -_.isElement(document.body); -// => true +_.size('curly'); +// => 5 ``` * * * @@ -1251,26 +1316,25 @@ _.isElement(document.body); -### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1318 "View in source") [Ⓣ][1] +### `_.some(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2264 "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". +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)*. + +#### Aliases +*any* #### Arguments -1. `value` *(Array|Object|String)*: The value to inspect. +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 of `callback`. #### Returns -*(Boolean)*: Returns `true` if the `value` is empty, else `false`. +*(Boolean)*: Returns `true` if any element passes the callback check, else `false`. #### Example ```js -_.isEmpty([1, 2, 3]); -// => false - -_.isEmpty({}); -// => true - -_.isEmpty(''); +_.some([null, 0, 'yes', false]); // => true ``` @@ -1281,28 +1345,29 @@ _.isEmpty(''); -### `_.isEqual(a, b)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1357 "View in source") [Ⓣ][1] +### `_.sortBy(collection, callback|property [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2294 "View in source") [Ⓣ][1] -Performs a deep comparison between two values to determine if they are equivalent to each other. +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. `a` *(Mixed)*: The value to compare. -2. `b` *(Mixed)*: The other value to compare. +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 of `callback`. #### Returns -*(Boolean)*: Returns `true` if the values are equvalent, else `false`. +*(Array)*: Returns a new array of sorted elements. #### Example ```js -var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; -var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; +_.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); +// => [3, 1, 2] -moe == clone; -// => false +_.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); +// => [3, 1, 2] -_.isEqual(moe, clone); -// => true +_.sortBy(['larry', 'brendan', 'moe'], 'length'); +// => ['moe', 'larry', 'brendan'] ``` * * * @@ -1312,27 +1377,21 @@ _.isEqual(moe, clone); -### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1514 "View in source") [Ⓣ][1] +### `_.toArray(collection)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2330 "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. +Converts the `collection`, to an array. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `collection` *(Array|Object|String)*: The collection to convert. #### Returns -*(Boolean)*: Returns `true` if the `value` is a finite number, else `false`. +*(Array)*: Returns the new converted array. #### Example ```js -_.isFinite(-101); -// => true - -_.isFinite('10'); -// => false - -_.isFinite(Infinity); -// => false +(function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); +// => [2, 3, 4] ``` * * * @@ -1342,21 +1401,28 @@ _.isFinite(Infinity); -### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L875 "View in source") [Ⓣ][1] +### `_.where(collection, properties)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2364 "View in source") [Ⓣ][1] -Checks if `value` is a function. +Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `properties` *(Object)*: The object of properties/values to filter by. #### Returns -*(Boolean)*: Returns `true` if the `value` is a function, else `false`. +*(Array)*: Returns a new array of elements that contain the given `properties`. #### Example ```js -_.isFunction(_); -// => true +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; + +_.where(stooges, { 'age': 40 }); +// => [{ 'name': 'moe', 'age': 40 }] ``` * * * @@ -1364,32 +1430,34 @@ _.isFunction(_); + + + -### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1572 "View in source") [Ⓣ][1] +## `“Functions” Methods` -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. + + +### `_.after(n, func)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3088 "View in source") [Ⓣ][1] + +Creates a function that is restricted to executing only after it is called `n` times. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `n` *(Number)*: The number of times the function must be called before it is executed. +2. `func` *(Function)*: The function to restrict. #### Returns -*(Boolean)*: Returns `true` if the `value` is `NaN`, else `false`. +*(Function)*: Returns the new restricted function. #### Example ```js -_.isNaN(NaN); -// => true - -_.isNaN(new Number(NaN)); -// => true - -isNaN(undefined); -// => true - -_.isNaN(undefined); -// => false +var renderNotes = _.after(notes.length, render); +_.forEach(notes, function(note) { + note.asyncSave({ 'success': renderNotes }); +}); +// `renderNotes` is run once, after all notes have saved ``` * * * @@ -1399,24 +1467,28 @@ _.isNaN(undefined); -### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1595 "View in source") [Ⓣ][1] +### `_.bind(func [, thisArg, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3121 "View in source") [Ⓣ][1] -Checks if `value` is `null`. +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. #### Arguments -1. `value` *(Mixed)*: The value to check. +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 -*(Boolean)*: Returns `true` if the `value` is `null`, else `false`. +*(Function)*: Returns the new bound function. #### Example ```js -_.isNull(null); -// => true +var func = function(greeting) { + return greeting + ' ' + this.name; +}; -_.isNull(undefined); -// => false +func = _.bind(func, { 'name': 'moe' }, 'hi'); +func(); +// => 'hi moe' ``` * * * @@ -1426,21 +1498,28 @@ _.isNull(undefined); -### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1612 "View in source") [Ⓣ][1] +### `_.bindAll(object [, methodName1, methodName2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3151 "View in source") [Ⓣ][1] -Checks if `value` is a number. +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. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `object` *(Object)*: The object to bind and assign the bound methods to. +2. `[methodName1, methodName2, ...]` *(String)*: Method names on the object to bind. #### Returns -*(Boolean)*: Returns `true` if the `value` is a number, else `false`. +*(Object)*: Returns `object`. #### Example ```js -_.isNumber(8.4 * 5); -// => true +var buttonView = { + 'label': 'lodash', + 'onClick': function() { alert('clicked: ' + this.label); } +}; + +_.bindAll(buttonView); +jQuery('#lodash_button').on('click', buttonView.onClick); +// => When the button is clicked, `this.label` will have the correct value ``` * * * @@ -1450,27 +1529,24 @@ _.isNumber(8.4 * 5); -### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1538 "View in source") [Ⓣ][1] +### `_.compose([func1, func2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3186 "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('')`)* +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()))`. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `[func1, func2, ...]` *(Function)*: Functions to compose. #### Returns -*(Boolean)*: Returns `true` if the `value` is an object, else `false`. +*(Function)*: Returns the new composed function. #### Example ```js -_.isObject({}); -// => true - -_.isObject([1, 2, 3]); -// => true - -_.isObject(1); -// => false +var greet = function(name) { return 'hi: ' + name; }; +var exclaim = function(statement) { return statement + '!'; }; +var welcome = _.compose(exclaim, greet); +welcome('moe'); +// => 'hi: moe!' ``` * * * @@ -1480,32 +1556,23 @@ _.isObject(1); -### `_.isPlainObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L909 "View in source") [Ⓣ][1] +### `_.debounce(func, wait, immediate)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3219 "View in source") [Ⓣ][1] -Checks if a given `value` is an object created by the `Object` constructor. +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. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `func` *(Function)*: The function to debounce. +2. `wait` *(Number)*: The number of milliseconds to delay. +3. `immediate` *(Boolean)*: A flag to indicate execution is on the leading edge of the timeout. #### Returns -*(Boolean)*: Returns `true` if `value` is a plain object, else `false`. +*(Function)*: Returns the new debounced function. #### 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 +var lazyLayout = _.debounce(calculateLayout, 300); +jQuery(window).on('resize', lazyLayout); ``` * * * @@ -1515,21 +1582,22 @@ _.isPlainObject({ 'name': 'moe', 'age': 40 }); -### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1629 "View in source") [Ⓣ][1] +### `_.defer(func [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3284 "View in source") [Ⓣ][1] -Checks if `value` is a regular expression. +Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `func` *(Function)*: The function to defer. +2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the function with. #### Returns -*(Boolean)*: Returns `true` if the `value` is a regular expression, else `false`. +*(Number)*: Returns the `setTimeout` timeout id. #### Example ```js -_.isRegExp(/moe/); -// => true +_.defer(function() { alert('deferred'); }); +// returns from the function before `alert` is called ``` * * * @@ -1539,21 +1607,24 @@ _.isRegExp(/moe/); -### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1646 "View in source") [Ⓣ][1] +### `_.delay(func, wait [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3264 "View in source") [Ⓣ][1] -Checks if `value` is a string. +Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `func` *(Function)*: The function to delay. +2. `wait` *(Number)*: The number of milliseconds to delay execution. +3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the function with. #### Returns -*(Boolean)*: Returns `true` if the `value` is a string, else `false`. +*(Number)*: Returns the `setTimeout` timeout id. #### Example ```js -_.isString('moe'); -// => true +var log = _.bind(console.log, console); +_.delay(log, 1000, 'logged later'); +// => 'logged later' (Appears after one second.) ``` * * * @@ -1563,21 +1634,38 @@ _.isString('moe'); -### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1664 "View in source") [Ⓣ][1] +### `_.lateBind(object, methodName [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3322 "View in source") [Ⓣ][1] -Checks if `value` is `undefined`. +Creates a function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. #### Arguments -1. `value` *(Mixed)*: The value to check. +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 -*(Boolean)*: Returns `true` if the `value` is `undefined`, else `false`. +*(Function)*: Returns the new bound function. + +#### Example +```js +var object = { + 'name': 'moe', + 'greet': function(greeting) { + return greeting + ' ' + this.name; + } +}; + +var func = _.lateBind(object, 'greet', 'hi'); +func(); +// => 'hi moe' + +object.greet = function(greeting) { + return greeting + ', ' + this.name + '!'; +}; -#### Example -```js -_.isUndefined(void 0); -// => true +func(); +// => 'hi, moe!' ``` * * * @@ -1587,21 +1675,23 @@ _.isUndefined(void 0); -### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1681 "View in source") [Ⓣ][1] +### `_.memoize(func [, resolver])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3344 "View in source") [Ⓣ][1] -Creates an array composed of the own enumerable property names of `object`. +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. #### Arguments -1. `object` *(Object)*: The object to inspect. +1. `func` *(Function)*: The function to have its output memoized. +2. `[resolver]` *(Function)*: A function used to resolve the cache key. #### Returns -*(Array)*: Returns a new array of property names. +*(Function)*: Returns the new memoizing function. #### Example ```js -_.keys({ 'one': 1, 'two': 2, 'three': 3 }); -// => ['one', 'two', 'three'] (order is not guaranteed) +var fibonacci = _.memoize(function(n) { + return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); +}); ``` * * * @@ -1611,22 +1701,23 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); -### `_.last(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2637 "View in source") [Ⓣ][1] +### `_.once(func)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3370 "View in source") [Ⓣ][1] -Gets the last element of the `array`. Pass `n` to return the last `n` elements of the `array`. +Creates a function that is restricted to one execution. Repeat calls to the function will return the value of the first call. #### Arguments -1. `array` *(Array)*: The array to query. -2. `[n]` *(Number)*: The number of elements to return. +1. `func` *(Function)*: The function to restrict. #### Returns -*(Mixed)*: Returns the last element or an array of the last `n` elements of `array`. +*(Function)*: Returns the new restricted function. #### Example ```js -_.last([3, 2, 1]); -// => 1 +var initialize = _.once(createApplication); +initialize(); +initialize(); +// Application is only created once. ``` * * * @@ -1636,26 +1727,24 @@ _.last([3, 2, 1]); -### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2663 "View in source") [Ⓣ][1] +### `_.partial(func [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3405 "View in source") [Ⓣ][1] -Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. +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. #### Arguments -1. `array` *(Array)*: The array to search. -2. `value` *(Mixed)*: The value to search for. -3. `[fromIndex=array.length-1]` *(Number)*: The index to start searching from. +1. `func` *(Function)*: The function to partially apply arguments to. +2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. #### Returns -*(Number)*: Returns the index of the matched value or `-1`. +*(Function)*: Returns the new partially applied function. #### Example ```js -_.lastIndexOf([1, 2, 3, 1, 2, 3], 2); -// => 4 - -_.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); -// => 1 +var greet = function(greeting, name) { return greeting + ': ' + name; }; +var hi = _.partial(greet, 'hi'); +hi('moe'); +// => 'hi: moe' ``` * * * @@ -1665,38 +1754,22 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); -### `_.lateBind(object, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3337 "View in source") [Ⓣ][1] +### `_.throttle(func, wait)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3427 "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 differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. +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. #### 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. +1. `func` *(Function)*: The function to throttle. +2. `wait` *(Number)*: The number of milliseconds to throttle executions to. #### Returns -*(Function)*: Returns the new bound function. +*(Function)*: Returns the new throttled function. #### Example ```js -var object = { - 'name': 'moe', - 'greet': function(greeting) { - return greeting + ' ' + this.name; - } -}; - -var func = _.lateBind(object, 'greet', 'hi'); -func(); -// => 'hi moe' - -object.greet = function(greeting) { - return greeting + ', ' + this.name + '!'; -}; - -func(); -// => 'hi, moe!' +var throttled = _.throttle(updatePosition, 100); +jQuery(window).on('scroll', throttled); ``` * * * @@ -1706,29 +1779,26 @@ func(); -### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2105 "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)*. +### `_.wrap(value, wrapper)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3478 "View in source") [Ⓣ][1] -#### Aliases -*collect* +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. #### 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 of `callback`. +1. `value` *(Mixed)*: The value to wrap. +2. `wrapper` *(Function)*: The wrapper function. #### Returns -*(Array)*: Returns a new array of the results of each `callback` execution. +*(Function)*: Returns the new function. #### Example ```js -_.map([1, 2, 3], function(num) { return num * 3; }); -// => [3, 6, 9] - -_.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); -// => [3, 6, 9] (order is not guaranteed) +var hello = function(name) { return 'hello: ' + name; }; +hello = _.wrap(hello, function(func) { + return 'before, ' + func('moe') + ', after'; +}); +hello(); +// => 'before, hello: moe, after' ``` * * * @@ -1736,20 +1806,26 @@ _.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#L2700 "View in source") [Ⓣ][1] +## `“Objects” Methods` -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)*. + + +### `_.clone(value, deep)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1030 "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. `array` *(Array)*: The array to iterate over. -2. `[callback]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `value` *(Mixed)*: The value to clone. +2. `deep` *(Boolean)*: A flag to indicate a deep clone. #### Returns -*(Mixed)*: Returns the maximum value. +*(Mixed)*: Returns the cloned `value`. #### Example ```js @@ -1759,8 +1835,16 @@ var stooges = [ { 'name': 'curly', 'age': 60 } ]; -_.max(stooges, function(stooge) { return stooge.age; }); -// => { 'name': 'curly', 'age': 60 }; +_.clone({ 'name': 'moe' }); +// => { 'name': 'moe' } + +var shallow = _.clone(stooges); +shallow[0] === stooges[0]; +// => true + +var deep = _.clone(stooges, true); +shallow[0] === stooges[0]; +// => false ``` * * * @@ -1770,23 +1854,23 @@ _.max(stooges, function(stooge) { return stooge.age; }); -### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3359 "View in source") [Ⓣ][1] +### `_.defaults(object [, default1, default2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1113 "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. +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. #### Arguments -1. `func` *(Function)*: The function to have its output memoized. -2. `[resolver]` *(Function)*: A function used to resolve the cache key. +1. `object` *(Object)*: The destination object. +2. `[default1, default2, ...]` *(Object)*: The default objects. #### Returns -*(Function)*: Returns the new memoizing function. +*(Object)*: Returns the destination object. #### Example ```js -var fibonacci = _.memoize(function(n) { - return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); -}); +var iceCream = { 'flavor': 'chocolate' }; +_.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); +// => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' } ``` * * * @@ -1796,10 +1880,10 @@ var fibonacci = _.memoize(function(n) { -### `_.merge(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1724 "View in source") [Ⓣ][1] +### `_.extend(object [, source1, source2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1133 "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. +Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. #### Arguments 1. `object` *(Object)*: The destination object. @@ -1810,18 +1894,8 @@ Merges enumerable properties of the source object(s) into the `destination` obje #### Example ```js -var stooges = [ - { 'name': 'moe' }, - { 'name': 'larry' } -]; - -var ages = [ - { 'age': 40 }, - { 'age': 50 } -]; - -_.merge(stooges, ages); -// => [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }] +_.extend({ 'name': 'moe' }, { 'age': 40 }); +// => { 'name': 'moe', 'age': 40 } ``` * * * @@ -1831,23 +1905,33 @@ _.merge(stooges, ages); -### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2735 "View in source") [Ⓣ][1] +### `_.forIn(object, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1163 "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)*. +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. `array` *(Array)*: The array to iterate over. -2. `[callback]` *(Function)*: The function called per iteration. +1. `object` *(Object)*: The object to iterate over. +2. `callback` *(Function)*: The function called per iteration. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Mixed)*: Returns the minimum value. +*(Object)*: Returns `object`. #### Example ```js -_.min([10, 5, 100, 2, 1000]); -// => 2 +function Dog(name) { + this.name = name; +} + +Dog.prototype.bark = function() { + alert('Woof, woof!'); +}; + +_.forIn(new Dog('Dagny'), function(value, key) { + alert(key); +}); +// => alerts 'name' and 'bark' (order is not guaranteed) ``` * * * @@ -1857,27 +1941,25 @@ _.min([10, 5, 100, 2, 1000]); -### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3565 "View in source") [Ⓣ][1] +### `_.forOwn(object, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1187 "View in source") [Ⓣ][1] -Adds functions properties of `object` to the `lodash` function and chainable wrapper. +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 of function properties to add to `lodash`. +1. `object` *(Object)*: The object to iterate over. +2. `callback` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. + +#### Returns +*(Object)*: Returns `object`. #### Example ```js -_.mixin({ - 'capitalize': function(string) { - return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); - } +_.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { + alert(key); }); - -_.capitalize('larry'); -// => 'Larry' - -_('curly').capitalize(); -// => 'Curly' +// => alerts '0', '1', and 'length' (order is not guaranteed) ``` * * * @@ -1887,17 +1969,24 @@ _('curly').capitalize(); -### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3596 "View in source") [Ⓣ][1] +### `_.functions(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1204 "View in source") [Ⓣ][1] -Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. +Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. + +#### Aliases +*methods* + +#### Arguments +1. `object` *(Object)*: The object to inspect. #### Returns -*(Function)*: Returns the `lodash` function. +*(Array)*: Returns a new array of property names that have function values. #### Example ```js -var lodash = _.noConflict(); +_.functions(_); +// => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...] ``` * * * @@ -1907,22 +1996,22 @@ var lodash = _.noConflict(); -### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2769 "View in source") [Ⓣ][1] +### `_.has(object, property)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1227 "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`. +Checks if the specified object `property` exists and is a direct property, instead of an inherited property. #### Arguments -1. `keys` *(Array)*: The array of keys. -2. `[values=[]]` *(Array)*: The array of values. +1. `object` *(Object)*: The object to check. +2. `property` *(String)*: The property to check for. #### Returns -*(Object)*: Returns an object composed of the given keys and corresponding values. +*(Boolean)*: Returns `true` if key is a direct property, else `false`. #### Example ```js -_.object(['moe', 'larry', 'curly'], [30, 40, 50]); -// => { 'moe': 30, 'larry': 40, 'curly': 50 } +_.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); +// => true ``` * * * @@ -1932,28 +2021,21 @@ _.object(['moe', 'larry', 'curly'], [30, 40, 50]); -### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1781 "View in source") [Ⓣ][1] +### `_.invert(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L805 "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)*. +Creates an object composed of the inverted keys and values of the given `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 of `callback`. +1. `object` *(Object)*: The object to invert. #### Returns -*(Object)*: Returns an object without the omitted properties. +*(Object)*: Returns the created inverted object. #### Example ```js -_.omit({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); -// => { 'name': 'moe', 'age': 40 } - -_.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(value, key) { - return key.charAt(0) == '_'; -}); -// => { 'name': 'moe' } +_.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); +// => { 'Moe': 'first', 'Larry': 'second', 'Curly': 'third' } (order is not guaranteed) ``` * * * @@ -1963,23 +2045,24 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va -### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3385 "View in source") [Ⓣ][1] +### `_.isArguments(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L827 "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. +Checks if `value` is an `arguments` object. #### Arguments -1. `func` *(Function)*: The function to restrict. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Function)*: Returns the new restricted function. +*(Boolean)*: Returns `true` if the `value` is an `arguments` object, else `false`. #### Example ```js -var initialize = _.once(createApplication); -initialize(); -initialize(); -// Application is only created once. +(function() { return _.isArguments(arguments); })(1, 2, 3); +// => true + +_.isArguments([1, 2, 3]); +// => false ``` * * * @@ -1989,21 +2072,24 @@ initialize(); -### `_.pairs(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1797 "View in source") [Ⓣ][1] +### `_.isArray(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L853 "View in source") [Ⓣ][1] -Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. +Checks if `value` is an array. #### Arguments -1. `object` *(Object)*: The object to inspect. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns new array of key-value pairs. +*(Boolean)*: Returns `true` if the `value` is an array, else `false`. #### Example ```js -_.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); -// => [['moe', 30], ['larry', 40], ['curly', 50]] (order is not guaranteed) +(function() { return _.isArray(arguments); })(); +// => false + +_.isArray([1, 2, 3]); +// => true ``` * * * @@ -2013,24 +2099,21 @@ _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); -### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3420 "View in source") [Ⓣ][1] +### `_.isBoolean(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1244 "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. +Checks if `value` is a boolean *(`true` or `false`)* value. #### Arguments -1. `func` *(Function)*: The function to partially apply arguments to. -2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Function)*: Returns the new partially applied function. +*(Boolean)*: Returns `true` if the `value` is a boolean value, else `false`. #### Example ```js -var greet = function(greeting, name) { return greeting + ': ' + name; }; -var hi = _.partial(greet, 'hi'); -hi('moe'); -// => 'hi: moe' +_.isBoolean(null); +// => false ``` * * * @@ -2040,28 +2123,21 @@ hi('moe'); -### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1828 "View in source") [Ⓣ][1] +### `_.isDate(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1261 "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)*. +Checks if `value` is a date. #### 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 of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Object)*: Returns an object composed of the picked properties. +*(Boolean)*: Returns `true` if the `value` is a date, else `false`. #### Example ```js -_.pick({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'name', 'age'); -// => { 'name': 'moe', 'age': 40 } - -_.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(value, key) { - return key.charAt(0) != '_'; -}); -// => { 'name': 'moe' } +_.isDate(new Date); +// => true ``` * * * @@ -2071,28 +2147,21 @@ _.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va -### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2128 "View in source") [Ⓣ][1] +### `_.isElement(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1278 "View in source") [Ⓣ][1] -Retrieves the value of a specified property from all elements in the `collection`. +Checks if `value` is a DOM element. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `property` *(String)*: The property to pluck. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns a new array of property values. +*(Boolean)*: Returns `true` if the `value` is a DOM element, else `false`. #### Example ```js -var stooges = [ - { 'name': 'moe', 'age': 40 }, - { 'name': 'larry', 'age': 50 }, - { 'name': 'curly', 'age': 60 } -]; - -_.pluck(stooges, 'name'); -// => ['moe', 'larry', 'curly'] +_.isElement(document.body); +// => true ``` * * * @@ -2102,25 +2171,27 @@ _.pluck(stooges, 'name'); -### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3619 "View in source") [Ⓣ][1] +### `_.isEmpty(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1303 "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. +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". #### Arguments -1. `[min=0]` *(Number)*: The minimum possible value. -2. `[max=1]` *(Number)*: The maximum possible value. +1. `value` *(Array|Object|String)*: The value to inspect. #### Returns -*(Number)*: Returns a random number. +*(Boolean)*: Returns `true` if the `value` is empty, else `false`. #### Example ```js -_.random(0, 5); -// => a number between 1 and 5 +_.isEmpty([1, 2, 3]); +// => false -_.random(5); -// => also a number between 1 and 5 +_.isEmpty({}); +// => true + +_.isEmpty(''); +// => true ``` * * * @@ -2130,35 +2201,28 @@ _.random(5); -### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2813 "View in source") [Ⓣ][1] +### `_.isEqual(a, b)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1342 "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. +Performs a deep comparison between two values to determine if they are equivalent to each other. #### Arguments -1. `[start=0]` *(Number)*: The start of the range. -2. `end` *(Number)*: The end of the range. -3. `[step=1]` *(Number)*: The value to increment or descrement by. +1. `a` *(Mixed)*: The value to compare. +2. `b` *(Mixed)*: The other value to compare. #### Returns -*(Array)*: Returns a new range array. +*(Boolean)*: Returns `true` if the values are equvalent, else `false`. #### Example ```js -_.range(10); -// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - -_.range(1, 11); -// => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - -_.range(0, 30, 5); -// => [0, 5, 10, 15, 20, 25] +var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; +var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; -_.range(0, -10, -1); -// => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] +moe == clone; +// => false -_.range(0); -// => [] +_.isEqual(moe, clone); +// => true ``` * * * @@ -2168,27 +2232,27 @@ _.range(0); -### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2156 "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)*. +### `_.isFinite(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1499 "View in source") [Ⓣ][1] -#### Aliases -*foldl, inject* +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. #### Arguments -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 of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Mixed)*: Returns the accumulated value. +*(Boolean)*: Returns `true` if the `value` is a finite number, else `false`. #### Example ```js -var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); -// => 6 +_.isFinite(-101); +// => true + +_.isFinite('10'); +// => false + +_.isFinite(Infinity); +// => false ``` * * * @@ -2198,28 +2262,21 @@ 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#L2193 "View in source") [Ⓣ][1] - -The right-associative version of `_.reduce`. +### `_.isFunction(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L870 "View in source") [Ⓣ][1] -#### Aliases -*foldr* +Checks if `value` is a function. #### Arguments -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 of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Mixed)*: Returns the accumulated value. +*(Boolean)*: Returns `true` if the `value` is a function, else `false`. #### Example ```js -var list = [[0, 1], [2, 3], [4, 5]]; -var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); -// => [4, 5, 2, 3, 0, 1] +_.isFunction(_); +// => true ``` * * * @@ -2229,23 +2286,30 @@ 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#L2230 "View in source") [Ⓣ][1] +### `_.isNaN(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1557 "View in source") [Ⓣ][1] -The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. +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. #### 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 of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns a new array of elements that did **not** pass the callback check. +*(Boolean)*: Returns `true` if the `value` is `NaN`, else `false`. #### Example ```js -var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -// => [1, 3, 5] +_.isNaN(NaN); +// => true + +_.isNaN(new Number(NaN)); +// => true + +isNaN(undefined); +// => true + +_.isNaN(undefined); +// => false ``` * * * @@ -2255,25 +2319,24 @@ 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#L2852 "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. +### `_.isNull(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1580 "View in source") [Ⓣ][1] -#### Aliases -*drop, tail* +Checks if `value` is `null`. #### Arguments -1. `array` *(Array)*: The array to query. -2. `[n]` *(Number)*: The number of elements to return. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns all but the first value or `n` values of `array`. +*(Boolean)*: Returns `true` if the `value` is `null`, else `false`. #### Example ```js -_.rest([3, 2, 1]); -// => [2, 1] +_.isNull(null); +// => true + +_.isNull(undefined); +// => false ``` * * * @@ -2283,32 +2346,21 @@ _.rest([3, 2, 1]); -### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3658 "View in source") [Ⓣ][1] +### `_.isNumber(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1597 "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. +Checks if `value` is a number. #### Arguments -1. `object` *(Object)*: The object to inspect. -2. `property` *(String)*: The property to get the value of. - -#### Returns -*(Mixed)*: Returns the resolved value. - -#### Example -```js -var object = { - 'cheese': 'crumpets', - 'stuff': function() { - return 'nonsense'; - } -}; - -_.result(object, 'cheese'); -// => 'crumpets' +1. `value` *(Mixed)*: The value to check. -_.result(object, 'stuff'); -// => 'nonsense' +#### Returns +*(Boolean)*: Returns `true` if the `value` is a number, else `false`. + +#### Example +```js +_.isNumber(8.4 * 5); +// => true ``` * * * @@ -2318,21 +2370,27 @@ _.result(object, 'stuff'); -### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2872 "View in source") [Ⓣ][1] +### `_.isObject(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1523 "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. +Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* #### Arguments -1. `array` *(Array)*: The array to shuffle. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns a new shuffled array. +*(Boolean)*: Returns `true` if the `value` is an object, else `false`. #### Example ```js -_.shuffle([1, 2, 3, 4, 5, 6]); -// => [4, 1, 6, 3, 5, 2] +_.isObject({}); +// => true + +_.isObject([1, 2, 3]); +// => true + +_.isObject(1); +// => false ``` * * * @@ -2342,27 +2400,32 @@ _.shuffle([1, 2, 3, 4, 5, 6]); -### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2254 "View in source") [Ⓣ][1] +### `_.isPlainObject(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L904 "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. +Checks if a given `value` is an object created by the `Object` constructor. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to inspect. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Number)*: Returns `collection.length` or number of own enumerable properties. +*(Boolean)*: Returns `true` if `value` is a plain object, else `false`. #### Example ```js -_.size([1, 2]); -// => 2 +function Stooge(name, age) { + this.name = name; + this.age = age; +} -_.size({ 'one': 1, 'two': 2, 'three': 3 }); -// => 3 +_.isPlainObject(new Stooge('moe', 40)); +// false -_.size('curly'); -// => 5 +_.isPlainObject([1, 2, 3]); +// false + +_.isPlainObject({ 'name': 'moe', 'age': 40 }); +// => true ``` * * * @@ -2372,25 +2435,20 @@ _.size('curly'); -### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2279 "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)*. +### `_.isRegExp(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1614 "View in source") [Ⓣ][1] -#### Aliases -*any* +Checks if `value` is a regular expression. #### 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 of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Boolean)*: Returns `true` if any element passes the callback check, else `false`. +*(Boolean)*: Returns `true` if the `value` is a regular expression, else `false`. #### Example ```js -_.some([null, 0, 'yes', false]); +_.isRegExp(/moe/); // => true ``` @@ -2401,29 +2459,21 @@ _.some([null, 0, 'yes', false]); -### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2309 "View in source") [Ⓣ][1] +### `_.isString(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1631 "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')*. +Checks if `value` is a string. #### 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 of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns a new array of sorted elements. +*(Boolean)*: Returns `true` if the `value` is a string, else `false`. #### Example ```js -_.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); -// => [3, 1, 2] - -_.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); -// => [3, 1, 2] - -_.sortBy(['larry', 'brendan', 'moe'], 'length'); -// => ['moe', 'larry', 'brendan'] +_.isString('moe'); +// => true ``` * * * @@ -2433,41 +2483,21 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); -### `_.sortedIndex(array, value [, callback=identity|property, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2925 "View in source") [Ⓣ][1] +### `_.isUndefined(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1649 "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. +Checks if `value` is `undefined`. #### Arguments -1. `array` *(Array)*: The array to iterate over. -2. `value` *(Mixed)*: The value to evaluate. -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`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Number)*: Returns the index at which the value should be inserted into `array`. +*(Boolean)*: Returns `true` if the `value` is `undefined`, else `false`. #### Example ```js -_.sortedIndex([20, 30, 50], 40); -// => 2 - -_.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); -// => 2 - -var dict = { - 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } -}; - -_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { - return dict.wordToNumber[word]; -}); -// => 2 - -_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { - return this.wordToNumber[word]; -}, dict); -// => 2 +_.isUndefined(void 0); +// => true ``` * * * @@ -2477,27 +2507,21 @@ _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { -### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3947 "View in source") [Ⓣ][1] +### `_.keys(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1666 "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. +Creates an array composed of the own enumerable property names of `object`. #### Arguments -1. `value` *(Mixed)*: The value to pass to `interceptor`. -2. `interceptor` *(Function)*: The function to invoke. +1. `object` *(Object)*: The object to inspect. #### Returns -*(Mixed)*: Returns `value`. +*(Array)*: Returns a new array of property names. #### Example ```js -_.chain([1, 2, 3, 200]) - .filter(function(num) { return num % 2 == 0; }) - .tap(alert) - .map(function(num) { return num * num }) - .value(); -// => // [2, 200] (alerted) -// => [4, 40000] +_.keys({ 'one': 1, 'two': 2, 'three': 3 }); +// => ['one', 'two', 'three'] (order is not guaranteed) ``` * * * @@ -2507,62 +2531,32 @@ _.chain([1, 2, 3, 200]) -### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3728 "View in source") [Ⓣ][1] +### `_.merge(object [, source1, source2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1709 "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 +Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. #### Arguments -1. `text` *(String)*: The template text. -2. `data` *(Obect)*: The data object used to populate the text. -3. `options` *(Object)*: The options object. +1. `object` *(Object)*: The destination object. +2. `[source1, source2, ...]` *(Object)*: The source objects. #### Returns -*(Function, String)*: Returns a compiled function when no `data` object is given, else it returns the interpolated text. +*(Object)*: Returns the destination object. #### Example ```js -// using a compiled template -var compiled = _.template('hello: <%= name %>'); -compiled({ 'name': 'moe' }); -// => 'hello: moe' - -var list = '<% _.forEach(people, function(name) { %>
  • <%= name %>
  • <% }); %>'; -_.template(list, { 'people': ['moe', 'larry', 'curly'] }); -// => '
  • moe
  • larry
  • curly
  • ' - -// using the "escape" delimiter to escape HTML in data property values -_.template('<%- value %>', { 'value': '