From 839e52ba30bfd7f1d74ae0a36d24ea15a73588e5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 7 Oct 2012 02:19:16 -0700 Subject: [PATCH] Organize docs by category. [closes #84] Former-commit-id: f4ebda7c32a0ce9c5a86cdb0fd1e689f76557e42 --- doc/README.md | 4586 +++++++++++----------- 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 | 341 +- 7 files changed, 2547 insertions(+), 2392 deletions(-) diff --git a/doc/README.md b/doc/README.md index 26337495c..c377cbc84 100644 --- a/doc/README.md +++ b/doc/README.md @@ -5,53 +5,114 @@ -## `_` -* [`_`](#_value) -* [`_.VERSION`](#_version) -* [`_.after`](#_aftern-func) -* [`_.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) +## `Arrays` * [`_.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) +* [`_.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) +* [`_.chain`](#_chainvalue) +* [`_.tap`](#_tapvalue-interceptor) +* [`_.prototype.chain`](#_prototypechain) +* [`_.prototype.value`](#_prototypevalue) + + + + + + +## `Collections` +* [`_.all`](#_everycollection--callbackidentity-thisarg) +* [`_.any`](#_somecollection--callbackidentity-thisarg) +* [`_.collect`](#_mapcollection--callbackidentity-thisarg) +* [`_.contains`](#_containscollection-target) +* [`_.countBy`](#_countbycollection-callbackproperty--thisarg) +* [`_.detect`](#_findcollection-callback--thisarg) +* [`_.each`](#_foreachcollection-callback--thisarg) +* [`_.every`](#_everycollection--callbackidentity-thisarg) +* [`_.filter`](#_filtercollection--callbackidentity-thisarg) +* [`_.find`](#_findcollection-callback--thisarg) * [`_.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) +* [`_.omit`](#_omitobject-callback-prop1-prop2--thisarg) +* [`_.pairs`](#_pairsobject) +* [`_.pick`](#_pickobject-callback-prop1-prop2--thisarg) +* [`_.values`](#_valuesobject) + + + + + + +## `Utilities` +* [`_.escape`](#_escapestring) +* [`_.identity`](#_identityvalue) * [`_.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) - - - - - - -## `_.templateSettings` +## `Properties` +* [`_.VERSION`](#_version) * [`_.templateSettings`](#_templatesettings) * [`_.templateSettings.escape`](#_templatesettingsescape) * [`_.templateSettings.evaluate`](#_templatesettingsevaluate) @@ -151,205 +179,12 @@ -## `_` - - - -### `_(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L241 "View in source") [Ⓣ][1] - -The `lodash` function. - -#### Arguments -1. `value` *(Mixed)*: The value to wrap in a `lodash` instance. - -#### Returns -*(Object)*: Returns a `lodash` instance. - -* * * - - - - - - -### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3995 "View in source") [Ⓣ][1] - -*(String)*: The semantic version number. - -* * * - - - - - - -### `_.after(n, func)` -# [Ⓢ](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. - -#### Arguments -1. `n` *(Number)*: The number of times the function must be called before it is executed. -2. `func` *(Function)*: The function to restrict. - -#### Returns -*(Function)*: Returns the new restricted function. - -#### 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 -``` - -* * * - - - - - - -### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](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. - -#### 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. - -#### Returns -*(Function)*: Returns the new bound function. - -#### Example -```js -var func = function(greeting) { - return greeting + ' ' + this.name; -}; - -func = _.bind(func, { 'name': 'moe' }, 'hi'); -func(); -// => 'hi moe' -``` - -* * * - - - - - - -### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](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. - -#### 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. - -#### Returns -*(Object)*: Returns `object`. - -#### Example -```js -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 -``` - -* * * - - - - - - -### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3920 "View in source") [Ⓣ][1] - -Wraps the value in a `lodash` wrapper object. - -#### Arguments -1. `value` *(Mixed)*: The value to wrap. - -#### Returns -*(Object)*: Returns the wrapper object. - -#### Example -```js -var stooges = [ - { 'name': 'moe', 'age': 40 }, - { 'name': 'larry', 'age': 50 }, - { 'name': 'curly', 'age': 60 } -]; - -var youngest = _.chain(stooges) - .sortBy(function(stooge) { return stooge.age; }) - .map(function(stooge) { return stooge.name + ' is ' + stooge.age; }) - .first() - .value(); -// => 'moe is 40' -``` - -* * * - - - - - - -### `_.clone(value, deep)` -# [Ⓢ](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. - -#### Arguments -1. `value` *(Mixed)*: The value to clone. -2. `deep` *(Boolean)*: A flag to indicate a deep clone. - -#### Returns -*(Mixed)*: Returns the cloned `value`. - -#### 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 -``` - -* * * - - - +## `“Arrays” Methods` ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2409 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2394 "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. @@ -370,207 +205,10 @@ _.compact([0, 1, false, 2, '', 3]); - - -### `_.compose([func1, func2, ...])` -# [Ⓢ](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()))`. - -#### Arguments -1. `[func1, func2, ...]` *(Function)*: Functions to compose. - -#### Returns -*(Function)*: Returns the new composed function. - -#### Example -```js -var greet = function(name) { return 'hi: ' + name; }; -var exclaim = function(statement) { return statement + '!'; }; -var welcome = _.compose(exclaim, greet); -welcome('moe'); -// => 'hi: 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. `===`. - -#### Aliases -*include* - -#### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `target` *(Mixed)*: The value to check for. - -#### Returns -*(Boolean)*: Returns `true` if the `target` element is found, else `false`. - -#### Example -```js -_.contains([1, 2, 3], 3); -// => true - -_.contains({ 'name': 'moe', 'age': 40 }, 'moe'); -// => true - -_.contains('curly', 'ur'); -// => true -``` - -* * * - - - - - - -### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](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')*. - -#### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback|property` *(Function|String)*: The function called per iteration or property name to count by. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. - -#### Returns -*(Object)*: Returns the composed aggregate object. - -#### 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 } - -_.countBy(['one', 'two', 'three'], 'length'); -// => { '3': 2, '5': 1 } -``` - -* * * - - - - - - -### `_.debounce(func, wait, immediate)` -# [Ⓢ](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. - -#### 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. - -#### Returns -*(Function)*: Returns the new debounced function. - -#### Example -```js -var lazyLayout = _.debounce(calculateLayout, 300); -jQuery(window).on('resize', lazyLayout); -``` - -* * * - - - - - - -### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](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. - -#### Arguments -1. `object` *(Object)*: The destination object. -2. `[default1, default2, ...]` *(Object)*: The default objects. - -#### Returns -*(Object)*: Returns the destination object. - -#### Example -```js -var iceCream = { 'flavor': 'chocolate' }; -_.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); -// => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' } -``` - -* * * - - - - - - -### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](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. - -#### Arguments -1. `func` *(Function)*: The function to defer. -2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the function with. - -#### Returns -*(Number)*: Returns the `setTimeout` timeout id. - -#### Example -```js -_.defer(function() { alert('deferred'); }); -// returns from the function before `alert` is called -``` - -* * * - - - - - - -### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](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. - -#### 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. - -#### Returns -*(Number)*: Returns the `setTimeout` timeout id. - -#### Example -```js -var log = _.bind(console.log, console); -_.delay(log, 1000, 'logged later'); -// => 'logged later' (Appears after one second.) -``` - -* * * - - - - ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2438 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2423 "View in source") [Ⓣ][1] Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -592,146 +230,10 @@ _.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] - -Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. - -#### Arguments -1. `string` *(String)*: The string to escape. - -#### Returns -*(String)*: Returns the escaped string. - -#### Example -```js -_.escape('Moe, Larry & Curly'); -// => "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)*. - -#### Aliases -*all* - -#### 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`. - -#### Returns -*(Boolean)*: Returns `true` if all elements pass the callback check, else `false`. - -#### Example -```js -_.every([true, 1, null, 'yes'], Boolean); -// => false -``` - -* * * - - - - - - -### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](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. - -#### Arguments -1. `object` *(Object)*: The destination object. -2. `[source1, source2, ...]` *(Object)*: The source objects. - -#### Returns -*(Object)*: Returns the destination object. - -#### Example -```js -_.extend({ 'name': 'moe' }, { 'age': 40 }); -// => { '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)*. - -#### Aliases -*select* - -#### 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`. - -#### Returns -*(Array)*: Returns a new array of elements that passed the callback check. - -#### Example -```js -var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -// => [2, 4, 6] -``` - -* * * - - - - - - -### `_.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)*. - -#### Aliases -*detect* - -#### 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`. - -#### Returns -*(Mixed)*: Returns the element that passed the callback check, else `undefined`. - -#### Example -```js -var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -// => 2 -``` - -* * * - - - - ### `_.first(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2476 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2461 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -759,7 +261,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2500 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2485 "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. @@ -784,215 +286,10 @@ _.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`. - -#### Aliases -*each* - -#### 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`. - -#### Returns -*(Array, Object, String)*: Returns `collection`. - -#### 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) -``` - -* * * - - - - - - -### `_.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`. - -#### 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`. - -#### Returns -*(Object)*: Returns `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) -``` - -* * * - - - - - - -### `_.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`. - -#### 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`. - -#### Returns -*(Object)*: Returns `object`. - -#### Example -```js -_.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { - alert(key); -}); -// => alerts '0', '1', and 'length' (order is not guaranteed) -``` - -* * * - - - - - - -### `_.functions(object)` -# [Ⓢ](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. - -#### Aliases -*methods* - -#### Arguments -1. `object` *(Object)*: The object to inspect. - -#### Returns -*(Array)*: Returns a new array of property names that have function values. - -#### Example -```js -_.functions(_); -// => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...] -``` - -* * * - - - - - - -### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](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')*. - -#### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback|property` *(Function|String)*: The function called per iteration or property name to group by. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. - -#### Returns -*(Object)*: Returns the composed aggregate object. - -#### Example -```js -_.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'] } -``` - -* * * - - - - - - -### `_.has(object, property)` -# [Ⓢ](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. - -#### Arguments -1. `object` *(Object)*: The object to check. -2. `property` *(String)*: The property to check for. - -#### Returns -*(Boolean)*: Returns `true` if key is a direct property, else `false`. - -#### Example -```js -_.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); -// => true -``` - -* * * - - - - - - -### `_.identity(value)` -# [Ⓢ](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. - -#### Arguments -1. `value` *(Mixed)*: Any value. - -#### Returns -*(Mixed)*: Returns `value`. - -#### Example -```js -var moe = { 'name': 'moe' }; -moe === _.identity(moe); -// => true -``` - -* * * - - - - ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2542 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2527 "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 +321,7 @@ _.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] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2562 "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 +346,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2598 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2583 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -1070,549 +367,10 @@ _.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] - -Creates an object composed of the inverted keys and values of the given `object`. - -#### Arguments -1. `object` *(Object)*: The object to invert. - -#### Returns -*(Object)*: Returns the created inverted object. - -#### Example -```js -_.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); -// => { 'Moe': 'first', 'Larry': 'second', 'Curly': 'third' } (order is not guaranteed) -``` - -* * * - - - - - - -### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](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`. - -#### 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. - -#### Returns -*(Array)*: Returns a new array of the results of each invoked method. - -#### Example -```js -_.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']] -``` - -* * * - - - - - - -### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L832 "View in source") [Ⓣ][1] - -Checks if `value` is an `arguments` object. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is an `arguments` object, else `false`. - -#### Example -```js -(function() { return _.isArguments(arguments); })(1, 2, 3); -// => true - -_.isArguments([1, 2, 3]); -// => false -``` - -* * * - - - - - - -### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L858 "View in source") [Ⓣ][1] - -Checks if `value` is an array. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is an array, else `false`. - -#### Example -```js -(function() { return _.isArray(arguments); })(); -// => false - -_.isArray([1, 2, 3]); -// => true -``` - -* * * - - - - - - -### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1259 "View in source") [Ⓣ][1] - -Checks if `value` is a boolean *(`true` or `false`)* value. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is a boolean value, else `false`. - -#### Example -```js -_.isBoolean(null); -// => false -``` - -* * * - - - - - - -### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1276 "View in source") [Ⓣ][1] - -Checks if `value` is a date. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is a date, else `false`. - -#### Example -```js -_.isDate(new Date); -// => true -``` - -* * * - - - - - - -### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1293 "View in source") [Ⓣ][1] - -Checks if `value` is a DOM element. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is a DOM element, else `false`. - -#### Example -```js -_.isElement(document.body); -// => true -``` - -* * * - - - - - - -### `_.isEmpty(value)` -# [Ⓢ](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". - -#### Arguments -1. `value` *(Array|Object|String)*: The value to inspect. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is empty, else `false`. - -#### Example -```js -_.isEmpty([1, 2, 3]); -// => false - -_.isEmpty({}); -// => true - -_.isEmpty(''); -// => true -``` - -* * * - - - - - - -### `_.isEqual(a, b)` -# [Ⓢ](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. - -#### Arguments -1. `a` *(Mixed)*: The value to compare. -2. `b` *(Mixed)*: The other value to compare. - -#### Returns -*(Boolean)*: Returns `true` if the values are equvalent, else `false`. - -#### Example -```js -var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; -var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; - -moe == clone; -// => false - -_.isEqual(moe, clone); -// => true -``` - -* * * - - - - - - -### `_.isFinite(value)` -# [Ⓢ](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. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is a finite number, else `false`. - -#### Example -```js -_.isFinite(-101); -// => true - -_.isFinite('10'); -// => false - -_.isFinite(Infinity); -// => false -``` - -* * * - - - - - - -### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L875 "View in source") [Ⓣ][1] - -Checks if `value` is a function. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is a function, else `false`. - -#### Example -```js -_.isFunction(_); -// => true -``` - -* * * - - - - - - -### `_.isNaN(value)` -# [Ⓢ](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. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is `NaN`, else `false`. - -#### Example -```js -_.isNaN(NaN); -// => true - -_.isNaN(new Number(NaN)); -// => true - -isNaN(undefined); -// => true - -_.isNaN(undefined); -// => false -``` - -* * * - - - - - - -### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1595 "View in source") [Ⓣ][1] - -Checks if `value` is `null`. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is `null`, else `false`. - -#### Example -```js -_.isNull(null); -// => true - -_.isNull(undefined); -// => false -``` - -* * * - - - - - - -### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1612 "View in source") [Ⓣ][1] - -Checks if `value` is a number. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is a number, else `false`. - -#### Example -```js -_.isNumber(8.4 * 5); -// => true -``` - -* * * - - - - - - -### `_.isObject(value)` -# [Ⓢ](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('')`)* - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is an object, else `false`. - -#### Example -```js -_.isObject({}); -// => true - -_.isObject([1, 2, 3]); -// => true - -_.isObject(1); -// => false -``` - -* * * - - - - - - -### `_.isPlainObject(value)` -# [Ⓢ](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. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if `value` is a plain object, else `false`. - -#### Example -```js -function Stooge(name, age) { - this.name = name; - this.age = age; -} - -_.isPlainObject(new Stooge('moe', 40)); -// false - -_.isPlainObject([1, 2, 3]); -// false - -_.isPlainObject({ 'name': 'moe', 'age': 40 }); -// => true -``` - -* * * - - - - - - -### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1629 "View in source") [Ⓣ][1] - -Checks if `value` is a regular expression. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is a regular expression, else `false`. - -#### Example -```js -_.isRegExp(/moe/); -// => true -``` - -* * * - - - - - - -### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1646 "View in source") [Ⓣ][1] - -Checks if `value` is a string. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is a string, else `false`. - -#### Example -```js -_.isString('moe'); -// => true -``` - -* * * - - - - - - -### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1664 "View in source") [Ⓣ][1] - -Checks if `value` is `undefined`. - -#### Arguments -1. `value` *(Mixed)*: The value to check. - -#### Returns -*(Boolean)*: Returns `true` if the `value` is `undefined`, else `false`. - -#### Example -```js -_.isUndefined(void 0); -// => true -``` - -* * * - - - - - - -### `_.keys(object)` -# [Ⓢ](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`. - -#### Arguments -1. `object` *(Object)*: The object to inspect. - -#### Returns -*(Array)*: Returns a new array of property names. - -#### Example -```js -_.keys({ 'one': 1, 'two': 2, 'three': 3 }); -// => ['one', 'two', 'three'] (order is not guaranteed) -``` - -* * * - - - - ### `_.last(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2637 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2622 "View in source") [Ⓣ][1] Gets the last element of the `array`. Pass `n` to return the last `n` elements of the `array`. @@ -1637,7 +395,7 @@ _.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] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2648 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1663,83 +421,10 @@ _.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] - -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. `object` *(Object)*: The object the method belongs to. -2. `methodName` *(String)*: The method name. -3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. - -#### Returns -*(Function)*: Returns the new bound function. - -#### Example -```js -var object = { - 'name': 'moe', - 'greet': function(greeting) { - return greeting + ' ' + this.name; - } -}; - -var func = _.lateBind(object, 'greet', 'hi'); -func(); -// => 'hi moe' - -object.greet = function(greeting) { - return greeting + ', ' + this.name + '!'; -}; - -func(); -// => 'hi, moe!' -``` - -* * * - - - - - - -### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#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)*. - -#### Aliases -*collect* - -#### 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`. - -#### Returns -*(Array)*: Returns a new array of the results of each `callback` execution. - -#### 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) -``` - -* * * - - - - ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2700 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2685 "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)*. @@ -1768,71 +453,10 @@ _.max(stooges, function(stooge) { return stooge.age; }); - - -### `_.memoize(func [, resolver])` -# [Ⓢ](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. - -#### Arguments -1. `func` *(Function)*: The function to have its output memoized. -2. `[resolver]` *(Function)*: A function used to resolve the cache key. - -#### Returns -*(Function)*: Returns the new memoizing function. - -#### Example -```js -var fibonacci = _.memoize(function(n) { - return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); -}); -``` - -* * * - - - - - - -### `_.merge(object [, source1, source2, ...])` -# [Ⓢ](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. - -#### Arguments -1. `object` *(Object)*: The destination object. -2. `[source1, source2, ...]` *(Object)*: The source objects. - -#### Returns -*(Object)*: Returns the destination object. - -#### 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 }] -``` - -* * * - - - - ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2735 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2720 "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)*. @@ -1855,60 +479,10 @@ _.min([10, 5, 100, 2, 1000]); - - -### `_.mixin(object)` -# [Ⓢ](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. - -#### Arguments -1. `object` *(Object)*: The object of function properties to add to `lodash`. - -#### Example -```js -_.mixin({ - 'capitalize': function(string) { - return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); - } -}); - -_.capitalize('larry'); -// => 'Larry' - -_('curly').capitalize(); -// => 'Curly' -``` - -* * * - - - - - - -### `_.noConflict()` -# [Ⓢ](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. - -#### Returns -*(Function)*: Returns the `lodash` function. - -#### Example -```js -var lodash = _.noConflict(); -``` - -* * * - - - - ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2769 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2754 "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`. @@ -1930,208 +504,10 @@ _.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] - -Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. - -#### Arguments -1. `object` *(Object)*: The source object. -2. `callback|[prop1, prop2, ...]` *(Function|String)*: The properties to omit or the function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. - -#### Returns -*(Object)*: Returns an object without the omitted properties. - -#### 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' } -``` - -* * * - - - - - - -### `_.once(func)` -# [Ⓢ](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. - -#### Arguments -1. `func` *(Function)*: The function to restrict. - -#### Returns -*(Function)*: Returns the new restricted function. - -#### Example -```js -var initialize = _.once(createApplication); -initialize(); -initialize(); -// Application is only created once. -``` - -* * * - - - - - - -### `_.pairs(object)` -# [Ⓢ](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]]`. - -#### Arguments -1. `object` *(Object)*: The object to inspect. - -#### Returns -*(Array)*: Returns new array of key-value pairs. - -#### Example -```js -_.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); -// => [['moe', 30], ['larry', 40], ['curly', 50]] (order is not guaranteed) -``` - -* * * - - - - - - -### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](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. - -#### Arguments -1. `func` *(Function)*: The function to partially apply arguments to. -2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. - -#### Returns -*(Function)*: Returns the new partially applied function. - -#### Example -```js -var greet = function(greeting, name) { return greeting + ': ' + name; }; -var hi = _.partial(greet, 'hi'); -hi('moe'); -// => 'hi: moe' -``` - -* * * - - - - - - -### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](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)*. - -#### 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`. - -#### Returns -*(Object)*: Returns an object composed of the picked properties. - -#### 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' } -``` - -* * * - - - - - - -### `_.pluck(collection, property)` -# [Ⓢ](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`. - -#### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `property` *(String)*: The property to pluck. - -#### Returns -*(Array)*: Returns a new array of property values. - -#### Example -```js -var stooges = [ - { 'name': 'moe', 'age': 40 }, - { 'name': 'larry', 'age': 50 }, - { 'name': 'curly', 'age': 60 } -]; - -_.pluck(stooges, 'name'); -// => ['moe', 'larry', 'curly'] -``` - -* * * - - - - - - -### `_.random([min=0, max=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. - -#### Arguments -1. `[min=0]` *(Number)*: The minimum possible value. -2. `[max=1]` *(Number)*: The maximum possible value. - -#### Returns -*(Number)*: Returns a random number. - -#### Example -```js -_.random(0, 5); -// => a number between 1 and 5 - -_.random(5); -// => also a number between 1 and 5 -``` - -* * * - - - - ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2813 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2799 "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. @@ -2166,97 +542,10 @@ _.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)*. - -#### Aliases -*foldl, inject* - -#### 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`. - -#### Returns -*(Mixed)*: Returns the accumulated value. - -#### Example -```js -var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); -// => 6 -``` - -* * * - - - - - - -### `_.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`. - -#### Aliases -*foldr* - -#### 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`. - -#### Returns -*(Mixed)*: Returns the accumulated value. - -#### 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] -``` - -* * * - - - - - - -### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](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. - -#### 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`. - -#### Returns -*(Array)*: Returns a new array of elements that did **not** pass the callback check. - -#### Example -```js -var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -// => [1, 3, 5] -``` - -* * * - - - - ### `_.rest(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2852 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2838 "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. @@ -2281,45 +570,10 @@ _.rest([3, 2, 1]); - - -### `_.result(object, property)` -# [Ⓢ](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. - -#### 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' - -_.result(object, 'stuff'); -// => 'nonsense' -``` - -* * * - - - - ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2872 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2858 "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. @@ -2340,101 +594,10 @@ _.shuffle([1, 2, 3, 4, 5, 6]); - - -### `_.size(collection)` -# [Ⓢ](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. - -#### Arguments -1. `collection` *(Array|Object|String)*: The collection to inspect. - -#### Returns -*(Number)*: Returns `collection.length` or number of own enumerable properties. - -#### Example -```js -_.size([1, 2]); -// => 2 - -_.size({ 'one': 1, 'two': 2, 'three': 3 }); -// => 3 - -_.size('curly'); -// => 5 -``` - -* * * - - - - - - -### `_.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)*. - -#### Aliases -*any* - -#### 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`. - -#### Returns -*(Boolean)*: Returns `true` if any element passes the callback check, else `false`. - -#### Example -```js -_.some([null, 0, 'yes', false]); -// => true -``` - -* * * - - - - - - -### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](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')*. - -#### 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`. - -#### Returns -*(Array)*: Returns a new array of sorted elements. - -#### 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'] -``` - -* * * - - - - ### `_.sortedIndex(array, value [, callback=identity|property, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2925 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2911 "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. @@ -2475,10 +638,181 @@ _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { + + +### `_.union([array1, array2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2939 "View in source") [Ⓣ][1] + +Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. + +#### Arguments +1. `[array1, array2, ...]` *(Array)*: Arrays to process. + +#### Returns +*(Array)*: Returns a new array of unique values, in order, that are present in one or more of the arrays. + +#### Example +```js +_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); +// => [1, 2, 3, 101, 10] +``` + +* * * + + + + + + +### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2984 "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)*. + +#### Aliases +*unique* + +#### Arguments +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 +*(Array)*: Returns a duplicate-value-free array. + +#### Example +```js +_.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] +``` + +* * * + + + + + + +### `_.without(array [, value1, value2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3025 "View in source") [Ⓣ][1] + +Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. + +#### Arguments +1. `array` *(Array)*: The array to filter. +2. `[value1, value2, ...]` *(Mixed)*: Values to remove. + +#### Returns +*(Array)*: Returns a new filtered array. + +#### Example +```js +_.without([1, 2, 1, 0, 3, 1, 4], 0, 1); +// => [2, 3, 4] +``` + +* * * + + + + + + +### `_.zip([array1, array2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3056 "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. + +#### Arguments +1. `[array1, array2, ...]` *(Array)*: Arrays to process. + +#### Returns +*(Array)*: Returns a new array of grouped elements. + +#### Example +```js +_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); +// => [['moe', 30, true], ['larry', 40, false], ['curly', 50, false]] +``` + +* * * + + + + + + + + + +## `“Chaining” Methods` + + + +### `_(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L242 "View in source") [Ⓣ][1] + +The `lodash` function. + +#### Arguments +1. `value` *(Mixed)*: The value to wrap in a `lodash` instance. + +#### Returns +*(Object)*: Returns a `lodash` instance. + +* * * + + + + + + +### `_.chain(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3905 "View in source") [Ⓣ][1] + +Wraps the value in a `lodash` wrapper object. + +#### Arguments +1. `value` *(Mixed)*: The value to wrap. + +#### Returns +*(Object)*: Returns the wrapper object. + +#### Example +```js +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; + +var youngest = _.chain(stooges) + .sortBy(function(stooge) { return stooge.age; }) + .map(function(stooge) { return stooge.name + ' is ' + stooge.age; }) + .first() + .value(); +// => 'moe is 40' +``` + +* * * + + + + ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3947 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3932 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2505,10 +839,2014 @@ _.chain([1, 2, 3, 200]) + + +### `_.prototype.chain()` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3950 "View in source") [Ⓣ][1] + +Enables method chaining on the wrapper object. + +#### Returns +*(Mixed)*: Returns the wrapper object. + +#### Example +```js +_([1, 2, 3]).value(); +// => [1, 2, 3] +``` + +* * * + + + + + + +### `_.prototype.value()` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3967 "View in source") [Ⓣ][1] + +Extracts the wrapped value. + +#### Returns +*(Mixed)*: Returns the wrapped value. + +#### Example +```js +_([1, 2, 3]).value(); +// => [1, 2, 3] +``` + +* * * + + + + + + + + + +## `“Collections” Methods` + + + +### `_.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 +*include* + +#### Arguments +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `target` *(Mixed)*: The value to check for. + +#### Returns +*(Boolean)*: Returns `true` if the `target` element is found, else `false`. + +#### Example +```js +_.contains([1, 2, 3], 3); +// => true + +_.contains({ 'name': 'moe', 'age': 40 }, 'moe'); +// => true + +_.contains('curly', 'ur'); +// => true +``` + +* * * + + + + + + +### `_.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 the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. + +#### Arguments +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `callback|property` *(Function|String)*: The function called per iteration or property name to count by. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. + +#### Returns +*(Object)*: Returns the composed aggregate object. + +#### 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 } + +_.countBy(['one', 'two', 'three'], 'length'); +// => { '3': 2, '5': 1 } +``` + +* * * + + + + + + +### `_.every(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1930 "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)*. + +#### Aliases +*all* + +#### 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`. + +#### Returns +*(Boolean)*: Returns `true` if all elements pass the callback check, else `false`. + +#### Example +```js +_.every([true, 1, null, 'yes'], Boolean); +// => false +``` + +* * * + + + + + + +### `_.filter(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1950 "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)*. + +#### Aliases +*select* + +#### 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`. + +#### Returns +*(Array)*: Returns a new array of elements that passed the callback check. + +#### Example +```js +var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +// => [2, 4, 6] +``` + +* * * + + + + + + +### `_.find(collection, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1972 "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)*. + +#### Aliases +*detect* + +#### 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`. + +#### Returns +*(Mixed)*: Returns the element that passed the callback check, else `undefined`. + +#### Example +```js +var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +// => 2 +``` + +* * * + + + + + + +### `_.forEach(collection, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1999 "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`. + +#### Aliases +*each* + +#### 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`. + +#### Returns +*(Array, Object, String)*: Returns `collection`. + +#### 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) +``` + +* * * + + + + + + +### `_.groupBy(collection, callback|property [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2027 "View in source") [Ⓣ][1] + +Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. + +#### Arguments +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `callback|property` *(Function|String)*: The function called per iteration or property name to group by. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. + +#### Returns +*(Object)*: Returns the composed aggregate object. + +#### Example +```js +_.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'] } +``` + +* * * + + + + + + +### `_.invoke(collection, methodName [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2055 "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`. + +#### 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. + +#### Returns +*(Array)*: Returns a new array of the results of each invoked method. + +#### Example +```js +_.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']] +``` + +* * * + + + + + + +### `_.map(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2090 "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)*. + +#### Aliases +*collect* + +#### 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`. + +#### Returns +*(Array)*: Returns a new array of the results of each `callback` execution. + +#### 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) +``` + +* * * + + + + + + +### `_.pluck(collection, property)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2113 "View in source") [Ⓣ][1] + +Retrieves the value of a specified property from all elements in the `collection`. + +#### Arguments +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `property` *(String)*: The property to pluck. + +#### Returns +*(Array)*: Returns a new array of property values. + +#### Example +```js +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; + +_.pluck(stooges, 'name'); +// => ['moe', 'larry', 'curly'] +``` + +* * * + + + + + + +### `_.reduce(collection, callback [, accumulator, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2141 "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)*. + +#### Aliases +*foldl, inject* + +#### 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`. + +#### Returns +*(Mixed)*: Returns the accumulated value. + +#### Example +```js +var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); +// => 6 +``` + +* * * + + + + + + +### `_.reduceRight(collection, callback [, accumulator, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2178 "View in source") [Ⓣ][1] + +The right-associative version of `_.reduce`. + +#### Aliases +*foldr* + +#### 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`. + +#### Returns +*(Mixed)*: Returns the accumulated value. + +#### 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] +``` + +* * * + + + + + + +### `_.reject(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2215 "View in source") [Ⓣ][1] + +The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. + +#### Arguments +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `[callback=identity]` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. + +#### Returns +*(Array)*: Returns a new array of elements that did **not** pass the callback check. + +#### Example +```js +var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +// => [1, 3, 5] +``` + +* * * + + + + + + +### `_.size(collection)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2239 "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. + +#### Arguments +1. `collection` *(Array|Object|String)*: The collection to inspect. + +#### Returns +*(Number)*: Returns `collection.length` or number of own enumerable properties. + +#### Example +```js +_.size([1, 2]); +// => 2 + +_.size({ 'one': 1, 'two': 2, 'three': 3 }); +// => 3 + +_.size('curly'); +// => 5 +``` + +* * * + + + + + + +### `_.some(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2264 "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)*. + +#### Aliases +*any* + +#### 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`. + +#### Returns +*(Boolean)*: Returns `true` if any element passes the callback check, else `false`. + +#### Example +```js +_.some([null, 0, 'yes', false]); +// => true +``` + +* * * + + + + + + +### `_.sortBy(collection, callback|property [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2294 "View in source") [Ⓣ][1] + +Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. + +#### Arguments +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `callback|property` *(Function|String)*: The function called per iteration or property name to sort by. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. + +#### Returns +*(Array)*: Returns a new array of sorted elements. + +#### 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'] +``` + +* * * + + + + + + +### `_.toArray(collection)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2330 "View in source") [Ⓣ][1] + +Converts the `collection`, to an array. + +#### Arguments +1. `collection` *(Array|Object|String)*: The collection to convert. + +#### Returns +*(Array)*: Returns the new converted array. + +#### Example +```js +(function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); +// => [2, 3, 4] +``` + +* * * + + + + + + +### `_.where(collection, properties)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2364 "View in source") [Ⓣ][1] + +Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. + +#### Arguments +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `properties` *(Object)*: The object of properties/values to filter by. + +#### Returns +*(Array)*: Returns a new array of elements that contain the given `properties`. + +#### Example +```js +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; + +_.where(stooges, { 'age': 40 }); +// => [{ 'name': 'moe', 'age': 40 }] +``` + +* * * + + + + + + + + + +## `“Functions” Methods` + + + +### `_.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. `n` *(Number)*: The number of times the function must be called before it is executed. +2. `func` *(Function)*: The function to restrict. + +#### Returns +*(Function)*: Returns the new restricted function. + +#### 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 +``` + +* * * + + + + + + +### `_.bind(func [, thisArg, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3121 "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. + +#### 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. + +#### Returns +*(Function)*: Returns the new bound function. + +#### Example +```js +var func = function(greeting) { + return greeting + ' ' + this.name; +}; + +func = _.bind(func, { 'name': 'moe' }, 'hi'); +func(); +// => 'hi moe' +``` + +* * * + + + + + + +### `_.bindAll(object [, methodName1, methodName2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3151 "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. + +#### 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. + +#### Returns +*(Object)*: Returns `object`. + +#### Example +```js +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 +``` + +* * * + + + + + + +### `_.compose([func1, func2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3186 "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()))`. + +#### Arguments +1. `[func1, func2, ...]` *(Function)*: Functions to compose. + +#### Returns +*(Function)*: Returns the new composed function. + +#### Example +```js +var greet = function(name) { return 'hi: ' + name; }; +var exclaim = function(statement) { return statement + '!'; }; +var welcome = _.compose(exclaim, greet); +welcome('moe'); +// => 'hi: moe!' +``` + +* * * + + + + + + +### `_.debounce(func, wait, immediate)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3219 "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. + +#### 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. + +#### Returns +*(Function)*: Returns the new debounced function. + +#### Example +```js +var lazyLayout = _.debounce(calculateLayout, 300); +jQuery(window).on('resize', lazyLayout); +``` + +* * * + + + + + + +### `_.defer(func [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3284 "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. + +#### Arguments +1. `func` *(Function)*: The function to defer. +2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the function with. + +#### Returns +*(Number)*: Returns the `setTimeout` timeout id. + +#### Example +```js +_.defer(function() { alert('deferred'); }); +// returns from the function before `alert` is called +``` + +* * * + + + + + + +### `_.delay(func, wait [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3264 "View in source") [Ⓣ][1] + +Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. + +#### 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. + +#### Returns +*(Number)*: Returns the `setTimeout` timeout id. + +#### Example +```js +var log = _.bind(console.log, console); +_.delay(log, 1000, 'logged later'); +// => 'logged later' (Appears after one second.) +``` + +* * * + + + + + + +### `_.lateBind(object, methodName [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3322 "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. + +#### Arguments +1. `object` *(Object)*: The object the method belongs to. +2. `methodName` *(String)*: The method name. +3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. + +#### Returns +*(Function)*: Returns the new bound function. + +#### Example +```js +var object = { + 'name': 'moe', + 'greet': function(greeting) { + return greeting + ' ' + this.name; + } +}; + +var func = _.lateBind(object, 'greet', 'hi'); +func(); +// => 'hi moe' + +object.greet = function(greeting) { + return greeting + ', ' + this.name + '!'; +}; + +func(); +// => 'hi, moe!' +``` + +* * * + + + + + + +### `_.memoize(func [, resolver])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3344 "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. + +#### Arguments +1. `func` *(Function)*: The function to have its output memoized. +2. `[resolver]` *(Function)*: A function used to resolve the cache key. + +#### Returns +*(Function)*: Returns the new memoizing function. + +#### Example +```js +var fibonacci = _.memoize(function(n) { + return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); +}); +``` + +* * * + + + + + + +### `_.once(func)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3370 "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. + +#### Arguments +1. `func` *(Function)*: The function to restrict. + +#### Returns +*(Function)*: Returns the new restricted function. + +#### Example +```js +var initialize = _.once(createApplication); +initialize(); +initialize(); +// Application is only created once. +``` + +* * * + + + + + + +### `_.partial(func [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3405 "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. + +#### Arguments +1. `func` *(Function)*: The function to partially apply arguments to. +2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. + +#### Returns +*(Function)*: Returns the new partially applied function. + +#### Example +```js +var greet = function(greeting, name) { return greeting + ': ' + name; }; +var hi = _.partial(greet, 'hi'); +hi('moe'); +// => 'hi: moe' +``` + +* * * + + + + + + +### `_.throttle(func, wait)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3427 "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. + +#### Arguments +1. `func` *(Function)*: The function to throttle. +2. `wait` *(Number)*: The number of milliseconds to throttle executions to. + +#### Returns +*(Function)*: Returns the new throttled function. + +#### Example +```js +var throttled = _.throttle(updatePosition, 100); +jQuery(window).on('scroll', throttled); +``` + +* * * + + + + + + +### `_.wrap(value, wrapper)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3478 "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. + +#### Arguments +1. `value` *(Mixed)*: The value to wrap. +2. `wrapper` *(Function)*: The wrapper function. + +#### Returns +*(Function)*: Returns the new function. + +#### Example +```js +var hello = function(name) { return 'hello: ' + name; }; +hello = _.wrap(hello, function(func) { + return 'before, ' + func('moe') + ', after'; +}); +hello(); +// => 'before, hello: moe, after' +``` + +* * * + + + + + + + + + +## `“Objects” Methods` + + + +### `_.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. `value` *(Mixed)*: The value to clone. +2. `deep` *(Boolean)*: A flag to indicate a deep clone. + +#### Returns +*(Mixed)*: Returns the cloned `value`. + +#### 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 +``` + +* * * + + + + + + +### `_.defaults(object [, default1, default2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1113 "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. + +#### Arguments +1. `object` *(Object)*: The destination object. +2. `[default1, default2, ...]` *(Object)*: The default objects. + +#### Returns +*(Object)*: Returns the destination object. + +#### Example +```js +var iceCream = { 'flavor': 'chocolate' }; +_.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); +// => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' } +``` + +* * * + + + + + + +### `_.extend(object [, source1, source2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1133 "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. + +#### Arguments +1. `object` *(Object)*: The destination object. +2. `[source1, source2, ...]` *(Object)*: The source objects. + +#### Returns +*(Object)*: Returns the destination object. + +#### Example +```js +_.extend({ 'name': 'moe' }, { 'age': 40 }); +// => { 'name': 'moe', 'age': 40 } +``` + +* * * + + + + + + +### `_.forIn(object, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1163 "View in source") [Ⓣ][1] + +Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. + +#### Arguments +1. `object` *(Object)*: The object to iterate over. +2. `callback` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. + +#### Returns +*(Object)*: Returns `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) +``` + +* * * + + + + + + +### `_.forOwn(object, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1187 "View in source") [Ⓣ][1] + +Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. + +#### Arguments +1. `object` *(Object)*: The object to iterate over. +2. `callback` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. + +#### Returns +*(Object)*: Returns `object`. + +#### Example +```js +_.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { + alert(key); +}); +// => alerts '0', '1', and 'length' (order is not guaranteed) +``` + +* * * + + + + + + +### `_.functions(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1204 "View in source") [Ⓣ][1] + +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 +*(Array)*: Returns a new array of property names that have function values. + +#### Example +```js +_.functions(_); +// => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...] +``` + +* * * + + + + + + +### `_.has(object, property)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1227 "View in source") [Ⓣ][1] + +Checks if the specified object `property` exists and is a direct property, instead of an inherited property. + +#### Arguments +1. `object` *(Object)*: The object to check. +2. `property` *(String)*: The property to check for. + +#### Returns +*(Boolean)*: Returns `true` if key is a direct property, else `false`. + +#### Example +```js +_.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); +// => true +``` + +* * * + + + + + + +### `_.invert(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L805 "View in source") [Ⓣ][1] + +Creates an object composed of the inverted keys and values of the given `object`. + +#### Arguments +1. `object` *(Object)*: The object to invert. + +#### Returns +*(Object)*: Returns the created inverted object. + +#### Example +```js +_.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); +// => { 'Moe': 'first', 'Larry': 'second', 'Curly': 'third' } (order is not guaranteed) +``` + +* * * + + + + + + +### `_.isArguments(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L827 "View in source") [Ⓣ][1] + +Checks if `value` is an `arguments` object. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is an `arguments` object, else `false`. + +#### Example +```js +(function() { return _.isArguments(arguments); })(1, 2, 3); +// => true + +_.isArguments([1, 2, 3]); +// => false +``` + +* * * + + + + + + +### `_.isArray(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L853 "View in source") [Ⓣ][1] + +Checks if `value` is an array. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is an array, else `false`. + +#### Example +```js +(function() { return _.isArray(arguments); })(); +// => false + +_.isArray([1, 2, 3]); +// => true +``` + +* * * + + + + + + +### `_.isBoolean(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1244 "View in source") [Ⓣ][1] + +Checks if `value` is a boolean *(`true` or `false`)* value. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is a boolean value, else `false`. + +#### Example +```js +_.isBoolean(null); +// => false +``` + +* * * + + + + + + +### `_.isDate(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1261 "View in source") [Ⓣ][1] + +Checks if `value` is a date. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is a date, else `false`. + +#### Example +```js +_.isDate(new Date); +// => true +``` + +* * * + + + + + + +### `_.isElement(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1278 "View in source") [Ⓣ][1] + +Checks if `value` is a DOM element. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is a DOM element, else `false`. + +#### Example +```js +_.isElement(document.body); +// => true +``` + +* * * + + + + + + +### `_.isEmpty(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1303 "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". + +#### Arguments +1. `value` *(Array|Object|String)*: The value to inspect. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is empty, else `false`. + +#### Example +```js +_.isEmpty([1, 2, 3]); +// => false + +_.isEmpty({}); +// => true + +_.isEmpty(''); +// => true +``` + +* * * + + + + + + +### `_.isEqual(a, b)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1342 "View in source") [Ⓣ][1] + +Performs a deep comparison between two values to determine if they are equivalent to each other. + +#### Arguments +1. `a` *(Mixed)*: The value to compare. +2. `b` *(Mixed)*: The other value to compare. + +#### Returns +*(Boolean)*: Returns `true` if the values are equvalent, else `false`. + +#### Example +```js +var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; +var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; + +moe == clone; +// => false + +_.isEqual(moe, clone); +// => true +``` + +* * * + + + + + + +### `_.isFinite(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1499 "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. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is a finite number, else `false`. + +#### Example +```js +_.isFinite(-101); +// => true + +_.isFinite('10'); +// => false + +_.isFinite(Infinity); +// => false +``` + +* * * + + + + + + +### `_.isFunction(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L870 "View in source") [Ⓣ][1] + +Checks if `value` is a function. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is a function, else `false`. + +#### Example +```js +_.isFunction(_); +// => true +``` + +* * * + + + + + + +### `_.isNaN(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1557 "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. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is `NaN`, else `false`. + +#### Example +```js +_.isNaN(NaN); +// => true + +_.isNaN(new Number(NaN)); +// => true + +isNaN(undefined); +// => true + +_.isNaN(undefined); +// => false +``` + +* * * + + + + + + +### `_.isNull(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1580 "View in source") [Ⓣ][1] + +Checks if `value` is `null`. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is `null`, else `false`. + +#### Example +```js +_.isNull(null); +// => true + +_.isNull(undefined); +// => false +``` + +* * * + + + + + + +### `_.isNumber(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1597 "View in source") [Ⓣ][1] + +Checks if `value` is a number. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is a number, else `false`. + +#### Example +```js +_.isNumber(8.4 * 5); +// => true +``` + +* * * + + + + + + +### `_.isObject(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1523 "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('')`)* + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is an object, else `false`. + +#### Example +```js +_.isObject({}); +// => true + +_.isObject([1, 2, 3]); +// => true + +_.isObject(1); +// => false +``` + +* * * + + + + + + +### `_.isPlainObject(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L904 "View in source") [Ⓣ][1] + +Checks if a given `value` is an object created by the `Object` constructor. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if `value` is a plain object, else `false`. + +#### Example +```js +function Stooge(name, age) { + this.name = name; + this.age = age; +} + +_.isPlainObject(new Stooge('moe', 40)); +// false + +_.isPlainObject([1, 2, 3]); +// false + +_.isPlainObject({ 'name': 'moe', 'age': 40 }); +// => true +``` + +* * * + + + + + + +### `_.isRegExp(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1614 "View in source") [Ⓣ][1] + +Checks if `value` is a regular expression. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is a regular expression, else `false`. + +#### Example +```js +_.isRegExp(/moe/); +// => true +``` + +* * * + + + + + + +### `_.isString(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1631 "View in source") [Ⓣ][1] + +Checks if `value` is a string. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is a string, else `false`. + +#### Example +```js +_.isString('moe'); +// => true +``` + +* * * + + + + + + +### `_.isUndefined(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1649 "View in source") [Ⓣ][1] + +Checks if `value` is `undefined`. + +#### Arguments +1. `value` *(Mixed)*: The value to check. + +#### Returns +*(Boolean)*: Returns `true` if the `value` is `undefined`, else `false`. + +#### Example +```js +_.isUndefined(void 0); +// => true +``` + +* * * + + + + + + +### `_.keys(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1666 "View in source") [Ⓣ][1] + +Creates an array composed of the own enumerable property names of `object`. + +#### Arguments +1. `object` *(Object)*: The object to inspect. + +#### Returns +*(Array)*: Returns a new array of property names. + +#### Example +```js +_.keys({ 'one': 1, 'two': 2, 'three': 3 }); +// => ['one', 'two', 'three'] (order is not guaranteed) +``` + +* * * + + + + + + +### `_.merge(object [, source1, source2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1709 "View in source") [Ⓣ][1] + +Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. + +#### Arguments +1. `object` *(Object)*: The destination object. +2. `[source1, source2, ...]` *(Object)*: The source objects. + +#### Returns +*(Object)*: Returns the destination object. + +#### 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 }] +``` + +* * * + + + + + + +### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1766 "View in source") [Ⓣ][1] + +Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. + +#### Arguments +1. `object` *(Object)*: The source object. +2. `callback|[prop1, prop2, ...]` *(Function|String)*: The properties to omit or the function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. + +#### Returns +*(Object)*: Returns an object without the omitted properties. + +#### 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' } +``` + +* * * + + + + + + +### `_.pairs(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1782 "View in source") [Ⓣ][1] + +Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. + +#### Arguments +1. `object` *(Object)*: The object to inspect. + +#### Returns +*(Array)*: Returns new array of key-value pairs. + +#### Example +```js +_.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); +// => [['moe', 30], ['larry', 40], ['curly', 50]] (order is not guaranteed) +``` + +* * * + + + + + + +### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1813 "View in source") [Ⓣ][1] + +Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, picking the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. + +#### Arguments +1. `object` *(Object)*: The source object. +2. `callback|[prop1, prop2, ...]` *(Function|String)*: The properties to pick or the function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. + +#### Returns +*(Object)*: Returns an object composed of the picked properties. + +#### 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' } +``` + +* * * + + + + + + +### `_.values(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1843 "View in source") [Ⓣ][1] + +Creates an array composed of the own enumerable property values of `object`. + +#### Arguments +1. `object` *(Object)*: The object to inspect. + +#### Returns +*(Array)*: Returns a new array of property values. + +#### Example +```js +_.values({ 'one': 1, 'two': 2, 'three': 3 }); +// => [1, 2, 3] +``` + +* * * + + + + + + + + + +## `“Utilities” Methods` + + + +### `_.escape(string)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3504 "View in source") [Ⓣ][1] + +Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. + +#### Arguments +1. `string` *(String)*: The string to escape. + +#### Returns +*(String)*: Returns the escaped string. + +#### Example +```js +_.escape('Moe, Larry & Curly'); +// => "Moe, Larry & Curly" +``` + +* * * + + + + + + +### `_.identity(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3524 "View in source") [Ⓣ][1] + +This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. + +#### Arguments +1. `value` *(Mixed)*: Any value. + +#### Returns +*(Mixed)*: Returns `value`. + +#### Example +```js +var moe = { 'name': 'moe' }; +moe === _.identity(moe); +// => true +``` + +* * * + + + + + + +### `_.mixin(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3550 "View in source") [Ⓣ][1] + +Adds functions properties of `object` to the `lodash` function and chainable wrapper. + +#### Arguments +1. `object` *(Object)*: The object of function properties to add to `lodash`. + +#### Example +```js +_.mixin({ + 'capitalize': function(string) { + return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); + } +}); + +_.capitalize('larry'); +// => 'Larry' + +_('curly').capitalize(); +// => 'Curly' +``` + +* * * + + + + + + +### `_.noConflict()` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3581 "View in source") [Ⓣ][1] + +Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. + +#### Returns +*(Function)*: Returns the `lodash` function. + +#### Example +```js +var lodash = _.noConflict(); +``` + +* * * + + + + + + +### `_.random([min=0, max=1])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3604 "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. + +#### Arguments +1. `[min=0]` *(Number)*: The minimum possible value. +2. `[max=1]` *(Number)*: The maximum possible value. + +#### Returns +*(Number)*: Returns a random number. + +#### Example +```js +_.random(0, 5); +// => a number between 1 and 5 + +_.random(5); +// => also a number between 1 and 5 +``` + +* * * + + + + + + +### `_.result(object, property)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3643 "View in source") [Ⓣ][1] + +Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. + +#### Arguments +1. `object` *(Object)*: The object to inspect. +2. `property` *(String)*: The property to get the value of. + +#### Returns +*(Mixed)*: Returns the resolved value. + +#### Example +```js +var object = { + 'cheese': 'crumpets', + 'stuff': function() { + return 'nonsense'; + } +}; + +_.result(object, 'cheese'); +// => 'crumpets' + +_.result(object, 'stuff'); +// => 'nonsense' +``` + +* * * + + + + ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3728 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3713 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: In the development build `_.template` utilizes sourceURLs for easier debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. See http://developer.chrome.com/trunk/extensions/sandboxingEval.html @@ -2570,35 +2908,10 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ - - -### `_.throttle(func, wait)` -# [Ⓢ](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. - -#### Arguments -1. `func` *(Function)*: The function to throttle. -2. `wait` *(Number)*: The number of milliseconds to throttle executions to. - -#### Returns -*(Function)*: Returns the new throttled function. - -#### Example -```js -var throttled = _.throttle(updatePosition, 100); -jQuery(window).on('scroll', throttled); -``` - -* * * - - - - ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3847 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3832 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -2627,34 +2940,10 @@ _.times(3, function(n) { this.cast(n); }, mage); - - -### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2345 "View in source") [Ⓣ][1] - -Converts the `collection`, to an array. - -#### Arguments -1. `collection` *(Array|Object|String)*: The collection to convert. - -#### Returns -*(Array)*: Returns the new converted array. - -#### Example -```js -(function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); -// => [2, 3, 4] -``` - -* * * - - - - ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3872 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3857 "View in source") [Ⓣ][1] Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -2675,73 +2964,10 @@ _.unescape('Moe, Larry & Curly'); - - -### `_.union([array1, array2, ...])` -# [Ⓢ](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. `===`. - -#### Arguments -1. `[array1, array2, ...]` *(Array)*: Arrays to process. - -#### Returns -*(Array)*: Returns a new array of unique values, in order, that are present in one or more of the arrays. - -#### Example -```js -_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); -// => [1, 2, 3, 101, 10] -``` - -* * * - - - - - - -### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](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)*. - -#### Aliases -*unique* - -#### Arguments -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 -*(Array)*: Returns a duplicate-value-free array. - -#### Example -```js -_.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] -``` - -* * * - - - - ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3890 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3875 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2762,199 +2988,29 @@ _.uniqueId('contact_'); + + + -### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1858 "View in source") [Ⓣ][1] +## `Properties` -Creates an array composed of the own enumerable property values of `object`. + -#### Arguments -1. `object` *(Object)*: The object to inspect. +### `_.VERSION` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3980 "View in source") [Ⓣ][1] -#### Returns -*(Array)*: Returns a new array of property values. - -#### Example -```js -_.values({ 'one': 1, 'two': 2, 'three': 3 }); -// => [1, 2, 3] -``` +*(String)*: The semantic version number. * * * - - -### `_.where(collection, properties)` -# [Ⓢ](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`. - -#### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `properties` *(Object)*: The object of properties/values to filter by. - -#### Returns -*(Array)*: Returns a new array of elements that contain the given `properties`. - -#### Example -```js -var stooges = [ - { 'name': 'moe', 'age': 40 }, - { 'name': 'larry', 'age': 50 }, - { 'name': 'curly', 'age': 60 } -]; - -_.where(stooges, { 'age': 40 }); -// => [{ 'name': 'moe', 'age': 40 }] -``` - -* * * - - - - - - -### `_.without(array [, value1, value2, ...])` -# [Ⓢ](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. `===`. - -#### Arguments -1. `array` *(Array)*: The array to filter. -2. `[value1, value2, ...]` *(Mixed)*: Values to remove. - -#### Returns -*(Array)*: Returns a new filtered array. - -#### Example -```js -_.without([1, 2, 1, 0, 3, 1, 4], 0, 1); -// => [2, 3, 4] -``` - -* * * - - - - - - -### `_.wrap(value, wrapper)` -# [Ⓢ](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. - -#### Arguments -1. `value` *(Mixed)*: The value to wrap. -2. `wrapper` *(Function)*: The wrapper function. - -#### Returns -*(Function)*: Returns the new function. - -#### Example -```js -var hello = function(name) { return 'hello: ' + name; }; -hello = _.wrap(hello, function(func) { - return 'before, ' + func('moe') + ', after'; -}); -hello(); -// => 'before, hello: moe, after' -``` - -* * * - - - - - - -### `_.zip([array1, array2, ...])` -# [Ⓢ](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. - -#### Arguments -1. `[array1, array2, ...]` *(Array)*: Arrays to process. - -#### Returns -*(Array)*: Returns a new array of grouped elements. - -#### Example -```js -_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); -// => [['moe', 30, true], ['larry', 40, false], ['curly', 50, false]] -``` - -* * * - - - - - - - - - -## `_.prototype` - - - -### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3965 "View in source") [Ⓣ][1] - -Enables method chaining on the wrapper object. - -#### Returns -*(Mixed)*: Returns the wrapper object. - -#### Example -```js -_([1, 2, 3]).value(); -// => [1, 2, 3] -``` - -* * * - - - - - - -### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3982 "View in source") [Ⓣ][1] - -Extracts the wrapped value. - -#### Returns -*(Mixed)*: Returns the wrapped value. - -#### Example -```js -_([1, 2, 3]).value(); -// => [1, 2, 3] -``` - -* * * - - - - - - - - - -## `_.templateSettings` - ### `_.templateSettings` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L262 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L263 "View in source") [Ⓣ][1] *(Object)*: By default, the template delimiters used by Lo-Dash are similar to those in embedded Ruby *(ERB)*. Change the following template settings to use alternative delimiters. @@ -2966,7 +3022,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.escape` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L271 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L272 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to be HTML-escaped. @@ -2978,7 +3034,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.evaluate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L280 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L281 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect code to be evaluated. @@ -2990,7 +3046,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.interpolate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L289 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L290 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to inject. @@ -3002,7 +3058,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.variable` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L298 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L299 "View in source") [Ⓣ][1] *(String)*: Used to reference the data object in the template text. @@ -3017,4 +3073,4 @@ _([1, 2, 3]).value(); - [1]: #_ "Jump back to the TOC." \ No newline at end of file + [1]: #Arrays "Jump back to the TOC." \ No newline at end of file diff --git a/doc/parse.php b/doc/parse.php index 240010d5e..09b63c7b0 100644 --- a/doc/parse.php +++ b/doc/parse.php @@ -20,9 +20,10 @@ // generate Markdown $markdown = docdown(array( - 'path' => '../' . $file, + 'path' => '../' . $file, 'title' => 'Lo-Dash v0.8.1', - 'url' => 'https://github.com/bestiejs/lodash/blob/master/lodash.js' + 'toc' => 'categories', + 'url' => 'https://github.com/bestiejs/lodash/blob/master/lodash.js' )); // save to a .md file diff --git a/lodash.js b/lodash.js index f5c91c982..665c60e0a 100644 --- a/lodash.js +++ b/lodash.js @@ -235,6 +235,7 @@ * * @name _ * @constructor + * @category Chaining * @param {Mixed} value The value to wrap in a `lodash` instance. * @returns {Object} Returns a `lodash` instance. */ diff --git a/vendor/docdown/docdown.php b/vendor/docdown/docdown.php index 6a960d49e..8db4ef4f6 100644 --- a/vendor/docdown/docdown.php +++ b/vendor/docdown/docdown.php @@ -8,7 +8,7 @@ require(dirname(__FILE__) . '/src/DocDown/Generator.php'); /** * Generates Markdown from JSDoc entries in a given file. - * + * * @param {Array} [$options=array()] The options array. * @returns {String} The generated Markdown. * @example diff --git a/vendor/docdown/src/DocDown/Alias.php b/vendor/docdown/src/DocDown/Alias.php index 6a873c0af..1ca539d71 100644 --- a/vendor/docdown/src/DocDown/Alias.php +++ b/vendor/docdown/src/DocDown/Alias.php @@ -22,7 +22,7 @@ class Alias { * @param {String} $name The alias name. * @param {Object} $owner The alias owner. */ - public function __construct($name, $owner) { + public function __construct( $name, $owner ) { $this->owner = $owner; $this->_name = $name; $this->_call = $owner->getCall(); diff --git a/vendor/docdown/src/DocDown/Entry.php b/vendor/docdown/src/DocDown/Entry.php index c61f9e852..933bf4005 100644 --- a/vendor/docdown/src/DocDown/Entry.php +++ b/vendor/docdown/src/DocDown/Entry.php @@ -166,6 +166,8 @@ class Entry { preg_match('#\* *@category\s+([^\n]+)#', $this->entry, $result); if (count($result)) { $result = trim(preg_replace('/(?:^|\n)\s*\* ?/', ' ', $result[1])); + } else { + $result = $this->getType() == 'Function' ? 'Methods' : 'Properties'; } $this->_category = $result; return $result; diff --git a/vendor/docdown/src/DocDown/Generator.php b/vendor/docdown/src/DocDown/Generator.php index e9ca1c27a..51e7416bf 100644 --- a/vendor/docdown/src/DocDown/Generator.php +++ b/vendor/docdown/src/DocDown/Generator.php @@ -7,6 +7,15 @@ require(dirname(__FILE__) . "/Entry.php"); */ class Generator { + /** + * The HTML for the close tag. + * + * @static + * @memberOf Generator + * @type String + */ + public $closeTag = "\n\n"; + /** * An array of JSDoc entries. * @@ -15,6 +24,15 @@ class Generator { */ public $entries = array(); + /** + * The HTML for the open tag. + * + * @static + * @memberOf Generator + * @type String + */ + public $openTag = "\n\n"; + /** * An options array used to configure the generator. * @@ -24,7 +42,7 @@ class Generator { public $options = array(); /** - * The entire file's source code. + * The file's source code. * * @memberOf Generator * @type String @@ -86,7 +104,7 @@ class Generator { * @param {String} $string The string to format. * @returns {String} The formatted string. */ - private static function format($string) { + private static function format( $string ) { $counter = 0; // tokenize inline code snippets @@ -121,7 +139,7 @@ class Generator { * @param {Array|Object} $object The template object. * @returns {String} The modified string. */ - private static function interpolate($string, $object) { + private static function interpolate( $string, $object ) { preg_match_all('/#\{([^}]+)\}/', $string, $tokens); $tokens = array_unique(array_pop($tokens)); @@ -149,6 +167,63 @@ class Generator { /*--------------------------------------------------------------------------*/ + /** + * Adds the given `$entries` to the `$result` array. + * + * @private + * @memberOf Generator + * @param {Array} $result The result array to modify. + * @param {Array} $entries The entries to add to the `$result`. + */ + private function addEntries( &$result, $entries ) { + foreach ($entries as $entry) { + // skip aliases + if ($entry->isAlias()) { + continue; + } + // name and description + array_push( + $result, + $this->openTag, + Generator::interpolate("### `#{member}#{separator}#{call}`\n# [Ⓢ](#{href} \"View in source\") [Ⓣ][1]\n\n#{desc}", $entry) + ); + + // @alias + if (count($aliases = $entry->getAliases())) { + array_push($result, '', '#### Aliases'); + foreach ($aliases as $index => $alias) { + $aliases[$index] = $alias->getName(); + } + $result[] = '*' . implode(', ', $aliases) . '*'; + } + // @param + if (count($params = $entry->getParams())) { + array_push($result, '', '#### Arguments'); + foreach ($params as $index => $param) { + $result[] = Generator::interpolate('#{num}. `#{name}` (#{type}): #{desc}', array( + 'desc' => $param[2], + 'name' => $param[1], + 'num' => $index + 1, + 'type' => $param[0] + )); + } + } + // @returns + if (count($returns = $entry->getReturns())) { + array_push( + $result, '', + '#### Returns', + Generator::interpolate('(#{type}): #{desc}', array('desc' => $returns[1], 'type' => $returns[0])) + ); + } + // @example + if ($example = $entry->getExample()) { + array_push($result, '', '#### Example', $example); + } + array_push($result, "\n* * *", $this->closeTag); + } + } + /** * Resolves the entry's hash used to navigate the documentation. * @@ -204,10 +279,11 @@ class Generator { */ public function generate() { $api = array(); + $byCategory = @$this->options['toc'] == 'categories'; $categories = array(); + $closeTag = $this->closeTag; $compiling = false; - $openTag = "\n\n"; - $closeTag = "\n\n"; + $openTag = $this->openTag; $result = array('# ' . $this->options['title']); $toc = 'toc'; @@ -231,18 +307,6 @@ class Generator { $api[$member]->plugin = array(); } - // 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))) { @@ -274,6 +338,26 @@ class Generator { } } + // add properties to each entry + foreach ($api as $key => $entry) { + $entry->hash = $this->getHash($entry); + $entry->href = $this->getLineUrl($entry); + + $member = $entry->getMembers(0); + $member = ($member ? $member . ($entry->isPlugin() ? '.prototype.' : '.') : '') . $entry->getName(); + $entry->member = preg_replace('/' . $entry->getName() . '$/', '', $member); + + // add properties to static and plugin sub-entries + foreach (array('static', 'plugin') as $kind) { + foreach ($entry->{$kind} as $subentry) { + $subentry->hash = $this->getHash($subentry); + $subentry->href = $this->getLineUrl($subentry); + $subentry->member = $member; + $subentry->separator = $this->getSeparator($subentry); + } + } + } + /*------------------------------------------------------------------------*/ // custom sort for root level entries @@ -323,48 +407,89 @@ class Generator { /*------------------------------------------------------------------------*/ + // add categories + foreach ($api as $key => $entry) { + $categories[$entry->getCategory()][] = $entry; + foreach (array('static', 'plugin') as $kind) { + foreach ($entry->{$kind} as $subentry) { + $categories[$subentry->getCategory()][] = $subentry; + } + } + } + + // sort categories + ksort($categories); + + foreach(array('Methods', 'Properties') as $category) { + if (isset($categories[$category])) { + $entries = $categories[$category]; + unset($categories[$category]); + $categories[$category] = $entries; + } + } + + /*------------------------------------------------------------------------*/ + // compile TOC $result[] = $openTag; - foreach ($api as $key => $entry) { - $entry->hash = $this->getHash($entry); - $entry->href = $this->getLineUrl($entry); - - $member = $entry->getMembers(0); - $member = ($member ? $member . ($entry->isPlugin() ? '.prototype.' : '.') : '') . $entry->getName(); - - $entry->member = preg_replace('/' . $entry->getName() . '$/', '', $member); - - $compiling = $compiling ? ($result[] = $closeTag) : true; - - // assign TOC hash - if (count($result) == 2) { - $toc = $member; - } - - // add root entry - array_push( - $result, - $openTag, '## ' . (count($result) == 2 ? '' : '') . '`' . $member . '`', - Generator::interpolate('* [`' . $member . '`](##{hash})', $entry) - ); - - // add static and plugin sub-entries - foreach (array('static', 'plugin') as $kind) { - if ($kind == 'plugin' && count($entry->plugin)) { - array_push( - $result, - $closeTag, - $openTag, - '## `' . $member . ($entry->isCtor() ? '.prototype`' : '`') - ); + // compile TOC by categories + if ($byCategory) { + foreach ($categories as $key => $entries) { + if ($compiling) { + $result[] = $closeTag; + } else { + $compiling = true; } - foreach ($entry->{$kind} as $subentry) { - $subentry->hash = $this->getHash($subentry); - $subentry->href = $this->getLineUrl($subentry); - $subentry->member = $member; - $subentry->separator = $this->getSeparator($subentry); - $result[] = Generator::interpolate('* [`#{member}#{separator}#{name}`](##{hash})', $subentry); + // assign TOC hash + if (count($result) == 2) { + $toc = $key; + } + // add category + array_push( + $result, + $openTag, '## ' . (count($result) == 2 ? '' : '') . '`' . $key . '`' + ); + // add entries + foreach ($entries as $entry) { + $result[] = Generator::interpolate('* [`#{member}#{separator}#{name}`](##{hash})', $entry); + } + } + } + // compile TOC by namespace + else { + foreach ($api as $key => $entry) { + if ($compiling) { + $result[] = $closeTag; + } else { + $compiling = true; + } + $member = $entry->member . $entry->getName(); + + // assign TOC hash + if (count($result) == 2) { + $toc = $member; + } + // add root entry + array_push( + $result, + $openTag, '## ' . (count($result) == 2 ? '' : '') . '`' . $member . '`', + Generator::interpolate('* [`' . $member . '`](##{hash})', $entry) + ); + + // add static and plugin sub-entries + foreach (array('static', 'plugin') as $kind) { + if ($kind == 'plugin' && count($entry->plugin)) { + array_push( + $result, + $closeTag, + $openTag, + '## `' . $member . ($entry->isCtor() ? '.prototype`' : '`') + ); + } + foreach ($entry->{$kind} as $subentry) { + $result[] = Generator::interpolate('* [`' . $member . '#{separator}#{name}`](##{hash})', $subentry); + } } } } @@ -377,81 +502,51 @@ class Generator { $compiling = false; $result[] = $openTag; - foreach ($api as $entry) { - // skip aliases - if ($entry->isAlias()) { - continue; - } - - // add root entry - $member = $entry->member . $entry->getName(); - $compiling = $compiling ? ($result[] = $closeTag) : true; - - array_push($result, $openTag, '## `' . $member . '`'); - - foreach (array($entry, 'static', 'plugin') as $kind) { - $subentries = is_string($kind) ? $entry->{$kind} : array($kind); - - // title - if ($kind != 'static' && $entry->getType() != 'Object' && - count($subentries) && $subentries[0] != $kind) { - if ($kind == 'plugin') { - $result[] = $closeTag; - } - array_push( - $result, - $openTag, - '## `' . $member . ($kind == 'plugin' ? '.prototype`' : '`') - ); + if ($byCategory) { + foreach ($categories as $key => $entries) { + if ($compiling) { + $result[] = $closeTag; + } else { + $compiling = true; } + if ($key != 'Methods' && $key != 'Properties') { + $key = '“' . $key . '” Methods'; + } + array_push($result, $openTag, '## `' . $key . '`'); + $this->addEntries($result, $entries); + } + } + else { + foreach ($api as $entry) { + // skip aliases + if ($entry->isAlias()) { + continue; + } + if ($compiling) { + $result[] = $closeTag; + } else { + $compiling = true; + } + // add root entry name + $member = $entry->member . $entry->getName(); + array_push($result, $openTag, '## `' . $member . '`'); - // body - foreach ($subentries as $subentry) { - // skip aliases - if ($subentry->isAlias()) { - continue; - } + foreach (array($entry, 'static', 'plugin') as $kind) { + $subentries = is_string($kind) ? $entry->{$kind} : array($kind); - // description - array_push( - $result, - $openTag, - Generator::interpolate("### `#{member}#{separator}#{call}`\n# [Ⓢ](#{href} \"View in source\") [Ⓣ][1]\n\n#{desc}", $subentry) - ); - - // @alias - if (count($aliases = $subentry->getAliases())) { - array_push($result, '', '#### Aliases'); - foreach ($aliases as $index => $alias) { - $aliases[$index] = $alias->getName(); + // add sub-entry name + if ($kind != 'static' && $entry->getType() != 'Object' && + count($subentries) && $subentries[0] != $kind) { + if ($kind == 'plugin') { + $result[] = $closeTag; } - $result[] = '*' . implode(', ', $aliases) . '*'; - } - // @param - if (count($params = $subentry->getParams())) { - array_push($result, '', '#### Arguments'); - foreach ($params as $index => $param) { - $result[] = Generator::interpolate('#{num}. `#{name}` (#{type}): #{desc}', array( - 'desc' => $param[2], - 'name' => $param[1], - 'num' => $index + 1, - 'type' => $param[0] - )); - } - } - // @returns - if (count($returns = $subentry->getReturns())) { array_push( - $result, '', - '#### Returns', - Generator::interpolate('(#{type}): #{desc}', array('desc' => $returns[1], 'type' => $returns[0])) + $result, + $openTag, + '## `' . $member . ($kind == 'plugin' ? '.prototype`' : '`') ); } - // @example - if ($example = $subentry->getExample()) { - array_push($result, '', '#### Example', $example); - } - array_push($result, "\n* * *", $closeTag); + $this->addEntries($result, $subentries); } } }