diff --git a/README.md b/README.md index 33a7ef26e..941c7e273 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash v4.3.0 +# lodash v4.4.0 The [lodash](https://lodash.com/) library exported as [Node.js](https://nodejs.org/) modules. @@ -12,23 +12,23 @@ $ npm i --save lodash In Node.js: ```js -// load the full build +// Load the full build. var _ = require('lodash'); -// load the core build +// Load the core build. var _ = require('lodash/core'); -// load the fp build for immutable auto-curried iteratee-first data-last methods +// Load the fp build for immutable auto-curried iteratee-first data-last methods. var _ = require('lodash/fp'); -// or a method category +// Load a method category. var array = require('lodash/array'); var object = require('lodash/fp/object'); -// or method for smaller builds with browserify/rollup/webpack +// Load a single method for smaller builds with browserify/rollup/webpack. var chunk = require('lodash/chunk'); var extend = require('lodash/fp/extend'); ``` -See the [package source](https://github.com/lodash/lodash/tree/4.3.0-npm) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.4.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.
diff --git a/_Hash.js b/_Hash.js index 25108ad7f..8647d1619 100644 --- a/_Hash.js +++ b/_Hash.js @@ -7,6 +7,7 @@ var objectProto = Object.prototype; * Creates an hash object. * * @private + * @constructor * @returns {Object} Returns the new hash object. */ function Hash() {} diff --git a/_LazyWrapper.js b/_LazyWrapper.js index 3c14d805c..ad01ef82c 100644 --- a/_LazyWrapper.js +++ b/_LazyWrapper.js @@ -8,6 +8,7 @@ var MAX_ARRAY_LENGTH = 4294967295; * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation. * * @private + * @constructor * @param {*} value The value to wrap. */ function LazyWrapper(value) { diff --git a/_MapCache.js b/_MapCache.js index 734324be5..26528437e 100644 --- a/_MapCache.js +++ b/_MapCache.js @@ -8,6 +8,7 @@ var mapClear = require('./_mapClear'), * Creates a map cache object to store key-value pairs. * * @private + * @constructor * @param {Array} [values] The values to cache. */ function MapCache(values) { diff --git a/_SetCache.js b/_SetCache.js index 66b8b614b..5d9d6201f 100644 --- a/_SetCache.js +++ b/_SetCache.js @@ -6,6 +6,7 @@ var MapCache = require('./_MapCache'), * Creates a set cache object to store unique values. * * @private + * @constructor * @param {Array} [values] The values to cache. */ function SetCache(values) { diff --git a/_Stack.js b/_Stack.js index 7c3c2f318..345577ed3 100644 --- a/_Stack.js +++ b/_Stack.js @@ -8,6 +8,7 @@ var stackClear = require('./_stackClear'), * Creates a stack cache object to store key-value pairs. * * @private + * @constructor * @param {Array} [values] The values to cache. */ function Stack(values) { diff --git a/_baseCastArrayLikeObject.js b/_baseCastArrayLikeObject.js new file mode 100644 index 000000000..17c0c8670 --- /dev/null +++ b/_baseCastArrayLikeObject.js @@ -0,0 +1,14 @@ +var isArrayLikeObject = require('./isArrayLikeObject'); + +/** + * Casts `value` to an empty array if it's not an array like object. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array} Returns the array-like object. + */ +function baseCastArrayLikeObject(value) { + return isArrayLikeObject(value) ? value : []; +} + +module.exports = baseCastArrayLikeObject; diff --git a/_baseCastFunction.js b/_baseCastFunction.js new file mode 100644 index 000000000..b3d0f720d --- /dev/null +++ b/_baseCastFunction.js @@ -0,0 +1,14 @@ +var identity = require('./identity'); + +/** + * Casts `value` to `identity` if it's not a function. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array} Returns the array-like object. + */ +function baseCastFunction(value) { + return typeof value == 'function' ? value : identity; +} + +module.exports = baseCastFunction; diff --git a/_baseCastPath.js b/_baseCastPath.js new file mode 100644 index 000000000..7634e5ba2 --- /dev/null +++ b/_baseCastPath.js @@ -0,0 +1,15 @@ +var isArray = require('./isArray'), + stringToPath = require('./_stringToPath'); + +/** + * Casts `value` to a path array if it's not one. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array} Returns the cast property path array. + */ +function baseCastPath(value) { + return isArray(value) ? value : stringToPath(value); +} + +module.exports = baseCastPath; diff --git a/_baseCreate.js b/_baseCreate.js index 64d53eccc..4372cad2b 100644 --- a/_baseCreate.js +++ b/_baseCreate.js @@ -1,5 +1,8 @@ var isObject = require('./isObject'); +/** Built-in value references. */ +var objectCreate = Object.create; + /** * The base implementation of `_.create` without support for assigning * properties to the created object. @@ -8,16 +11,8 @@ var isObject = require('./isObject'); * @param {Object} prototype The object to inherit from. * @returns {Object} Returns the new object. */ -var baseCreate = (function() { - function object() {} - return function(prototype) { - if (isObject(prototype)) { - object.prototype = prototype; - var result = new object; - object.prototype = undefined; - } - return result || {}; - }; -}()); +function baseCreate(proto) { + return isObject(proto) ? objectCreate(proto) : {}; +} module.exports = baseCreate; diff --git a/_baseFlatten.js b/_baseFlatten.js index 8a4cb460d..7d024dd23 100644 --- a/_baseFlatten.js +++ b/_baseFlatten.js @@ -8,12 +8,12 @@ var arrayPush = require('./_arrayPush'), * * @private * @param {Array} array The array to flatten. - * @param {boolean} [isDeep] Specify a deep flatten. + * @param {number} depth The maximum recursion depth. * @param {boolean} [isStrict] Restrict flattening to arrays-like objects. * @param {Array} [result=[]] The initial result value. * @returns {Array} Returns the new flattened array. */ -function baseFlatten(array, isDeep, isStrict, result) { +function baseFlatten(array, depth, isStrict, result) { result || (result = []); var index = -1, @@ -21,11 +21,11 @@ function baseFlatten(array, isDeep, isStrict, result) { while (++index < length) { var value = array[index]; - if (isArrayLikeObject(value) && + if (depth > 0 && isArrayLikeObject(value) && (isStrict || isArray(value) || isArguments(value))) { - if (isDeep) { + if (depth > 1) { // Recursively flatten arrays (susceptible to call stack limits). - baseFlatten(value, isDeep, isStrict, result); + baseFlatten(value, depth - 1, isStrict, result); } else { arrayPush(result, value); } diff --git a/_baseGet.js b/_baseGet.js index d11de17bf..ef9623a9b 100644 --- a/_baseGet.js +++ b/_baseGet.js @@ -1,4 +1,4 @@ -var baseToPath = require('./_baseToPath'), +var baseCastPath = require('./_baseCastPath'), isKey = require('./_isKey'); /** @@ -10,7 +10,7 @@ var baseToPath = require('./_baseToPath'), * @returns {*} Returns the resolved value. */ function baseGet(object, path) { - path = isKey(path, object) ? [path + ''] : baseToPath(path); + path = isKey(path, object) ? [path + ''] : baseCastPath(path); var index = 0, length = path.length; diff --git a/_baseIntersection.js b/_baseIntersection.js index 77e463f85..662e23f13 100644 --- a/_baseIntersection.js +++ b/_baseIntersection.js @@ -42,11 +42,17 @@ function baseIntersection(arrays, iteratee, comparator) { var value = array[index], computed = iteratee ? iteratee(value) : value; - if (!(seen ? cacheHas(seen, computed) : includes(result, computed, comparator))) { + if (!(seen + ? cacheHas(seen, computed) + : includes(result, computed, comparator) + )) { var othIndex = othLength; while (--othIndex) { var cache = caches[othIndex]; - if (!(cache ? cacheHas(cache, computed) : includes(arrays[othIndex], computed, comparator))) { + if (!(cache + ? cacheHas(cache, computed) + : includes(arrays[othIndex], computed, comparator)) + ) { continue outer; } } diff --git a/_baseInvoke.js b/_baseInvoke.js index a19a5f8f8..7a94a3f3a 100644 --- a/_baseInvoke.js +++ b/_baseInvoke.js @@ -1,5 +1,5 @@ var apply = require('./_apply'), - baseToPath = require('./_baseToPath'), + baseCastPath = require('./_baseCastPath'), isKey = require('./_isKey'), last = require('./last'), parent = require('./_parent'); @@ -16,7 +16,7 @@ var apply = require('./_apply'), */ function baseInvoke(object, path, args) { if (!isKey(path, object)) { - path = baseToPath(path); + path = baseCastPath(path); object = parent(object, path); path = last(path); } diff --git a/_baseKeys.js b/_baseKeys.js index 4b747d50f..2c8ccb912 100644 --- a/_baseKeys.js +++ b/_baseKeys.js @@ -6,7 +6,6 @@ var nativeKeys = Object.keys; * property of prototypes or treat sparse arrays as dense. * * @private - * @type Function * @param {Object} object The object to query. * @returns {Array} Returns the array of property names. */ diff --git a/_baseMerge.js b/_baseMerge.js index 977846484..04cda5846 100644 --- a/_baseMerge.js +++ b/_baseMerge.js @@ -21,7 +21,10 @@ function baseMerge(object, source, srcIndex, customizer, stack) { if (object === source) { return; } - var props = (isArray(source) || isTypedArray(source)) ? undefined : keysIn(source); + var props = (isArray(source) || isTypedArray(source)) + ? undefined + : keysIn(source); + arrayEach(props || source, function(srcValue, key) { if (props) { key = srcValue; @@ -32,7 +35,10 @@ function baseMerge(object, source, srcIndex, customizer, stack) { baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack); } else { - var newValue = customizer ? customizer(object[key], srcValue, (key + ''), object, source, stack) : undefined; + var newValue = customizer + ? customizer(object[key], srcValue, (key + ''), object, source, stack) + : undefined; + if (newValue === undefined) { newValue = srcValue; } diff --git a/_baseMergeDeep.js b/_baseMergeDeep.js index d5caf3fff..68266d1c3 100644 --- a/_baseMergeDeep.js +++ b/_baseMergeDeep.js @@ -33,21 +33,24 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, sta assignMergeValue(object, key, stacked); return; } - var newValue = customizer ? customizer(objValue, srcValue, (key + ''), object, source, stack) : undefined, - isCommon = newValue === undefined; + var newValue = customizer + ? customizer(objValue, srcValue, (key + ''), object, source, stack) + : undefined; + + var isCommon = newValue === undefined; if (isCommon) { newValue = srcValue; if (isArray(srcValue) || isTypedArray(srcValue)) { if (isArray(objValue)) { - newValue = srcIndex ? copyArray(objValue) : objValue; + newValue = objValue; } else if (isArrayLikeObject(objValue)) { newValue = copyArray(objValue); } else { isCommon = false; - newValue = baseClone(srcValue); + newValue = baseClone(srcValue, true); } } else if (isPlainObject(srcValue) || isArguments(srcValue)) { @@ -56,10 +59,10 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, sta } else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { isCommon = false; - newValue = baseClone(srcValue); + newValue = baseClone(srcValue, true); } else { - newValue = srcIndex ? baseClone(objValue) : objValue; + newValue = objValue; } } else { diff --git a/_basePullAt.js b/_basePullAt.js index 206b1965f..eb9ed21e8 100644 --- a/_basePullAt.js +++ b/_basePullAt.js @@ -1,4 +1,4 @@ -var baseToPath = require('./_baseToPath'), +var baseCastPath = require('./_baseCastPath'), isIndex = require('./_isIndex'), isKey = require('./_isKey'), last = require('./last'), @@ -31,7 +31,7 @@ function basePullAt(array, indexes) { splice.call(array, index, 1); } else if (!isKey(index, array)) { - var path = baseToPath(index), + var path = baseCastPath(index), object = parent(array, path); if (object != null) { diff --git a/_baseSet.js b/_baseSet.js index 07b18406d..0596d8941 100644 --- a/_baseSet.js +++ b/_baseSet.js @@ -1,5 +1,5 @@ var assignValue = require('./_assignValue'), - baseToPath = require('./_baseToPath'), + baseCastPath = require('./_baseCastPath'), isIndex = require('./_isIndex'), isKey = require('./_isKey'), isObject = require('./isObject'); @@ -15,7 +15,7 @@ var assignValue = require('./_assignValue'), * @returns {Object} Returns `object`. */ function baseSet(object, path, value, customizer) { - path = isKey(path, object) ? [path + ''] : baseToPath(path); + path = isKey(path, object) ? [path + ''] : baseCastPath(path); var index = -1, length = path.length, @@ -30,7 +30,9 @@ function baseSet(object, path, value, customizer) { var objValue = nested[key]; newValue = customizer ? customizer(objValue, key, nested) : undefined; if (newValue === undefined) { - newValue = objValue == null ? (isIndex(path[index + 1]) ? [] : {}) : objValue; + newValue = objValue == null + ? (isIndex(path[index + 1]) ? [] : {}) + : objValue; } } assignValue(nested, key, newValue); diff --git a/_baseToPath.js b/_baseToPath.js deleted file mode 100644 index eb45827ca..000000000 --- a/_baseToPath.js +++ /dev/null @@ -1,16 +0,0 @@ -var isArray = require('./isArray'), - stringToPath = require('./_stringToPath'); - -/** - * The base implementation of `_.toPath` which only converts `value` to a - * path if it's not one. - * - * @private - * @param {*} value The value to process. - * @returns {Array} Returns the property path array. - */ -function baseToPath(value) { - return isArray(value) ? value : stringToPath(value); -} - -module.exports = baseToPath; diff --git a/_baseUnset.js b/_baseUnset.js index 2be1c1270..02b564069 100644 --- a/_baseUnset.js +++ b/_baseUnset.js @@ -1,4 +1,4 @@ -var baseToPath = require('./_baseToPath'), +var baseCastPath = require('./_baseCastPath'), has = require('./has'), isKey = require('./_isKey'), last = require('./last'), @@ -13,7 +13,7 @@ var baseToPath = require('./_baseToPath'), * @returns {boolean} Returns `true` if the property is deleted, else `false`. */ function baseUnset(object, path) { - path = isKey(path, object) ? [path + ''] : baseToPath(path); + path = isKey(path, object) ? [path + ''] : baseCastPath(path); object = parent(object, path); var key = last(path); return (object != null && has(object, key)) ? delete object[key] : true; diff --git a/_cloneTypedArray.js b/_cloneTypedArray.js index 8a2d0f7e6..26895a671 100644 --- a/_cloneTypedArray.js +++ b/_cloneTypedArray.js @@ -9,10 +9,11 @@ var cloneArrayBuffer = require('./_cloneArrayBuffer'); * @returns {Object} Returns the cloned typed array. */ function cloneTypedArray(typedArray, isDeep) { - var buffer = typedArray.buffer, + var arrayBuffer = typedArray.buffer, + buffer = isDeep ? cloneArrayBuffer(arrayBuffer) : arrayBuffer, Ctor = typedArray.constructor; - return new Ctor(isDeep ? cloneArrayBuffer(buffer) : buffer, typedArray.byteOffset, typedArray.length); + return new Ctor(buffer, typedArray.byteOffset, typedArray.length); } module.exports = cloneTypedArray; diff --git a/_copyObjectWith.js b/_copyObjectWith.js index ac5b9d3be..c4c1f45b3 100644 --- a/_copyObjectWith.js +++ b/_copyObjectWith.js @@ -18,8 +18,11 @@ function copyObjectWith(source, props, object, customizer) { length = props.length; while (++index < length) { - var key = props[index], - newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key]; + var key = props[index]; + + var newValue = customizer + ? customizer(object[key], source[key], key, object, source) + : source[key]; assignValue(object, key, newValue); } diff --git a/_createAssigner.js b/_createAssigner.js index 72c3039e5..1e81db931 100644 --- a/_createAssigner.js +++ b/_createAssigner.js @@ -15,7 +15,10 @@ function createAssigner(assigner) { customizer = length > 1 ? sources[length - 1] : undefined, guard = length > 2 ? sources[2] : undefined; - customizer = typeof customizer == 'function' ? (length--, customizer) : undefined; + customizer = typeof customizer == 'function' + ? (length--, customizer) + : undefined; + if (guard && isIterateeCall(sources[0], sources[1], guard)) { customizer = length < 3 ? undefined : customizer; length = 1; diff --git a/_createCaseFirst.js b/_createCaseFirst.js index 5718f6f4a..a6f70543e 100644 --- a/_createCaseFirst.js +++ b/_createCaseFirst.js @@ -24,8 +24,11 @@ function createCaseFirst(methodName) { return function(string) { string = toString(string); - var strSymbols = reHasComplexSymbol.test(string) ? stringToArray(string) : undefined, - chr = strSymbols ? strSymbols[0] : string.charAt(0), + var strSymbols = reHasComplexSymbol.test(string) + ? stringToArray(string) + : undefined; + + var chr = strSymbols ? strSymbols[0] : string.charAt(0), trailing = strSymbols ? strSymbols.slice(1).join('') : string.slice(1); return chr[methodName]() + trailing; diff --git a/_createFlow.js b/_createFlow.js index 1d5e5f181..eb2449400 100644 --- a/_createFlow.js +++ b/_createFlow.js @@ -27,7 +27,7 @@ var FUNC_ERROR_TEXT = 'Expected a function'; */ function createFlow(fromRight) { return rest(function(funcs) { - funcs = baseFlatten(funcs); + funcs = baseFlatten(funcs, 1); var length = funcs.length, index = length, @@ -52,7 +52,10 @@ function createFlow(fromRight) { var funcName = getFuncName(func), data = funcName == 'wrapper' ? getData(func) : undefined; - if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) { + if (data && isLaziable(data[0]) && + data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && + !data[4].length && data[9] == 1 + ) { wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); } else { wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func); @@ -62,7 +65,8 @@ function createFlow(fromRight) { var args = arguments, value = args[0]; - if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) { + if (wrapper && args.length == 1 && + isArray(value) && value.length >= LARGE_ARRAY_SIZE) { return wrapper.plant(value).value(); } var index = 0, diff --git a/_createHybridWrapper.js b/_createHybridWrapper.js index 7d34c7491..827fe882a 100644 --- a/_createHybridWrapper.js +++ b/_createHybridWrapper.js @@ -60,7 +60,10 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials length -= argsHolders.length; if (length < arity) { - return createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder, thisArg, args, argsHolders, argPos, ary, arity - length); + return createRecurryWrapper( + func, bitmask, createHybridWrapper, placeholder, thisArg, args, + argsHolders, argPos, ary, arity - length + ); } } var thisBinding = isBind ? thisArg : this, diff --git a/_createOver.js b/_createOver.js index 62fed0216..f0a99c354 100644 --- a/_createOver.js +++ b/_createOver.js @@ -13,7 +13,7 @@ var apply = require('./_apply'), */ function createOver(arrayFunc) { return rest(function(iteratees) { - iteratees = arrayMap(baseFlatten(iteratees), baseIteratee); + iteratees = arrayMap(baseFlatten(iteratees, 1), baseIteratee); return rest(function(args) { var thisArg = this; return arrayFunc(iteratees, function(iteratee) { diff --git a/_createRecurryWrapper.js b/_createRecurryWrapper.js index 2e3f10a89..46422cd5b 100644 --- a/_createRecurryWrapper.js +++ b/_createRecurryWrapper.js @@ -40,9 +40,12 @@ function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, par if (!(bitmask & CURRY_BOUND_FLAG)) { bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG); } - var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, arity], - result = wrapFunc.apply(undefined, newData); + var newData = [ + func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, + newHoldersRight, newArgPos, ary, arity + ]; + var result = wrapFunc.apply(undefined, newData); if (isLaziable(func)) { setData(result, newData); } diff --git a/_createWrapper.js b/_createWrapper.js index f391c1a35..6512f56ae 100644 --- a/_createWrapper.js +++ b/_createWrapper.js @@ -67,8 +67,12 @@ function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, a partials = holders = undefined; } - var data = isBindKey ? undefined : getData(func), - newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity]; + var data = isBindKey ? undefined : getData(func); + + var newData = [ + func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, + argPos, ary, arity + ]; if (data) { mergeData(newData, data); diff --git a/_hasPath.js b/_hasPath.js index c063592ce..ed4f1a1c3 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -1,4 +1,4 @@ -var baseToPath = require('./_baseToPath'), +var baseCastPath = require('./_baseCastPath'), isArguments = require('./isArguments'), isArray = require('./isArray'), isIndex = require('./_isIndex'), @@ -23,7 +23,7 @@ function hasPath(object, path, hasFunc) { } var result = hasFunc(object, path); if (!result && !isKey(path)) { - path = baseToPath(path); + path = baseCastPath(path); object = parent(object, path); if (object != null) { path = last(path); diff --git a/_isKeyable.js b/_isKeyable.js index a2521b2da..5df83c0e9 100644 --- a/_isKeyable.js +++ b/_isKeyable.js @@ -8,7 +8,7 @@ function isKeyable(value) { var type = typeof value; return type == 'number' || type == 'boolean' || - (type == 'string' && value !== '__proto__') || value == null; + (type == 'string' && value != '__proto__') || value == null; } module.exports = isKeyable; diff --git a/_lazyValue.js b/_lazyValue.js index cc6ebcff1..09bf14b43 100644 --- a/_lazyValue.js +++ b/_lazyValue.js @@ -36,7 +36,8 @@ function lazyValue() { resIndex = 0, takeCount = nativeMin(length, this.__takeCount__); - if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) { + if (!isArr || arrLength < LARGE_ARRAY_SIZE || + (arrLength == length && takeCount == length)) { return baseWrapperValue(array, this.__actions__); } var result = []; diff --git a/_mapClear.js b/_mapClear.js index c8ca3ef7c..296f41794 100644 --- a/_mapClear.js +++ b/_mapClear.js @@ -9,7 +9,11 @@ var Hash = require('./_Hash'), * @memberOf MapCache */ function mapClear() { - this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash }; + this.__data__ = { + 'hash': new Hash, + 'map': Map ? new Map : [], + 'string': new Hash + }; } module.exports = mapClear; diff --git a/_root.js b/_root.js index b491ca4e6..d2cfd3114 100644 --- a/_root.js +++ b/_root.js @@ -7,10 +7,14 @@ var objectTypes = { }; /** Detect free variable `exports`. */ -var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null; +var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) + ? exports + : undefined; /** Detect free variable `module`. */ -var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null; +var freeModule = (objectTypes[typeof module] && module && !module.nodeType) + ? module + : undefined; /** Detect free variable `global` from Node.js. */ var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global); @@ -30,6 +34,8 @@ var thisGlobal = checkGlobal(objectTypes[typeof this] && this); * 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')(); +var root = freeGlobal || + ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || + freeSelf || thisGlobal || Function('return this')(); module.exports = root; diff --git a/_toArrayLikeObject.js b/_toArrayLikeObject.js deleted file mode 100644 index be01dabc7..000000000 --- a/_toArrayLikeObject.js +++ /dev/null @@ -1,14 +0,0 @@ -var isArrayLikeObject = require('./isArrayLikeObject'); - -/** - * Converts `value` to an array-like object if it's not one. - * - * @private - * @param {*} value The value to process. - * @returns {Array} Returns the array-like object. - */ -function toArrayLikeObject(value) { - return isArrayLikeObject(value) ? value : []; -} - -module.exports = toArrayLikeObject; diff --git a/_toFunction.js b/_toFunction.js deleted file mode 100644 index 4fa85d171..000000000 --- a/_toFunction.js +++ /dev/null @@ -1,14 +0,0 @@ -var identity = require('./identity'); - -/** - * Converts `value` to a function if it's not one. - * - * @private - * @param {*} value The value to process. - * @returns {Function} Returns the function. - */ -function toFunction(value) { - return typeof value == 'function' ? value : identity; -} - -module.exports = toFunction; diff --git a/array.js b/array.js index 01c121671..c1f54a58a 100644 --- a/array.js +++ b/array.js @@ -14,6 +14,7 @@ module.exports = { 'findLastIndex': require('./findLastIndex'), 'flatten': require('./flatten'), 'flattenDeep': require('./flattenDeep'), + 'flattenDepth': require('./flattenDepth'), 'fromPairs': require('./fromPairs'), 'head': require('./head'), 'indexOf': require('./indexOf'), diff --git a/at.js b/at.js index cc3618835..cb35a54c3 100644 --- a/at.js +++ b/at.js @@ -23,7 +23,7 @@ var baseAt = require('./_baseAt'), * // => ['a', 'c'] */ var at = rest(function(object, paths) { - return baseAt(object, baseFlatten(paths)); + return baseAt(object, baseFlatten(paths, 1)); }); module.exports = at; diff --git a/attempt.js b/attempt.js index 322bf2fd1..52bc3e327 100644 --- a/attempt.js +++ b/attempt.js @@ -1,5 +1,5 @@ var apply = require('./_apply'), - isObject = require('./isObject'), + isError = require('./isError'), rest = require('./rest'); /** @@ -26,7 +26,7 @@ var attempt = rest(function(func, args) { try { return apply(func, undefined, args); } catch (e) { - return isObject(e) ? e : new Error(e); + return isError(e) ? e : new Error(e); } }); diff --git a/bindAll.js b/bindAll.js index d5bde4249..ddbc2ffbb 100644 --- a/bindAll.js +++ b/bindAll.js @@ -30,7 +30,7 @@ var arrayEach = require('./_arrayEach'), * // => logs 'clicked docs' when clicked */ var bindAll = rest(function(object, methodNames) { - arrayEach(baseFlatten(methodNames), function(key) { + arrayEach(baseFlatten(methodNames, 1), function(key) { object[key] = bind(object[key], object); }); return object; diff --git a/castArray.js b/castArray.js new file mode 100644 index 000000000..4ea96fc37 --- /dev/null +++ b/castArray.js @@ -0,0 +1,43 @@ +var isArray = require('./isArray'); + +/** + * Casts `value` as an array if it's not one. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to inspect. + * @returns {Array} Returns the cast array. + * @example + * + * _.castArray(1); + * // => [1] + * + * _.castArray({ 'a': 1 }); + * // => [{ 'a': 1 }] + * + * _.castArray('abc'); + * // => ['abc'] + * + * _.castArray(null); + * // => [null] + * + * _.castArray(undefined); + * // => [undefined] + * + * _.castArray(); + * // => [] + * + * var array = [1, 2, 3]; + * console.log(_.castArray(array) === array); + * // => true + */ +function castArray() { + if (!arguments.length) { + return []; + } + var value = arguments[0]; + return isArray(value) ? value : [value]; +} + +module.exports = castArray; diff --git a/concat.js b/concat.js index a3a78df0e..1d2b84661 100644 --- a/concat.js +++ b/concat.js @@ -28,7 +28,7 @@ var concat = rest(function(array, values) { if (!isArray(array)) { array = array == null ? [] : [Object(array)]; } - values = baseFlatten(values); + values = baseFlatten(values, 1); return arrayConcat(array, values); }); diff --git a/core.js b/core.js index ee2a004e7..963c9c72c 100644 --- a/core.js +++ b/core.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.3.0 (Custom Build) + * lodash 4.4.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.3.0'; + var VERSION = '4.4.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1, @@ -27,7 +27,8 @@ var FUNC_ERROR_TEXT = 'Expected a function'; /** Used as references for various `Number` constants. */ - var MAX_SAFE_INTEGER = 9007199254740991; + var INFINITY = 1 / 0, + MAX_SAFE_INTEGER = 9007199254740991; /** `Object#toString` result references. */ var argsTag = '[object Arguments]', @@ -66,10 +67,19 @@ }; /** Detect free variable `exports`. */ - var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null; + var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) + ? exports + : undefined; /** Detect free variable `module`. */ - var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null; + var freeModule = (objectTypes[typeof module] && module && !module.nodeType) + ? module + : undefined; + + /** Detect the popular CommonJS extension `module.exports`. */ + var moduleExports = (freeModule && freeModule.exports === freeExports) + ? freeExports + : undefined; /** Detect free variable `global` from Node.js. */ var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global); @@ -80,9 +90,6 @@ /** Detect free variable `window`. */ var freeWindow = checkGlobal(objectTypes[typeof window] && window); - /** Detect the popular CommonJS extension `module.exports`. */ - var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null; - /** Detect `this` as the global object. */ var thisGlobal = checkGlobal(objectTypes[typeof this] && this); @@ -92,7 +99,9 @@ * 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')(); + var root = freeGlobal || + ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || + freeSelf || thisGlobal || Function('return this')(); /*--------------------------------------------------------------------------*/ @@ -365,6 +374,7 @@ Symbol = root.Symbol, Uint8Array = root.Uint8Array, enumerate = Reflect ? Reflect.enumerate : undefined, + objectCreate = Object.create, propertyIsEnumerable = objectProto.propertyIsEnumerable; /* Built-in method references for those with the same name as other `lodash` methods. */ @@ -413,28 +423,28 @@ * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` * * The chainable wrapper methods are: - * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, - * `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`, - * `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`, - * `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`, + * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`, + * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`, + * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, + * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`, * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`, - * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`, - * `flowRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`, - * `intersection`, `intersectionBy`, `intersectionWith`, `invert`, `invertBy`, - * `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, - * `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, - * `method`, `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, - * `orderBy`, `over`, `overArgs`, `overEvery`, `overSome`, `partial`, - * `partialRight`, `partition`, `pick`, `pickBy`, `plant`, `property`, - * `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, - * `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, `sampleSize`, - * `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, - * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, - * `thru`, `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, - * `transform`, `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, - * `uniqWith`, `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, - * `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, - * `zipObjectDeep`, and `zipWith` + * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flattenDepth`, + * `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, `functionsIn`, + * `groupBy`, `initial`, `intersection`, `intersectionBy`, `intersectionWith`, + * `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`, + * `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, `memoize`, + * `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, `nthArg`, + * `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, `overEvery`, + * `overSome`, `partial`, `partialRight`, `partition`, `pick`, `pickBy`, `plant`, + * `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`, + * `range`, `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, + * `sampleSize`, `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, + * `splice`, `spread`, `tail`, `take`, `takeRight`, `takeRightWhile`, + * `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, `toPairs`, `toPairsIn`, + * `toPath`, `toPlainObject`, `transform`, `unary`, `union`, `unionBy`, + * `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, `unshift`, `unzip`, + * `unzipWith`, `values`, `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, + * `xorWith`, `zip`, `zipObject`, `zipObjectDeep`, and `zipWith` * * The wrapper methods that are **not** chainable by default are: * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, @@ -549,6 +559,17 @@ } } + /** + * Casts `value` to `identity` if it's not a function. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array} Returns the array-like object. + */ + function baseCastFunction(value) { + return typeof value == 'function' ? value : identity; + } + /** * The base implementation of `_.create` without support for assigning * properties to the created object. @@ -557,17 +578,9 @@ * @param {Object} prototype The object to inherit from. * @returns {Object} Returns the new object. */ - var baseCreate = (function() { - function object() {} - return function(prototype) { - if (isObject(prototype)) { - object.prototype = prototype; - var result = new object; - object.prototype = undefined; - } - return result || {}; - }; - }()); + function baseCreate(proto) { + return isObject(proto) ? objectCreate(proto) : {}; + } /** * The base implementation of `_.delay` and `_.defer` which accepts an array @@ -636,12 +649,12 @@ * * @private * @param {Array} array The array to flatten. - * @param {boolean} [isDeep] Specify a deep flatten. + * @param {number} depth The maximum recursion depth. * @param {boolean} [isStrict] Restrict flattening to arrays-like objects. * @param {Array} [result=[]] The initial result value. * @returns {Array} Returns the new flattened array. */ - function baseFlatten(array, isDeep, isStrict, result) { + function baseFlatten(array, depth, isStrict, result) { result || (result = []); var index = -1, @@ -649,11 +662,11 @@ while (++index < length) { var value = array[index]; - if (isArrayLikeObject(value) && + if (depth > 0 && isArrayLikeObject(value) && (isStrict || isArray(value) || isArguments(value))) { - if (isDeep) { + if (depth > 1) { // Recursively flatten arrays (susceptible to call stack limits). - baseFlatten(value, isDeep, isStrict, result); + baseFlatten(value, depth - 1, isStrict, result); } else { arrayPush(result, value); } @@ -816,7 +829,6 @@ * property of prototypes or treat sparse arrays as dense. * * @private - * @type Function * @param {Object} object The object to query. * @returns {Array} Returns the array of property names. */ @@ -1032,8 +1044,11 @@ length = props.length; while (++index < length) { - var key = props[index], - newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key]; + var key = props[index]; + + var newValue = customizer + ? customizer(object[key], source[key], key, object, source) + : source[key]; assignValue(object, key, newValue); } @@ -1053,7 +1068,10 @@ length = sources.length, customizer = length > 1 ? sources[length - 1] : undefined; - customizer = typeof customizer == 'function' ? (length--, customizer) : undefined; + customizer = typeof customizer == 'function' + ? (length--, customizer) + : undefined; + object = Object(object); while (++index < length) { var source = sources[index]; @@ -1382,17 +1400,6 @@ return value === proto; } - /** - * Converts `value` to a function if it's not one. - * - * @private - * @param {*} value The value to process. - * @returns {Function} Returns the function. - */ - function toFunction(value) { - return typeof value == 'function' ? value : identity; - } - /** * Creates a clone of `wrapper`. * @@ -1451,12 +1458,12 @@ if (!isArray(array)) { array = array == null ? [] : [Object(array)]; } - values = baseFlatten(values); + values = baseFlatten(values, 1); return arrayConcat(array, values); }); /** - * Flattens `array` a single level. + * Flattens `array` a single level deep. * * @static * @memberOf _ @@ -1465,30 +1472,30 @@ * @returns {Array} Returns the new flattened array. * @example * - * _.flatten([1, [2, 3, [4]]]); - * // => [1, 2, 3, [4]] + * _.flatten([1, [2, [3, [4]], 5]]); + * // => [1, 2, [3, [4]], 5] */ function flatten(array) { var length = array ? array.length : 0; - return length ? baseFlatten(array) : []; + return length ? baseFlatten(array, 1) : []; } /** - * This method is like `_.flatten` except that it recursively flattens `array`. + * Recursively flattens `array`. * * @static * @memberOf _ * @category Array - * @param {Array} array The array to recursively flatten. + * @param {Array} array The array to flatten. * @returns {Array} Returns the new flattened array. * @example * - * _.flattenDeep([1, [2, 3, [4]]]); - * // => [1, 2, 3, 4] + * _.flattenDeep([1, [2, [3, [4]], 5]]); + * // => [1, 2, 3, 4, 5] */ function flattenDeep(array) { var length = array ? array.length : 0; - return length ? baseFlatten(array, true) : []; + return length ? baseFlatten(array, INFINITY) : []; } /** @@ -1872,7 +1879,7 @@ * // => logs 'a' then 'b' (iteration order is not guaranteed) */ function forEach(collection, iteratee) { - return baseEach(collection, toFunction(iteratee)); + return baseEach(collection, baseCastFunction(iteratee)); } /** @@ -2400,7 +2407,7 @@ * * @static * @memberOf _ - * @type Function + * @type {Function} * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. @@ -2427,7 +2434,6 @@ * * @static * @memberOf _ - * @type Function * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is array-like, else `false`. @@ -2456,7 +2462,6 @@ * * @static * @memberOf _ - * @type Function * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`. @@ -2548,7 +2553,8 @@ */ function isEmpty(value) { if (isArrayLike(value) && - (isArray(value) || isString(value) || isFunction(value.splice) || isArguments(value))) { + (isArray(value) || isString(value) || + isFunction(value.splice) || isArguments(value))) { return !value.length; } for (var key in value) { @@ -2667,7 +2673,8 @@ * // => false */ function isLength(value) { - return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; + return typeof value == 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; } /** @@ -3295,7 +3302,7 @@ * // => { 'a': 1, 'c': 3 } */ var pick = rest(function(object, props) { - return object == null ? {} : basePick(object, baseFlatten(props)); + return object == null ? {} : basePick(object, baseFlatten(props, 1)); }); /** @@ -3429,7 +3436,8 @@ * Creates a function that invokes `func` with the arguments of the created * function. If `func` is a property name the created callback returns the * property value for a given element. If `func` is an object the created - * callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`. + * callback returns `true` for elements that contain the equivalent object + * properties, otherwise it returns `false`. * * @static * @memberOf _ @@ -3457,9 +3465,10 @@ var iteratee = baseIteratee; /** - * Creates a function that performs a deep partial comparison between a given + * Creates a function that performs a partial deep comparison between a given * object and `source`, returning `true` if the given object has equivalent - * property values, else `false`. + * property values, else `false`. The created function is equivalent to + * `_.isMatch` with a `source` partially applied. * * **Note:** This method supports comparing the same values as `_.isEqual`. * @@ -3597,7 +3606,7 @@ * @static * @memberOf _ * @category Util - * @param {string} [prefix] The value to prefix the ID with. + * @param {string} [prefix=''] The value to prefix the ID with. * @returns {string} Returns the unique ID. * @example * @@ -3759,7 +3768,7 @@ * * @static * @memberOf _ - * @type string + * @type {string} */ lodash.VERSION = VERSION; diff --git a/debounce.js b/debounce.js index fd735e933..45f52ce3c 100644 --- a/debounce.js +++ b/debounce.js @@ -138,8 +138,10 @@ function debounce(func, wait, options) { if (!lastCalled && !maxTimeoutId && !leading) { lastCalled = stamp; } - var remaining = maxWait - (stamp - lastCalled), - isCalled = remaining <= 0 || remaining > maxWait; + var remaining = maxWait - (stamp - lastCalled); + + var isCalled = (remaining <= 0 || remaining > maxWait) && + (leading || maxTimeoutId); if (isCalled) { if (maxTimeoutId) { diff --git a/difference.js b/difference.js index 5036d8ef7..3a63f3395 100644 --- a/difference.js +++ b/difference.js @@ -21,7 +21,7 @@ var baseDifference = require('./_baseDifference'), */ var difference = rest(function(array, values) { return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, false, true)) + ? baseDifference(array, baseFlatten(values, 1, true)) : []; }); diff --git a/differenceBy.js b/differenceBy.js index 550ccfa0f..f4bc8438d 100644 --- a/differenceBy.js +++ b/differenceBy.js @@ -32,7 +32,7 @@ var differenceBy = rest(function(array, values) { iteratee = undefined; } return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, false, true), baseIteratee(iteratee)) + ? baseDifference(array, baseFlatten(values, 1, true), baseIteratee(iteratee)) : []; }); diff --git a/differenceWith.js b/differenceWith.js index b60f3a068..39f780160 100644 --- a/differenceWith.js +++ b/differenceWith.js @@ -29,7 +29,7 @@ var differenceWith = rest(function(array, values) { comparator = undefined; } return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, false, true), undefined, comparator) + ? baseDifference(array, baseFlatten(values, 1, true), undefined, comparator) : []; }); diff --git a/flatMap.js b/flatMap.js index 1aaf28c4b..0117bb492 100644 --- a/flatMap.js +++ b/flatMap.js @@ -22,7 +22,7 @@ var baseFlatten = require('./_baseFlatten'), * // => [1, 1, 2, 2] */ function flatMap(collection, iteratee) { - return baseFlatten(map(collection, iteratee)); + return baseFlatten(map(collection, iteratee), 1); } module.exports = flatMap; diff --git a/flatten.js b/flatten.js index 6a6b8cf7c..b8f701dc7 100644 --- a/flatten.js +++ b/flatten.js @@ -1,7 +1,7 @@ var baseFlatten = require('./_baseFlatten'); /** - * Flattens `array` a single level. + * Flattens `array` a single level deep. * * @static * @memberOf _ @@ -10,12 +10,12 @@ var baseFlatten = require('./_baseFlatten'); * @returns {Array} Returns the new flattened array. * @example * - * _.flatten([1, [2, 3, [4]]]); - * // => [1, 2, 3, [4]] + * _.flatten([1, [2, [3, [4]], 5]]); + * // => [1, 2, [3, [4]], 5] */ function flatten(array) { var length = array ? array.length : 0; - return length ? baseFlatten(array) : []; + return length ? baseFlatten(array, 1) : []; } module.exports = flatten; diff --git a/flattenDeep.js b/flattenDeep.js index 3daab79e1..b96cd56b1 100644 --- a/flattenDeep.js +++ b/flattenDeep.js @@ -1,21 +1,24 @@ var baseFlatten = require('./_baseFlatten'); +/** Used as references for various `Number` constants. */ +var INFINITY = 1 / 0; + /** - * This method is like `_.flatten` except that it recursively flattens `array`. + * Recursively flattens `array`. * * @static * @memberOf _ * @category Array - * @param {Array} array The array to recursively flatten. + * @param {Array} array The array to flatten. * @returns {Array} Returns the new flattened array. * @example * - * _.flattenDeep([1, [2, 3, [4]]]); - * // => [1, 2, 3, 4] + * _.flattenDeep([1, [2, [3, [4]], 5]]); + * // => [1, 2, 3, 4, 5] */ function flattenDeep(array) { var length = array ? array.length : 0; - return length ? baseFlatten(array, true) : []; + return length ? baseFlatten(array, INFINITY) : []; } module.exports = flattenDeep; diff --git a/flattenDepth.js b/flattenDepth.js new file mode 100644 index 000000000..e045711ef --- /dev/null +++ b/flattenDepth.js @@ -0,0 +1,32 @@ +var baseFlatten = require('./_baseFlatten'), + toInteger = require('./toInteger'); + +/** + * Recursively flatten `array` up to `depth` times. + * + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array to flatten. + * @param {number} [depth=1] The maximum recursion depth. + * @returns {Array} Returns the new flattened array. + * @example + * + * var array = [1, [2, [3, [4]], 5]]; + * + * _.flattenDepth(array, 1); + * // => [1, 2, [3, [4]], 5] + * + * _.flattenDepth(array, 2); + * // => [1, 2, 3, [4], 5] + */ +function flattenDepth(array, depth) { + var length = array ? array.length : 0; + if (!length) { + return []; + } + depth = depth === undefined ? 1 : toInteger(depth); + return baseFlatten(array, depth); +} + +module.exports = flattenDepth; diff --git a/forEach.js b/forEach.js index e7bde6dee..a11eb2253 100644 --- a/forEach.js +++ b/forEach.js @@ -1,7 +1,7 @@ var arrayEach = require('./_arrayEach'), + baseCastFunction = require('./_baseCastFunction'), baseEach = require('./_baseEach'), - isArray = require('./isArray'), - toFunction = require('./_toFunction'); + isArray = require('./isArray'); /** * Iterates over elements of `collection` invoking `iteratee` for each element. @@ -34,7 +34,7 @@ var arrayEach = require('./_arrayEach'), function forEach(collection, iteratee) { return (typeof iteratee == 'function' && isArray(collection)) ? arrayEach(collection, iteratee) - : baseEach(collection, toFunction(iteratee)); + : baseEach(collection, baseCastFunction(iteratee)); } module.exports = forEach; diff --git a/forEachRight.js b/forEachRight.js index 68f2e2f2c..ea58e7c87 100644 --- a/forEachRight.js +++ b/forEachRight.js @@ -1,7 +1,7 @@ var arrayEachRight = require('./_arrayEachRight'), + baseCastFunction = require('./_baseCastFunction'), baseEachRight = require('./_baseEachRight'), - isArray = require('./isArray'), - toFunction = require('./_toFunction'); + isArray = require('./isArray'); /** * This method is like `_.forEach` except that it iterates over elements of @@ -24,7 +24,7 @@ var arrayEachRight = require('./_arrayEachRight'), function forEachRight(collection, iteratee) { return (typeof iteratee == 'function' && isArray(collection)) ? arrayEachRight(collection, iteratee) - : baseEachRight(collection, toFunction(iteratee)); + : baseEachRight(collection, baseCastFunction(iteratee)); } module.exports = forEachRight; diff --git a/forIn.js b/forIn.js index d68dd3ada..747175fcd 100644 --- a/forIn.js +++ b/forIn.js @@ -1,6 +1,6 @@ -var baseFor = require('./_baseFor'), - keysIn = require('./keysIn'), - toFunction = require('./_toFunction'); +var baseCastFunction = require('./_baseCastFunction'), + baseFor = require('./_baseFor'), + keysIn = require('./keysIn'); /** * Iterates over own and inherited enumerable properties of an object invoking @@ -29,7 +29,9 @@ var baseFor = require('./_baseFor'), * // => logs 'a', 'b', then 'c' (iteration order is not guaranteed) */ function forIn(object, iteratee) { - return object == null ? object : baseFor(object, toFunction(iteratee), keysIn); + return object == null + ? object + : baseFor(object, baseCastFunction(iteratee), keysIn); } module.exports = forIn; diff --git a/forInRight.js b/forInRight.js index 9dedc259d..fa74e9e16 100644 --- a/forInRight.js +++ b/forInRight.js @@ -1,6 +1,6 @@ -var baseForRight = require('./_baseForRight'), - keysIn = require('./keysIn'), - toFunction = require('./_toFunction'); +var baseCastFunction = require('./_baseCastFunction'), + baseForRight = require('./_baseForRight'), + keysIn = require('./keysIn'); /** * This method is like `_.forIn` except that it iterates over properties of @@ -27,7 +27,9 @@ var baseForRight = require('./_baseForRight'), * // => logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c' */ function forInRight(object, iteratee) { - return object == null ? object : baseForRight(object, toFunction(iteratee), keysIn); + return object == null + ? object + : baseForRight(object, baseCastFunction(iteratee), keysIn); } module.exports = forInRight; diff --git a/forOwn.js b/forOwn.js index ee066cc7c..ac5ddc640 100644 --- a/forOwn.js +++ b/forOwn.js @@ -1,5 +1,5 @@ -var baseForOwn = require('./_baseForOwn'), - toFunction = require('./_toFunction'); +var baseCastFunction = require('./_baseCastFunction'), + baseForOwn = require('./_baseForOwn'); /** * Iterates over own enumerable properties of an object invoking `iteratee` @@ -28,7 +28,7 @@ var baseForOwn = require('./_baseForOwn'), * // => logs 'a' then 'b' (iteration order is not guaranteed) */ function forOwn(object, iteratee) { - return object && baseForOwn(object, toFunction(iteratee)); + return object && baseForOwn(object, baseCastFunction(iteratee)); } module.exports = forOwn; diff --git a/forOwnRight.js b/forOwnRight.js index 1016195b9..7bda5dee3 100644 --- a/forOwnRight.js +++ b/forOwnRight.js @@ -1,5 +1,5 @@ -var baseForOwnRight = require('./_baseForOwnRight'), - toFunction = require('./_toFunction'); +var baseCastFunction = require('./_baseCastFunction'), + baseForOwnRight = require('./_baseForOwnRight'); /** * This method is like `_.forOwn` except that it iterates over properties of @@ -26,7 +26,7 @@ var baseForOwnRight = require('./_baseForOwnRight'), * // => logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b' */ function forOwnRight(object, iteratee) { - return object && baseForOwnRight(object, toFunction(iteratee)); + return object && baseForOwnRight(object, baseCastFunction(iteratee)); } module.exports = forOwnRight; diff --git a/fp.js b/fp.js index d8887e0fe..39196b993 100644 --- a/fp.js +++ b/fp.js @@ -1,2 +1,2 @@ -var _ = require('./lodash').noConflict().runInContext(); +var _ = require('./lodash').runInContext(); module.exports = require('./fp/convert')(_); diff --git a/fp/_baseConvert.js b/fp/_baseConvert.js index 76cc02ce8..d0504cacc 100644 --- a/fp/_baseConvert.js +++ b/fp/_baseConvert.js @@ -18,15 +18,20 @@ var mapping = require('./_mapping'), * @returns {Function|Object} Returns the converted function or object. */ function baseConvert(util, name, func, options) { - options || (options = {}); + var setPlaceholder, + isLib = typeof name == 'function', + isObj = name === Object(name); - if (typeof func != 'function') { + if (isObj) { + options = func; func = name; name = undefined; } if (func == null) { throw new TypeError; } + options || (options = {}); + var config = { 'cap': 'cap' in options ? options.cap : true, 'curry': 'curry' in options ? options.curry : true, @@ -37,13 +42,12 @@ function baseConvert(util, name, func, options) { var forceRearg = ('rearg' in options) && options.rearg; - var isLib = name === undefined && typeof func.VERSION == 'string'; - - var _ = isLib ? func : { + var helpers = isLib ? func : { 'ary': util.ary, 'cloneDeep': util.cloneDeep, 'curry': util.curry, 'forEach': util.forEach, + 'isArray': util.isArray, 'isFunction': util.isFunction, 'iteratee': util.iteratee, 'keys': util.keys, @@ -51,14 +55,17 @@ function baseConvert(util, name, func, options) { 'spread': util.spread }; - var ary = _.ary, - cloneDeep = _.cloneDeep, - curry = _.curry, - each = _.forEach, - isFunction = _.isFunction, - keys = _.keys, - rearg = _.rearg, - spread = _.spread; + var ary = helpers.ary, + cloneDeep = helpers.cloneDeep, + curry = helpers.curry, + each = helpers.forEach, + isArray = helpers.isArray, + isFunction = helpers.isFunction, + keys = helpers.keys, + rearg = helpers.rearg, + spread = helpers.spread; + + var aryMethodKeys = keys(mapping.aryMethod); var baseArity = function(func, n) { return n == 2 @@ -89,7 +96,19 @@ function baseConvert(util, name, func, options) { }; var immutWrap = function(func, cloner) { - return overArg(func, cloner, true); + return function() { + var length = arguments.length; + if (!length) { + return result; + } + var args = Array(length); + while (length--) { + args[length] = arguments[length]; + } + var result = args[0] = cloner(args[0]); + func.apply(undefined, args); + return result; + }; }; var iterateeAry = function(func, n) { @@ -98,28 +117,31 @@ function baseConvert(util, name, func, options) { }); }; - var iterateeRearg = function(func, indexes) { - return overArg(func, function(func) { - var n = indexes.length; - return baseArity(rearg(baseAry(func, n), indexes), n); - }); - }; - var overArg = function(func, iteratee, retArg) { return function() { - var length = arguments.length, - args = Array(length); - + var length = arguments.length; + if (!length) { + return func(); + } + var args = Array(length); while (length--) { args[length] = arguments[length]; } - args[0] = iteratee(args[0]); - var result = func.apply(undefined, args); - return retArg ? args[0] : result; + var index = config.rearg ? 0 : (length - 1); + args[index] = iteratee(args[index]); + return func.apply(undefined, args); }; }; var wrappers = { + 'castArray': function(castArray) { + return function() { + var value = arguments[0]; + return isArray(value) + ? castArray(cloneArray(value)) + : castArray.apply(undefined, arguments); + }; + }, 'iteratee': function(iteratee) { return function() { var func = arguments[0], @@ -166,7 +188,7 @@ function baseConvert(util, name, func, options) { }, 'runInContext': function(runInContext) { return function(context) { - return baseConvert(util, runInContext(context), undefined, options); + return baseConvert(util, runInContext(context), options); }; } }; @@ -190,30 +212,26 @@ function baseConvert(util, name, func, options) { } } var result; - each(mapping.caps, function(cap) { - each(mapping.aryMethod[cap], function(otherName) { + each(aryMethodKeys, function(aryKey) { + each(mapping.aryMethod[aryKey], function(otherName) { if (name == otherName) { var aryN = !isLib && mapping.iterateeAry[name], - reargIndexes = mapping.iterateeRearg[name], spreadStart = mapping.methodSpread[name]; + result = wrapped; if (config.fixed) { result = spreadStart === undefined - ? ary(wrapped, cap) - : spread(wrapped, spreadStart); + ? ary(result, aryKey) + : spread(result, spreadStart); } - if (config.rearg && cap > 1 && (forceRearg || !mapping.skipRearg[name])) { - result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[cap]); + if (config.rearg && aryKey > 1 && (forceRearg || !mapping.skipRearg[name])) { + result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[aryKey]); } - if (config.cap) { - if (reargIndexes) { - result = iterateeRearg(result, reargIndexes); - } else if (aryN) { - result = iterateeAry(result, aryN); - } + if (config.cap && aryN) { + result = iterateeAry(result, aryN); } - if (config.curry && cap > 1) { - result = curry(result, cap); + if (config.curry && aryKey > 1) { + result = curry(result, aryKey); } return false; } @@ -221,24 +239,24 @@ function baseConvert(util, name, func, options) { return !result; }); - result || (result = func); + result || (result = wrapped); if (mapping.placeholder[name]) { + setPlaceholder = true; func.placeholder = result.placeholder = placeholder; } return result; }; - if (!isLib) { + if (!isObj) { return wrap(name, func); } - // Add placeholder. - _.placeholder = placeholder; + var _ = func; // Iterate over methods for the current ary cap. var pairs = []; - each(mapping.caps, function(cap) { - each(mapping.aryMethod[cap], function(key) { - var func = _[mapping.rename[key] || key]; + each(aryMethodKeys, function(aryKey) { + each(mapping.aryMethod[aryKey], function(key) { + var func = _[mapping.remap[key] || key]; if (func) { pairs.push([key, wrap(key, func)]); } @@ -250,6 +268,9 @@ function baseConvert(util, name, func, options) { _[pair[0]] = pair[1]; }); + if (setPlaceholder) { + _.placeholder = placeholder; + } // Wrap the lodash method and its aliases. each(keys(_), function(key) { each(mapping.realToAlias[key] || [], function(alias) { diff --git a/fp/_convertBrowser.js b/fp/_convertBrowser.js index 0e69e66cd..fbd217485 100644 --- a/fp/_convertBrowser.js +++ b/fp/_convertBrowser.js @@ -8,7 +8,10 @@ var baseConvert = require('./_baseConvert'); * @returns {Function} Returns the converted `lodash`. */ function browserConvert(lodash, options) { - return baseConvert(lodash, lodash, undefined, options); + return baseConvert(lodash, lodash, options); } +if (typeof _ == 'function') { + _ = browserConvert(_.runInContext()); +} module.exports = browserConvert; diff --git a/fp/_mapping.js b/fp/_mapping.js index 75f0babaa..56ac6ef8e 100644 --- a/fp/_mapping.js +++ b/fp/_mapping.js @@ -38,55 +38,52 @@ exports.aliasToReal = { /** 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', 'trimChars', 'trimCharsEnd', - 'trimCharsStart', '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' - ] + '1': [ + 'attempt', 'castArray', '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', 'flattenDepth', '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', 'trimChars', 'trimCharsEnd', + 'trimCharsStart', '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] + '2': [1, 0], + '3': [2, 0, 1], + '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.iterateeAry = { 'assignWith': 2, @@ -127,25 +124,18 @@ exports.iterateeAry = { 'transform': 2 }; -/** Used to map method names to iteratee rearg configs. */ -exports.iterateeRearg = { - 'findKey': [1], - 'findLastKey': [1], - 'mapKeys': [1] -}; - /** Used to map method names to rearg configs. */ exports.methodRearg = { 'assignInWith': [1, 2, 0], 'assignWith': [1, 2, 0], - 'clamp': [2, 0, 1], + 'getOr': [2, 1, 0], + 'isMatchWith': [2, 1, 0], 'mergeWith': [1, 2, 0], - 'reduce': [2, 0, 1], - 'reduceRight': [2, 0, 1], - 'set': [2, 0, 1], + 'pullAllBy': [2, 1, 0], 'setWith': [3, 1, 2, 0], - 'slice': [2, 0, 1], - 'transform': [2, 0, 1] + 'sortedIndexBy': [2, 1, 0], + 'sortedLastIndexBy': [2, 1, 0], + 'zipWith': [1, 2, 0] }; /** Used to map method names to spread configs. */ @@ -210,7 +200,7 @@ exports.realToAlias = (function() { }()); /** Used to map method names to other names. */ -exports.rename = { +exports.remap = { 'curryN': 'curry', 'curryRightN': 'curryRight', 'getOr': 'get', diff --git a/fp/_util.js b/fp/_util.js index e1baf3b0a..6f776a9e9 100644 --- a/fp/_util.js +++ b/fp/_util.js @@ -3,6 +3,7 @@ module.exports = { 'cloneDeep': require('../cloneDeep'), 'curry': require('../curry'), 'forEach': require('../_arrayEach'), + 'isArray': require('../isArray'), 'isFunction': require('../isFunction'), 'iteratee': require('../iteratee'), 'keys': require('../_baseKeys'), diff --git a/fp/castArray.js b/fp/castArray.js new file mode 100644 index 000000000..2a75bb97f --- /dev/null +++ b/fp/castArray.js @@ -0,0 +1,2 @@ +var convert = require('./convert'); +module.exports = convert('castArray', require('../castArray')); diff --git a/fp/flattenDepth.js b/fp/flattenDepth.js new file mode 100644 index 000000000..731e27a47 --- /dev/null +++ b/fp/flattenDepth.js @@ -0,0 +1,2 @@ +var convert = require('./convert'); +module.exports = convert('flattenDepth', require('../flattenDepth')); diff --git a/intersection.js b/intersection.js index e97efddb7..d66817117 100644 --- a/intersection.js +++ b/intersection.js @@ -1,7 +1,7 @@ var arrayMap = require('./_arrayMap'), + baseCastArrayLikeObject = require('./_baseCastArrayLikeObject'), baseIntersection = require('./_baseIntersection'), - rest = require('./rest'), - toArrayLikeObject = require('./_toArrayLikeObject'); + rest = require('./rest'); /** * Creates an array of unique values that are included in all given arrays @@ -19,7 +19,7 @@ var arrayMap = require('./_arrayMap'), * // => [2] */ var intersection = rest(function(arrays) { - var mapped = arrayMap(arrays, toArrayLikeObject); + var mapped = arrayMap(arrays, baseCastArrayLikeObject); return (mapped.length && mapped[0] === arrays[0]) ? baseIntersection(mapped) : []; diff --git a/intersectionBy.js b/intersectionBy.js index 2c9e0d330..b631c4785 100644 --- a/intersectionBy.js +++ b/intersectionBy.js @@ -1,9 +1,9 @@ var arrayMap = require('./_arrayMap'), + baseCastArrayLikeObject = require('./_baseCastArrayLikeObject'), baseIntersection = require('./_baseIntersection'), baseIteratee = require('./_baseIteratee'), last = require('./last'), - rest = require('./rest'), - toArrayLikeObject = require('./_toArrayLikeObject'); + rest = require('./rest'); /** * This method is like `_.intersection` except that it accepts `iteratee` @@ -27,7 +27,7 @@ var arrayMap = require('./_arrayMap'), */ var intersectionBy = rest(function(arrays) { var iteratee = last(arrays), - mapped = arrayMap(arrays, toArrayLikeObject); + mapped = arrayMap(arrays, baseCastArrayLikeObject); if (iteratee === last(mapped)) { iteratee = undefined; diff --git a/intersectionWith.js b/intersectionWith.js index c39e38f53..d019d7353 100644 --- a/intersectionWith.js +++ b/intersectionWith.js @@ -1,8 +1,8 @@ var arrayMap = require('./_arrayMap'), + baseCastArrayLikeObject = require('./_baseCastArrayLikeObject'), baseIntersection = require('./_baseIntersection'), last = require('./last'), - rest = require('./rest'), - toArrayLikeObject = require('./_toArrayLikeObject'); + rest = require('./rest'); /** * This method is like `_.intersection` except that it accepts `comparator` @@ -25,7 +25,7 @@ var arrayMap = require('./_arrayMap'), */ var intersectionWith = rest(function(arrays) { var comparator = last(arrays), - mapped = arrayMap(arrays, toArrayLikeObject); + mapped = arrayMap(arrays, baseCastArrayLikeObject); if (comparator === last(mapped)) { comparator = undefined; diff --git a/isArray.js b/isArray.js index 22a1a22eb..fa9b055f4 100644 --- a/isArray.js +++ b/isArray.js @@ -3,7 +3,7 @@ * * @static * @memberOf _ - * @type Function + * @type {Function} * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. diff --git a/isArrayBuffer.js b/isArrayBuffer.js index 80b85633f..a22a9ee45 100644 --- a/isArrayBuffer.js +++ b/isArrayBuffer.js @@ -16,7 +16,6 @@ var objectToString = objectProto.toString; * * @static * @memberOf _ - * @type Function * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. diff --git a/isArrayLike.js b/isArrayLike.js index 9f4ddd51b..0059d636b 100644 --- a/isArrayLike.js +++ b/isArrayLike.js @@ -9,7 +9,6 @@ var getLength = require('./_getLength'), * * @static * @memberOf _ - * @type Function * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is array-like, else `false`. diff --git a/isArrayLikeObject.js b/isArrayLikeObject.js index 22b357737..0b8b2ca08 100644 --- a/isArrayLikeObject.js +++ b/isArrayLikeObject.js @@ -7,7 +7,6 @@ var isArrayLike = require('./isArrayLike'), * * @static * @memberOf _ - * @type Function * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`. diff --git a/isBuffer.js b/isBuffer.js index 1e6b8b6d3..cee6b2218 100644 --- a/isBuffer.js +++ b/isBuffer.js @@ -8,13 +8,19 @@ var objectTypes = { }; /** Detect free variable `exports`. */ -var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null; +var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) + ? exports + : undefined; /** Detect free variable `module`. */ -var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null; +var freeModule = (objectTypes[typeof module] && module && !module.nodeType) + ? module + : undefined; /** Detect the popular CommonJS extension `module.exports`. */ -var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null; +var moduleExports = (freeModule && freeModule.exports === freeExports) + ? freeExports + : undefined; /** Built-in value references. */ var Buffer = moduleExports ? root.Buffer : undefined; diff --git a/isEmpty.js b/isEmpty.js index 29062ed4b..138e28e52 100644 --- a/isEmpty.js +++ b/isEmpty.js @@ -39,7 +39,8 @@ var hasOwnProperty = objectProto.hasOwnProperty; */ function isEmpty(value) { if (isArrayLike(value) && - (isArray(value) || isString(value) || isFunction(value.splice) || isArguments(value))) { + (isArray(value) || isString(value) || + isFunction(value.splice) || isArguments(value))) { return !value.length; } for (var key in value) { diff --git a/isEqualWith.js b/isEqualWith.js index 60fe95d9e..4643a357d 100644 --- a/isEqualWith.js +++ b/isEqualWith.js @@ -1,10 +1,10 @@ var baseIsEqual = require('./_baseIsEqual'); /** - * This method is like `_.isEqual` except that it accepts `customizer` which is - * invoked to compare values. If `customizer` returns `undefined` comparisons are - * handled by the method instead. The `customizer` is invoked with up to six arguments: - * (objValue, othValue [, index|key, object, other, stack]). + * This method is like `_.isEqual` except that it accepts `customizer` which + * is invoked to compare values. If `customizer` returns `undefined` comparisons + * are handled by the method instead. The `customizer` is invoked with up to + * six arguments: (objValue, othValue [, index|key, object, other, stack]). * * @static * @memberOf _ diff --git a/isError.js b/isError.js index e66b443d8..301000dee 100644 --- a/isError.js +++ b/isError.js @@ -30,8 +30,12 @@ var objectToString = objectProto.toString; * // => false */ function isError(value) { - return isObjectLike(value) && - typeof value.message == 'string' && objectToString.call(value) == errorTag; + if (!isObjectLike(value)) { + return false; + } + var Ctor = value.constructor; + return (objectToString.call(value) == errorTag) || + (typeof Ctor == 'function' && objectToString.call(Ctor.prototype) == errorTag); } module.exports = isError; diff --git a/isLength.js b/isLength.js index 2f04aca81..b095123d2 100644 --- a/isLength.js +++ b/isLength.js @@ -26,7 +26,8 @@ var MAX_SAFE_INTEGER = 9007199254740991; * // => false */ function isLength(value) { - return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; + return typeof value == 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; } module.exports = isLength; diff --git a/isMatch.js b/isMatch.js index a14131fef..faf08985f 100644 --- a/isMatch.js +++ b/isMatch.js @@ -2,8 +2,9 @@ var baseIsMatch = require('./_baseIsMatch'), getMatchData = require('./_getMatchData'); /** - * Performs a deep comparison between `object` and `source` to determine if - * `object` contains equivalent property values. + * Performs a partial deep comparison between `object` and `source` to + * determine if `object` contains equivalent property values. This method is + * equivalent to a `_.matches` function when `source` is partially applied. * * **Note:** This method supports comparing the same values as `_.isEqual`. * diff --git a/isPlainObject.js b/isPlainObject.js index 1d68332c0..26aafb4f0 100644 --- a/isPlainObject.js +++ b/isPlainObject.js @@ -50,7 +50,8 @@ var getPrototypeOf = Object.getPrototypeOf; * // => true */ function isPlainObject(value) { - if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) { + if (!isObjectLike(value) || + objectToString.call(value) != objectTag || isHostObject(value)) { return false; } var proto = objectProto; diff --git a/isTypedArray.js b/isTypedArray.js index 9e9b0a274..128332221 100644 --- a/isTypedArray.js +++ b/isTypedArray.js @@ -68,7 +68,8 @@ var objectToString = objectProto.toString; * // => false */ function isTypedArray(value) { - return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; + return isObjectLike(value) && + isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; } module.exports = isTypedArray; diff --git a/iteratee.js b/iteratee.js index c761adbbc..e9d2f8a93 100644 --- a/iteratee.js +++ b/iteratee.js @@ -5,7 +5,8 @@ var baseClone = require('./_baseClone'), * Creates a function that invokes `func` with the arguments of the created * function. If `func` is a property name the created callback returns the * property value for a given element. If `func` is an object the created - * callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`. + * callback returns `true` for elements that contain the equivalent object + * properties, otherwise it returns `false`. * * @static * @memberOf _ diff --git a/lang.js b/lang.js index d3be68f06..665f5c66c 100644 --- a/lang.js +++ b/lang.js @@ -1,4 +1,5 @@ module.exports = { + 'castArray': require('./castArray'), 'clone': require('./clone'), 'cloneDeep': require('./cloneDeep'), 'cloneDeepWith': require('./cloneDeepWith'), diff --git a/lodash.js b/lodash.js index d314acd09..27f4a37c4 100644 --- a/lodash.js +++ b/lodash.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.3.0 (Custom Build) + * lodash 4.4.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.3.0'; + var VERSION = '4.4.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1, @@ -335,10 +335,19 @@ freeParseInt = parseInt; /** Detect free variable `exports`. */ - var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null; + var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) + ? exports + : undefined; /** Detect free variable `module`. */ - var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null; + var freeModule = (objectTypes[typeof module] && module && !module.nodeType) + ? module + : undefined; + + /** Detect the popular CommonJS extension `module.exports`. */ + var moduleExports = (freeModule && freeModule.exports === freeExports) + ? freeExports + : undefined; /** Detect free variable `global` from Node.js. */ var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global); @@ -349,9 +358,6 @@ /** Detect free variable `window`. */ var freeWindow = checkGlobal(objectTypes[typeof window] && window); - /** Detect the popular CommonJS extension `module.exports`. */ - var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null; - /** Detect `this` as the global object. */ var thisGlobal = checkGlobal(objectTypes[typeof this] && this); @@ -361,7 +367,9 @@ * 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')(); + var root = freeGlobal || + ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || + freeSelf || thisGlobal || Function('return this')(); /*--------------------------------------------------------------------------*/ @@ -1316,6 +1324,7 @@ getPrototypeOf = Object.getPrototypeOf, getOwnPropertySymbols = Object.getOwnPropertySymbols, iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined, + objectCreate = Object.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, setTimeout = context.setTimeout, splice = arrayProto.splice; @@ -1395,28 +1404,28 @@ * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` * * The chainable wrapper methods are: - * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, - * `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`, - * `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`, - * `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`, + * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`, + * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`, + * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, + * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`, * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`, - * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`, - * `flowRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`, - * `intersection`, `intersectionBy`, `intersectionWith`, `invert`, `invertBy`, - * `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, - * `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, - * `method`, `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, - * `orderBy`, `over`, `overArgs`, `overEvery`, `overSome`, `partial`, - * `partialRight`, `partition`, `pick`, `pickBy`, `plant`, `property`, - * `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, - * `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, `sampleSize`, - * `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, - * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, - * `thru`, `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, - * `transform`, `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, - * `uniqWith`, `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, - * `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, - * `zipObjectDeep`, and `zipWith` + * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flattenDepth`, + * `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, `functionsIn`, + * `groupBy`, `initial`, `intersection`, `intersectionBy`, `intersectionWith`, + * `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`, + * `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, `memoize`, + * `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, `nthArg`, + * `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, `overEvery`, + * `overSome`, `partial`, `partialRight`, `partition`, `pick`, `pickBy`, `plant`, + * `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`, + * `range`, `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, + * `sampleSize`, `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, + * `splice`, `spread`, `tail`, `take`, `takeRight`, `takeRightWhile`, + * `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, `toPairs`, `toPairsIn`, + * `toPath`, `toPlainObject`, `transform`, `unary`, `union`, `unionBy`, + * `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, `unshift`, `unzip`, + * `unzipWith`, `values`, `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, + * `xorWith`, `zip`, `zipObject`, `zipObjectDeep`, and `zipWith` * * The wrapper methods that are **not** chainable by default are: * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, @@ -1510,7 +1519,7 @@ * * @static * @memberOf _ - * @type Object + * @type {Object} */ lodash.templateSettings = { @@ -1518,7 +1527,7 @@ * Used to detect `data` property values to be HTML-escaped. * * @memberOf _.templateSettings - * @type RegExp + * @type {RegExp} */ 'escape': reEscape, @@ -1526,7 +1535,7 @@ * Used to detect code to be evaluated. * * @memberOf _.templateSettings - * @type RegExp + * @type {RegExp} */ 'evaluate': reEvaluate, @@ -1534,7 +1543,7 @@ * Used to detect `data` property values to inject. * * @memberOf _.templateSettings - * @type RegExp + * @type {RegExp} */ 'interpolate': reInterpolate, @@ -1542,7 +1551,7 @@ * Used to reference the data object in the template text. * * @memberOf _.templateSettings - * @type string + * @type {string} */ 'variable': '', @@ -1550,7 +1559,7 @@ * Used to import variables into the compiled template. * * @memberOf _.templateSettings - * @type Object + * @type {Object} */ 'imports': { @@ -1558,7 +1567,7 @@ * A reference to the `lodash` function. * * @memberOf _.templateSettings.imports - * @type Function + * @type {Function} */ '_': lodash } @@ -1570,6 +1579,7 @@ * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation. * * @private + * @constructor * @param {*} value The value to wrap. */ function LazyWrapper(value) { @@ -1645,7 +1655,8 @@ resIndex = 0, takeCount = nativeMin(length, this.__takeCount__); - if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) { + if (!isArr || arrLength < LARGE_ARRAY_SIZE || + (arrLength == length && takeCount == length)) { return baseWrapperValue(array, this.__actions__); } var result = []; @@ -1684,6 +1695,7 @@ * Creates an hash object. * * @private + * @constructor * @returns {Object} Returns the new hash object. */ function Hash() {} @@ -1746,6 +1758,7 @@ * Creates a map cache object to store key-value pairs. * * @private + * @constructor * @param {Array} [values] The values to cache. */ function MapCache(values) { @@ -1767,7 +1780,11 @@ * @memberOf MapCache */ function mapClear() { - this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash }; + this.__data__ = { + 'hash': new Hash, + 'map': Map ? new Map : [], + 'string': new Hash + }; } /** @@ -1850,6 +1867,7 @@ * Creates a set cache object to store unique values. * * @private + * @constructor * @param {Array} [values] The values to cache. */ function SetCache(values) { @@ -1908,6 +1926,7 @@ * Creates a stack cache object to store key-value pairs. * * @private + * @constructor * @param {Array} [values] The values to cache. */ function Stack(values) { @@ -2199,6 +2218,39 @@ return result; } + /** + * Casts `value` to an empty array if it's not an array like object. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array} Returns the array-like object. + */ + function baseCastArrayLikeObject(value) { + return isArrayLikeObject(value) ? value : []; + } + + /** + * Casts `value` to `identity` if it's not a function. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array} Returns the array-like object. + */ + function baseCastFunction(value) { + return typeof value == 'function' ? value : identity; + } + + /** + * Casts `value` to a path array if it's not one. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array} Returns the cast property path array. + */ + function baseCastPath(value) { + return isArray(value) ? value : stringToPath(value); + } + /** * The base implementation of `_.clamp` which doesn't coerce arguments to numbers. * @@ -2323,17 +2375,9 @@ * @param {Object} prototype The object to inherit from. * @returns {Object} Returns the new object. */ - var baseCreate = (function() { - function object() {} - return function(prototype) { - if (isObject(prototype)) { - object.prototype = prototype; - var result = new object; - object.prototype = undefined; - } - return result || {}; - }; - }()); + function baseCreate(proto) { + return isObject(proto) ? objectCreate(proto) : {}; + } /** * The base implementation of `_.delay` and `_.defer` which accepts an array @@ -2495,12 +2539,12 @@ * * @private * @param {Array} array The array to flatten. - * @param {boolean} [isDeep] Specify a deep flatten. + * @param {number} depth The maximum recursion depth. * @param {boolean} [isStrict] Restrict flattening to arrays-like objects. * @param {Array} [result=[]] The initial result value. * @returns {Array} Returns the new flattened array. */ - function baseFlatten(array, isDeep, isStrict, result) { + function baseFlatten(array, depth, isStrict, result) { result || (result = []); var index = -1, @@ -2508,11 +2552,11 @@ while (++index < length) { var value = array[index]; - if (isArrayLikeObject(value) && + if (depth > 0 && isArrayLikeObject(value) && (isStrict || isArray(value) || isArguments(value))) { - if (isDeep) { + if (depth > 1) { // Recursively flatten arrays (susceptible to call stack limits). - baseFlatten(value, isDeep, isStrict, result); + baseFlatten(value, depth - 1, isStrict, result); } else { arrayPush(result, value); } @@ -2609,7 +2653,7 @@ * @returns {*} Returns the resolved value. */ function baseGet(object, path) { - path = isKey(path, object) ? [path + ''] : baseToPath(path); + path = isKey(path, object) ? [path + ''] : baseCastPath(path); var index = 0, length = path.length; @@ -2698,11 +2742,17 @@ var value = array[index], computed = iteratee ? iteratee(value) : value; - if (!(seen ? cacheHas(seen, computed) : includes(result, computed, comparator))) { + if (!(seen + ? cacheHas(seen, computed) + : includes(result, computed, comparator) + )) { var othIndex = othLength; while (--othIndex) { var cache = caches[othIndex]; - if (!(cache ? cacheHas(cache, computed) : includes(arrays[othIndex], computed, comparator))) { + if (!(cache + ? cacheHas(cache, computed) + : includes(arrays[othIndex], computed, comparator)) + ) { continue outer; } } @@ -2745,7 +2795,7 @@ */ function baseInvoke(object, path, args) { if (!isKey(path, object)) { - path = baseToPath(path); + path = baseCastPath(path); object = parent(object, path); path = last(path); } @@ -2918,7 +2968,6 @@ * property of prototypes or treat sparse arrays as dense. * * @private - * @type Function * @param {Object} object The object to query. * @returns {Array} Returns the array of property names. */ @@ -3026,7 +3075,10 @@ if (object === source) { return; } - var props = (isArray(source) || isTypedArray(source)) ? undefined : keysIn(source); + var props = (isArray(source) || isTypedArray(source)) + ? undefined + : keysIn(source); + arrayEach(props || source, function(srcValue, key) { if (props) { key = srcValue; @@ -3037,7 +3089,10 @@ baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack); } else { - var newValue = customizer ? customizer(object[key], srcValue, (key + ''), object, source, stack) : undefined; + var newValue = customizer + ? customizer(object[key], srcValue, (key + ''), object, source, stack) + : undefined; + if (newValue === undefined) { newValue = srcValue; } @@ -3069,21 +3124,24 @@ assignMergeValue(object, key, stacked); return; } - var newValue = customizer ? customizer(objValue, srcValue, (key + ''), object, source, stack) : undefined, - isCommon = newValue === undefined; + var newValue = customizer + ? customizer(objValue, srcValue, (key + ''), object, source, stack) + : undefined; + + var isCommon = newValue === undefined; if (isCommon) { newValue = srcValue; if (isArray(srcValue) || isTypedArray(srcValue)) { if (isArray(objValue)) { - newValue = srcIndex ? copyArray(objValue) : objValue; + newValue = objValue; } else if (isArrayLikeObject(objValue)) { newValue = copyArray(objValue); } else { isCommon = false; - newValue = baseClone(srcValue); + newValue = baseClone(srcValue, true); } } else if (isPlainObject(srcValue) || isArguments(srcValue)) { @@ -3092,10 +3150,10 @@ } else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { isCommon = false; - newValue = baseClone(srcValue); + newValue = baseClone(srcValue, true); } else { - newValue = srcIndex ? baseClone(objValue) : objValue; + newValue = objValue; } } else { @@ -3269,7 +3327,7 @@ splice.call(array, index, 1); } else if (!isKey(index, array)) { - var path = baseToPath(index), + var path = baseCastPath(index), object = parent(array, path); if (object != null) { @@ -3331,7 +3389,7 @@ * @returns {Object} Returns `object`. */ function baseSet(object, path, value, customizer) { - path = isKey(path, object) ? [path + ''] : baseToPath(path); + path = isKey(path, object) ? [path + ''] : baseCastPath(path); var index = -1, length = path.length, @@ -3346,7 +3404,9 @@ var objValue = nested[key]; newValue = customizer ? customizer(objValue, key, nested) : undefined; if (newValue === undefined) { - newValue = objValue == null ? (isIndex(path[index + 1]) ? [] : {}) : objValue; + newValue = objValue == null + ? (isIndex(path[index + 1]) ? [] : {}) + : objValue; } } assignValue(nested, key, newValue); @@ -3537,18 +3597,6 @@ return result; } - /** - * The base implementation of `_.toPath` which only converts `value` to a - * path if it's not one. - * - * @private - * @param {*} value The value to process. - * @returns {Array} Returns the property path array. - */ - function baseToPath(value) { - return isArray(value) ? value : stringToPath(value); - } - /** * The base implementation of `_.uniqBy` without support for iteratee shorthands. * @@ -3618,7 +3666,7 @@ * @returns {boolean} Returns `true` if the property is deleted, else `false`. */ function baseUnset(object, path) { - path = isKey(path, object) ? [path + ''] : baseToPath(path); + path = isKey(path, object) ? [path + ''] : baseCastPath(path); object = parent(object, path); var key = last(path); return (object != null && has(object, key)) ? delete object[key] : true; @@ -3807,10 +3855,11 @@ * @returns {Object} Returns the cloned typed array. */ function cloneTypedArray(typedArray, isDeep) { - var buffer = typedArray.buffer, + var arrayBuffer = typedArray.buffer, + buffer = isDeep ? cloneArrayBuffer(arrayBuffer) : arrayBuffer, Ctor = typedArray.constructor; - return new Ctor(isDeep ? cloneArrayBuffer(buffer) : buffer, typedArray.byteOffset, typedArray.length); + return new Ctor(buffer, typedArray.byteOffset, typedArray.length); } /** @@ -3925,8 +3974,11 @@ length = props.length; while (++index < length) { - var key = props[index], - newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key]; + var key = props[index]; + + var newValue = customizer + ? customizer(object[key], source[key], key, object, source) + : source[key]; assignValue(object, key, newValue); } @@ -3976,7 +4028,10 @@ customizer = length > 1 ? sources[length - 1] : undefined, guard = length > 2 ? sources[2] : undefined; - customizer = typeof customizer == 'function' ? (length--, customizer) : undefined; + customizer = typeof customizer == 'function' + ? (length--, customizer) + : undefined; + if (guard && isIterateeCall(sources[0], sources[1], guard)) { customizer = length < 3 ? undefined : customizer; length = 1; @@ -4077,8 +4132,11 @@ return function(string) { string = toString(string); - var strSymbols = reHasComplexSymbol.test(string) ? stringToArray(string) : undefined, - chr = strSymbols ? strSymbols[0] : string.charAt(0), + var strSymbols = reHasComplexSymbol.test(string) + ? stringToArray(string) + : undefined; + + var chr = strSymbols ? strSymbols[0] : string.charAt(0), trailing = strSymbols ? strSymbols.slice(1).join('') : string.slice(1); return chr[methodName]() + trailing; @@ -4174,7 +4232,7 @@ */ function createFlow(fromRight) { return rest(function(funcs) { - funcs = baseFlatten(funcs); + funcs = baseFlatten(funcs, 1); var length = funcs.length, index = length, @@ -4199,7 +4257,10 @@ var funcName = getFuncName(func), data = funcName == 'wrapper' ? getData(func) : undefined; - if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) { + if (data && isLaziable(data[0]) && + data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && + !data[4].length && data[9] == 1 + ) { wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); } else { wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func); @@ -4209,7 +4270,8 @@ var args = arguments, value = args[0]; - if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) { + if (wrapper && args.length == 1 && + isArray(value) && value.length >= LARGE_ARRAY_SIZE) { return wrapper.plant(value).value(); } var index = 0, @@ -4269,7 +4331,10 @@ length -= argsHolders.length; if (length < arity) { - return createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder, thisArg, args, argsHolders, argPos, ary, arity - length); + return createRecurryWrapper( + func, bitmask, createHybridWrapper, placeholder, thisArg, args, + argsHolders, argPos, ary, arity - length + ); } } var thisBinding = isBind ? thisArg : this, @@ -4314,7 +4379,7 @@ */ function createOver(arrayFunc) { return rest(function(iteratees) { - iteratees = arrayMap(baseFlatten(iteratees), getIteratee()); + iteratees = arrayMap(baseFlatten(iteratees, 1), getIteratee()); return rest(function(args) { var thisArg = this; return arrayFunc(iteratees, function(iteratee) { @@ -4441,9 +4506,12 @@ if (!(bitmask & CURRY_BOUND_FLAG)) { bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG); } - var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, arity], - result = wrapFunc.apply(undefined, newData); + var newData = [ + func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, + newHoldersRight, newArgPos, ary, arity + ]; + var result = wrapFunc.apply(undefined, newData); if (isLaziable(func)) { setData(result, newData); } @@ -4532,8 +4600,12 @@ partials = holders = undefined; } - var data = isBindKey ? undefined : getData(func), - newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity]; + var data = isBindKey ? undefined : getData(func); + + var newData = [ + func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, + argPos, ary, arity + ]; if (data) { mergeData(newData, data); @@ -4941,7 +5013,7 @@ } var result = hasFunc(object, path); if (!result && !isKey(path)) { - path = baseToPath(path); + path = baseCastPath(path); object = parent(object, path); if (object != null) { path = last(path); @@ -5100,7 +5172,7 @@ function isKeyable(value) { var type = typeof value; return type == 'number' || type == 'boolean' || - (type == 'string' && value !== '__proto__') || value == null; + (type == 'string' && value != '__proto__') || value == null; } /** @@ -5322,28 +5394,6 @@ return result; } - /** - * Converts `value` to an array-like object if it's not one. - * - * @private - * @param {*} value The value to process. - * @returns {Array} Returns the array-like object. - */ - function toArrayLikeObject(value) { - return isArrayLikeObject(value) ? value : []; - } - - /** - * Converts `value` to a function if it's not one. - * - * @private - * @param {*} value The value to process. - * @returns {Function} Returns the function. - */ - function toFunction(value) { - return typeof value == 'function' ? value : identity; - } - /** * Creates a clone of `wrapper`. * @@ -5454,7 +5504,7 @@ if (!isArray(array)) { array = array == null ? [] : [Object(array)]; } - values = baseFlatten(values); + values = baseFlatten(values, 1); return arrayConcat(array, values); }); @@ -5476,7 +5526,7 @@ */ var difference = rest(function(array, values) { return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, false, true)) + ? baseDifference(array, baseFlatten(values, 1, true)) : []; }); @@ -5507,7 +5557,7 @@ iteratee = undefined; } return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, false, true), getIteratee(iteratee)) + ? baseDifference(array, baseFlatten(values, 1, true), getIteratee(iteratee)) : []; }); @@ -5536,7 +5586,7 @@ comparator = undefined; } return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, false, true), undefined, comparator) + ? baseDifference(array, baseFlatten(values, 1, true), undefined, comparator) : []; }); @@ -5806,7 +5856,7 @@ } /** - * Flattens `array` a single level. + * Flattens `array` a single level deep. * * @static * @memberOf _ @@ -5815,30 +5865,58 @@ * @returns {Array} Returns the new flattened array. * @example * - * _.flatten([1, [2, 3, [4]]]); - * // => [1, 2, 3, [4]] + * _.flatten([1, [2, [3, [4]], 5]]); + * // => [1, 2, [3, [4]], 5] */ function flatten(array) { var length = array ? array.length : 0; - return length ? baseFlatten(array) : []; + return length ? baseFlatten(array, 1) : []; } /** - * This method is like `_.flatten` except that it recursively flattens `array`. + * Recursively flattens `array`. * * @static * @memberOf _ * @category Array - * @param {Array} array The array to recursively flatten. + * @param {Array} array The array to flatten. * @returns {Array} Returns the new flattened array. * @example * - * _.flattenDeep([1, [2, 3, [4]]]); - * // => [1, 2, 3, 4] + * _.flattenDeep([1, [2, [3, [4]], 5]]); + * // => [1, 2, 3, 4, 5] */ function flattenDeep(array) { var length = array ? array.length : 0; - return length ? baseFlatten(array, true) : []; + return length ? baseFlatten(array, INFINITY) : []; + } + + /** + * Recursively flatten `array` up to `depth` times. + * + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array to flatten. + * @param {number} [depth=1] The maximum recursion depth. + * @returns {Array} Returns the new flattened array. + * @example + * + * var array = [1, [2, [3, [4]], 5]]; + * + * _.flattenDepth(array, 1); + * // => [1, 2, [3, [4]], 5] + * + * _.flattenDepth(array, 2); + * // => [1, 2, 3, [4], 5] + */ + function flattenDepth(array, depth) { + var length = array ? array.length : 0; + if (!length) { + return []; + } + depth = depth === undefined ? 1 : toInteger(depth); + return baseFlatten(array, depth); } /** @@ -5955,7 +6033,7 @@ * // => [2] */ var intersection = rest(function(arrays) { - var mapped = arrayMap(arrays, toArrayLikeObject); + var mapped = arrayMap(arrays, baseCastArrayLikeObject); return (mapped.length && mapped[0] === arrays[0]) ? baseIntersection(mapped) : []; @@ -5983,7 +6061,7 @@ */ var intersectionBy = rest(function(arrays) { var iteratee = last(arrays), - mapped = arrayMap(arrays, toArrayLikeObject); + mapped = arrayMap(arrays, baseCastArrayLikeObject); if (iteratee === last(mapped)) { iteratee = undefined; @@ -6016,7 +6094,7 @@ */ var intersectionWith = rest(function(arrays) { var comparator = last(arrays), - mapped = arrayMap(arrays, toArrayLikeObject); + mapped = arrayMap(arrays, baseCastArrayLikeObject); if (comparator === last(mapped)) { comparator = undefined; @@ -6206,7 +6284,7 @@ * // => [10, 20] */ var pullAt = rest(function(array, indexes) { - indexes = arrayMap(baseFlatten(indexes), String); + indexes = arrayMap(baseFlatten(indexes, 1), String); var result = baseAt(array, indexes); basePullAt(array, indexes.sort(compareAscending)); @@ -6678,7 +6756,7 @@ * // => [2, 1, 4] */ var union = rest(function(arrays) { - return baseUniq(baseFlatten(arrays, false, true)); + return baseUniq(baseFlatten(arrays, 1, true)); }); /** @@ -6706,7 +6784,7 @@ if (isArrayLikeObject(iteratee)) { iteratee = undefined; } - return baseUniq(baseFlatten(arrays, false, true), getIteratee(iteratee)); + return baseUniq(baseFlatten(arrays, 1, true), getIteratee(iteratee)); }); /** @@ -6733,7 +6811,7 @@ if (isArrayLikeObject(comparator)) { comparator = undefined; } - return baseUniq(baseFlatten(arrays, false, true), undefined, comparator); + return baseUniq(baseFlatten(arrays, 1, true), undefined, comparator); }); /** @@ -7157,17 +7235,22 @@ * // => ['a', 'c'] */ var wrapperAt = rest(function(paths) { - paths = baseFlatten(paths); + paths = baseFlatten(paths, 1); var length = paths.length, start = length ? paths[0] : 0, value = this.__wrapped__, interceptor = function(object) { return baseAt(object, paths); }; - if (length > 1 || this.__actions__.length || !(value instanceof LazyWrapper) || !isIndex(start)) { + if (length > 1 || this.__actions__.length || + !(value instanceof LazyWrapper) || !isIndex(start)) { return this.thru(interceptor); } value = value.slice(start, +start + (length ? 1 : 0)); - value.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined }); + value.__actions__.push({ + 'func': thru, + 'args': [interceptor], + 'thisArg': undefined + }); return new LodashWrapper(value, this.__chain__).thru(function(array) { if (length && !array.length) { array.push(undefined); @@ -7378,7 +7461,11 @@ wrapped = new LazyWrapper(this); } wrapped = wrapped.reverse(); - wrapped.__actions__.push({ 'func': thru, 'args': [reverse], 'thisArg': undefined }); + wrapped.__actions__.push({ + 'func': thru, + 'args': [reverse], + 'thisArg': undefined + }); return new LodashWrapper(wrapped, this.__chain__); } return this.thru(reverse); @@ -7597,7 +7684,7 @@ * // => [1, 1, 2, 2] */ function flatMap(collection, iteratee) { - return baseFlatten(map(collection, iteratee)); + return baseFlatten(map(collection, iteratee), 1); } /** @@ -7631,7 +7718,7 @@ function forEach(collection, iteratee) { return (typeof iteratee == 'function' && isArray(collection)) ? arrayEach(collection, iteratee) - : baseEach(collection, toFunction(iteratee)); + : baseEach(collection, baseCastFunction(iteratee)); } /** @@ -7655,7 +7742,7 @@ function forEachRight(collection, iteratee) { return (typeof iteratee == 'function' && isArray(collection)) ? arrayEachRight(collection, iteratee) - : baseEachRight(collection, toFunction(iteratee)); + : baseEachRight(collection, baseCastFunction(iteratee)); } /** @@ -8219,7 +8306,7 @@ } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { iteratees.length = 1; } - return baseOrderBy(collection, baseFlatten(iteratees), []); + return baseOrderBy(collection, baseFlatten(iteratees, 1), []); }); /*------------------------------------------------------------------------*/ @@ -8230,7 +8317,7 @@ * * @static * @memberOf _ - * @type Function + * @type {Function} * @category Date * @returns {number} Returns the timestamp. * @example @@ -8656,8 +8743,10 @@ if (!lastCalled && !maxTimeoutId && !leading) { lastCalled = stamp; } - var remaining = maxWait - (stamp - lastCalled), - isCalled = remaining <= 0 || remaining > maxWait; + var remaining = maxWait - (stamp - lastCalled); + + var isCalled = (remaining <= 0 || remaining > maxWait) && + (leading || maxTimeoutId); if (isCalled) { if (maxTimeoutId) { @@ -8897,7 +8986,7 @@ * // => [100, 10] */ var overArgs = rest(function(func, transforms) { - transforms = arrayMap(baseFlatten(transforms), getIteratee()); + transforms = arrayMap(baseFlatten(transforms, 1), getIteratee()); var funcsLength = transforms.length; return rest(function(args) { @@ -9011,7 +9100,7 @@ * // => ['a', 'b', 'c'] */ var rearg = rest(function(func, indexes) { - return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes)); + return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1)); }); /** @@ -9163,7 +9252,11 @@ leading = 'leading' in options ? !!options.leading : leading; trailing = 'trailing' in options ? !!options.trailing : trailing; } - return debounce(func, wait, { 'leading': leading, 'maxWait': wait, 'trailing': trailing }); + return debounce(func, wait, { + 'leading': leading, + 'maxWait': wait, + 'trailing': trailing + }); } /** @@ -9194,7 +9287,7 @@ * @memberOf _ * @category Function * @param {*} value The value to wrap. - * @param {Function} wrapper The wrapper function. + * @param {Function} [wrapper=identity] The wrapper function. * @returns {Function} Returns the new function. * @example * @@ -9212,6 +9305,46 @@ /*------------------------------------------------------------------------*/ + /** + * Casts `value` as an array if it's not one. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to inspect. + * @returns {Array} Returns the cast array. + * @example + * + * _.castArray(1); + * // => [1] + * + * _.castArray({ 'a': 1 }); + * // => [{ 'a': 1 }] + * + * _.castArray('abc'); + * // => ['abc'] + * + * _.castArray(null); + * // => [null] + * + * _.castArray(undefined); + * // => [undefined] + * + * _.castArray(); + * // => [] + * + * var array = [1, 2, 3]; + * console.log(_.castArray(array) === array); + * // => true + */ + function castArray() { + if (!arguments.length) { + return []; + } + var value = arguments[0]; + return isArray(value) ? value : [value]; + } + /** * Creates a shallow clone of `value`. * @@ -9432,7 +9565,7 @@ * * @static * @memberOf _ - * @type Function + * @type {Function} * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. @@ -9457,7 +9590,6 @@ * * @static * @memberOf _ - * @type Function * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. @@ -9480,7 +9612,6 @@ * * @static * @memberOf _ - * @type Function * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is array-like, else `false`. @@ -9509,7 +9640,6 @@ * * @static * @memberOf _ - * @type Function * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`. @@ -9641,7 +9771,8 @@ */ function isEmpty(value) { if (isArrayLike(value) && - (isArray(value) || isString(value) || isFunction(value.splice) || isArguments(value))) { + (isArray(value) || isString(value) || + isFunction(value.splice) || isArguments(value))) { return !value.length; } for (var key in value) { @@ -9684,10 +9815,10 @@ } /** - * This method is like `_.isEqual` except that it accepts `customizer` which is - * invoked to compare values. If `customizer` returns `undefined` comparisons are - * handled by the method instead. The `customizer` is invoked with up to six arguments: - * (objValue, othValue [, index|key, object, other, stack]). + * This method is like `_.isEqual` except that it accepts `customizer` which + * is invoked to compare values. If `customizer` returns `undefined` comparisons + * are handled by the method instead. The `customizer` is invoked with up to + * six arguments: (objValue, othValue [, index|key, object, other, stack]). * * @static * @memberOf _ @@ -9738,8 +9869,12 @@ * // => false */ function isError(value) { - return isObjectLike(value) && - typeof value.message == 'string' && objectToString.call(value) == errorTag; + if (!isObjectLike(value)) { + return false; + } + var Ctor = value.constructor; + return (objectToString.call(value) == errorTag) || + (typeof Ctor == 'function' && objectToString.call(Ctor.prototype) == errorTag); } /** @@ -9847,7 +9982,8 @@ * // => false */ function isLength(value) { - return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; + return typeof value == 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; } /** @@ -9926,8 +10062,9 @@ } /** - * Performs a deep comparison between `object` and `source` to determine if - * `object` contains equivalent property values. + * Performs a partial deep comparison between `object` and `source` to + * determine if `object` contains equivalent property values. This method is + * equivalent to a `_.matches` function when `source` is partially applied. * * **Note:** This method supports comparing the same values as `_.isEqual`. * @@ -10146,7 +10283,8 @@ * // => true */ function isPlainObject(value) { - if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) { + if (!isObjectLike(value) || + objectToString.call(value) != objectTag || isHostObject(value)) { return false; } var proto = objectProto; @@ -10289,7 +10427,8 @@ * // => false */ function isTypedArray(value) { - return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; + return isObjectLike(value) && + isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; } /** @@ -10781,7 +10920,7 @@ * // => ['a', 'c'] */ var at = rest(function(object, paths) { - return baseAt(object, baseFlatten(paths)); + return baseAt(object, baseFlatten(paths, 1)); }); /** @@ -10969,7 +11108,9 @@ * // => logs 'a', 'b', then 'c' (iteration order is not guaranteed) */ function forIn(object, iteratee) { - return object == null ? object : baseFor(object, toFunction(iteratee), keysIn); + return object == null + ? object + : baseFor(object, baseCastFunction(iteratee), keysIn); } /** @@ -10997,7 +11138,9 @@ * // => logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c' */ function forInRight(object, iteratee) { - return object == null ? object : baseForRight(object, toFunction(iteratee), keysIn); + return object == null + ? object + : baseForRight(object, baseCastFunction(iteratee), keysIn); } /** @@ -11027,7 +11170,7 @@ * // => logs 'a' then 'b' (iteration order is not guaranteed) */ function forOwn(object, iteratee) { - return object && baseForOwn(object, toFunction(iteratee)); + return object && baseForOwn(object, baseCastFunction(iteratee)); } /** @@ -11055,7 +11198,7 @@ * // => logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b' */ function forOwnRight(object, iteratee) { - return object && baseForOwnRight(object, toFunction(iteratee)); + return object && baseForOwnRight(object, baseCastFunction(iteratee)); } /** @@ -11422,12 +11565,12 @@ } /** - * Recursively merges own and inherited enumerable properties of source - * objects into the destination object, skipping source properties that resolve - * to `undefined`. Array and plain object properties are merged recursively. - * Other objects and value types are overridden by assignment. Source objects - * are applied from left to right. Subsequent sources overwrite property - * assignments of previous sources. + * Recursively merges own and inherited enumerable properties of source objects + * into the destination object. Source properties that resolve to `undefined` + * are skipped if a destination value exists. Array and plain object properties + * are merged recursively. Other objects and value types are overridden by + * assignment. Source objects are applied from left to right. Subsequent + * sources overwrite property assignments of previous sources. * * **Note:** This method mutates `object`. * @@ -11504,7 +11647,7 @@ * @category Object * @param {Object} object The source object. * @param {...(string|string[])} [props] The property names to omit, specified - * individually or in arrays.. + * individually or in arrays. * @returns {Object} Returns the new object. * @example * @@ -11517,7 +11660,7 @@ if (object == null) { return {}; } - props = arrayMap(baseFlatten(props), String); + props = arrayMap(baseFlatten(props, 1), String); return basePick(object, baseDifference(keysIn(object), props)); }); @@ -11564,7 +11707,7 @@ * // => { 'a': 1, 'c': 3 } */ var pick = rest(function(object, props) { - return object == null ? {} : basePick(object, baseFlatten(props)); + return object == null ? {} : basePick(object, baseFlatten(props, 1)); }); /** @@ -11618,7 +11761,7 @@ */ function result(object, path, defaultValue) { if (!isKey(path, object)) { - path = baseToPath(path); + path = baseCastPath(path); var result = get(object, path); object = parent(object, path); } else { @@ -11688,7 +11831,8 @@ } /** - * Creates an array of own enumerable key-value pairs for `object`. + * Creates an array of own enumerable key-value pairs for `object` which + * can be consumed by `_.fromPairs`. * * @static * @memberOf _ @@ -11712,7 +11856,8 @@ } /** - * Creates an array of own and inherited enumerable key-value pairs for `object`. + * Creates an array of own and inherited enumerable key-value pairs for + * `object` which can be consumed by `_.fromPairs`. * * @static * @memberOf _ @@ -11867,7 +12012,7 @@ * // => [1, 2, 3] (iteration order is not guaranteed) */ function valuesIn(object) { - return object == null ? baseValues(object, keysIn(object)) : []; + return object == null ? [] : baseValues(object, keysIn(object)); } /*------------------------------------------------------------------------*/ @@ -12365,7 +12510,7 @@ * @memberOf _ * @category String * @param {string} string The string to convert. - * @param {number} [radix] The radix to interpret `value` by. + * @param {number} [radix=10] The radix to interpret `value` by. * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. * @returns {number} Returns the converted integer. * @example @@ -12737,7 +12882,8 @@ 'return __p\n}'; var result = attempt(function() { - return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues); + return Function(importsKeys, sourceURL + 'return ' + source) + .apply(undefined, importsValues); }); // Provide the compiled function's source by its `toString` method or @@ -12831,7 +12977,9 @@ var strSymbols = stringToArray(string), chrSymbols = stringToArray(chars); - return strSymbols.slice(charsStartIndex(strSymbols, chrSymbols), charsEndIndex(strSymbols, chrSymbols) + 1).join(''); + return strSymbols + .slice(charsStartIndex(strSymbols, chrSymbols), charsEndIndex(strSymbols, chrSymbols) + 1) + .join(''); } /** @@ -12865,7 +13013,9 @@ return string; } var strSymbols = stringToArray(string); - return strSymbols.slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1).join(''); + return strSymbols + .slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1) + .join(''); } /** @@ -12899,7 +13049,9 @@ return string; } var strSymbols = stringToArray(string); - return strSymbols.slice(charsStartIndex(strSymbols, stringToArray(chars))).join(''); + return strSymbols + .slice(charsStartIndex(strSymbols, stringToArray(chars))) + .join(''); } /** @@ -12911,7 +13063,7 @@ * @memberOf _ * @category String * @param {string} [string=''] The string to truncate. - * @param {Object} [options] The options object. + * @param {Object} [options=({})] The options object. * @param {number} [options.length=30] The maximum string length. * @param {string} [options.omission='...'] The string to indicate text is omitted. * @param {RegExp|string} [options.separator] The separator pattern to truncate to. @@ -13096,7 +13248,7 @@ try { return apply(func, undefined, args); } catch (e) { - return isObject(e) ? e : new Error(e); + return isError(e) ? e : new Error(e); } }); @@ -13127,7 +13279,7 @@ * // => logs 'clicked docs' when clicked */ var bindAll = rest(function(object, methodNames) { - arrayEach(baseFlatten(methodNames), function(key) { + arrayEach(baseFlatten(methodNames, 1), function(key) { object[key] = bind(object[key], object); }); return object; @@ -13295,7 +13447,8 @@ * Creates a function that invokes `func` with the arguments of the created * function. If `func` is a property name the created callback returns the * property value for a given element. If `func` is an object the created - * callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`. + * callback returns `true` for elements that contain the equivalent object + * properties, otherwise it returns `false`. * * @static * @memberOf _ @@ -13325,9 +13478,10 @@ } /** - * Creates a function that performs a deep partial comparison between a given + * Creates a function that performs a partial deep comparison between a given * object and `source`, returning `true` if the given object has equivalent - * property values, else `false`. + * property values, else `false`. The created function is equivalent to + * `_.isMatch` with a `source` partially applied. * * **Note:** This method supports comparing the same values as `_.isEqual`. * @@ -13351,7 +13505,7 @@ } /** - * Creates a function that performs a deep partial comparison between the + * Creates a function that performs a partial deep comparison between the * value at `path` of a given object to `srcValue`, returning `true` if the * object value is equivalent, else `false`. * @@ -13785,7 +13939,7 @@ var index = MAX_ARRAY_LENGTH, length = nativeMin(n, MAX_ARRAY_LENGTH); - iteratee = toFunction(iteratee); + iteratee = baseCastFunction(iteratee); n -= MAX_ARRAY_LENGTH; var result = baseTimes(length, iteratee); @@ -13830,7 +13984,7 @@ * @static * @memberOf _ * @category Util - * @param {string} [prefix] The value to prefix the ID with. + * @param {string} [prefix=''] The value to prefix the ID with. * @returns {string} Returns the unique ID. * @example * @@ -14181,6 +14335,7 @@ lodash.bind = bind; lodash.bindAll = bindAll; lodash.bindKey = bindKey; + lodash.castArray = castArray; lodash.chain = chain; lodash.chunk = chunk; lodash.compact = compact; @@ -14209,6 +14364,7 @@ lodash.flatMap = flatMap; lodash.flatten = flatten; lodash.flattenDeep = flattenDeep; + lodash.flattenDepth = flattenDepth; lodash.flip = flip; lodash.flow = flow; lodash.flowRight = flowRight; @@ -14483,7 +14639,7 @@ * * @static * @memberOf _ - * @type string + * @type {string} */ lodash.VERSION = VERSION; @@ -14505,7 +14661,10 @@ if (filtered) { result.__takeCount__ = nativeMin(n, result.__takeCount__); } else { - result.__views__.push({ 'size': nativeMin(n, MAX_ARRAY_LENGTH), 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') }); + result.__views__.push({ + 'size': nativeMin(n, MAX_ARRAY_LENGTH), + 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') + }); } return result; }; @@ -14522,7 +14681,10 @@ LazyWrapper.prototype[methodName] = function(iteratee) { var result = this.clone(); - result.__iteratees__.push({ 'iteratee': getIteratee(iteratee, 3), 'type': type }); + result.__iteratees__.push({ + 'iteratee': getIteratee(iteratee, 3), + 'type': type + }); result.__filtered__ = result.__filtered__ || isFilter; return result; }; @@ -14674,7 +14836,10 @@ } }); - realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }]; + realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ + 'name': 'wrapper', + 'func': undefined + }]; // Add functions to the lazy wrapper. LazyWrapper.prototype.clone = lazyClone; diff --git a/matches.js b/matches.js index 5a2926ae5..4a9cec6f5 100644 --- a/matches.js +++ b/matches.js @@ -2,9 +2,10 @@ var baseClone = require('./_baseClone'), baseMatches = require('./_baseMatches'); /** - * Creates a function that performs a deep partial comparison between a given + * Creates a function that performs a partial deep comparison between a given * object and `source`, returning `true` if the given object has equivalent - * property values, else `false`. + * property values, else `false`. The created function is equivalent to + * `_.isMatch` with a `source` partially applied. * * **Note:** This method supports comparing the same values as `_.isEqual`. * diff --git a/matchesProperty.js b/matchesProperty.js index d4356fb95..b49a9a43d 100644 --- a/matchesProperty.js +++ b/matchesProperty.js @@ -2,7 +2,7 @@ var baseClone = require('./_baseClone'), baseMatchesProperty = require('./_baseMatchesProperty'); /** - * Creates a function that performs a deep partial comparison between the + * Creates a function that performs a partial deep comparison between the * value at `path` of a given object to `srcValue`, returning `true` if the * object value is equivalent, else `false`. * diff --git a/merge.js b/merge.js index 07625956a..845edd79f 100644 --- a/merge.js +++ b/merge.js @@ -2,12 +2,12 @@ var baseMerge = require('./_baseMerge'), createAssigner = require('./_createAssigner'); /** - * Recursively merges own and inherited enumerable properties of source - * objects into the destination object, skipping source properties that resolve - * to `undefined`. Array and plain object properties are merged recursively. - * Other objects and value types are overridden by assignment. Source objects - * are applied from left to right. Subsequent sources overwrite property - * assignments of previous sources. + * Recursively merges own and inherited enumerable properties of source objects + * into the destination object. Source properties that resolve to `undefined` + * are skipped if a destination value exists. Array and plain object properties + * are merged recursively. Other objects and value types are overridden by + * assignment. Source objects are applied from left to right. Subsequent + * sources overwrite property assignments of previous sources. * * **Note:** This method mutates `object`. * diff --git a/now.js b/now.js index eca3b9edd..b306f9ed6 100644 --- a/now.js +++ b/now.js @@ -4,7 +4,7 @@ * * @static * @memberOf _ - * @type Function + * @type {Function} * @category Date * @returns {number} Returns the timestamp. * @example diff --git a/omit.js b/omit.js index dd3c70dc6..bdd8f74df 100644 --- a/omit.js +++ b/omit.js @@ -14,7 +14,7 @@ var arrayMap = require('./_arrayMap'), * @category Object * @param {Object} object The source object. * @param {...(string|string[])} [props] The property names to omit, specified - * individually or in arrays.. + * individually or in arrays. * @returns {Object} Returns the new object. * @example * @@ -27,7 +27,7 @@ var omit = rest(function(object, props) { if (object == null) { return {}; } - props = arrayMap(baseFlatten(props), String); + props = arrayMap(baseFlatten(props, 1), String); return basePick(object, baseDifference(keysIn(object), props)); }); diff --git a/overArgs.js b/overArgs.js index 0bb760fde..848e2a6eb 100644 --- a/overArgs.js +++ b/overArgs.js @@ -39,7 +39,7 @@ var nativeMin = Math.min; * // => [100, 10] */ var overArgs = rest(function(func, transforms) { - transforms = arrayMap(baseFlatten(transforms), baseIteratee); + transforms = arrayMap(baseFlatten(transforms, 1), baseIteratee); var funcsLength = transforms.length; return rest(function(args) { diff --git a/package.json b/package.json index d2d7465b8..92066d895 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash", - "version": "4.3.0", + "version": "4.4.0", "description": "Lodash modular utilities.", "homepage": "https://lodash.com/", "icon": "https://lodash.com/icon.svg", diff --git a/parseInt.js b/parseInt.js index ae608ce59..8fedf5a5c 100644 --- a/parseInt.js +++ b/parseInt.js @@ -22,7 +22,7 @@ var nativeParseInt = root.parseInt; * @memberOf _ * @category String * @param {string} string The string to convert. - * @param {number} [radix] The radix to interpret `value` by. + * @param {number} [radix=10] The radix to interpret `value` by. * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. * @returns {number} Returns the converted integer. * @example diff --git a/pick.js b/pick.js index 44745755f..280b5bd89 100644 --- a/pick.js +++ b/pick.js @@ -20,7 +20,7 @@ var baseFlatten = require('./_baseFlatten'), * // => { 'a': 1, 'c': 3 } */ var pick = rest(function(object, props) { - return object == null ? {} : basePick(object, baseFlatten(props)); + return object == null ? {} : basePick(object, baseFlatten(props, 1)); }); module.exports = pick; diff --git a/pullAt.js b/pullAt.js index 5938c0566..f589dab67 100644 --- a/pullAt.js +++ b/pullAt.js @@ -30,7 +30,7 @@ var arrayMap = require('./_arrayMap'), * // => [10, 20] */ var pullAt = rest(function(array, indexes) { - indexes = arrayMap(baseFlatten(indexes), String); + indexes = arrayMap(baseFlatten(indexes, 1), String); var result = baseAt(array, indexes); basePullAt(array, indexes.sort(compareAscending)); diff --git a/rearg.js b/rearg.js index 1fc204afd..22ed6faf7 100644 --- a/rearg.js +++ b/rearg.js @@ -28,7 +28,7 @@ var REARG_FLAG = 256; * // => ['a', 'b', 'c'] */ var rearg = rest(function(func, indexes) { - return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes)); + return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1)); }); module.exports = rearg; diff --git a/result.js b/result.js index 99b7f1bac..706483c76 100644 --- a/result.js +++ b/result.js @@ -1,4 +1,4 @@ -var baseToPath = require('./_baseToPath'), +var baseCastPath = require('./_baseCastPath'), get = require('./get'), isFunction = require('./isFunction'), isKey = require('./_isKey'), @@ -34,7 +34,7 @@ var baseToPath = require('./_baseToPath'), */ function result(object, path, defaultValue) { if (!isKey(path, object)) { - path = baseToPath(path); + path = baseCastPath(path); var result = get(object, path); object = parent(object, path); } else { diff --git a/sortBy.js b/sortBy.js index 96cbdb2c6..5a8fa301f 100644 --- a/sortBy.js +++ b/sortBy.js @@ -46,7 +46,7 @@ var sortBy = rest(function(collection, iteratees) { } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { iteratees.length = 1; } - return baseOrderBy(collection, baseFlatten(iteratees), []); + return baseOrderBy(collection, baseFlatten(iteratees, 1), []); }); module.exports = sortBy; diff --git a/template.js b/template.js index c09fcde87..ab94abccb 100644 --- a/template.js +++ b/template.js @@ -210,7 +210,8 @@ function template(string, options, guard) { 'return __p\n}'; var result = attempt(function() { - return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues); + return Function(importsKeys, sourceURL + 'return ' + source) + .apply(undefined, importsValues); }); // Provide the compiled function's source by its `toString` method or diff --git a/templateSettings.js b/templateSettings.js index 67dc19b4c..bce2f749c 100644 --- a/templateSettings.js +++ b/templateSettings.js @@ -10,7 +10,7 @@ var escape = require('./escape'), * * @static * @memberOf _ - * @type Object + * @type {Object} */ var templateSettings = { @@ -18,7 +18,7 @@ var templateSettings = { * Used to detect `data` property values to be HTML-escaped. * * @memberOf _.templateSettings - * @type RegExp + * @type {RegExp} */ 'escape': reEscape, @@ -26,7 +26,7 @@ var templateSettings = { * Used to detect code to be evaluated. * * @memberOf _.templateSettings - * @type RegExp + * @type {RegExp} */ 'evaluate': reEvaluate, @@ -34,7 +34,7 @@ var templateSettings = { * Used to detect `data` property values to inject. * * @memberOf _.templateSettings - * @type RegExp + * @type {RegExp} */ 'interpolate': reInterpolate, @@ -42,7 +42,7 @@ var templateSettings = { * Used to reference the data object in the template text. * * @memberOf _.templateSettings - * @type string + * @type {string} */ 'variable': '', @@ -50,7 +50,7 @@ var templateSettings = { * Used to import variables into the compiled template. * * @memberOf _.templateSettings - * @type Object + * @type {Object} */ 'imports': { @@ -58,7 +58,7 @@ var templateSettings = { * A reference to the `lodash` function. * * @memberOf _.templateSettings.imports - * @type Function + * @type {Function} */ '_': { 'escape': escape } } diff --git a/throttle.js b/throttle.js index ff7dc7579..976b0760c 100644 --- a/throttle.js +++ b/throttle.js @@ -55,7 +55,11 @@ function throttle(func, wait, options) { leading = 'leading' in options ? !!options.leading : leading; trailing = 'trailing' in options ? !!options.trailing : trailing; } - return debounce(func, wait, { 'leading': leading, 'maxWait': wait, 'trailing': trailing }); + return debounce(func, wait, { + 'leading': leading, + 'maxWait': wait, + 'trailing': trailing + }); } module.exports = throttle; diff --git a/times.js b/times.js index b7ede33bd..748fbf375 100644 --- a/times.js +++ b/times.js @@ -1,5 +1,5 @@ -var baseTimes = require('./_baseTimes'), - toFunction = require('./_toFunction'), +var baseCastFunction = require('./_baseCastFunction'), + baseTimes = require('./_baseTimes'), toInteger = require('./toInteger'); /** Used as references for various `Number` constants. */ @@ -37,7 +37,7 @@ function times(n, iteratee) { var index = MAX_ARRAY_LENGTH, length = nativeMin(n, MAX_ARRAY_LENGTH); - iteratee = toFunction(iteratee); + iteratee = baseCastFunction(iteratee); n -= MAX_ARRAY_LENGTH; var result = baseTimes(length, iteratee); diff --git a/toPairs.js b/toPairs.js index 8c6e4d0b0..1f584d729 100644 --- a/toPairs.js +++ b/toPairs.js @@ -2,7 +2,8 @@ var baseToPairs = require('./_baseToPairs'), keys = require('./keys'); /** - * Creates an array of own enumerable key-value pairs for `object`. + * Creates an array of own enumerable key-value pairs for `object` which + * can be consumed by `_.fromPairs`. * * @static * @memberOf _ diff --git a/toPairsIn.js b/toPairsIn.js index a6f882bc4..308884844 100644 --- a/toPairsIn.js +++ b/toPairsIn.js @@ -2,7 +2,8 @@ var baseToPairs = require('./_baseToPairs'), keysIn = require('./keysIn'); /** - * Creates an array of own and inherited enumerable key-value pairs for `object`. + * Creates an array of own and inherited enumerable key-value pairs for + * `object` which can be consumed by `_.fromPairs`. * * @static * @memberOf _ diff --git a/trim.js b/trim.js index 47f73b686..fa3b0a8d5 100644 --- a/trim.js +++ b/trim.js @@ -42,7 +42,9 @@ function trim(string, chars, guard) { var strSymbols = stringToArray(string), chrSymbols = stringToArray(chars); - return strSymbols.slice(charsStartIndex(strSymbols, chrSymbols), charsEndIndex(strSymbols, chrSymbols) + 1).join(''); + return strSymbols + .slice(charsStartIndex(strSymbols, chrSymbols), charsEndIndex(strSymbols, chrSymbols) + 1) + .join(''); } module.exports = trim; diff --git a/trimEnd.js b/trimEnd.js index 743dc41c9..bed4e135a 100644 --- a/trimEnd.js +++ b/trimEnd.js @@ -36,7 +36,9 @@ function trimEnd(string, chars, guard) { return string; } var strSymbols = stringToArray(string); - return strSymbols.slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1).join(''); + return strSymbols + .slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1) + .join(''); } module.exports = trimEnd; diff --git a/trimStart.js b/trimStart.js index cdd3b6a99..2373493cf 100644 --- a/trimStart.js +++ b/trimStart.js @@ -36,7 +36,9 @@ function trimStart(string, chars, guard) { return string; } var strSymbols = stringToArray(string); - return strSymbols.slice(charsStartIndex(strSymbols, stringToArray(chars))).join(''); + return strSymbols + .slice(charsStartIndex(strSymbols, stringToArray(chars))) + .join(''); } module.exports = trimStart; diff --git a/truncate.js b/truncate.js index 18b1c39c8..bc15e0439 100644 --- a/truncate.js +++ b/truncate.js @@ -33,7 +33,7 @@ var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange * @memberOf _ * @category String * @param {string} [string=''] The string to truncate. - * @param {Object} [options] The options object. + * @param {Object} [options=({})] The options object. * @param {number} [options.length=30] The maximum string length. * @param {string} [options.omission='...'] The string to indicate text is omitted. * @param {RegExp|string} [options.separator] The separator pattern to truncate to. diff --git a/union.js b/union.js index fafe1885e..10dfb7c16 100644 --- a/union.js +++ b/union.js @@ -18,7 +18,7 @@ var baseFlatten = require('./_baseFlatten'), * // => [2, 1, 4] */ var union = rest(function(arrays) { - return baseUniq(baseFlatten(arrays, false, true)); + return baseUniq(baseFlatten(arrays, 1, true)); }); module.exports = union; diff --git a/unionBy.js b/unionBy.js index 26050bcd4..36a182c69 100644 --- a/unionBy.js +++ b/unionBy.js @@ -30,7 +30,7 @@ var unionBy = rest(function(arrays) { if (isArrayLikeObject(iteratee)) { iteratee = undefined; } - return baseUniq(baseFlatten(arrays, false, true), baseIteratee(iteratee)); + return baseUniq(baseFlatten(arrays, 1, true), baseIteratee(iteratee)); }); module.exports = unionBy; diff --git a/unionWith.js b/unionWith.js index 1eca72906..2c7e32f5f 100644 --- a/unionWith.js +++ b/unionWith.js @@ -28,7 +28,7 @@ var unionWith = rest(function(arrays) { if (isArrayLikeObject(comparator)) { comparator = undefined; } - return baseUniq(baseFlatten(arrays, false, true), undefined, comparator); + return baseUniq(baseFlatten(arrays, 1, true), undefined, comparator); }); module.exports = unionWith; diff --git a/uniqueId.js b/uniqueId.js index a39b2bcbe..78f278d1b 100644 --- a/uniqueId.js +++ b/uniqueId.js @@ -9,7 +9,7 @@ var idCounter = 0; * @static * @memberOf _ * @category Util - * @param {string} [prefix] The value to prefix the ID with. + * @param {string} [prefix=''] The value to prefix the ID with. * @returns {string} Returns the unique ID. * @example * diff --git a/valuesIn.js b/valuesIn.js index 2e8b8ba8e..379a3382e 100644 --- a/valuesIn.js +++ b/valuesIn.js @@ -24,7 +24,7 @@ var baseValues = require('./_baseValues'), * // => [1, 2, 3] (iteration order is not guaranteed) */ function valuesIn(object) { - return object == null ? baseValues(object, keysIn(object)) : []; + return object == null ? [] : baseValues(object, keysIn(object)); } module.exports = valuesIn; diff --git a/wrap.js b/wrap.js index 51dcf2fee..001244383 100644 --- a/wrap.js +++ b/wrap.js @@ -11,7 +11,7 @@ var identity = require('./identity'), * @memberOf _ * @category Function * @param {*} value The value to wrap. - * @param {Function} wrapper The wrapper function. + * @param {Function} [wrapper=identity] The wrapper function. * @returns {Function} Returns the new function. * @example * diff --git a/wrapperAt.js b/wrapperAt.js index ce06e72b9..c9482a9c8 100644 --- a/wrapperAt.js +++ b/wrapperAt.js @@ -26,17 +26,22 @@ var LazyWrapper = require('./_LazyWrapper'), * // => ['a', 'c'] */ var wrapperAt = rest(function(paths) { - paths = baseFlatten(paths); + paths = baseFlatten(paths, 1); var length = paths.length, start = length ? paths[0] : 0, value = this.__wrapped__, interceptor = function(object) { return baseAt(object, paths); }; - if (length > 1 || this.__actions__.length || !(value instanceof LazyWrapper) || !isIndex(start)) { + if (length > 1 || this.__actions__.length || + !(value instanceof LazyWrapper) || !isIndex(start)) { return this.thru(interceptor); } value = value.slice(start, +start + (length ? 1 : 0)); - value.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined }); + value.__actions__.push({ + 'func': thru, + 'args': [interceptor], + 'thisArg': undefined + }); return new LodashWrapper(value, this.__chain__).thru(function(array) { if (length && !array.length) { array.push(undefined); diff --git a/wrapperLodash.js b/wrapperLodash.js index 3c38eb9cb..c3ce05db4 100644 --- a/wrapperLodash.js +++ b/wrapperLodash.js @@ -50,28 +50,28 @@ var hasOwnProperty = objectProto.hasOwnProperty; * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` * * The chainable wrapper methods are: - * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, - * `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`, - * `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`, - * `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`, + * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`, + * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`, + * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, + * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`, * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`, - * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`, - * `flowRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`, - * `intersection`, `intersectionBy`, `intersectionWith`, `invert`, `invertBy`, - * `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, - * `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, - * `method`, `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, - * `orderBy`, `over`, `overArgs`, `overEvery`, `overSome`, `partial`, - * `partialRight`, `partition`, `pick`, `pickBy`, `plant`, `property`, - * `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, - * `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, `sampleSize`, - * `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, - * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, - * `thru`, `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, - * `transform`, `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, - * `uniqWith`, `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, - * `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, - * `zipObjectDeep`, and `zipWith` + * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flattenDepth`, + * `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, `functionsIn`, + * `groupBy`, `initial`, `intersection`, `intersectionBy`, `intersectionWith`, + * `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`, + * `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, `memoize`, + * `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, `nthArg`, + * `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, `overEvery`, + * `overSome`, `partial`, `partialRight`, `partition`, `pick`, `pickBy`, `plant`, + * `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`, + * `range`, `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, + * `sampleSize`, `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, + * `splice`, `spread`, `tail`, `take`, `takeRight`, `takeRightWhile`, + * `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, `toPairs`, `toPairsIn`, + * `toPath`, `toPlainObject`, `transform`, `unary`, `union`, `unionBy`, + * `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, `unshift`, `unzip`, + * `unzipWith`, `values`, `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, + * `xorWith`, `zip`, `zipObject`, `zipObjectDeep`, and `zipWith` * * The wrapper methods that are **not** chainable by default are: * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, diff --git a/wrapperReverse.js b/wrapperReverse.js index 51d44b9ba..dffd25f97 100644 --- a/wrapperReverse.js +++ b/wrapperReverse.js @@ -30,7 +30,11 @@ function wrapperReverse() { wrapped = new LazyWrapper(this); } wrapped = wrapped.reverse(); - wrapped.__actions__.push({ 'func': thru, 'args': [reverse], 'thisArg': undefined }); + wrapped.__actions__.push({ + 'func': thru, + 'args': [reverse], + 'thisArg': undefined + }); return new LodashWrapper(wrapped, this.__chain__); } return this.thru(reverse);