From 24a4285b708bd3b4bfc4893e3b78473a7039ad3f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 31 Jan 2016 18:48:02 -0800 Subject: [PATCH] Bump to v4.2.0. --- README.md | 10 +- _Hash.js | 2 +- _Map.js | 5 +- _Reflect.js | 4 +- _Set.js | 5 +- _Symbol.js | 4 +- _Uint8Array.js | 4 +- _WeakMap.js | 5 +- _apply.js | 4 +- _assignInDefaults.js | 2 +- _assignValue.js | 2 +- _assocDelete.js | 2 +- _baseHas.js | 2 +- _baseIsEqualDeep.js | 2 +- _baseKeysIn.js | 2 +- _basePullAllBy.js | 2 +- _basePullAt.js | 2 +- _baseSum.js | 2 +- _checkGlobal.js | 12 ++ _createBaseWrapper.js | 5 +- _createCurryWrapper.js | 5 +- _createHybridWrapper.js | 5 +- _createPartialWrapper.js | 5 +- _getFuncName.js | 2 +- _getTag.js | 4 +- _hashGet.js | 2 +- _hashHas.js | 2 +- _initCloneArray.js | 2 +- _isPrototype.js | 2 +- _root.js | 35 +++++ array.js | 1 - attempt.js | 6 +- bind.js | 2 +- bindKey.js | 2 +- collection.js | 1 + core.js | 59 ++++---- countBy.js | 2 +- curry.js | 2 +- curryRight.js | 2 +- debounce.js | 8 +- defer.js | 2 +- differenceBy.js | 2 +- dropRightWhile.js | 6 +- dropWhile.js | 6 +- every.js | 6 +- filter.js | 6 +- find.js | 6 +- findIndex.js | 6 +- findKey.js | 6 +- findLastIndex.js | 6 +- findLastKey.js | 6 +- flatMap.js | 20 ++- fp/_baseConvert.js | 29 ++-- fp/_mapping.js | 129 +++++++++-------- fp/_util.js | 3 +- fp/assoc.js | 1 + fp/assocPath.js | 1 + fp/dissoc.js | 2 +- fp/dissocPath.js | 1 + fp/partial.js | 3 +- fp/partialRight.js | 3 +- fp/spread.js | 3 +- groupBy.js | 4 +- indexOf.js | 5 +- intersectionBy.js | 2 +- invertBy.js | 2 +- isArguments.js | 2 +- isBoolean.js | 2 +- isDate.js | 2 +- isEmpty.js | 2 +- isError.js | 2 +- isFinite.js | 4 +- isFunction.js | 2 +- isNative.js | 4 +- isNumber.js | 2 +- isPlainObject.js | 4 +- isRegExp.js | 2 +- isString.js | 2 +- isSymbol.js | 2 +- isTypedArray.js | 2 +- iteratee.js | 12 +- join.js | 2 +- keysIn.js | 2 +- lastIndexOf.js | 2 +- lodash.js | 295 ++++++++++++++++++++------------------- map.js | 2 +- mapValues.js | 2 +- maxBy.js | 2 +- memoize.js | 4 +- mergeWith.js | 2 + minBy.js | 2 +- orderBy.js | 2 +- package.json | 2 +- parseInt.js | 5 +- partial.js | 2 +- partialRight.js | 2 +- partition.js | 6 +- pickBy.js | 2 +- random.js | 2 +- reject.js | 6 +- reverse.js | 2 +- set.js | 2 + setWith.js | 2 + some.js | 6 +- sortedIndexBy.js | 2 +- sortedLastIndexBy.js | 2 +- sortedUniqBy.js | 2 +- spread.js | 25 +++- sumBy.js | 2 +- takeRightWhile.js | 6 +- takeWhile.js | 6 +- tap.js | 8 +- template.js | 24 ++-- throttle.js | 6 +- thru.js | 2 + toNumber.js | 2 +- unionBy.js | 2 +- uniqBy.js | 2 +- unset.js | 2 + wrapperChain.js | 4 +- wrapperLodash.js | 6 +- xorBy.js | 2 +- 122 files changed, 561 insertions(+), 439 deletions(-) create mode 100644 _checkGlobal.js create mode 100644 _root.js create mode 100644 fp/assoc.js create mode 100644 fp/assocPath.js create mode 100644 fp/dissocPath.js diff --git a/README.md b/README.md index d87bd2c48..71bfe82c7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash v4.1.0 +# lodash v4.2.0 The [lodash](https://lodash.com/) library exported as [Node.js](https://nodejs.org/) modules. @@ -28,7 +28,7 @@ var chunk = require('lodash/chunk'); var extend = require('lodash/fp/extend'); ``` -See the [package source](https://github.com/lodash/lodash/tree/4.1.0-npm) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.2.0-npm) for more details. **Note:**
Don’t assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.
@@ -36,9 +36,9 @@ Install [n_](https://www.npmjs.com/package/n_) for a REPL that includes lodash b ## Module formats -Lodash is also available in a variety of other builds & module formats. +Lodash is available in a variety of other builds & module formats. - * [lodash](https://www.npmjs.com/package/lodash) & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) packages + * [lodash](https://www.npmjs.com/package/lodash) & [per method packages](https://www.npmjs.com/browse/keyword/lodash-modularized) * [lodash-amd](https://www.npmjs.com/package/lodash-amd) * [lodash-es](https://www.npmjs.com/package/lodash-es) & [babel-plugin-lodash](https://www.npmjs.com/package/babel-plugin-lodash) @@ -52,5 +52,5 @@ Lodash is also available in a variety of other builds & module formats. ## Support -Tested in Chrome 46-47, Firefox 42-43, IE 9-11, Edge 13, Safari 8-9, Node.js 0.10, 0.12, 4, & 5, & PhantomJS 1.9.8. +Tested in Chrome 47-48, Firefox 43-44, IE 9-11, Edge 13, Safari 8-9, Node.js 0.10, 0.12, 4, & 5, & PhantomJS 1.9.8. Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available. Special thanks to [Sauce Labs](https://saucelabs.com/) for providing automated browser testing. diff --git a/_Hash.js b/_Hash.js index e7792aafb..25108ad7f 100644 --- a/_Hash.js +++ b/_Hash.js @@ -1,7 +1,7 @@ var nativeCreate = require('./_nativeCreate'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Creates an hash object. diff --git a/_Map.js b/_Map.js index dc7e604e5..b73f29a0f 100644 --- a/_Map.js +++ b/_Map.js @@ -1,6 +1,7 @@ -var getNative = require('./_getNative'); +var getNative = require('./_getNative'), + root = require('./_root'); /* Built-in method references that are verified to be native. */ -var Map = getNative(global, 'Map'); +var Map = getNative(root, 'Map'); module.exports = Map; diff --git a/_Reflect.js b/_Reflect.js index b923b8197..1de7475b8 100644 --- a/_Reflect.js +++ b/_Reflect.js @@ -1,4 +1,6 @@ +var root = require('./_root'); + /** Built-in value references. */ -var Reflect = global.Reflect; +var Reflect = root.Reflect; module.exports = Reflect; diff --git a/_Set.js b/_Set.js index a57920070..b3c8dcbf0 100644 --- a/_Set.js +++ b/_Set.js @@ -1,6 +1,7 @@ -var getNative = require('./_getNative'); +var getNative = require('./_getNative'), + root = require('./_root'); /* Built-in method references that are verified to be native. */ -var Set = getNative(global, 'Set'); +var Set = getNative(root, 'Set'); module.exports = Set; diff --git a/_Symbol.js b/_Symbol.js index 9f903d2a8..a013f7c5b 100644 --- a/_Symbol.js +++ b/_Symbol.js @@ -1,4 +1,6 @@ +var root = require('./_root'); + /** Built-in value references. */ -var Symbol = global.Symbol; +var Symbol = root.Symbol; module.exports = Symbol; diff --git a/_Uint8Array.js b/_Uint8Array.js index d527c23f0..2fb30e157 100644 --- a/_Uint8Array.js +++ b/_Uint8Array.js @@ -1,4 +1,6 @@ +var root = require('./_root'); + /** Built-in value references. */ -var Uint8Array = global.Uint8Array; +var Uint8Array = root.Uint8Array; module.exports = Uint8Array; diff --git a/_WeakMap.js b/_WeakMap.js index fd917f8f3..567f86c61 100644 --- a/_WeakMap.js +++ b/_WeakMap.js @@ -1,6 +1,7 @@ -var getNative = require('./_getNative'); +var getNative = require('./_getNative'), + root = require('./_root'); /* Built-in method references that are verified to be native. */ -var WeakMap = getNative(global, 'WeakMap'); +var WeakMap = getNative(root, 'WeakMap'); module.exports = WeakMap; diff --git a/_apply.js b/_apply.js index e371dab9e..22d4f8a70 100644 --- a/_apply.js +++ b/_apply.js @@ -5,11 +5,11 @@ * @private * @param {Function} func The function to invoke. * @param {*} thisArg The `this` binding of `func`. - * @param {...*} [args] The arguments to invoke `func` with. + * @param {...*} args The arguments to invoke `func` with. * @returns {*} Returns the result of `func`. */ function apply(func, thisArg, args) { - var length = args ? args.length : 0; + var length = args.length; switch (length) { case 0: return func.call(thisArg); case 1: return func.call(thisArg, args[0]); diff --git a/_assignInDefaults.js b/_assignInDefaults.js index 6608d42fc..ea6b0e358 100644 --- a/_assignInDefaults.js +++ b/_assignInDefaults.js @@ -1,7 +1,7 @@ var eq = require('./eq'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/_assignValue.js b/_assignValue.js index 70e89b9b7..7563b604e 100644 --- a/_assignValue.js +++ b/_assignValue.js @@ -1,7 +1,7 @@ var eq = require('./eq'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/_assocDelete.js b/_assocDelete.js index 7c6bff62d..709a04a9c 100644 --- a/_assocDelete.js +++ b/_assocDelete.js @@ -1,7 +1,7 @@ var assocIndexOf = require('./_assocIndexOf'); /** Used for built-in method references. */ -var arrayProto = global.Array.prototype; +var arrayProto = Array.prototype; /** Built-in value references. */ var splice = arrayProto.splice; diff --git a/_baseHas.js b/_baseHas.js index 003ac132a..b3932069d 100644 --- a/_baseHas.js +++ b/_baseHas.js @@ -1,5 +1,5 @@ /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/_baseIsEqualDeep.js b/_baseIsEqualDeep.js index b72b4e66a..54eca3506 100644 --- a/_baseIsEqualDeep.js +++ b/_baseIsEqualDeep.js @@ -16,7 +16,7 @@ var argsTag = '[object Arguments]', objectTag = '[object Object]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/_baseKeysIn.js b/_baseKeysIn.js index a9f30e1b1..7455fd889 100644 --- a/_baseKeysIn.js +++ b/_baseKeysIn.js @@ -2,7 +2,7 @@ var Reflect = require('./_Reflect'), iteratorToArray = require('./_iteratorToArray'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Built-in value references. */ var enumerate = Reflect ? Reflect.enumerate : undefined, diff --git a/_basePullAllBy.js b/_basePullAllBy.js index eba83b0f1..00167fad6 100644 --- a/_basePullAllBy.js +++ b/_basePullAllBy.js @@ -2,7 +2,7 @@ var arrayMap = require('./_arrayMap'), baseIndexOf = require('./_baseIndexOf'); /** Used for built-in method references. */ -var arrayProto = global.Array.prototype; +var arrayProto = Array.prototype; /** Built-in value references. */ var splice = arrayProto.splice; diff --git a/_basePullAt.js b/_basePullAt.js index 134281db4..206b1965f 100644 --- a/_basePullAt.js +++ b/_basePullAt.js @@ -5,7 +5,7 @@ var baseToPath = require('./_baseToPath'), parent = require('./_parent'); /** Used for built-in method references. */ -var arrayProto = global.Array.prototype; +var arrayProto = Array.prototype; /** Built-in value references. */ var splice = arrayProto.splice; diff --git a/_baseSum.js b/_baseSum.js index 980f41b37..348b5e8c0 100644 --- a/_baseSum.js +++ b/_baseSum.js @@ -17,7 +17,7 @@ function baseSum(array, iteratee) { result = result === undefined ? current : (result + current); } } - return length ? result : 0; + return result; } module.exports = baseSum; diff --git a/_checkGlobal.js b/_checkGlobal.js new file mode 100644 index 000000000..b0ea47e12 --- /dev/null +++ b/_checkGlobal.js @@ -0,0 +1,12 @@ +/** + * Checks if `value` is a global object. + * + * @private + * @param {*} value The value to check. + * @returns {null|Object} Returns `value` if it's a global object, else `null`. + */ +function checkGlobal(value) { + return (value && value.Object === Object) ? value : null; +} + +module.exports = checkGlobal; diff --git a/_createBaseWrapper.js b/_createBaseWrapper.js index f1e81c35b..fd3bb9a69 100644 --- a/_createBaseWrapper.js +++ b/_createBaseWrapper.js @@ -1,4 +1,5 @@ -var createCtorWrapper = require('./_createCtorWrapper'); +var createCtorWrapper = require('./_createCtorWrapper'), + root = require('./_root'); /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1; @@ -18,7 +19,7 @@ function createBaseWrapper(func, bitmask, thisArg) { Ctor = createCtorWrapper(func); function wrapper() { - var fn = (this && this !== global && this instanceof wrapper) ? Ctor : func; + var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; return fn.apply(isBind ? thisArg : this, arguments); } return wrapper; diff --git a/_createCurryWrapper.js b/_createCurryWrapper.js index c48d0df99..2fc9f7e6c 100644 --- a/_createCurryWrapper.js +++ b/_createCurryWrapper.js @@ -2,7 +2,8 @@ var apply = require('./_apply'), createCtorWrapper = require('./_createCtorWrapper'), createHybridWrapper = require('./_createHybridWrapper'), createRecurryWrapper = require('./_createRecurryWrapper'), - replaceHolders = require('./_replaceHolders'); + replaceHolders = require('./_replaceHolders'), + root = require('./_root'); /** * Creates a function that wraps `func` to enable currying. @@ -20,7 +21,7 @@ function createCurryWrapper(func, bitmask, arity) { var length = arguments.length, index = length, args = Array(length), - fn = (this && this !== global && this instanceof wrapper) ? Ctor : func, + fn = (this && this !== root && this instanceof wrapper) ? Ctor : func, placeholder = wrapper.placeholder; while (index--) { diff --git a/_createHybridWrapper.js b/_createHybridWrapper.js index b8d587fa1..7d34c7491 100644 --- a/_createHybridWrapper.js +++ b/_createHybridWrapper.js @@ -3,7 +3,8 @@ var composeArgs = require('./_composeArgs'), createCtorWrapper = require('./_createCtorWrapper'), createRecurryWrapper = require('./_createRecurryWrapper'), reorder = require('./_reorder'), - replaceHolders = require('./_replaceHolders'); + replaceHolders = require('./_replaceHolders'), + root = require('./_root'); /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1, @@ -73,7 +74,7 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials if (isAry && ary < args.length) { args.length = ary; } - if (this && this !== global && this instanceof wrapper) { + if (this && this !== root && this instanceof wrapper) { fn = Ctor || createCtorWrapper(fn); } return fn.apply(thisBinding, args); diff --git a/_createPartialWrapper.js b/_createPartialWrapper.js index cd4e26986..1fc3a9b01 100644 --- a/_createPartialWrapper.js +++ b/_createPartialWrapper.js @@ -1,5 +1,6 @@ var apply = require('./_apply'), - createCtorWrapper = require('./_createCtorWrapper'); + createCtorWrapper = require('./_createCtorWrapper'), + root = require('./_root'); /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1; @@ -26,7 +27,7 @@ function createPartialWrapper(func, bitmask, thisArg, partials) { leftIndex = -1, leftLength = partials.length, args = Array(leftLength + argsLength), - fn = (this && this !== global && this instanceof wrapper) ? Ctor : func; + fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; while (++leftIndex < leftLength) { args[leftIndex] = partials[leftIndex]; diff --git a/_getFuncName.js b/_getFuncName.js index 65bb80178..21e15b337 100644 --- a/_getFuncName.js +++ b/_getFuncName.js @@ -1,7 +1,7 @@ var realNames = require('./_realNames'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/_getTag.js b/_getTag.js index 297e33208..ceacc4fa1 100644 --- a/_getTag.js +++ b/_getTag.js @@ -7,10 +7,10 @@ var mapTag = '[object Map]', setTag = '[object Set]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to resolve the decompiled source of functions. */ -var funcToString = global.Function.prototype.toString; +var funcToString = Function.prototype.toString; /** * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) diff --git a/_hashGet.js b/_hashGet.js index d8610c9e9..ba509b6f7 100644 --- a/_hashGet.js +++ b/_hashGet.js @@ -4,7 +4,7 @@ var nativeCreate = require('./_nativeCreate'); var HASH_UNDEFINED = '__lodash_hash_undefined__'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/_hashHas.js b/_hashHas.js index 2d658b979..3bbff4843 100644 --- a/_hashHas.js +++ b/_hashHas.js @@ -1,7 +1,7 @@ var nativeCreate = require('./_nativeCreate'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/_initCloneArray.js b/_initCloneArray.js index a9b850d06..aef02120e 100644 --- a/_initCloneArray.js +++ b/_initCloneArray.js @@ -1,5 +1,5 @@ /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/_isPrototype.js b/_isPrototype.js index 3459b4968..0f29498d4 100644 --- a/_isPrototype.js +++ b/_isPrototype.js @@ -1,5 +1,5 @@ /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Checks if `value` is likely a prototype object. diff --git a/_root.js b/_root.js new file mode 100644 index 000000000..b491ca4e6 --- /dev/null +++ b/_root.js @@ -0,0 +1,35 @@ +var checkGlobal = require('./_checkGlobal'); + +/** Used to determine if values are of the language type `Object`. */ +var objectTypes = { + 'function': true, + 'object': true +}; + +/** Detect free variable `exports`. */ +var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null; + +/** Detect free variable `module`. */ +var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null; + +/** Detect free variable `global` from Node.js. */ +var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global); + +/** Detect free variable `self`. */ +var freeSelf = checkGlobal(objectTypes[typeof self] && self); + +/** Detect free variable `window`. */ +var freeWindow = checkGlobal(objectTypes[typeof window] && window); + +/** Detect `this` as the global object. */ +var thisGlobal = checkGlobal(objectTypes[typeof this] && this); + +/** + * Used as a reference to the global object. + * + * The `this` value is used if it's the global object to avoid Greasemonkey's + * restricted `window` object, otherwise the `window` object is used. + */ +var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')(); + +module.exports = root; diff --git a/array.js b/array.js index eea0b10df..01c121671 100644 --- a/array.js +++ b/array.js @@ -12,7 +12,6 @@ module.exports = { 'fill': require('./fill'), 'findIndex': require('./findIndex'), 'findLastIndex': require('./findLastIndex'), - 'flatMap': require('./flatMap'), 'flatten': require('./flatten'), 'flattenDeep': require('./flattenDeep'), 'fromPairs': require('./fromPairs'), diff --git a/attempt.js b/attempt.js index 305fd007b..322bf2fd1 100644 --- a/attempt.js +++ b/attempt.js @@ -1,5 +1,5 @@ var apply = require('./_apply'), - isError = require('./isError'), + isObject = require('./isObject'), rest = require('./rest'); /** @@ -13,7 +13,7 @@ var apply = require('./_apply'), * @returns {*} Returns the `func` result or error object. * @example * - * // avoid throwing errors for invalid selectors + * // Avoid throwing errors for invalid selectors. * var elements = _.attempt(function(selector) { * return document.querySelectorAll(selector); * }, '>_>'); @@ -26,7 +26,7 @@ var attempt = rest(function(func, args) { try { return apply(func, undefined, args); } catch (e) { - return isError(e) ? e : new Error(e); + return isObject(e) ? e : new Error(e); } }); diff --git a/bind.js b/bind.js index 6e383b742..72e26338d 100644 --- a/bind.js +++ b/bind.js @@ -36,7 +36,7 @@ var BIND_FLAG = 1, * bound('!'); * // => 'hi fred!' * - * // using placeholders + * // Bound with placeholders. * var bound = _.bind(greet, object, _, '!'); * bound('hi'); * // => 'hi fred!' diff --git a/bindKey.js b/bindKey.js index a9d97abd2..74b4e1495 100644 --- a/bindKey.js +++ b/bindKey.js @@ -46,7 +46,7 @@ var BIND_FLAG = 1, * bound('!'); * // => 'hiya fred!' * - * // using placeholders + * // Bound with placeholders. * var bound = _.bindKey(object, 'greet', _, '!'); * bound('hi'); * // => 'hiya fred!' diff --git a/collection.js b/collection.js index 35b399c89..6d37b3fd1 100644 --- a/collection.js +++ b/collection.js @@ -7,6 +7,7 @@ module.exports = { 'filter': require('./filter'), 'find': require('./find'), 'findLast': require('./findLast'), + 'flatMap': require('./flatMap'), 'forEach': require('./forEach'), 'forEachRight': require('./forEachRight'), 'groupBy': require('./groupBy'), diff --git a/core.js b/core.js index cdb750eca..168de5663 100644 --- a/core.js +++ b/core.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.1.0 (Custom Build) + * lodash 4.2.0 (Custom Build) * Build: `lodash core -o ./dist/lodash.core.js` * Copyright 2012-2016 The Dojo Foundation * Based on Underscore.js 1.8.3 @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.1.0'; + var VERSION = '4.2.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1, @@ -472,11 +472,11 @@ * * var wrapped = _([1, 2, 3]); * - * // returns an unwrapped value + * // Returns an unwrapped value. * wrapped.reduce(_.add); * // => 6 * - * // returns a wrapped value + * // Returns a wrapped value. * var squares = wrapped.map(square); * * _.isArray(squares); @@ -1516,8 +1516,7 @@ * Gets the index at which the first occurrence of `value` is found in `array` * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * for equality comparisons. If `fromIndex` is negative, it's used as the offset - * from the end of `array`. If `array` is sorted providing `true` for `fromIndex` - * performs a faster binary search. + * from the end of `array`. * * @static * @memberOf _ @@ -1531,7 +1530,7 @@ * _.indexOf([1, 2, 1, 2], 2); * // => 1 * - * // using `fromIndex` + * // Search from the `fromIndex`. * _.indexOf([1, 2, 1, 2], 2, 2); * // => 3 */ @@ -1629,10 +1628,9 @@ } /** - * This method invokes `interceptor` and returns `value`. The interceptor is - * invoked with one argument; (value). The purpose of this method is to "tap into" - * a method chain in order to perform operations on intermediate results within - * the chain. + * This method invokes `interceptor` and returns `value`. The interceptor + * is invoked with one argument; (value). The purpose of this method is to + * "tap into" a method chain in order to modify intermediate results. * * @static * @memberOf _ @@ -1644,6 +1642,7 @@ * * _([1, 2, 3]) * .tap(function(array) { + * // Mutate input array. * array.pop(); * }) * .reverse() @@ -1657,6 +1656,8 @@ /** * This method is like `_.tap` except that it returns the result of `interceptor`. + * The purpose of this method is to "pass thru" values replacing intermediate + * results in a method chain. * * @static * @memberOf _ @@ -1693,11 +1694,11 @@ * { 'user': 'fred', 'age': 40 } * ]; * - * // without explicit chaining + * // A sequence without explicit chaining. * _(users).head(); * // => { 'user': 'barney', 'age': 36 } * - * // with explicit chaining + * // A sequence with explicit chaining. * _(users) * .chain() * .head() @@ -1750,15 +1751,15 @@ * { 'user': 'fred', 'active': false } * ]; * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.every(users, { 'user': 'barney', 'active': false }); * // => false * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.every(users, ['active', false]); * // => true * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.every(users, 'active'); * // => false */ @@ -1788,15 +1789,15 @@ * _.filter(users, function(o) { return !o.active; }); * // => objects for ['fred'] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.filter(users, { 'age': 36, 'active': true }); * // => objects for ['barney'] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.filter(users, ['active', false]); * // => objects for ['fred'] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.filter(users, 'active'); * // => objects for ['barney'] */ @@ -1826,15 +1827,15 @@ * _.find(users, function(o) { return o.age < 40; }); * // => object for 'barney' * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.find(users, { 'age': 1, 'active': true }); * // => object for 'pebbles' * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.find(users, ['active', false]); * // => object for 'fred' * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.find(users, 'active'); * // => object for 'barney' */ @@ -1911,7 +1912,7 @@ * { 'user': 'fred' } * ]; * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.map(users, 'user'); * // => ['barney', 'fred'] */ @@ -2008,15 +2009,15 @@ * { 'user': 'fred', 'active': false } * ]; * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.some(users, { 'user': 'barney', 'active': false }); * // => false * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.some(users, ['active', false]); * // => true * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.some(users, 'active'); * // => true */ @@ -2134,7 +2135,7 @@ * bound('!'); * // => 'hi fred!' * - * // using placeholders + * // Bound with placeholders. * var bound = _.bind(greet, object, _, '!'); * bound('hi'); * // => 'hi fred!' @@ -2158,7 +2159,7 @@ * _.defer(function(text) { * console.log(text); * }, 'deferred'); - * // logs 'deferred' after one or more milliseconds + * // => logs 'deferred' after one or more milliseconds */ var defer = rest(function(func, args) { return baseDelay(func, 1, args); @@ -3442,7 +3443,7 @@ * { 'user': 'fred', 'age': 40 } * ]; * - * // create custom iteratee shorthands + * // Create custom iteratee shorthands. * _.iteratee = _.wrap(_.iteratee, function(callback, func) { * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func); * return !p ? callback(func) : function(object) { diff --git a/countBy.js b/countBy.js index 814262e0e..aff966d59 100644 --- a/countBy.js +++ b/countBy.js @@ -1,7 +1,7 @@ var createAggregator = require('./_createAggregator'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/curry.js b/curry.js index a1c35e634..13874ce00 100644 --- a/curry.js +++ b/curry.js @@ -39,7 +39,7 @@ var CURRY_FLAG = 8; * curried(1, 2, 3); * // => [1, 2, 3] * - * // using placeholders + * // Curried with placeholders. * curried(1)(_, 3)(2); * // => [1, 2, 3] */ diff --git a/curryRight.js b/curryRight.js index 9ed278a22..f809955b3 100644 --- a/curryRight.js +++ b/curryRight.js @@ -36,7 +36,7 @@ var CURRY_RIGHT_FLAG = 16; * curried(1, 2, 3); * // => [1, 2, 3] * - * // using placeholders + * // Curried with placeholders. * curried(3)(1, _)(2); * // => [1, 2, 3] */ diff --git a/debounce.js b/debounce.js index f223aed8e..92a5d6665 100644 --- a/debounce.js +++ b/debounce.js @@ -40,21 +40,21 @@ var nativeMax = Math.max; * @returns {Function} Returns the new debounced function. * @example * - * // avoid costly calculations while the window size is in flux + * // Avoid costly calculations while the window size is in flux. * jQuery(window).on('resize', _.debounce(calculateLayout, 150)); * - * // invoke `sendMail` when clicked, debouncing subsequent calls + * // Invoke `sendMail` when clicked, debouncing subsequent calls. * jQuery(element).on('click', _.debounce(sendMail, 300, { * 'leading': true, * 'trailing': false * })); * - * // ensure `batchLog` is invoked once after 1 second of debounced calls + * // Ensure `batchLog` is invoked once after 1 second of debounced calls. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); * var source = new EventSource('/stream'); * jQuery(source).on('message', debounced); * - * // cancel a trailing debounced invocation + * // Cancel the trailing debounced invocation. * jQuery(window).on('popstate', debounced.cancel); */ function debounce(func, wait, options) { diff --git a/defer.js b/defer.js index 2587bef72..f492b3df7 100644 --- a/defer.js +++ b/defer.js @@ -16,7 +16,7 @@ var baseDelay = require('./_baseDelay'), * _.defer(function(text) { * console.log(text); * }, 'deferred'); - * // logs 'deferred' after one or more milliseconds + * // => logs 'deferred' after one or more milliseconds */ var defer = rest(function(func, args) { return baseDelay(func, 1, args); diff --git a/differenceBy.js b/differenceBy.js index 51bcc7d4f..550ccfa0f 100644 --- a/differenceBy.js +++ b/differenceBy.js @@ -22,7 +22,7 @@ var baseDifference = require('./_baseDifference'), * _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor); * // => [3.1, 1.3] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); * // => [{ 'x': 2 }] */ diff --git a/dropRightWhile.js b/dropRightWhile.js index f9e30cca0..0c04ed25a 100644 --- a/dropRightWhile.js +++ b/dropRightWhile.js @@ -23,15 +23,15 @@ var baseIteratee = require('./_baseIteratee'), * _.dropRightWhile(users, function(o) { return !o.active; }); * // => objects for ['barney'] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }); * // => objects for ['barney', 'fred'] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.dropRightWhile(users, ['active', false]); * // => objects for ['barney'] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.dropRightWhile(users, 'active'); * // => objects for ['barney', 'fred', 'pebbles'] */ diff --git a/dropWhile.js b/dropWhile.js index 0a343110d..72f94484c 100644 --- a/dropWhile.js +++ b/dropWhile.js @@ -23,15 +23,15 @@ var baseIteratee = require('./_baseIteratee'), * _.dropWhile(users, function(o) { return !o.active; }); * // => objects for ['pebbles'] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.dropWhile(users, { 'user': 'barney', 'active': false }); * // => objects for ['fred', 'pebbles'] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.dropWhile(users, ['active', false]); * // => objects for ['pebbles'] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.dropWhile(users, 'active'); * // => objects for ['barney', 'fred', 'pebbles'] */ diff --git a/every.js b/every.js index 88a5e7821..d100d0dbe 100644 --- a/every.js +++ b/every.js @@ -26,15 +26,15 @@ var arrayEvery = require('./_arrayEvery'), * { 'user': 'fred', 'active': false } * ]; * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.every(users, { 'user': 'barney', 'active': false }); * // => false * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.every(users, ['active', false]); * // => true * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.every(users, 'active'); * // => false */ diff --git a/filter.js b/filter.js index 34544855a..1df81c4cc 100644 --- a/filter.js +++ b/filter.js @@ -24,15 +24,15 @@ var arrayFilter = require('./_arrayFilter'), * _.filter(users, function(o) { return !o.active; }); * // => objects for ['fred'] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.filter(users, { 'age': 36, 'active': true }); * // => objects for ['barney'] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.filter(users, ['active', false]); * // => objects for ['fred'] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.filter(users, 'active'); * // => objects for ['barney'] */ diff --git a/find.js b/find.js index 40f982e0d..c2ba356a0 100644 --- a/find.js +++ b/find.js @@ -26,15 +26,15 @@ var baseEach = require('./_baseEach'), * _.find(users, function(o) { return o.age < 40; }); * // => object for 'barney' * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.find(users, { 'age': 1, 'active': true }); * // => object for 'pebbles' * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.find(users, ['active', false]); * // => object for 'fred' * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.find(users, 'active'); * // => object for 'barney' */ diff --git a/findIndex.js b/findIndex.js index e61263ca6..5343fd124 100644 --- a/findIndex.js +++ b/findIndex.js @@ -22,15 +22,15 @@ var baseFindIndex = require('./_baseFindIndex'), * _.findIndex(users, function(o) { return o.user == 'barney'; }); * // => 0 * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.findIndex(users, { 'user': 'fred', 'active': false }); * // => 1 * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.findIndex(users, ['active', false]); * // => 0 * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.findIndex(users, 'active'); * // => 2 */ diff --git a/findKey.js b/findKey.js index ae6e1d83e..95d01f392 100644 --- a/findKey.js +++ b/findKey.js @@ -23,15 +23,15 @@ var baseFind = require('./_baseFind'), * _.findKey(users, function(o) { return o.age < 40; }); * // => 'barney' (iteration order is not guaranteed) * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.findKey(users, { 'age': 1, 'active': true }); * // => 'pebbles' * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.findKey(users, ['active', false]); * // => 'fred' * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.findKey(users, 'active'); * // => 'barney' */ diff --git a/findLastIndex.js b/findLastIndex.js index 621cb3657..2e62b3676 100644 --- a/findLastIndex.js +++ b/findLastIndex.js @@ -22,15 +22,15 @@ var baseFindIndex = require('./_baseFindIndex'), * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; }); * // => 2 * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.findLastIndex(users, { 'user': 'barney', 'active': true }); * // => 0 * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.findLastIndex(users, ['active', false]); * // => 2 * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.findLastIndex(users, 'active'); * // => 0 */ diff --git a/findLastKey.js b/findLastKey.js index b68c123f4..0380b07ce 100644 --- a/findLastKey.js +++ b/findLastKey.js @@ -23,15 +23,15 @@ var baseFind = require('./_baseFind'), * _.findLastKey(users, function(o) { return o.age < 40; }); * // => returns 'pebbles' assuming `_.findKey` returns 'barney' * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.findLastKey(users, { 'age': 36, 'active': true }); * // => 'barney' * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.findLastKey(users, ['active', false]); * // => 'fred' * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.findLastKey(users, 'active'); * // => 'pebbles' */ diff --git a/flatMap.js b/flatMap.js index e9cb01bda..1aaf28c4b 100644 --- a/flatMap.js +++ b/flatMap.js @@ -1,18 +1,17 @@ -var arrayMap = require('./_arrayMap'), - baseFlatten = require('./_baseFlatten'), - baseIteratee = require('./_baseIteratee'); +var baseFlatten = require('./_baseFlatten'), + map = require('./map'); /** - * Creates an array of flattened values by running each element in `array` + * Creates an array of flattened values by running each element in `collection` * through `iteratee` and concating its result to the other mapped values. - * The iteratee is invoked with three arguments: (value, index|key, array). + * The iteratee is invoked with three arguments: (value, index|key, collection). * * @static * @memberOf _ - * @category Array - * @param {Array} array The array to iterate over. + * @category Collection + * @param {Array|Object} collection The collection to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. - * @returns {Array} Returns the new array. + * @returns {Array} Returns the new flattened array. * @example * * function duplicate(n) { @@ -22,9 +21,8 @@ var arrayMap = require('./_arrayMap'), * _.flatMap([1, 2], duplicate); * // => [1, 1, 2, 2] */ -function flatMap(array, iteratee) { - var length = array ? array.length : 0; - return length ? baseFlatten(arrayMap(array, baseIteratee(iteratee, 3))) : []; +function flatMap(collection, iteratee) { + return baseFlatten(map(collection, iteratee)); } module.exports = flatMap; diff --git a/fp/_baseConvert.js b/fp/_baseConvert.js index 5e71b64d8..d85983ca7 100644 --- a/fp/_baseConvert.js +++ b/fp/_baseConvert.js @@ -29,7 +29,8 @@ function baseConvert(util, name, func) { 'isFunction': util.isFunction, 'iteratee': util.iteratee, 'keys': util.keys, - 'rearg': util.rearg + 'rearg': util.rearg, + 'rest': util.rest }; var ary = _.ary, @@ -38,7 +39,8 @@ function baseConvert(util, name, func) { each = _.forEach, isFunction = _.isFunction, keys = _.keys, - rearg = _.rearg; + rearg = _.rearg, + spread = _.spread; var baseArity = function(func, n) { return n == 2 @@ -167,17 +169,21 @@ function baseConvert(util, name, func) { each(mapping.caps, function(cap) { each(mapping.aryMethod[cap], function(otherName) { if (name == otherName) { - var indexes = mapping.iterateeRearg[name], - n = !isLib && mapping.aryIteratee[name]; + var aryN = !isLib && mapping.iterateeAry[name], + reargIndexes = mapping.iterateeRearg[name], + spreadStart = mapping.methodSpread[name]; + + result = spreadStart === undefined + ? ary(func, cap) + : spread(func, spreadStart); - result = ary(func, cap); if (cap > 1 && !mapping.skipRearg[name]) { result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[cap]); } - if (indexes) { - result = iterateeRearg(result, indexes); - } else if (n) { - result = iterateeAry(result, n); + if (reargIndexes) { + result = iterateeRearg(result, reargIndexes); + } else if (aryN) { + result = iterateeAry(result, aryN); } if (cap > 1) { result = curry(result, cap); @@ -198,11 +204,14 @@ function baseConvert(util, name, func) { if (!isLib) { return wrap(name, func); } + // Add placeholder alias. + _.__ = placeholder; + // Iterate over methods for the current ary cap. var pairs = []; each(mapping.caps, function(cap) { each(mapping.aryMethod[cap], function(key) { - var func = _[mapping.key[key] || key]; + var func = _[mapping.rename[key] || key]; if (func) { pairs.push([key, wrap(key, func)]); } diff --git a/fp/_mapping.js b/fp/_mapping.js index 711ac45c5..3fe602629 100644 --- a/fp/_mapping.js +++ b/fp/_mapping.js @@ -3,9 +3,12 @@ exports.aliasToReal = { 'all': 'some', 'allPass': 'overEvery', 'apply': 'spread', + 'assoc': 'set', + 'assocPath': 'set', 'compose': 'flowRight', 'contains': 'includes', - 'dissoc': 'omit', + 'dissoc': 'unset', + 'dissocPath': 'unset', 'each': 'forEach', 'eachRight': 'forEachRight', 'equals': 'isEqual', @@ -32,8 +35,59 @@ exports.aliasToReal = { 'zipObj': 'zipObject' }; +/** Used to map ary to method names. */ +exports.aryMethod = { + 1: [ + 'attempt', 'ceil', 'create', 'curry', 'curryRight', 'floor', 'fromPairs', + 'invert', 'iteratee', 'memoize', 'method', 'methodOf', 'mixin', 'over', + 'overEvery', 'overSome', 'rest', 'reverse', 'round', 'runInContext', + 'spread', 'template', 'trim', 'trimEnd', 'trimStart', 'uniqueId', 'words' + ], + 2: [ + 'add', 'after', 'ary', 'assign', 'assignIn', 'at', 'before', 'bind', 'bindKey', + 'chunk', 'cloneDeepWith', 'cloneWith', 'concat', 'countBy', 'curryN', + 'curryRightN', 'debounce', 'defaults', 'defaultsDeep', 'delay', 'difference', + 'drop', 'dropRight', 'dropRightWhile', 'dropWhile', 'endsWith', 'eq', 'every', + 'filter', 'find', 'find', 'findIndex', 'findKey', 'findLast', 'findLastIndex', + 'findLastKey', 'flatMap', 'forEach', 'forEachRight', 'forIn', 'forInRight', + 'forOwn', 'forOwnRight', 'get', 'groupBy', 'gt', 'gte', 'has', 'hasIn', + 'includes', 'indexOf', 'intersection', 'invertBy', 'invoke', 'invokeMap', + 'isEqual', 'isMatch', 'join', 'keyBy', 'lastIndexOf', 'lt', 'lte', 'map', + 'mapKeys', 'mapValues', 'matchesProperty', 'maxBy', 'merge', 'minBy', 'omit', + 'omitBy', 'orderBy', 'overArgs', 'pad', 'padEnd', 'padStart', 'parseInt', + 'partial', 'partialRight', 'partition', 'pick', 'pickBy', 'pull', 'pullAll', + 'pullAt', 'random', 'range', 'rangeRight', 'rearg', 'reject', 'remove', + 'repeat', 'result', 'sampleSize', 'some', 'sortBy', 'sortedIndex', + 'sortedIndexOf', 'sortedLastIndex', 'sortedLastIndexOf', 'sortedUniqBy', + 'split', 'startsWith', 'subtract', 'sumBy', 'take', 'takeRight', 'takeRightWhile', + 'takeWhile', 'tap', 'throttle', 'thru', 'times', 'truncate', 'union', 'uniqBy', + 'uniqWith', 'unset', 'unzipWith', 'without', 'wrap', 'xor', 'zip', 'zipObject', + 'zipObjectDeep' + ], + 3: [ + 'assignInWith', 'assignWith', 'clamp', 'differenceBy', 'differenceWith', + 'getOr', 'inRange', 'intersectionBy', 'intersectionWith', 'isEqualWith', + 'isMatchWith', 'mergeWith', 'pullAllBy', 'reduce', 'reduceRight', 'replace', + 'set', 'slice', 'sortedIndexBy', 'sortedLastIndexBy', 'transform', 'unionBy', + 'unionWith', 'xorBy', 'xorWith', 'zipWith' + ], + 4: [ + 'fill', 'setWith' + ] +}; + +/** Used to map ary to rearg configs. */ +exports.aryRearg = { + 2: [1, 0], + 3: [2, 1, 0], + 4: [3, 2, 0, 1] +}; + +/** Used to iterate `mapping.aryMethod` keys. */ +exports.caps = [1, 2, 3, 4]; + /** Used to map method names to their iteratee ary. */ -exports.aryIteratee = { +exports.iterateeAry = { 'assignWith': 2, 'assignInWith': 2, 'cloneDeepWith': 1, @@ -72,53 +126,6 @@ exports.aryIteratee = { 'transform': 2 }; -/** Used to map ary to method names. */ -exports.aryMethod = { - 1: [ - 'attempt', 'ceil', 'create', 'curry', 'curryRight', 'floor', 'fromPairs', - 'invert', 'iteratee', 'memoize', 'method', 'methodOf', 'mixin', 'over', - 'overEvery', 'overSome', 'rest', 'reverse', 'round', 'runInContext', - 'template', 'trim', 'trimEnd', 'trimStart', 'uniqueId', 'words' - ], - 2: [ - 'add', 'after', 'ary', 'assign', 'assignIn', 'at', 'before', 'bind', 'bindKey', - 'chunk', 'cloneDeepWith', 'cloneWith', 'concat', 'countBy', 'curryN', - 'curryRightN', 'debounce', 'defaults', 'defaultsDeep', 'delay', 'difference', - 'drop', 'dropRight', 'dropRightWhile', 'dropWhile', 'endsWith', 'eq', 'every', - 'filter', 'find', 'find', 'findIndex', 'findKey', 'findLast', 'findLastIndex', - 'findLastKey', 'flatMap', 'forEach', 'forEachRight', 'forIn', 'forInRight', - 'forOwn', 'forOwnRight', 'get', 'groupBy', 'gt', 'gte', 'has', 'hasIn', - 'includes', 'indexOf', 'intersection', 'invertBy', 'invoke', 'invokeMap', - 'isEqual', 'isMatch', 'join', 'keyBy', 'lastIndexOf', 'lt', 'lte', 'map', - 'mapKeys', 'mapValues', 'matchesProperty', 'maxBy', 'merge', 'minBy', 'omit', - 'omitBy', 'orderBy', 'overArgs', 'pad', 'padEnd', 'padStart', 'parseInt', - 'partition', 'pick', 'pickBy', 'pull', 'pullAll', 'pullAt', 'random', 'range', - 'rangeRight', 'rearg', 'reject', 'remove', 'repeat', 'result', 'sampleSize', - 'some', 'sortBy', 'sortedIndex', 'sortedIndexOf', 'sortedLastIndex', - 'sortedLastIndexOf', 'sortedUniqBy', 'split', 'startsWith', 'subtract', - 'sumBy', 'take', 'takeRight', 'takeRightWhile', 'takeWhile', 'tap', 'throttle', - 'thru', 'times', 'truncate', 'union', 'uniqBy', 'uniqWith', 'unset', 'unzipWith', - 'without', 'wrap', 'xor', 'zip', 'zipObject', 'zipObjectDeep' - ], - 3: [ - 'assignInWith', 'assignWith', 'clamp', 'differenceBy', 'differenceWith', - 'getOr', 'inRange', 'intersectionBy', 'intersectionWith', 'isEqualWith', - 'isMatchWith', 'mergeWith', 'pullAllBy', 'reduce', 'reduceRight', 'replace', - 'set', 'slice', 'sortedIndexBy', 'sortedLastIndexBy', 'transform', 'unionBy', - 'unionWith', 'xorBy', 'xorWith', 'zipWith' - ], - 4: [ - 'fill', 'setWith' - ] -}; - -/** Used to map ary to rearg configs. */ -exports.aryRearg = { - 2: [1, 0], - 3: [2, 1, 0], - 4: [3, 2, 0, 1] -}; - /** Used to map method names to iteratee rearg configs. */ exports.iterateeRearg = { 'findKey': [1], @@ -140,14 +147,10 @@ exports.methodRearg = { 'transform': [2, 0, 1] }; -/** Used to iterate `mapping.aryMethod` keys. */ -exports.caps = [1, 2, 3, 4]; - -/** Used to map keys to other keys. */ -exports.key = { - 'curryN': 'curry', - 'curryRightN': 'curryRight', - 'getOr': 'get' +/** Used to map method names to spread configs. */ +exports.methodSpread = { + 'partial': 1, + 'partialRight': 1 }; /** Used to identify methods which mutate arrays or objects. */ @@ -173,7 +176,8 @@ exports.mutate = { }, 'set': { 'set': true, - 'setWith': true + 'setWith': true, + 'unset': true } }; @@ -204,6 +208,13 @@ exports.realToAlias = (function() { return result; }()); +/** Used to map method names to other names. */ +exports.rename = { + 'curryN': 'curry', + 'curryRightN': 'curryRight', + 'getOr': 'get' +}; + /** Used to track methods that skip `_.rearg`. */ exports.skipRearg = { 'assign': true, @@ -212,6 +223,8 @@ exports.skipRearg = { 'difference': true, 'matchesProperty': true, 'merge': true, + 'partial': true, + 'partialRight': true, 'random': true, 'range': true, 'rangeRight': true, diff --git a/fp/_util.js b/fp/_util.js index d076f4643..e1baf3b0a 100644 --- a/fp/_util.js +++ b/fp/_util.js @@ -6,5 +6,6 @@ module.exports = { 'isFunction': require('../isFunction'), 'iteratee': require('../iteratee'), 'keys': require('../_baseKeys'), - 'rearg': require('../rearg') + 'rearg': require('../rearg'), + 'spread': require('../spread') }; diff --git a/fp/assoc.js b/fp/assoc.js new file mode 100644 index 000000000..7648820c9 --- /dev/null +++ b/fp/assoc.js @@ -0,0 +1 @@ +module.exports = require('./set'); diff --git a/fp/assocPath.js b/fp/assocPath.js new file mode 100644 index 000000000..7648820c9 --- /dev/null +++ b/fp/assocPath.js @@ -0,0 +1 @@ +module.exports = require('./set'); diff --git a/fp/dissoc.js b/fp/dissoc.js index 144cf4b96..7ec7be190 100644 --- a/fp/dissoc.js +++ b/fp/dissoc.js @@ -1 +1 @@ -module.exports = require('./omit'); +module.exports = require('./unset'); diff --git a/fp/dissocPath.js b/fp/dissocPath.js new file mode 100644 index 000000000..7ec7be190 --- /dev/null +++ b/fp/dissocPath.js @@ -0,0 +1 @@ +module.exports = require('./unset'); diff --git a/fp/partial.js b/fp/partial.js index fe07680ac..a687d0c8c 100644 --- a/fp/partial.js +++ b/fp/partial.js @@ -1 +1,2 @@ -module.exports = require('../partial'); +var convert = require('./convert'); +module.exports = convert('partial', require('../partial')); diff --git a/fp/partialRight.js b/fp/partialRight.js index 667859067..28428c033 100644 --- a/fp/partialRight.js +++ b/fp/partialRight.js @@ -1 +1,2 @@ -module.exports = require('../partialRight'); +var convert = require('./convert'); +module.exports = convert('partialRight', require('../partialRight')); diff --git a/fp/spread.js b/fp/spread.js index 162e77d9f..0348df25c 100644 --- a/fp/spread.js +++ b/fp/spread.js @@ -1 +1,2 @@ -module.exports = require('../spread'); +var convert = require('./convert'); +module.exports = convert('spread', require('../spread')); diff --git a/groupBy.js b/groupBy.js index f3c9b7ef8..728a6daba 100644 --- a/groupBy.js +++ b/groupBy.js @@ -1,7 +1,7 @@ var createAggregator = require('./_createAggregator'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; @@ -23,7 +23,7 @@ var hasOwnProperty = objectProto.hasOwnProperty; * _.groupBy([6.1, 4.2, 6.3], Math.floor); * // => { '4': [4.2], '6': [6.1, 6.3] } * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.groupBy(['one', 'two', 'three'], 'length'); * // => { '3': ['one', 'two'], '5': ['three'] } */ diff --git a/indexOf.js b/indexOf.js index e20637a4f..4474d0caf 100644 --- a/indexOf.js +++ b/indexOf.js @@ -8,8 +8,7 @@ var nativeMax = Math.max; * Gets the index at which the first occurrence of `value` is found in `array` * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * for equality comparisons. If `fromIndex` is negative, it's used as the offset - * from the end of `array`. If `array` is sorted providing `true` for `fromIndex` - * performs a faster binary search. + * from the end of `array`. * * @static * @memberOf _ @@ -23,7 +22,7 @@ var nativeMax = Math.max; * _.indexOf([1, 2, 1, 2], 2); * // => 1 * - * // using `fromIndex` + * // Search from the `fromIndex`. * _.indexOf([1, 2, 1, 2], 2, 2); * // => 3 */ diff --git a/intersectionBy.js b/intersectionBy.js index a8b38e750..2c9e0d330 100644 --- a/intersectionBy.js +++ b/intersectionBy.js @@ -21,7 +21,7 @@ var arrayMap = require('./_arrayMap'), * _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor); * // => [2.1] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }] */ diff --git a/invertBy.js b/invertBy.js index 6206f708c..513f62b92 100644 --- a/invertBy.js +++ b/invertBy.js @@ -2,7 +2,7 @@ var baseIteratee = require('./_baseIteratee'), createInverter = require('./_createInverter'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/isArguments.js b/isArguments.js index bbc3eebcc..73fbafe0d 100644 --- a/isArguments.js +++ b/isArguments.js @@ -4,7 +4,7 @@ var isArrayLikeObject = require('./isArrayLikeObject'); var argsTag = '[object Arguments]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/isBoolean.js b/isBoolean.js index 663a12cc0..53ec5d6e5 100644 --- a/isBoolean.js +++ b/isBoolean.js @@ -4,7 +4,7 @@ var isObjectLike = require('./isObjectLike'); var boolTag = '[object Boolean]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) diff --git a/isDate.js b/isDate.js index 3aad994d2..6e3611a05 100644 --- a/isDate.js +++ b/isDate.js @@ -4,7 +4,7 @@ var isObjectLike = require('./isObjectLike'); var dateTag = '[object Date]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) diff --git a/isEmpty.js b/isEmpty.js index 32abeaf83..29062ed4b 100644 --- a/isEmpty.js +++ b/isEmpty.js @@ -5,7 +5,7 @@ var isArguments = require('./isArguments'), isString = require('./isString'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/isError.js b/isError.js index c8d9c6761..e66b443d8 100644 --- a/isError.js +++ b/isError.js @@ -4,7 +4,7 @@ var isObjectLike = require('./isObjectLike'); var errorTag = '[object Error]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) diff --git a/isFinite.js b/isFinite.js index 1f5b1a9e4..44be4bc9d 100644 --- a/isFinite.js +++ b/isFinite.js @@ -1,5 +1,7 @@ +var root = require('./_root'); + /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeIsFinite = global.isFinite; +var nativeIsFinite = root.isFinite; /** * Checks if `value` is a finite primitive number. diff --git a/isFunction.js b/isFunction.js index e85a5f3d3..a1d9530c6 100644 --- a/isFunction.js +++ b/isFunction.js @@ -5,7 +5,7 @@ var funcTag = '[object Function]', genTag = '[object GeneratorFunction]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) diff --git a/isNative.js b/isNative.js index 1422779b7..616a832e6 100644 --- a/isNative.js +++ b/isNative.js @@ -9,10 +9,10 @@ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; var reIsHostCtor = /^\[object .+?Constructor\]$/; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to resolve the decompiled source of functions. */ -var funcToString = global.Function.prototype.toString; +var funcToString = Function.prototype.toString; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/isNumber.js b/isNumber.js index ffaa818c6..0c8fb9ae9 100644 --- a/isNumber.js +++ b/isNumber.js @@ -4,7 +4,7 @@ var isObjectLike = require('./isObjectLike'); var numberTag = '[object Number]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) diff --git a/isPlainObject.js b/isPlainObject.js index 81f8b59ae..1d68332c0 100644 --- a/isPlainObject.js +++ b/isPlainObject.js @@ -5,10 +5,10 @@ var isHostObject = require('./_isHostObject'), var objectTag = '[object Object]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to resolve the decompiled source of functions. */ -var funcToString = global.Function.prototype.toString; +var funcToString = Function.prototype.toString; /** Used to infer the `Object` constructor. */ var objectCtorString = funcToString.call(Object); diff --git a/isRegExp.js b/isRegExp.js index f9e02fbf4..e127e5aae 100644 --- a/isRegExp.js +++ b/isRegExp.js @@ -4,7 +4,7 @@ var isObject = require('./isObject'); var regexpTag = '[object RegExp]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) diff --git a/isString.js b/isString.js index 277fc25a7..5ed392e40 100644 --- a/isString.js +++ b/isString.js @@ -5,7 +5,7 @@ var isArray = require('./isArray'), var stringTag = '[object String]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) diff --git a/isSymbol.js b/isSymbol.js index 59f2df0f6..5e11a00d3 100644 --- a/isSymbol.js +++ b/isSymbol.js @@ -4,7 +4,7 @@ var isObjectLike = require('./isObjectLike'); var symbolTag = '[object Symbol]'; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) diff --git a/isTypedArray.js b/isTypedArray.js index e7bfa228b..9e9b0a274 100644 --- a/isTypedArray.js +++ b/isTypedArray.js @@ -43,7 +43,7 @@ typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false; /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) diff --git a/iteratee.js b/iteratee.js index 2cad2ede9..c761adbbc 100644 --- a/iteratee.js +++ b/iteratee.js @@ -1,7 +1,5 @@ -var baseIteratee = require('./_baseIteratee'), - isArray = require('./isArray'), - isObjectLike = require('./isObjectLike'), - matches = require('./matches'); +var baseClone = require('./_baseClone'), + baseIteratee = require('./_baseIteratee'); /** * Creates a function that invokes `func` with the arguments of the created @@ -21,7 +19,7 @@ var baseIteratee = require('./_baseIteratee'), * { 'user': 'fred', 'age': 40 } * ]; * - * // create custom iteratee shorthands + * // Create custom iteratee shorthands. * _.iteratee = _.wrap(_.iteratee, function(callback, func) { * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func); * return !p ? callback(func) : function(object) { @@ -33,9 +31,7 @@ var baseIteratee = require('./_baseIteratee'), * // => [{ 'user': 'fred', 'age': 40 }] */ function iteratee(func) { - return (isObjectLike(func) && !isArray(func)) - ? matches(func) - : baseIteratee(func); + return baseIteratee(typeof func == 'function' ? func : baseClone(func, true)); } module.exports = iteratee; diff --git a/join.js b/join.js index 1aabc0718..79d308d28 100644 --- a/join.js +++ b/join.js @@ -1,5 +1,5 @@ /** Used for built-in method references. */ -var arrayProto = global.Array.prototype; +var arrayProto = Array.prototype; /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeJoin = arrayProto.join; diff --git a/keysIn.js b/keysIn.js index ca2d3b572..e327b874d 100644 --- a/keysIn.js +++ b/keysIn.js @@ -4,7 +4,7 @@ var baseKeysIn = require('./_baseKeysIn'), isPrototype = require('./_isPrototype'); /** Used for built-in method references. */ -var objectProto = global.Object.prototype; +var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/lastIndexOf.js b/lastIndexOf.js index 6ce7227f8..1eb2f2836 100644 --- a/lastIndexOf.js +++ b/lastIndexOf.js @@ -21,7 +21,7 @@ var nativeMax = Math.max, * _.lastIndexOf([1, 2, 1, 2], 2); * // => 3 * - * // using `fromIndex` + * // Search from the `fromIndex`. * _.lastIndexOf([1, 2, 1, 2], 2, 2); * // => 1 */ diff --git a/lodash.js b/lodash.js index 14beccfca..e78a24801 100644 --- a/lodash.js +++ b/lodash.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.1.0 (Custom Build) + * lodash 4.2.0 (Custom Build) * Build: `lodash -d -o ./foo/lodash.js` * Copyright 2012-2016 The Dojo Foundation * Based on Underscore.js 1.8.3 @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.1.0'; + var VERSION = '4.2.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1, @@ -397,11 +397,11 @@ * @private * @param {Function} func The function to invoke. * @param {*} thisArg The `this` binding of `func`. - * @param {...*} [args] The arguments to invoke `func` with. + * @param {...*} args The arguments to invoke `func` with. * @returns {*} Returns the result of `func`. */ function apply(func, thisArg, args) { - var length = args ? args.length : 0; + var length = args.length; switch (length) { case 0: return func.call(thisArg); case 1: return func.call(thisArg, args[0]); @@ -841,7 +841,7 @@ result = result === undefined ? current : (result + current); } } - return length ? result : 0; + return result; } /** @@ -1254,14 +1254,14 @@ * lodash.isFunction(lodash.bar); * // => true * - * // using `context` to mock `Date#getTime` use in `_.now` + * // Use `context` to mock `Date#getTime` use in `_.now`. * var mock = _.runInContext({ * 'Date': function() { * return { 'getTime': getTimeMock }; * } * }); * - * // or creating a suped-up `defer` in Node.js + * // Create a suped-up `defer` in Node.js. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; */ function runInContext(context) { @@ -1451,11 +1451,11 @@ * * var wrapped = _([1, 2, 3]); * - * // returns an unwrapped value + * // Returns an unwrapped value. * wrapped.reduce(_.add); * // => 6 * - * // returns a wrapped value + * // Returns a wrapped value. * var squares = wrapped.map(square); * * _.isArray(squares); @@ -5471,7 +5471,7 @@ * _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor); * // => [3.1, 1.3] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); * // => [{ 'x': 2 }] */ @@ -5603,15 +5603,15 @@ * _.dropRightWhile(users, function(o) { return !o.active; }); * // => objects for ['barney'] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }); * // => objects for ['barney', 'fred'] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.dropRightWhile(users, ['active', false]); * // => objects for ['barney'] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.dropRightWhile(users, 'active'); * // => objects for ['barney', 'fred', 'pebbles'] */ @@ -5643,15 +5643,15 @@ * _.dropWhile(users, function(o) { return !o.active; }); * // => objects for ['pebbles'] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.dropWhile(users, { 'user': 'barney', 'active': false }); * // => objects for ['fred', 'pebbles'] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.dropWhile(users, ['active', false]); * // => objects for ['pebbles'] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.dropWhile(users, 'active'); * // => objects for ['barney', 'fred', 'pebbles'] */ @@ -5722,15 +5722,15 @@ * _.findIndex(users, function(o) { return o.user == 'barney'; }); * // => 0 * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.findIndex(users, { 'user': 'fred', 'active': false }); * // => 1 * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.findIndex(users, ['active', false]); * // => 0 * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.findIndex(users, 'active'); * // => 2 */ @@ -5761,15 +5761,15 @@ * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; }); * // => 2 * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.findLastIndex(users, { 'user': 'barney', 'active': true }); * // => 0 * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.findLastIndex(users, ['active', false]); * // => 2 * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.findLastIndex(users, 'active'); * // => 0 */ @@ -5779,31 +5779,6 @@ : -1; } - /** - * Creates an array of flattened values by running each element in `array` - * through `iteratee` and concating its result to the other mapped values. - * The iteratee is invoked with three arguments: (value, index|key, array). - * - * @static - * @memberOf _ - * @category Array - * @param {Array} array The array to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. - * @returns {Array} Returns the new array. - * @example - * - * function duplicate(n) { - * return [n, n]; - * } - * - * _.flatMap([1, 2], duplicate); - * // => [1, 1, 2, 2] - */ - function flatMap(array, iteratee) { - var length = array ? array.length : 0; - return length ? baseFlatten(arrayMap(array, getIteratee(iteratee, 3))) : []; - } - /** * Flattens `array` a single level. * @@ -5891,8 +5866,7 @@ * Gets the index at which the first occurrence of `value` is found in `array` * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * for equality comparisons. If `fromIndex` is negative, it's used as the offset - * from the end of `array`. If `array` is sorted providing `true` for `fromIndex` - * performs a faster binary search. + * from the end of `array`. * * @static * @memberOf _ @@ -5906,7 +5880,7 @@ * _.indexOf([1, 2, 1, 2], 2); * // => 1 * - * // using `fromIndex` + * // Search from the `fromIndex`. * _.indexOf([1, 2, 1, 2], 2, 2); * // => 3 */ @@ -5977,7 +5951,7 @@ * _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor); * // => [2.1] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }] */ @@ -6080,7 +6054,7 @@ * _.lastIndexOf([1, 2, 1, 2], 2); * // => 3 * - * // using `fromIndex` + * // Search from the `fromIndex`. * _.lastIndexOf([1, 2, 1, 2], 2, 2); * // => 1 */ @@ -6356,7 +6330,7 @@ * _.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict)); * // => 1 * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x'); * // => 0 */ @@ -6424,7 +6398,7 @@ * @returns {number} Returns the index at which `value` should be inserted into `array`. * @example * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x'); * // => 1 */ @@ -6491,7 +6465,7 @@ * @example * * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor); - * // => [1.1, 2.2] + * // => [1.1, 2.3] */ function sortedUniqBy(array, iteratee) { return (array && array.length) @@ -6604,15 +6578,15 @@ * _.takeRightWhile(users, function(o) { return !o.active; }); * // => objects for ['fred', 'pebbles'] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false }); * // => objects for ['pebbles'] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.takeRightWhile(users, ['active', false]); * // => objects for ['fred', 'pebbles'] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.takeRightWhile(users, 'active'); * // => [] */ @@ -6644,15 +6618,15 @@ * _.takeWhile(users, function(o) { return !o.active; }); * // => objects for ['barney', 'fred'] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.takeWhile(users, { 'user': 'barney', 'active': false }); * // => objects for ['barney'] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.takeWhile(users, ['active', false]); * // => objects for ['barney', 'fred'] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.takeWhile(users, 'active'); * // => [] */ @@ -6697,7 +6671,7 @@ * _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor); * // => [2.1, 1.2, 4.3] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }, { 'x': 2 }] */ @@ -6774,7 +6748,7 @@ * _.uniqBy([2.1, 1.2, 2.3], Math.floor); * // => [2.1, 1.2] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }, { 'x': 2 }] */ @@ -6930,7 +6904,7 @@ * _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor); * // => [1.2, 4.3] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 2 }] */ @@ -7085,10 +7059,9 @@ } /** - * This method invokes `interceptor` and returns `value`. The interceptor is - * invoked with one argument; (value). The purpose of this method is to "tap into" - * a method chain in order to perform operations on intermediate results within - * the chain. + * This method invokes `interceptor` and returns `value`. The interceptor + * is invoked with one argument; (value). The purpose of this method is to + * "tap into" a method chain in order to modify intermediate results. * * @static * @memberOf _ @@ -7100,6 +7073,7 @@ * * _([1, 2, 3]) * .tap(function(array) { + * // Mutate input array. * array.pop(); * }) * .reverse() @@ -7113,6 +7087,8 @@ /** * This method is like `_.tap` except that it returns the result of `interceptor`. + * The purpose of this method is to "pass thru" values replacing intermediate + * results in a method chain. * * @static * @memberOf _ @@ -7188,11 +7164,11 @@ * { 'user': 'fred', 'age': 40 } * ]; * - * // without explicit chaining + * // A sequence without explicit chaining. * _(users).head(); * // => { 'user': 'barney', 'age': 36 } * - * // with explicit chaining + * // A sequence with explicit chaining. * _(users) * .chain() * .head() @@ -7447,15 +7423,15 @@ * { 'user': 'fred', 'active': false } * ]; * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.every(users, { 'user': 'barney', 'active': false }); * // => false * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.every(users, ['active', false]); * // => true * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.every(users, 'active'); * // => false */ @@ -7488,15 +7464,15 @@ * _.filter(users, function(o) { return !o.active; }); * // => objects for ['fred'] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.filter(users, { 'age': 36, 'active': true }); * // => objects for ['barney'] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.filter(users, ['active', false]); * // => objects for ['fred'] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.filter(users, 'active'); * // => objects for ['barney'] */ @@ -7527,15 +7503,15 @@ * _.find(users, function(o) { return o.age < 40; }); * // => object for 'barney' * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.find(users, { 'age': 1, 'active': true }); * // => object for 'pebbles' * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.find(users, ['active', false]); * // => object for 'fred' * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.find(users, 'active'); * // => object for 'barney' */ @@ -7574,6 +7550,30 @@ return baseFind(collection, predicate, baseEachRight); } + /** + * Creates an array of flattened values by running each element in `collection` + * through `iteratee` and concating its result to the other mapped values. + * The iteratee is invoked with three arguments: (value, index|key, collection). + * + * @static + * @memberOf _ + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [n, n]; + * } + * + * _.flatMap([1, 2], duplicate); + * // => [1, 1, 2, 2] + */ + function flatMap(collection, iteratee) { + return baseFlatten(map(collection, iteratee)); + } + /** * Iterates over elements of `collection` invoking `iteratee` for each element. * The iteratee is invoked with three arguments: (value, index|key, collection). @@ -7649,7 +7649,7 @@ * _.groupBy([6.1, 4.2, 6.3], Math.floor); * // => { '4': [4.2], '6': [6.1, 6.3] } * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.groupBy(['one', 'two', 'three'], 'length'); * // => { '3': ['one', 'two'], '5': ['three'] } */ @@ -7805,7 +7805,7 @@ * { 'user': 'fred' } * ]; * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.map(users, 'user'); * // => ['barney', 'fred'] */ @@ -7837,7 +7837,7 @@ * { 'user': 'barney', 'age': 36 } * ]; * - * // sort by `user` in ascending order and by `age` in descending order + * // Sort by `user` in ascending order and by `age` in descending order. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']); * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] */ @@ -7878,15 +7878,15 @@ * _.partition(users, function(o) { return o.active; }); * // => objects for [['fred'], ['barney', 'pebbles']] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.partition(users, { 'age': 1, 'active': false }); * // => objects for [['pebbles'], ['barney', 'fred']] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.partition(users, ['active', false]); * // => objects for [['barney', 'pebbles'], ['fred']] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.partition(users, 'active'); * // => objects for [['fred'], ['barney', 'pebbles']] */ @@ -7983,15 +7983,15 @@ * _.reject(users, function(o) { return !o.active; }); * // => objects for ['fred'] * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.reject(users, { 'age': 40, 'active': true }); * // => objects for ['barney'] * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.reject(users, ['active', false]); * // => objects for ['fred'] * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.reject(users, 'active'); * // => objects for ['barney'] */ @@ -8130,15 +8130,15 @@ * { 'user': 'fred', 'active': false } * ]; * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.some(users, { 'user': 'barney', 'active': false }); * // => false * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.some(users, ['active', false]); * // => true * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.some(users, 'active'); * // => true */ @@ -8338,7 +8338,7 @@ * bound('!'); * // => 'hi fred!' * - * // using placeholders + * // Bound with placeholders. * var bound = _.bind(greet, object, _, '!'); * bound('hi'); * // => 'hi fred!' @@ -8391,7 +8391,7 @@ * bound('!'); * // => 'hiya fred!' * - * // using placeholders + * // Bound with placeholders. * var bound = _.bindKey(object, 'greet', _, '!'); * bound('hi'); * // => 'hiya fred!' @@ -8441,7 +8441,7 @@ * curried(1, 2, 3); * // => [1, 2, 3] * - * // using placeholders + * // Curried with placeholders. * curried(1)(_, 3)(2); * // => [1, 2, 3] */ @@ -8485,7 +8485,7 @@ * curried(1, 2, 3); * // => [1, 2, 3] * - * // using placeholders + * // Curried with placeholders. * curried(3)(1, _)(2); * // => [1, 2, 3] */ @@ -8528,21 +8528,21 @@ * @returns {Function} Returns the new debounced function. * @example * - * // avoid costly calculations while the window size is in flux + * // Avoid costly calculations while the window size is in flux. * jQuery(window).on('resize', _.debounce(calculateLayout, 150)); * - * // invoke `sendMail` when clicked, debouncing subsequent calls + * // Invoke `sendMail` when clicked, debouncing subsequent calls. * jQuery(element).on('click', _.debounce(sendMail, 300, { * 'leading': true, * 'trailing': false * })); * - * // ensure `batchLog` is invoked once after 1 second of debounced calls + * // Ensure `batchLog` is invoked once after 1 second of debounced calls. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); * var source = new EventSource('/stream'); * jQuery(source).on('message', debounced); * - * // cancel a trailing debounced invocation + * // Cancel the trailing debounced invocation. * jQuery(window).on('popstate', debounced.cancel); */ function debounce(func, wait, options) { @@ -8675,7 +8675,7 @@ * _.defer(function(text) { * console.log(text); * }, 'deferred'); - * // logs 'deferred' after one or more milliseconds + * // => logs 'deferred' after one or more milliseconds */ var defer = rest(function(func, args) { return baseDelay(func, 1, args); @@ -8758,12 +8758,12 @@ * values(object); * // => [1, 2] * - * // modifying the result cache + * // Modify the result cache. * values.cache.set(object, ['a', 'b']); * values(object); * // => ['a', 'b'] * - * // replacing `_.memoize.Cache` + * // Replace `_.memoize.Cache`. * _.memoize.Cache = WeakMap; */ function memoize(func, resolver) { @@ -8908,7 +8908,7 @@ * sayHelloTo('fred'); * // => 'hello fred' * - * // using placeholders + * // Partially applied with placeholders. * var greetFred = _.partial(greet, _, 'fred'); * greetFred('hi'); * // => 'hi fred' @@ -8944,7 +8944,7 @@ * greetFred('hi'); * // => 'hi fred' * - * // using placeholders + * // Partially applied with placeholders. * var sayHelloTo = _.partialRight(greet, 'hello', _); * sayHelloTo('fred'); * // => 'hello fred' @@ -9041,6 +9041,7 @@ * @memberOf _ * @category Function * @param {Function} func The function to spread arguments over. + * @param {number} [start=0] The start position of the spread. * @returns {Function} Returns the new function. * @example * @@ -9051,7 +9052,6 @@ * say(['fred', 'hello']); * // => 'fred says hello' * - * // with a Promise * var numbers = Promise.all([ * Promise.resolve(40), * Promise.resolve(36) @@ -9062,13 +9062,20 @@ * })); * // => a Promise of 76 */ - function spread(func) { + function spread(func, start) { if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } - return function(array) { - return apply(func, this, array); - }; + start = start === undefined ? 0 : nativeMax(toInteger(start), 0); + return rest(function(args) { + var array = args[start], + otherArgs = args.slice(0, start); + + if (array) { + arrayPush(otherArgs, array); + } + return apply(func, this, otherArgs); + }); } /** @@ -9101,14 +9108,14 @@ * @returns {Function} Returns the new throttled function. * @example * - * // avoid excessively updating the position while scrolling + * // Avoid excessively updating the position while scrolling. * jQuery(window).on('scroll', _.throttle(updatePosition, 100)); * - * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes + * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); * jQuery(element).on('click', throttled); * - * // cancel a trailing throttled invocation + * // Cancel the trailing throttled invocation. * jQuery(window).on('popstate', throttled.cancel); */ function throttle(func, wait, options) { @@ -10727,15 +10734,15 @@ * _.findKey(users, function(o) { return o.age < 40; }); * // => 'barney' (iteration order is not guaranteed) * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.findKey(users, { 'age': 1, 'active': true }); * // => 'pebbles' * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.findKey(users, ['active', false]); * // => 'fred' * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.findKey(users, 'active'); * // => 'barney' */ @@ -10764,15 +10771,15 @@ * _.findLastKey(users, function(o) { return o.age < 40; }); * // => returns 'pebbles' assuming `_.findKey` returns 'barney' * - * // using the `_.matches` iteratee shorthand + * // The `_.matches` iteratee shorthand. * _.findLastKey(users, { 'age': 36, 'active': true }); * // => 'barney' * - * // using the `_.matchesProperty` iteratee shorthand + * // The `_.matchesProperty` iteratee shorthand. * _.findLastKey(users, ['active', false]); * // => 'fred' * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.findLastKey(users, 'active'); * // => 'pebbles' */ @@ -11245,7 +11252,7 @@ * _.mapValues(users, function(o) { return o.age; }); * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) * - * // using the `_.property` iteratee shorthand + * // The `_.property` iteratee shorthand. * _.mapValues(users, 'age'); * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) */ @@ -11299,6 +11306,8 @@ * method instead. The `customizer` is invoked with seven arguments: * (objValue, srcValue, key, object, source, stack). * + * **Note:** This method mutates `object`. + * * @static * @memberOf _ * @category Object @@ -11405,7 +11414,7 @@ /** * Creates an object composed of the `object` properties `predicate` returns - * truthy for. The predicate is invoked with one argument: (value). + * truthy for. The predicate is invoked with two arguments: (value, key). * * @static * @memberOf _ @@ -11472,6 +11481,8 @@ * are created for all other missing properties. Use `_.setWith` to customize * `path` creation. * + * **Note:** This method mutates `object`. + * * @static * @memberOf _ * @category Object @@ -11501,6 +11512,8 @@ * path creation is handled by the method instead. The `customizer` is invoked * with three arguments: (nsValue, key, nsObject). * + * **Note:** This method mutates `object`. + * * @static * @memberOf _ * @category Object @@ -11620,6 +11633,8 @@ /** * Removes the property at `path` of `object`. * + * **Note:** This method mutates `object`. + * * @static * @memberOf _ * @category Object @@ -12409,54 +12424,54 @@ * @returns {Function} Returns the compiled template function. * @example * - * // using the "interpolate" delimiter to create a compiled template + * // Use the "interpolate" delimiter to create a compiled template. * var compiled = _.template('hello <%= user %>!'); * compiled({ 'user': 'fred' }); * // => 'hello fred!' * - * // using the HTML "escape" delimiter to escape data property values + * // Use the HTML "escape" delimiter to escape data property values. * var compiled = _.template('<%- value %>'); * compiled({ 'value': '