diff --git a/README.md b/README.md index 31aa97751..d6a9495d8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-amd v4.13.1 +# lodash-amd v4.14.0 The [Lodash](https://lodash.com/) library exported as [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules. @@ -27,4 +27,4 @@ require({ }); ``` -See the [package source](https://github.com/lodash/lodash/tree/4.13.1-amd) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.14.0-amd) for more details. diff --git a/_addMapEntry.js b/_addMapEntry.js index fd79d274a..788300012 100644 --- a/_addMapEntry.js +++ b/_addMapEntry.js @@ -9,7 +9,7 @@ define([], function() { * @returns {Object} Returns `map`. */ function addMapEntry(map, pair) { - // Don't return `Map#set` because it doesn't return the map instance in IE 11. + // Don't return `map.set` because it's not chainable in IE 11. map.set(pair[0], pair[1]); return map; } diff --git a/_addSetEntry.js b/_addSetEntry.js index cd9ca4bc4..26ddb79a8 100644 --- a/_addSetEntry.js +++ b/_addSetEntry.js @@ -9,6 +9,7 @@ define([], function() { * @returns {Object} Returns `set`. */ function addSetEntry(set, value) { + // Don't return `set.add` because it's not chainable in IE 11. set.add(value); return set; } diff --git a/_apply.js b/_apply.js index b264e0a63..fbd254cb4 100644 --- a/_apply.js +++ b/_apply.js @@ -11,8 +11,7 @@ define([], function() { * @returns {*} Returns the result of `func`. */ function apply(func, thisArg, args) { - var length = args.length; - switch (length) { + switch (args.length) { case 0: return func.call(thisArg); case 1: return func.call(thisArg, args[0]); case 2: return func.call(thisArg, args[0], args[1]); diff --git a/_baseClamp.js b/_baseClamp.js index 552245a16..6d36712f6 100644 --- a/_baseClamp.js +++ b/_baseClamp.js @@ -4,7 +4,7 @@ define([], function() { var undefined; /** - * The base implementation of `_.clamp` which doesn't coerce arguments to numbers. + * The base implementation of `_.clamp` which doesn't coerce arguments. * * @private * @param {number} number The number to clamp. diff --git a/_baseClone.js b/_baseClone.js index f7ddeeab5..57b138c31 100644 --- a/_baseClone.js +++ b/_baseClone.js @@ -112,14 +112,17 @@ define(['./_Stack', './_arrayEach', './_assignValue', './_baseAssign', './_clone if (!isArr) { var props = isFull ? getAllKeys(value) : keys(value); } - // Recursively populate clone (susceptible to call stack limits). arrayEach(props || value, function(subValue, key) { if (props) { key = subValue; subValue = value[key]; } + // Recursively populate clone (susceptible to call stack limits). assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack)); }); + if (!isFull) { + stack['delete'](value); + } return result; } diff --git a/_baseConforms.js b/_baseConforms.js index efea557a2..8246b2747 100644 --- a/_baseConforms.js +++ b/_baseConforms.js @@ -1,7 +1,4 @@ -define(['./keys'], function(keys) { - - /** Used as a safe reference for `undefined` in pre-ES5 environments. */ - var undefined; +define(['./_baseConformsTo', './keys'], function(baseConformsTo, keys) { /** * The base implementation of `_.conforms` which doesn't clone `source`. @@ -11,25 +8,9 @@ define(['./keys'], function(keys) { * @returns {Function} Returns the new spec function. */ function baseConforms(source) { - var props = keys(source), - length = props.length; - + var props = keys(source); return function(object) { - if (object == null) { - return !length; - } - var index = length; - while (index--) { - var key = props[index], - predicate = source[key], - value = object[key]; - - if ((value === undefined && - !(key in Object(object))) || !predicate(value)) { - return false; - } - } - return true; + return baseConformsTo(object, source, props); }; } diff --git a/_baseConformsTo.js b/_baseConformsTo.js new file mode 100644 index 000000000..46bd8a088 --- /dev/null +++ b/_baseConformsTo.js @@ -0,0 +1,34 @@ +define([], function() { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * The base implementation of `_.conformsTo` which accepts `props` to check. + * + * @private + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + */ + function baseConformsTo(object, source, props) { + var length = props.length; + if (object == null) { + return !length; + } + var index = length; + while (index--) { + var key = props[index], + predicate = source[key], + value = object[key]; + + if ((value === undefined && + !(key in Object(object))) || !predicate(value)) { + return false; + } + } + return true; + } + + return baseConformsTo; +}); diff --git a/_baseDelay.js b/_baseDelay.js index e12fbcc67..a4589e785 100644 --- a/_baseDelay.js +++ b/_baseDelay.js @@ -7,13 +7,13 @@ define([], function() { var FUNC_ERROR_TEXT = 'Expected a function'; /** - * The base implementation of `_.delay` and `_.defer` which accepts an array - * of `func` arguments. + * The base implementation of `_.delay` and `_.defer` which accepts `args` + * to provide to `func`. * * @private * @param {Function} func The function to delay. * @param {number} wait The number of milliseconds to delay invocation. - * @param {Object} args The arguments to provide to `func`. + * @param {Array} args The arguments to provide to `func`. * @returns {number} Returns the timer id. */ function baseDelay(func, wait, args) { diff --git a/_baseGetTag.js b/_baseGetTag.js new file mode 100644 index 000000000..c1d0e3116 --- /dev/null +++ b/_baseGetTag.js @@ -0,0 +1,25 @@ +define([], function() { + + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ + var objectToString = objectProto.toString; + + /** + * The base implementation of `getTag`. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + function baseGetTag(value) { + return objectToString.call(value); + } + + return baseGetTag; +}); diff --git a/_baseGt.js b/_baseGt.js index 905376ed5..3ed0f1c22 100644 --- a/_baseGt.js +++ b/_baseGt.js @@ -1,7 +1,7 @@ define([], function() { /** - * The base implementation of `_.gt` which doesn't coerce arguments to numbers. + * The base implementation of `_.gt` which doesn't coerce arguments. * * @private * @param {*} value The value to compare. diff --git a/_baseInRange.js b/_baseInRange.js index 88b6a1abf..dceb19e48 100644 --- a/_baseInRange.js +++ b/_baseInRange.js @@ -5,7 +5,7 @@ define([], function() { nativeMin = Math.min; /** - * The base implementation of `_.inRange` which doesn't coerce arguments to numbers. + * The base implementation of `_.inRange` which doesn't coerce arguments. * * @private * @param {number} number The number to check. diff --git a/_baseIndexOf.js b/_baseIndexOf.js index 3e96d0681..3ad0c6134 100644 --- a/_baseIndexOf.js +++ b/_baseIndexOf.js @@ -1,4 +1,4 @@ -define(['./_indexOfNaN'], function(indexOfNaN) { +define(['./_baseFindIndex', './_baseIsNaN'], function(baseFindIndex, baseIsNaN) { /** * The base implementation of `_.indexOf` without `fromIndex` bounds checks. @@ -11,7 +11,7 @@ define(['./_indexOfNaN'], function(indexOfNaN) { */ function baseIndexOf(array, value, fromIndex) { if (value !== value) { - return indexOfNaN(array, fromIndex); + return baseFindIndex(array, baseIsNaN, fromIndex); } var index = fromIndex - 1, length = array.length; diff --git a/_baseIsArrayBuffer.js b/_baseIsArrayBuffer.js new file mode 100644 index 000000000..837dbfd43 --- /dev/null +++ b/_baseIsArrayBuffer.js @@ -0,0 +1,27 @@ +define(['./isObjectLike'], function(isObjectLike) { + + var arrayBufferTag = '[object ArrayBuffer]'; + + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ + var objectToString = objectProto.toString; + + /** + * The base implementation of `_.isArrayBuffer` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. + */ + function baseIsArrayBuffer(value) { + return isObjectLike(value) && objectToString.call(value) == arrayBufferTag; + } + + return baseIsArrayBuffer; +}); diff --git a/_baseIsDate.js b/_baseIsDate.js new file mode 100644 index 000000000..ecffb6246 --- /dev/null +++ b/_baseIsDate.js @@ -0,0 +1,28 @@ +define(['./isObjectLike'], function(isObjectLike) { + + /** `Object#toString` result references. */ + var dateTag = '[object Date]'; + + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ + var objectToString = objectProto.toString; + + /** + * The base implementation of `_.isDate` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a date object, else `false`. + */ + function baseIsDate(value) { + return isObjectLike(value) && objectToString.call(value) == dateTag; + } + + return baseIsDate; +}); diff --git a/_baseIsMap.js b/_baseIsMap.js new file mode 100644 index 000000000..345084832 --- /dev/null +++ b/_baseIsMap.js @@ -0,0 +1,18 @@ +define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { + + /** `Object#toString` result references. */ + var mapTag = '[object Map]'; + + /** + * The base implementation of `_.isMap` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a map, else `false`. + */ + function baseIsMap(value) { + return isObjectLike(value) && getTag(value) == mapTag; + } + + return baseIsMap; +}); diff --git a/_baseIsNaN.js b/_baseIsNaN.js new file mode 100644 index 000000000..ff64a9c15 --- /dev/null +++ b/_baseIsNaN.js @@ -0,0 +1,15 @@ +define([], function() { + + /** + * The base implementation of `_.isNaN` without support for number objects. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. + */ + function baseIsNaN(value) { + return value !== value; + } + + return baseIsNaN; +}); diff --git a/_baseIsRegExp.js b/_baseIsRegExp.js new file mode 100644 index 000000000..1cbd88604 --- /dev/null +++ b/_baseIsRegExp.js @@ -0,0 +1,28 @@ +define(['./isObject'], function(isObject) { + + /** `Object#toString` result references. */ + var regexpTag = '[object RegExp]'; + + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ + var objectToString = objectProto.toString; + + /** + * The base implementation of `_.isRegExp` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. + */ + function baseIsRegExp(value) { + return isObject(value) && objectToString.call(value) == regexpTag; + } + + return baseIsRegExp; +}); diff --git a/_baseIsSet.js b/_baseIsSet.js new file mode 100644 index 000000000..b61b1136f --- /dev/null +++ b/_baseIsSet.js @@ -0,0 +1,18 @@ +define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { + + /** `Object#toString` result references. */ + var setTag = '[object Set]'; + + /** + * The base implementation of `_.isSet` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a set, else `false`. + */ + function baseIsSet(value) { + return isObjectLike(value) && getTag(value) == setTag; + } + + return baseIsSet; +}); diff --git a/_baseIsTypedArray.js b/_baseIsTypedArray.js new file mode 100644 index 000000000..0bacaf06f --- /dev/null +++ b/_baseIsTypedArray.js @@ -0,0 +1,69 @@ +define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { + + /** `Object#toString` result references. */ + var argsTag = '[object Arguments]', + arrayTag = '[object Array]', + boolTag = '[object Boolean]', + dateTag = '[object Date]', + errorTag = '[object Error]', + funcTag = '[object Function]', + mapTag = '[object Map]', + numberTag = '[object Number]', + objectTag = '[object Object]', + regexpTag = '[object RegExp]', + setTag = '[object Set]', + stringTag = '[object String]', + weakMapTag = '[object WeakMap]'; + + var arrayBufferTag = '[object ArrayBuffer]', + dataViewTag = '[object DataView]', + float32Tag = '[object Float32Array]', + float64Tag = '[object Float64Array]', + int8Tag = '[object Int8Array]', + int16Tag = '[object Int16Array]', + int32Tag = '[object Int32Array]', + uint8Tag = '[object Uint8Array]', + uint8ClampedTag = '[object Uint8ClampedArray]', + uint16Tag = '[object Uint16Array]', + uint32Tag = '[object Uint32Array]'; + + /** Used to identify `toStringTag` values of typed arrays. */ + var typedArrayTags = {}; + typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = + typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = + typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = + typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = + typedArrayTags[uint32Tag] = true; + typedArrayTags[argsTag] = typedArrayTags[arrayTag] = + typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = + typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = + typedArrayTags[errorTag] = typedArrayTags[funcTag] = + typedArrayTags[mapTag] = typedArrayTags[numberTag] = + typedArrayTags[objectTag] = typedArrayTags[regexpTag] = + typedArrayTags[setTag] = typedArrayTags[stringTag] = + typedArrayTags[weakMapTag] = false; + + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ + var objectToString = objectProto.toString; + + /** + * The base implementation of `_.isTypedArray` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. + */ + function baseIsTypedArray(value) { + return isObjectLike(value) && + isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; + } + + return baseIsTypedArray; +}); diff --git a/_baseKeys.js b/_baseKeys.js index 10890112b..ee94f3748 100644 --- a/_baseKeys.js +++ b/_baseKeys.js @@ -1,4 +1,4 @@ -define([], function() { +define(['./_overArg'], function(overArg) { /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeKeys = Object.keys; @@ -11,9 +11,7 @@ define([], function() { * @param {Object} object The object to query. * @returns {Array} Returns the array of property names. */ - function baseKeys(object) { - return nativeKeys(Object(object)); - } + var baseKeys = overArg(nativeKeys, Object); return baseKeys; }); diff --git a/_baseLt.js b/_baseLt.js index a06cd13b9..afa8abd57 100644 --- a/_baseLt.js +++ b/_baseLt.js @@ -1,7 +1,7 @@ define([], function() { /** - * The base implementation of `_.lt` which doesn't coerce arguments to numbers. + * The base implementation of `_.lt` which doesn't coerce arguments. * * @private * @param {*} value The value to compare. diff --git a/_baseMergeDeep.js b/_baseMergeDeep.js index 68f61460e..edcb6db78 100644 --- a/_baseMergeDeep.js +++ b/_baseMergeDeep.js @@ -63,13 +63,12 @@ define(['./_assignMergeValue', './_baseClone', './_copyArray', './isArguments', isCommon = false; } } - stack.set(srcValue, newValue); - if (isCommon) { // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, newValue); mergeFunc(newValue, srcValue, srcIndex, customizer, stack); + stack['delete'](srcValue); } - stack['delete'](srcValue); assignMergeValue(object, key, newValue); } diff --git a/_baseNth.js b/_baseNth.js index d3a1ecfea..b672fdb41 100644 --- a/_baseNth.js +++ b/_baseNth.js @@ -4,7 +4,7 @@ define(['./_isIndex'], function(isIndex) { var undefined; /** - * The base implementation of `_.nth` which doesn't coerce `n` to an integer. + * The base implementation of `_.nth` which doesn't coerce arguments. * * @private * @param {Array} array The array to query. diff --git a/_basePick.js b/_basePick.js index 4ad9c8061..705e10709 100644 --- a/_basePick.js +++ b/_basePick.js @@ -1,4 +1,4 @@ -define(['./_arrayReduce'], function(arrayReduce) { +define(['./_basePickBy'], function(basePickBy) { /** * The base implementation of `_.pick` without support for individual @@ -11,12 +11,9 @@ define(['./_arrayReduce'], function(arrayReduce) { */ function basePick(object, props) { object = Object(object); - return arrayReduce(props, function(result, key) { - if (key in object) { - result[key] = object[key]; - } - return result; - }, {}); + return basePickBy(object, props, function(value, key) { + return key in object; + }); } return basePick; diff --git a/_basePickBy.js b/_basePickBy.js index a08b25e34..396df10cb 100644 --- a/_basePickBy.js +++ b/_basePickBy.js @@ -1,16 +1,16 @@ -define(['./_getAllKeysIn'], function(getAllKeysIn) { +define([], function() { /** * The base implementation of `_.pickBy` without support for iteratee shorthands. * * @private * @param {Object} object The source object. + * @param {string[]} props The property identifiers to pick from. * @param {Function} predicate The function invoked per property. * @returns {Object} Returns the new object. */ - function basePickBy(object, predicate) { + function basePickBy(object, props, predicate) { var index = -1, - props = getAllKeysIn(object), length = props.length, result = {}; diff --git a/_basePropertyOf.js b/_basePropertyOf.js new file mode 100644 index 000000000..e2a85d60c --- /dev/null +++ b/_basePropertyOf.js @@ -0,0 +1,20 @@ +define([], function() { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * The base implementation of `_.propertyOf` without support for deep paths. + * + * @private + * @param {Object} object The object to query. + * @returns {Function} Returns the new accessor function. + */ + function basePropertyOf(object) { + return function(key) { + return object == null ? undefined : object[key]; + }; + } + + return basePropertyOf; +}); diff --git a/_baseRange.js b/_baseRange.js index 8897acb06..6b98f22f8 100644 --- a/_baseRange.js +++ b/_baseRange.js @@ -6,7 +6,7 @@ define([], function() { /** * The base implementation of `_.range` and `_.rangeRight` which doesn't - * coerce arguments to numbers. + * coerce arguments. * * @private * @param {number} start The start of the range. diff --git a/_baseRest.js b/_baseRest.js new file mode 100644 index 000000000..f2a6ca592 --- /dev/null +++ b/_baseRest.js @@ -0,0 +1,39 @@ +define(['./_apply'], function(apply) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeMax = Math.max; + + /** + * The base implementation of `_.rest` which doesn't validate or coerce arguments. + * + * @private + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @returns {Function} Returns the new function. + */ + function baseRest(func, start) { + start = nativeMax(start === undefined ? (func.length - 1) : start, 0); + return function() { + var args = arguments, + index = -1, + length = nativeMax(args.length - start, 0), + array = Array(length); + + while (++index < length) { + array[index] = args[start + index]; + } + index = -1; + var otherArgs = Array(start + 1); + while (++index < start) { + otherArgs[index] = args[index]; + } + otherArgs[start] = array; + return apply(func, this, otherArgs); + }; + } + + return baseRest; +}); diff --git a/_baseUnary.js b/_baseUnary.js index fe7a7d70e..eca125dcb 100644 --- a/_baseUnary.js +++ b/_baseUnary.js @@ -1,7 +1,7 @@ define([], function() { /** - * The base implementation of `_.unary` without support for storing wrapper metadata. + * The base implementation of `_.unary` without support for storing metadata. * * @private * @param {Function} func The function to cap arguments for. diff --git a/_checkGlobal.js b/_checkGlobal.js deleted file mode 100644 index 172c8ab26..000000000 --- a/_checkGlobal.js +++ /dev/null @@ -1,15 +0,0 @@ -define([], function() { - - /** - * Checks if `value` is a global object. - * - * @private - * @param {*} value The value to check. - * @returns {null|Object} Returns `value` if it's a global object, else `null`. - */ - function checkGlobal(value) { - return (value && value.Object === Object) ? value : null; - } - - return checkGlobal; -}); diff --git a/_copyObject.js b/_copyObject.js index 236f7f36b..4e41d3a41 100644 --- a/_copyObject.js +++ b/_copyObject.js @@ -1,5 +1,8 @@ define(['./_assignValue'], function(assignValue) { + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + /** * Copies properties of `source` to `object`. * @@ -21,9 +24,9 @@ define(['./_assignValue'], function(assignValue) { var newValue = customizer ? customizer(object[key], source[key], key, object, source) - : source[key]; + : undefined; - assignValue(object, key, newValue); + assignValue(object, key, newValue === undefined ? source[key] : newValue); } return object; } diff --git a/_createAggregator.js b/_createAggregator.js index 6623ddd19..f2d452b97 100644 --- a/_createAggregator.js +++ b/_createAggregator.js @@ -13,7 +13,7 @@ define(['./_arrayAggregator', './_baseAggregator', './_baseIteratee', './isArray var func = isArray(collection) ? arrayAggregator : baseAggregator, accumulator = initializer ? initializer() : {}; - return func(collection, setter, baseIteratee(iteratee), accumulator); + return func(collection, setter, baseIteratee(iteratee, 2), accumulator); }; } diff --git a/_createAssigner.js b/_createAssigner.js index 4f9d0565a..392405385 100644 --- a/_createAssigner.js +++ b/_createAssigner.js @@ -1,4 +1,4 @@ -define(['./_isIterateeCall', './rest'], function(isIterateeCall, rest) { +define(['./_baseRest', './_isIterateeCall'], function(baseRest, isIterateeCall) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -11,7 +11,7 @@ define(['./_isIterateeCall', './rest'], function(isIterateeCall, rest) { * @returns {Function} Returns the new assigner function. */ function createAssigner(assigner) { - return rest(function(object, sources) { + return baseRest(function(object, sources) { var index = -1, length = sources.length, customizer = length > 1 ? sources[length - 1] : undefined, diff --git a/_createBaseWrapper.js b/_createBind.js similarity index 60% rename from _createBaseWrapper.js rename to _createBind.js index 54656fedf..7b89d84ee 100644 --- a/_createBaseWrapper.js +++ b/_createBind.js @@ -1,6 +1,6 @@ -define(['./_createCtorWrapper', './_root'], function(createCtorWrapper, root) { +define(['./_createCtor', './_root'], function(createCtor, root) { - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1; /** @@ -9,14 +9,13 @@ define(['./_createCtorWrapper', './_root'], function(createCtorWrapper, root) { * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` - * for more details. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {*} [thisArg] The `this` binding of `func`. * @returns {Function} Returns the new wrapped function. */ - function createBaseWrapper(func, bitmask, thisArg) { + function createBind(func, bitmask, thisArg) { var isBind = bitmask & BIND_FLAG, - Ctor = createCtorWrapper(func); + Ctor = createCtor(func); function wrapper() { var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; @@ -25,5 +24,5 @@ define(['./_createCtorWrapper', './_root'], function(createCtorWrapper, root) { return wrapper; } - return createBaseWrapper; + return createBind; }); diff --git a/_createCtorWrapper.js b/_createCtor.js similarity index 95% rename from _createCtorWrapper.js rename to _createCtor.js index 5b76869b2..ef5d00f24 100644 --- a/_createCtorWrapper.js +++ b/_createCtor.js @@ -8,7 +8,7 @@ define(['./_baseCreate', './isObject'], function(baseCreate, isObject) { * @param {Function} Ctor The constructor to wrap. * @returns {Function} Returns the new wrapped function. */ - function createCtorWrapper(Ctor) { + function createCtor(Ctor) { return function() { // Use a `switch` statement to work with class constructors. See // http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist @@ -33,5 +33,5 @@ define(['./_baseCreate', './isObject'], function(baseCreate, isObject) { }; } - return createCtorWrapper; + return createCtor; }); diff --git a/_createCurryWrapper.js b/_createCurry.js similarity index 62% rename from _createCurryWrapper.js rename to _createCurry.js index 0f47a21b8..711039bd3 100644 --- a/_createCurryWrapper.js +++ b/_createCurry.js @@ -1,4 +1,4 @@ -define(['./_apply', './_createCtorWrapper', './_createHybridWrapper', './_createRecurryWrapper', './_getHolder', './_replaceHolders', './_root'], function(apply, createCtorWrapper, createHybridWrapper, createRecurryWrapper, getHolder, replaceHolders, root) { +define(['./_apply', './_createCtor', './_createHybrid', './_createRecurry', './_getHolder', './_replaceHolders', './_root'], function(apply, createCtor, createHybrid, createRecurry, getHolder, replaceHolders, root) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -8,13 +8,12 @@ define(['./_apply', './_createCtorWrapper', './_createHybridWrapper', './_create * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` - * for more details. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {number} arity The arity of `func`. * @returns {Function} Returns the new wrapped function. */ - function createCurryWrapper(func, bitmask, arity) { - var Ctor = createCtorWrapper(func); + function createCurry(func, bitmask, arity) { + var Ctor = createCtor(func); function wrapper() { var length = arguments.length, @@ -31,8 +30,8 @@ define(['./_apply', './_createCtorWrapper', './_createHybridWrapper', './_create length -= holders.length; if (length < arity) { - return createRecurryWrapper( - func, bitmask, createHybridWrapper, wrapper.placeholder, undefined, + return createRecurry( + func, bitmask, createHybrid, wrapper.placeholder, undefined, args, holders, undefined, undefined, arity - length); } var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; @@ -41,5 +40,5 @@ define(['./_apply', './_createCtorWrapper', './_createHybridWrapper', './_create return wrapper; } - return createCurryWrapper; + return createCurry; }); diff --git a/_createFind.js b/_createFind.js index 3b0ead4be..297ed7533 100644 --- a/_createFind.js +++ b/_createFind.js @@ -13,18 +13,13 @@ define(['./_baseIteratee', './isArrayLike', './keys'], function(baseIteratee, is function createFind(findIndexFunc) { return function(collection, predicate, fromIndex) { var iterable = Object(collection); - predicate = baseIteratee(predicate, 3); if (!isArrayLike(collection)) { - var props = keys(collection); + var iteratee = baseIteratee(predicate, 3); + collection = keys(collection); + predicate = function(key) { return iteratee(iterable[key], key, iterable); }; } - var index = findIndexFunc(props || collection, function(value, key) { - if (props) { - key = value; - value = iterable[key]; - } - return predicate(value, key, iterable); - }, fromIndex); - return index > -1 ? collection[props ? props[index] : index] : undefined; + var index = findIndexFunc(collection, predicate, fromIndex); + return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined; }; } diff --git a/_createFlow.js b/_createFlow.js index cd35fcab9..5ea89772b 100644 --- a/_createFlow.js +++ b/_createFlow.js @@ -1,4 +1,4 @@ -define(['./_LodashWrapper', './_baseFlatten', './_getData', './_getFuncName', './isArray', './_isLaziable', './rest'], function(LodashWrapper, baseFlatten, getData, getFuncName, isArray, isLaziable, rest) { +define(['./_LodashWrapper', './_baseFlatten', './_baseRest', './_getData', './_getFuncName', './isArray', './_isLaziable'], function(LodashWrapper, baseFlatten, baseRest, getData, getFuncName, isArray, isLaziable) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -9,7 +9,7 @@ define(['./_LodashWrapper', './_baseFlatten', './_getData', './_getFuncName', '. /** Used as the `TypeError` message for "Functions" methods. */ var FUNC_ERROR_TEXT = 'Expected a function'; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var CURRY_FLAG = 8, PARTIAL_FLAG = 32, ARY_FLAG = 128, @@ -23,7 +23,7 @@ define(['./_LodashWrapper', './_baseFlatten', './_getData', './_getFuncName', '. * @returns {Function} Returns the new flow function. */ function createFlow(fromRight) { - return rest(function(funcs) { + return baseRest(function(funcs) { funcs = baseFlatten(funcs, 1); var length = funcs.length, diff --git a/_createHybridWrapper.js b/_createHybrid.js similarity index 76% rename from _createHybridWrapper.js rename to _createHybrid.js index 0c4d3b3cf..8e9c24d05 100644 --- a/_createHybridWrapper.js +++ b/_createHybrid.js @@ -1,9 +1,9 @@ -define(['./_composeArgs', './_composeArgsRight', './_countHolders', './_createCtorWrapper', './_createRecurryWrapper', './_getHolder', './_reorder', './_replaceHolders', './_root'], function(composeArgs, composeArgsRight, countHolders, createCtorWrapper, createRecurryWrapper, getHolder, reorder, replaceHolders, root) { +define(['./_composeArgs', './_composeArgsRight', './_countHolders', './_createCtor', './_createRecurry', './_getHolder', './_reorder', './_replaceHolders', './_root'], function(composeArgs, composeArgsRight, countHolders, createCtor, createRecurry, getHolder, reorder, replaceHolders, root) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1, BIND_KEY_FLAG = 2, CURRY_FLAG = 8, @@ -17,8 +17,7 @@ define(['./_composeArgs', './_composeArgsRight', './_countHolders', './_createCt * * @private * @param {Function|string} func The function or method name to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` - * for more details. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {*} [thisArg] The `this` binding of `func`. * @param {Array} [partials] The arguments to prepend to those provided to * the new function. @@ -31,13 +30,13 @@ define(['./_composeArgs', './_composeArgsRight', './_countHolders', './_createCt * @param {number} [arity] The arity of `func`. * @returns {Function} Returns the new wrapped function. */ - function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { + function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { var isAry = bitmask & ARY_FLAG, isBind = bitmask & BIND_FLAG, isBindKey = bitmask & BIND_KEY_FLAG, isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG), isFlip = bitmask & FLIP_FLAG, - Ctor = isBindKey ? undefined : createCtorWrapper(func); + Ctor = isBindKey ? undefined : createCtor(func); function wrapper() { var length = arguments.length, @@ -60,8 +59,8 @@ define(['./_composeArgs', './_composeArgsRight', './_countHolders', './_createCt length -= holdersCount; if (isCurried && length < arity) { var newHolders = replaceHolders(args, placeholder); - return createRecurryWrapper( - func, bitmask, createHybridWrapper, wrapper.placeholder, thisArg, + return createRecurry( + func, bitmask, createHybrid, wrapper.placeholder, thisArg, args, newHolders, argPos, ary, arity - length ); } @@ -78,12 +77,12 @@ define(['./_composeArgs', './_composeArgsRight', './_countHolders', './_createCt args.length = ary; } if (this && this !== root && this instanceof wrapper) { - fn = Ctor || createCtorWrapper(fn); + fn = Ctor || createCtor(fn); } return fn.apply(thisBinding, args); } return wrapper; } - return createHybridWrapper; + return createHybrid; }); diff --git a/_createMathOperation.js b/_createMathOperation.js index 1aea44d5c..550d7d543 100644 --- a/_createMathOperation.js +++ b/_createMathOperation.js @@ -8,13 +8,14 @@ define(['./_baseToNumber', './_baseToString'], function(baseToNumber, baseToStri * * @private * @param {Function} operator The function to perform the operation. + * @param {number} [defaultValue] The value used for `undefined` arguments. * @returns {Function} Returns the new mathematical operation function. */ - function createMathOperation(operator) { + function createMathOperation(operator, defaultValue) { return function(value, other) { var result; if (value === undefined && other === undefined) { - return 0; + return defaultValue; } if (value !== undefined) { result = value; diff --git a/_createOver.js b/_createOver.js index f630892f0..dc19d997c 100644 --- a/_createOver.js +++ b/_createOver.js @@ -1,4 +1,4 @@ -define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_baseUnary', './isArray', './_isFlattenableIteratee', './rest'], function(apply, arrayMap, baseFlatten, baseIteratee, baseUnary, isArray, isFlattenableIteratee, rest) { +define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_baseRest', './_baseUnary', './isArray'], function(apply, arrayMap, baseFlatten, baseIteratee, baseRest, baseUnary, isArray) { /** * Creates a function like `_.over`. @@ -8,12 +8,12 @@ define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_base * @returns {Function} Returns the new over function. */ function createOver(arrayFunc) { - return rest(function(iteratees) { + return baseRest(function(iteratees) { iteratees = (iteratees.length == 1 && isArray(iteratees[0])) ? arrayMap(iteratees[0], baseUnary(baseIteratee)) - : arrayMap(baseFlatten(iteratees, 1, isFlattenableIteratee), baseUnary(baseIteratee)); + : arrayMap(baseFlatten(iteratees, 1), baseUnary(baseIteratee)); - return rest(function(args) { + return baseRest(function(args) { var thisArg = this; return arrayFunc(iteratees, function(iteratee) { return apply(iteratee, thisArg, args); diff --git a/_createPartialWrapper.js b/_createPartial.js similarity index 72% rename from _createPartialWrapper.js rename to _createPartial.js index 055762326..b42c70c15 100644 --- a/_createPartialWrapper.js +++ b/_createPartial.js @@ -1,6 +1,6 @@ -define(['./_apply', './_createCtorWrapper', './_root'], function(apply, createCtorWrapper, root) { +define(['./_apply', './_createCtor', './_root'], function(apply, createCtor, root) { - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1; /** @@ -9,16 +9,15 @@ define(['./_apply', './_createCtorWrapper', './_root'], function(apply, createCt * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` - * for more details. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {*} thisArg The `this` binding of `func`. * @param {Array} partials The arguments to prepend to those provided to * the new function. * @returns {Function} Returns the new wrapped function. */ - function createPartialWrapper(func, bitmask, thisArg, partials) { + function createPartial(func, bitmask, thisArg, partials) { var isBind = bitmask & BIND_FLAG, - Ctor = createCtorWrapper(func); + Ctor = createCtor(func); function wrapper() { var argsIndex = -1, @@ -39,5 +38,5 @@ define(['./_apply', './_createCtorWrapper', './_root'], function(apply, createCt return wrapper; } - return createPartialWrapper; + return createPartial; }); diff --git a/_createRecurryWrapper.js b/_createRecurry.js similarity index 80% rename from _createRecurryWrapper.js rename to _createRecurry.js index 4213ef033..65eef4187 100644 --- a/_createRecurryWrapper.js +++ b/_createRecurry.js @@ -1,9 +1,9 @@ -define(['./_isLaziable', './_setData'], function(isLaziable, setData) { +define(['./_isLaziable', './_setData', './_setWrapToString'], function(isLaziable, setData, setWrapToString) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1, BIND_KEY_FLAG = 2, CURRY_BOUND_FLAG = 4, @@ -16,8 +16,7 @@ define(['./_isLaziable', './_setData'], function(isLaziable, setData) { * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` - * for more details. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {Function} wrapFunc The function to create the `func` wrapper. * @param {*} placeholder The placeholder value. * @param {*} [thisArg] The `this` binding of `func`. @@ -29,7 +28,7 @@ define(['./_isLaziable', './_setData'], function(isLaziable, setData) { * @param {number} [arity] The arity of `func`. * @returns {Function} Returns the new wrapped function. */ - function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { + function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { var isCurry = bitmask & CURRY_FLAG, newHolders = isCurry ? holders : undefined, newHoldersRight = isCurry ? undefined : holders, @@ -52,8 +51,8 @@ define(['./_isLaziable', './_setData'], function(isLaziable, setData) { setData(result, newData); } result.placeholder = placeholder; - return result; + return setWrapToString(result, func, bitmask); } - return createRecurryWrapper; + return createRecurry; }); diff --git a/_createSet.js b/_createSet.js index e79cf1046..16a9cc9af 100644 --- a/_createSet.js +++ b/_createSet.js @@ -4,7 +4,7 @@ define(['./_Set', './noop', './_setToArray'], function(Set, noop, setToArray) { var INFINITY = 1 / 0; /** - * Creates a set of `values`. + * Creates a set object of `values`. * * @private * @param {Array} values The values to add to the set. diff --git a/_createWrapper.js b/_createWrap.js similarity index 78% rename from _createWrapper.js rename to _createWrap.js index 47b8b2ede..6c5fb128c 100644 --- a/_createWrapper.js +++ b/_createWrap.js @@ -1,4 +1,4 @@ -define(['./_baseSetData', './_createBaseWrapper', './_createCurryWrapper', './_createHybridWrapper', './_createPartialWrapper', './_getData', './_mergeData', './_setData', './toInteger'], function(baseSetData, createBaseWrapper, createCurryWrapper, createHybridWrapper, createPartialWrapper, getData, mergeData, setData, toInteger) { +define(['./_baseSetData', './_createBind', './_createCurry', './_createHybrid', './_createPartial', './_getData', './_mergeData', './_setData', './_setWrapToString', './toInteger'], function(baseSetData, createBind, createCurry, createHybrid, createPartial, getData, mergeData, setData, setWrapToString, toInteger) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -6,7 +6,7 @@ define(['./_baseSetData', './_createBaseWrapper', './_createCurryWrapper', './_c /** Used as the `TypeError` message for "Functions" methods. */ var FUNC_ERROR_TEXT = 'Expected a function'; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1, BIND_KEY_FLAG = 2, CURRY_FLAG = 8, @@ -23,7 +23,7 @@ define(['./_baseSetData', './_createBaseWrapper', './_createCurryWrapper', './_c * * @private * @param {Function|string} func The function or method name to wrap. - * @param {number} bitmask The bitmask of wrapper flags. + * @param {number} bitmask The bitmask flags. * The bitmask may be composed of the following flags: * 1 - `_.bind` * 2 - `_.bindKey` @@ -43,7 +43,7 @@ define(['./_baseSetData', './_createBaseWrapper', './_createCurryWrapper', './_c * @param {number} [arity] The arity of `func`. * @returns {Function} Returns the new wrapped function. */ - function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { + function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { var isBindKey = bitmask & BIND_KEY_FLAG; if (!isBindKey && typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); @@ -86,17 +86,17 @@ define(['./_baseSetData', './_createBaseWrapper', './_createCurryWrapper', './_c bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG); } if (!bitmask || bitmask == BIND_FLAG) { - var result = createBaseWrapper(func, bitmask, thisArg); + var result = createBind(func, bitmask, thisArg); } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) { - result = createCurryWrapper(func, bitmask, arity); + result = createCurry(func, bitmask, arity); } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) { - result = createPartialWrapper(func, bitmask, thisArg, partials); + result = createPartial(func, bitmask, thisArg, partials); } else { - result = createHybridWrapper.apply(undefined, newData); + result = createHybrid.apply(undefined, newData); } var setter = data ? baseSetData : setData; - return setter(result, newData); + return setWrapToString(setter(result, newData), func, bitmask); } - return createWrapper; + return createWrap; }); diff --git a/_deburrLetter.js b/_deburrLetter.js index b2217907b..a05732e4d 100644 --- a/_deburrLetter.js +++ b/_deburrLetter.js @@ -1,4 +1,4 @@ -define([], function() { +define(['./_basePropertyOf'], function(basePropertyOf) { /** Used to map latin-1 supplementary letters to basic latin letters. */ var deburredLetters = { @@ -28,9 +28,7 @@ define([], function() { * @param {string} letter The matched letter to deburr. * @returns {string} Returns the deburred letter. */ - function deburrLetter(letter) { - return deburredLetters[letter]; - } + var deburrLetter = basePropertyOf(deburredLetters); return deburrLetter; }); diff --git a/_defineProperty.js b/_defineProperty.js new file mode 100644 index 000000000..51d1ba1cf --- /dev/null +++ b/_defineProperty.js @@ -0,0 +1,15 @@ +define(['./_getNative'], function(getNative) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /* Used to set `toString` methods. */ + var defineProperty = (function() { + var func = getNative(Object, 'defineProperty'), + name = getNative.name; + + return (name && name.length > 2) ? func : undefined; + }()); + + return defineProperty; +}); diff --git a/_equalArrays.js b/_equalArrays.js index f87a2e0a5..d4612aecf 100644 --- a/_equalArrays.js +++ b/_equalArrays.js @@ -31,7 +31,7 @@ define(['./_SetCache', './_arraySome'], function(SetCache, arraySome) { } // Assume cyclic values are equal. var stacked = stack.get(array); - if (stacked) { + if (stacked && stack.get(other)) { return stacked == other; } var index = -1, @@ -39,6 +39,7 @@ define(['./_SetCache', './_arraySome'], function(SetCache, arraySome) { seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined; stack.set(array, other); + stack.set(other, array); // Ignore non-index properties. while (++index < arrLength) { diff --git a/_equalByTag.js b/_equalByTag.js index 4a9d234c2..196993702 100644 --- a/_equalByTag.js +++ b/_equalByTag.js @@ -1,4 +1,4 @@ -define(['./_Symbol', './_Uint8Array', './_equalArrays', './_mapToArray', './_setToArray'], function(Symbol, Uint8Array, equalArrays, mapToArray, setToArray) { +define(['./_Symbol', './_Uint8Array', './eq', './_equalArrays', './_mapToArray', './_setToArray'], function(Symbol, Uint8Array, eq, equalArrays, mapToArray, setToArray) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -62,18 +62,14 @@ define(['./_Symbol', './_Uint8Array', './_equalArrays', './_mapToArray', './_set case boolTag: case dateTag: - // Coerce dates and booleans to numbers, dates to milliseconds and - // booleans to `1` or `0` treating invalid dates coerced to `NaN` as - // not equal. - return +object == +other; + case numberTag: + // Coerce booleans to `1` or `0` and dates to milliseconds. + // Invalid dates are coerced to `NaN`. + return eq(+object, +other); case errorTag: return object.name == other.name && object.message == other.message; - case numberTag: - // Treat `NaN` vs. `NaN` as equal. - return (object != +object) ? other != +other : object == +other; - case regexpTag: case stringTag: // Coerce regexes to strings and treat strings, primitives and objects, @@ -97,10 +93,12 @@ define(['./_Symbol', './_Uint8Array', './_equalArrays', './_mapToArray', './_set return stacked == other; } bitmask |= UNORDERED_COMPARE_FLAG; - stack.set(object, other); // Recursively compare objects (susceptible to call stack limits). - return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack); + stack.set(object, other); + var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack); + stack['delete'](object); + return result; case symbolTag: if (symbolValueOf) { diff --git a/_equalObjects.js b/_equalObjects.js index a18e4b9e4..1d3a1f955 100644 --- a/_equalObjects.js +++ b/_equalObjects.js @@ -39,11 +39,12 @@ define(['./_baseHas', './keys'], function(baseHas, keys) { } // Assume cyclic values are equal. var stacked = stack.get(object); - if (stacked) { + if (stacked && stack.get(other)) { return stacked == other; } var result = true; stack.set(object, other); + stack.set(other, object); var skipCtor = isPartial; while (++index < objLength) { diff --git a/_escapeHtmlChar.js b/_escapeHtmlChar.js index 401f35d1a..7dd9b4644 100644 --- a/_escapeHtmlChar.js +++ b/_escapeHtmlChar.js @@ -1,4 +1,4 @@ -define([], function() { +define(['./_basePropertyOf'], function(basePropertyOf) { /** Used to map characters to HTML entities. */ var htmlEscapes = { @@ -17,9 +17,7 @@ define([], function() { * @param {string} chr The matched character to escape. * @returns {string} Returns the escaped character. */ - function escapeHtmlChar(chr) { - return htmlEscapes[chr]; - } + var escapeHtmlChar = basePropertyOf(htmlEscapes); return escapeHtmlChar; }); diff --git a/_freeGlobal.js b/_freeGlobal.js new file mode 100644 index 000000000..6221096a2 --- /dev/null +++ b/_freeGlobal.js @@ -0,0 +1,7 @@ +define([], function() { + + /** Detect free variable `global` from Node.js. */ + var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; + + return freeGlobal; +}); diff --git a/_getPrototype.js b/_getPrototype.js index e3b18ace8..23b90a35f 100644 --- a/_getPrototype.js +++ b/_getPrototype.js @@ -1,4 +1,4 @@ -define([], function() { +define(['./_overArg'], function(overArg) { /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeGetPrototype = Object.getPrototypeOf; @@ -10,9 +10,7 @@ define([], function() { * @param {*} value The value to query. * @returns {null|Object} Returns the `[[Prototype]]`. */ - function getPrototype(value) { - return nativeGetPrototype(Object(value)); - } + var getPrototype = overArg(nativeGetPrototype, Object); return getPrototype; }); diff --git a/_getSymbols.js b/_getSymbols.js index e091c3adf..abdb4b185 100644 --- a/_getSymbols.js +++ b/_getSymbols.js @@ -1,7 +1,7 @@ -define(['./stubArray'], function(stubArray) { +define(['./_overArg', './stubArray'], function(overArg, stubArray) { - /** Built-in value references. */ - var getOwnPropertySymbols = Object.getOwnPropertySymbols; + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeGetSymbols = Object.getOwnPropertySymbols; /** * Creates an array of the own enumerable symbol properties of `object`. @@ -10,16 +10,7 @@ define(['./stubArray'], function(stubArray) { * @param {Object} object The object to query. * @returns {Array} Returns the array of symbols. */ - function getSymbols(object) { - // Coerce `object` to an object to avoid non-object errors in V8. - // See https://bugs.chromium.org/p/v8/issues/detail?id=3443 for more details. - return getOwnPropertySymbols(Object(object)); - } - - // Fallback for IE < 11. - if (!getOwnPropertySymbols) { - getSymbols = stubArray; - } + var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray; return getSymbols; }); diff --git a/_getSymbolsIn.js b/_getSymbolsIn.js index a0bba888e..70653943a 100644 --- a/_getSymbolsIn.js +++ b/_getSymbolsIn.js @@ -1,7 +1,7 @@ define(['./_arrayPush', './_getPrototype', './_getSymbols'], function(arrayPush, getPrototype, getSymbols) { - /** Built-in value references. */ - var getOwnPropertySymbols = Object.getOwnPropertySymbols; + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeGetSymbols = Object.getOwnPropertySymbols; /** * Creates an array of the own and inherited enumerable symbol properties @@ -11,7 +11,7 @@ define(['./_arrayPush', './_getPrototype', './_getSymbols'], function(arrayPush, * @param {Object} object The object to query. * @returns {Array} Returns the array of symbols. */ - var getSymbolsIn = !getOwnPropertySymbols ? getSymbols : function(object) { + var getSymbolsIn = !nativeGetSymbols ? getSymbols : function(object) { var result = []; while (object) { arrayPush(result, getSymbols(object)); diff --git a/_getTag.js b/_getTag.js index 872e4f8ea..fb364a10b 100644 --- a/_getTag.js +++ b/_getTag.js @@ -1,4 +1,4 @@ -define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap', './_toSource'], function(DataView, Map, Promise, Set, WeakMap, toSource) { +define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap', './_baseGetTag', './_toSource'], function(DataView, Map, Promise, Set, WeakMap, baseGetTag, toSource) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -36,9 +36,7 @@ define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap', './_toSou * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ - function getTag(value) { - return objectToString.call(value); - } + var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11, // for data views in Edge, and promises in Node.js. diff --git a/_getWrapDetails.js b/_getWrapDetails.js new file mode 100644 index 000000000..f4a090405 --- /dev/null +++ b/_getWrapDetails.js @@ -0,0 +1,20 @@ +define([], function() { + + /** Used to match wrap detail comments. */ + var reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, + reSplitDetails = /,? & /; + + /** + * Extracts wrapper details from the `source` body comment. + * + * @private + * @param {string} source The source to inspect. + * @returns {Array} Returns the wrapper details. + */ + function getWrapDetails(source) { + var match = source.match(reWrapDetails); + return match ? match[1].split(reSplitDetails) : []; + } + + return getWrapDetails; +}); diff --git a/_indexOfNaN.js b/_indexOfNaN.js deleted file mode 100644 index 18756d573..000000000 --- a/_indexOfNaN.js +++ /dev/null @@ -1,26 +0,0 @@ -define([], function() { - - /** - * Gets the index at which the first occurrence of `NaN` is found in `array`. - * - * @private - * @param {Array} array The array to search. - * @param {number} fromIndex The index to search from. - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {number} Returns the index of the matched `NaN`, else `-1`. - */ - function indexOfNaN(array, fromIndex, fromRight) { - var length = array.length, - index = fromIndex + (fromRight ? 1 : -1); - - while ((fromRight ? index-- : ++index < length)) { - var other = array[index]; - if (other !== other) { - return index; - } - } - return -1; - } - - return indexOfNaN; -}); diff --git a/_insertWrapDetails.js b/_insertWrapDetails.js new file mode 100644 index 000000000..491577d26 --- /dev/null +++ b/_insertWrapDetails.js @@ -0,0 +1,24 @@ +define([], function() { + + /** Used to match wrap detail comments. */ + var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/; + + /** + * Inserts wrapper `details` in a comment at the top of the `source` body. + * + * @private + * @param {string} source The source to modify. + * @returns {Array} details The details to insert. + * @returns {string} Returns the modified source. + */ + function insertWrapDetails(source, details) { + var length = details.length, + lastIndex = length - 1; + + details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex]; + details = details.join(length > 2 ? ', ' : ' '); + return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n'); + } + + return insertWrapDetails; +}); diff --git a/_isFlattenable.js b/_isFlattenable.js index 945ad25fb..6efe010bb 100644 --- a/_isFlattenable.js +++ b/_isFlattenable.js @@ -1,4 +1,10 @@ -define(['./isArguments', './isArray'], function(isArguments, isArray) { +define(['./_Symbol', './isArguments', './isArray'], function(Symbol, isArguments, isArray) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** Built-in value references. */ + var spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; /** * Checks if `value` is a flattenable `arguments` object or array. @@ -8,7 +14,8 @@ define(['./isArguments', './isArray'], function(isArguments, isArray) { * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. */ function isFlattenable(value) { - return isArray(value) || isArguments(value); + return isArray(value) || isArguments(value) || + !!(spreadableSymbol && value && value[spreadableSymbol]) } return isFlattenable; diff --git a/_isFlattenableIteratee.js b/_isFlattenableIteratee.js deleted file mode 100644 index 7390271f3..000000000 --- a/_isFlattenableIteratee.js +++ /dev/null @@ -1,16 +0,0 @@ -define(['./isArray', './isFunction'], function(isArray, isFunction) { - - /** - * Checks if `value` is a flattenable array and not a `_.matchesProperty` - * iteratee shorthand. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. - */ - function isFlattenableIteratee(value) { - return isArray(value) && !(value.length == 2 && !isFunction(value[0])); - } - - return isFlattenableIteratee; -}); diff --git a/_mergeData.js b/_mergeData.js index fb03a3898..ba1aed3ae 100644 --- a/_mergeData.js +++ b/_mergeData.js @@ -3,7 +3,7 @@ define(['./_composeArgs', './_composeArgsRight', './_replaceHolders'], function( /** Used as the internal argument placeholder. */ var PLACEHOLDER = '__lodash_placeholder__'; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1, BIND_KEY_FLAG = 2, CURRY_BOUND_FLAG = 4, diff --git a/_mergeDefaults.js b/_mergeDefaults.js index 172c3dbce..c4c6dc25b 100644 --- a/_mergeDefaults.js +++ b/_mergeDefaults.js @@ -18,7 +18,10 @@ define(['./_baseMerge', './isObject'], function(baseMerge, isObject) { */ function mergeDefaults(objValue, srcValue, key, object, source, stack) { if (isObject(objValue) && isObject(srcValue)) { - baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue)); + // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, objValue); + baseMerge(objValue, srcValue, undefined, mergeDefaults, stack); + stack['delete'](srcValue); } return objValue; } diff --git a/_nodeUtil.js b/_nodeUtil.js new file mode 100644 index 000000000..48738eef0 --- /dev/null +++ b/_nodeUtil.js @@ -0,0 +1,23 @@ +define(['./_freeGlobal'], function(freeGlobal) { + + /** Detect free variable `exports`. */ + var freeExports = freeGlobal && typeof exports == 'object' && exports; + + /** Detect free variable `module`. */ + var freeModule = freeExports && typeof module == 'object' && module; + + /** Detect the popular CommonJS extension `module.exports`. */ + var moduleExports = freeModule && freeModule.exports === freeExports; + + /** Detect free variable `process` from Node.js. */ + var freeProcess = moduleExports && freeGlobal.process; + + /** Used to access faster Node.js helpers. */ + var nodeUtil = (function() { + try { + return freeProcess && freeProcess.binding('util'); + } catch (e) {} + }()); + + return nodeUtil; +}); diff --git a/_overArg.js b/_overArg.js new file mode 100644 index 000000000..e39423dfb --- /dev/null +++ b/_overArg.js @@ -0,0 +1,18 @@ +define([], function() { + + /** + * Creates a function that invokes `func` with its first argument transformed. + * + * @private + * @param {Function} func The function to wrap. + * @param {Function} transform The argument transform. + * @returns {Function} Returns the new function. + */ + function overArg(func, transform) { + return function(arg) { + return func(transform(arg)); + }; + } + + return overArg; +}); diff --git a/_root.js b/_root.js index 826108997..0b9007083 100644 --- a/_root.js +++ b/_root.js @@ -1,16 +1,10 @@ -define(['./_checkGlobal'], function(checkGlobal) { - - /** Detect free variable `global` from Node.js. */ - var freeGlobal = checkGlobal(typeof global == 'object' && global); +define(['./_freeGlobal'], function(freeGlobal) { /** Detect free variable `self`. */ - var freeSelf = checkGlobal(typeof self == 'object' && self); - - /** Detect `this` as the global object. */ - var thisGlobal = checkGlobal(typeof this == 'object' && this); + var freeSelf = typeof self == 'object' && self && self.Object === Object && self; /** Used as a reference to the global object. */ - var root = freeGlobal || freeSelf || thisGlobal || Function('return this')(); + var root = freeGlobal || freeSelf || Function('return this')(); return root; }); diff --git a/_setWrapToString.js b/_setWrapToString.js new file mode 100644 index 000000000..07d8951ca --- /dev/null +++ b/_setWrapToString.js @@ -0,0 +1,23 @@ +define(['./constant', './_defineProperty', './_getWrapDetails', './identity', './_insertWrapDetails', './_updateWrapDetails'], function(constant, defineProperty, getWrapDetails, identity, insertWrapDetails, updateWrapDetails) { + + /** + * Sets the `toString` method of `wrapper` to mimic the source of `reference` + * with wrapper details in a comment at the top of the source body. + * + * @private + * @param {Function} wrapper The function to modify. + * @param {Function} reference The reference function. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @returns {Function} Returns `wrapper`. + */ + var setWrapToString = !defineProperty ? identity : function(wrapper, reference, bitmask) { + var source = (reference + ''); + return defineProperty(wrapper, 'toString', { + 'configurable': true, + 'enumerable': false, + 'value': constant(insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask))) + }); + }; + + return setWrapToString; +}); diff --git a/_stackSet.js b/_stackSet.js index 05ac02657..8ee7616bc 100644 --- a/_stackSet.js +++ b/_stackSet.js @@ -1,4 +1,4 @@ -define(['./_ListCache', './_MapCache'], function(ListCache, MapCache) { +define(['./_ListCache', './_Map', './_MapCache'], function(ListCache, Map, MapCache) { /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -15,8 +15,13 @@ define(['./_ListCache', './_MapCache'], function(ListCache, MapCache) { */ function stackSet(key, value) { var cache = this.__data__; - if (cache instanceof ListCache && cache.__data__.length == LARGE_ARRAY_SIZE) { - cache = this.__data__ = new MapCache(cache.__data__); + if (cache instanceof ListCache) { + var pairs = cache.__data__; + if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) { + pairs.push([key, value]); + return this; + } + cache = this.__data__ = new MapCache(pairs); } cache.set(key, value); return this; diff --git a/_unescapeHtmlChar.js b/_unescapeHtmlChar.js index 5406efd3b..4bea17471 100644 --- a/_unescapeHtmlChar.js +++ b/_unescapeHtmlChar.js @@ -1,4 +1,4 @@ -define([], function() { +define(['./_basePropertyOf'], function(basePropertyOf) { /** Used to map HTML entities to characters. */ var htmlUnescapes = { @@ -17,9 +17,7 @@ define([], function() { * @param {string} chr The matched character to unescape. * @returns {string} Returns the unescaped character. */ - function unescapeHtmlChar(chr) { - return htmlUnescapes[chr]; - } + var unescapeHtmlChar = basePropertyOf(htmlUnescapes); return unescapeHtmlChar; }); diff --git a/_updateWrapDetails.js b/_updateWrapDetails.js new file mode 100644 index 000000000..43a7d8871 --- /dev/null +++ b/_updateWrapDetails.js @@ -0,0 +1,46 @@ +define(['./_arrayEach', './_arrayIncludes'], function(arrayEach, arrayIncludes) { + + /** Used to compose bitmasks for function metadata. */ + var BIND_FLAG = 1, + BIND_KEY_FLAG = 2, + CURRY_FLAG = 8, + CURRY_RIGHT_FLAG = 16, + PARTIAL_FLAG = 32, + PARTIAL_RIGHT_FLAG = 64, + ARY_FLAG = 128, + REARG_FLAG = 256, + FLIP_FLAG = 512; + + /** Used to associate wrap methods with their bit flags. */ + var wrapFlags = [ + ['ary', ARY_FLAG], + ['bind', BIND_FLAG], + ['bindKey', BIND_KEY_FLAG], + ['curry', CURRY_FLAG], + ['curryRight', CURRY_RIGHT_FLAG], + ['flip', FLIP_FLAG], + ['partial', PARTIAL_FLAG], + ['partialRight', PARTIAL_RIGHT_FLAG], + ['rearg', REARG_FLAG] + ]; + + /** + * Updates wrapper `details` based on `bitmask` flags. + * + * @private + * @returns {Array} details The details to modify. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @returns {Array} Returns `details`. + */ + function updateWrapDetails(details, bitmask) { + arrayEach(wrapFlags, function(pair) { + var value = '_.' + pair[0]; + if ((bitmask & pair[1]) && !arrayIncludes(details, value)) { + details.push(value); + } + }); + return details.sort(); + } + + return updateWrapDetails; +}); diff --git a/add.js b/add.js index c9a8930dc..eb94f3623 100644 --- a/add.js +++ b/add.js @@ -17,7 +17,7 @@ define(['./_createMathOperation'], function(createMathOperation) { */ var add = createMathOperation(function(augend, addend) { return augend + addend; - }); + }, 0); return add; }); diff --git a/ary.js b/ary.js index 2cc6c72d7..dc5d06ec8 100644 --- a/ary.js +++ b/ary.js @@ -1,9 +1,9 @@ -define(['./_createWrapper'], function(createWrapper) { +define(['./_createWrap'], function(createWrap) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var ARY_FLAG = 128; /** @@ -26,7 +26,7 @@ define(['./_createWrapper'], function(createWrapper) { function ary(func, n, guard) { n = guard ? undefined : n; n = (func && n == null) ? func.length : n; - return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n); + return createWrap(func, ARY_FLAG, undefined, undefined, undefined, undefined, n); } return ary; diff --git a/assign.js b/assign.js index 438b5c3d4..47f495bb4 100644 --- a/assign.js +++ b/assign.js @@ -31,18 +31,18 @@ define(['./_assignValue', './_copyObject', './_createAssigner', './isArrayLike', * @example * * function Foo() { - * this.c = 3; + * this.a = 1; * } * * function Bar() { - * this.e = 5; + * this.c = 3; * } * - * Foo.prototype.d = 4; - * Bar.prototype.f = 6; + * Foo.prototype.b = 2; + * Bar.prototype.d = 4; * - * _.assign({ 'a': 1 }, new Foo, new Bar); - * // => { 'a': 1, 'c': 3, 'e': 5 } + * _.assign({ 'a': 0 }, new Foo, new Bar); + * // => { 'a': 1, 'c': 3 } */ var assign = createAssigner(function(object, source) { if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) { diff --git a/assignIn.js b/assignIn.js index cd4e1013e..a9533795e 100644 --- a/assignIn.js +++ b/assignIn.js @@ -27,18 +27,18 @@ define(['./_assignValue', './_copyObject', './_createAssigner', './isArrayLike', * @example * * function Foo() { - * this.b = 2; + * this.a = 1; * } * * function Bar() { - * this.d = 4; + * this.c = 3; * } * - * Foo.prototype.c = 3; - * Bar.prototype.e = 5; + * Foo.prototype.b = 2; + * Bar.prototype.d = 4; * - * _.assignIn({ 'a': 1 }, new Foo, new Bar); - * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 } + * _.assignIn({ 'a': 0 }, new Foo, new Bar); + * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } */ var assignIn = createAssigner(function(object, source) { if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) { diff --git a/at.js b/at.js index 63332193c..62e894f88 100644 --- a/at.js +++ b/at.js @@ -1,4 +1,4 @@ -define(['./_baseAt', './_baseFlatten', './rest'], function(baseAt, baseFlatten, rest) { +define(['./_baseAt', './_baseFlatten', './_baseRest'], function(baseAt, baseFlatten, baseRest) { /** * Creates an array of values corresponding to `paths` of `object`. @@ -17,7 +17,7 @@ define(['./_baseAt', './_baseFlatten', './rest'], function(baseAt, baseFlatten, * _.at(object, ['a[0].b.c', 'a[1]']); * // => [3, 4] */ - var at = rest(function(object, paths) { + var at = baseRest(function(object, paths) { return baseAt(object, baseFlatten(paths, 1)); }); diff --git a/attempt.js b/attempt.js index 3a4cc8fe0..eccaad11e 100644 --- a/attempt.js +++ b/attempt.js @@ -1,4 +1,4 @@ -define(['./_apply', './isError', './rest'], function(apply, isError, rest) { +define(['./_apply', './_baseRest', './isError'], function(apply, baseRest, isError) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -25,7 +25,7 @@ define(['./_apply', './isError', './rest'], function(apply, isError, rest) { * elements = []; * } */ - var attempt = rest(function(func, args) { + var attempt = baseRest(function(func, args) { try { return apply(func, undefined, args); } catch (e) { diff --git a/before.js b/before.js index 7adb1412b..c72884d5f 100644 --- a/before.js +++ b/before.js @@ -21,7 +21,7 @@ define(['./toInteger'], function(toInteger) { * @example * * jQuery(element).on('click', _.before(5, addContactToList)); - * // => allows adding up to 4 contacts to the list + * // => Allows adding up to 4 contacts to the list. */ function before(n, func) { var result; diff --git a/bind.js b/bind.js index e29d5235a..614465939 100644 --- a/bind.js +++ b/bind.js @@ -1,6 +1,6 @@ -define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], function(createWrapper, getHolder, replaceHolders, rest) { +define(['./_baseRest', './_createWrap', './_getHolder', './_replaceHolders'], function(baseRest, createWrap, getHolder, replaceHolders) { - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1, PARTIAL_FLAG = 32; @@ -24,9 +24,9 @@ define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], func * @returns {Function} Returns the new bound function. * @example * - * var greet = function(greeting, punctuation) { + * function greet(greeting, punctuation) { * return greeting + ' ' + this.user + punctuation; - * }; + * } * * var object = { 'user': 'fred' }; * @@ -39,13 +39,13 @@ define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], func * bound('hi'); * // => 'hi fred!' */ - var bind = rest(function(func, thisArg, partials) { + var bind = baseRest(function(func, thisArg, partials) { var bitmask = BIND_FLAG; if (partials.length) { var holders = replaceHolders(partials, getHolder(bind)); bitmask |= PARTIAL_FLAG; } - return createWrapper(func, bitmask, thisArg, partials, holders); + return createWrap(func, bitmask, thisArg, partials, holders); }); // Assign default placeholders. diff --git a/bindAll.js b/bindAll.js index 0ebbd240f..4c04a1e52 100644 --- a/bindAll.js +++ b/bindAll.js @@ -1,4 +1,4 @@ -define(['./_arrayEach', './_baseFlatten', './bind', './rest', './_toKey'], function(arrayEach, baseFlatten, bind, rest, toKey) { +define(['./_arrayEach', './_baseFlatten', './_baseRest', './bind', './_toKey'], function(arrayEach, baseFlatten, baseRest, bind, toKey) { /** * Binds methods of an object to the object itself, overwriting the existing @@ -17,16 +17,16 @@ define(['./_arrayEach', './_baseFlatten', './bind', './rest', './_toKey'], funct * * var view = { * 'label': 'docs', - * 'onClick': function() { + * 'click': function() { * console.log('clicked ' + this.label); * } * }; * - * _.bindAll(view, ['onClick']); - * jQuery(element).on('click', view.onClick); + * _.bindAll(view, ['click']); + * jQuery(element).on('click', view.click); * // => Logs 'clicked docs' when clicked. */ - var bindAll = rest(function(object, methodNames) { + var bindAll = baseRest(function(object, methodNames) { arrayEach(baseFlatten(methodNames, 1), function(key) { key = toKey(key); object[key] = bind(object[key], object); diff --git a/bindKey.js b/bindKey.js index 163ada25a..c4cbe271e 100644 --- a/bindKey.js +++ b/bindKey.js @@ -1,6 +1,6 @@ -define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], function(createWrapper, getHolder, replaceHolders, rest) { +define(['./_baseRest', './_createWrap', './_getHolder', './_replaceHolders'], function(baseRest, createWrap, getHolder, replaceHolders) { - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1, BIND_KEY_FLAG = 2, PARTIAL_FLAG = 32; @@ -50,13 +50,13 @@ define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], func * bound('hi'); * // => 'hiya fred!' */ - var bindKey = rest(function(object, key, partials) { + var bindKey = baseRest(function(object, key, partials) { var bitmask = BIND_FLAG | BIND_KEY_FLAG; if (partials.length) { var holders = replaceHolders(partials, getHolder(bindKey)); bitmask |= PARTIAL_FLAG; } - return createWrapper(key, bitmask, object, partials, holders); + return createWrap(key, bitmask, object, partials, holders); }); // Assign default placeholders. diff --git a/collection.js b/collection.js index 3102572b4..f138ff1eb 100644 --- a/collection.js +++ b/collection.js @@ -1,6 +1,5 @@ -define(['./at', './countBy', './each', './eachRight', './every', './filter', './find', './findLast', './flatMap', './flatMapDeep', './flatMapDepth', './forEach', './forEachRight', './groupBy', './includes', './invokeMap', './keyBy', './map', './orderBy', './partition', './reduce', './reduceRight', './reject', './sample', './sampleSize', './shuffle', './size', './some', './sortBy'], function(at, countBy, each, eachRight, every, filter, find, findLast, flatMap, flatMapDeep, flatMapDepth, forEach, forEachRight, groupBy, includes, invokeMap, keyBy, map, orderBy, partition, reduce, reduceRight, reject, sample, sampleSize, shuffle, size, some, sortBy) { +define(['./countBy', './each', './eachRight', './every', './filter', './find', './findLast', './flatMap', './flatMapDeep', './flatMapDepth', './forEach', './forEachRight', './groupBy', './includes', './invokeMap', './keyBy', './map', './orderBy', './partition', './reduce', './reduceRight', './reject', './sample', './sampleSize', './shuffle', './size', './some', './sortBy'], function(countBy, each, eachRight, every, filter, find, findLast, flatMap, flatMapDeep, flatMapDepth, forEach, forEachRight, groupBy, includes, invokeMap, keyBy, map, orderBy, partition, reduce, reduceRight, reject, sample, sampleSize, shuffle, size, some, sortBy) { return { - 'at': at, 'countBy': countBy, 'each': each, 'eachRight': eachRight, diff --git a/cond.js b/cond.js index 9613b5227..6b3bee705 100644 --- a/cond.js +++ b/cond.js @@ -1,4 +1,4 @@ -define(['./_apply', './_arrayMap', './_baseIteratee', './rest'], function(apply, arrayMap, baseIteratee, rest) { +define(['./_apply', './_arrayMap', './_baseIteratee', './_baseRest'], function(apply, arrayMap, baseIteratee, baseRest) { /** Used as the `TypeError` message for "Functions" methods. */ var FUNC_ERROR_TEXT = 'Expected a function'; @@ -20,7 +20,7 @@ define(['./_apply', './_arrayMap', './_baseIteratee', './rest'], function(apply, * var func = _.cond([ * [_.matches({ 'a': 1 }), _.constant('matches A')], * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')], - * [_.constant(true), _.constant('no match')] + * [_.stubTrue, _.constant('no match')] * ]); * * func({ 'a': 1, 'b': 2 }); @@ -43,7 +43,7 @@ define(['./_apply', './_arrayMap', './_baseIteratee', './rest'], function(apply, return [toIteratee(pair[0]), pair[1]]; }); - return rest(function(args) { + return baseRest(function(args) { var index = -1; while (++index < length) { var pair = pairs[index]; diff --git a/conforms.js b/conforms.js index d07f74788..82d28236c 100644 --- a/conforms.js +++ b/conforms.js @@ -13,13 +13,13 @@ define(['./_baseClone', './_baseConforms'], function(baseClone, baseConforms) { * @returns {Function} Returns the new spec function. * @example * - * var users = [ - * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 40 } + * var objects = [ + * { 'a': 2, 'b': 1 }, + * { 'a': 1, 'b': 2 } * ]; * - * _.filter(users, _.conforms({ 'age': function(n) { return n > 38; } })); - * // => [{ 'user': 'fred', 'age': 40 }] + * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } })); + * // => [{ 'a': 1, 'b': 2 }] */ function conforms(source) { return baseConforms(baseClone(source, true)); diff --git a/conformsTo.js b/conformsTo.js new file mode 100644 index 000000000..901c62f39 --- /dev/null +++ b/conformsTo.js @@ -0,0 +1,30 @@ +define(['./_baseConformsTo', './keys'], function(baseConformsTo, keys) { + + /** + * Checks if `object` conforms to `source` by invoking the predicate properties + * of `source` with the corresponding property values of `object`. This method + * is equivalent to a `_.conforms` function when `source` is partially applied. + * + * @static + * @memberOf _ + * @since 4.14.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + * @example + * + * var object = { 'a': 1, 'b': 2 }; + * + * _.conformsTo(object, { 'b': function(n) { return n > 1; } }); + * // => true + * + * _.conformsTo(object, { 'b': function(n) { return n > 2; } }); + * // => false + */ + function conformsTo(object, source) { + return source == null || baseConformsTo(object, source, keys(source)); + } + + return conformsTo; +}); diff --git a/countBy.js b/countBy.js index 905676cc8..a1473b820 100644 --- a/countBy.js +++ b/countBy.js @@ -17,7 +17,7 @@ define(['./_createAggregator'], function(createAggregator) { * @since 0.5.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example diff --git a/curry.js b/curry.js index bda3bd183..e5c8b5442 100644 --- a/curry.js +++ b/curry.js @@ -1,9 +1,9 @@ -define(['./_createWrapper'], function(createWrapper) { +define(['./_createWrap'], function(createWrap) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var CURRY_FLAG = 8; /** @@ -49,7 +49,7 @@ define(['./_createWrapper'], function(createWrapper) { */ function curry(func, arity, guard) { arity = guard ? undefined : arity; - var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); + var result = createWrap(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); result.placeholder = curry.placeholder; return result; } diff --git a/curryRight.js b/curryRight.js index d21ca4a85..d12df475c 100644 --- a/curryRight.js +++ b/curryRight.js @@ -1,9 +1,9 @@ -define(['./_createWrapper'], function(createWrapper) { +define(['./_createWrap'], function(createWrap) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var CURRY_RIGHT_FLAG = 16; /** @@ -46,7 +46,7 @@ define(['./_createWrapper'], function(createWrapper) { */ function curryRight(func, arity, guard) { arity = guard ? undefined : arity; - var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); + var result = createWrap(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); result.placeholder = curryRight.placeholder; return result; } diff --git a/debounce.js b/debounce.js index dc5ef9310..98486a936 100644 --- a/debounce.js +++ b/debounce.js @@ -143,6 +143,9 @@ define(['./isObject', './now', './toNumber'], function(isObject, now, toNumber) } function cancel() { + if (timerId !== undefined) { + clearTimeout(timerId); + } lastInvokeTime = 0; lastArgs = lastCallTime = lastThis = timerId = undefined; } diff --git a/defaultTo.js b/defaultTo.js new file mode 100644 index 000000000..21dbcc55f --- /dev/null +++ b/defaultTo.js @@ -0,0 +1,28 @@ +define([], function() { + + /** + * Checks `value` to determine whether a default value should be returned in + * its place. The `defaultValue` is returned if `value` is `NaN`, `null`, + * or `undefined`. + * + * @static + * @memberOf _ + * @since 4.14.0 + * @category Util + * @param {*} value The value to check. + * @param {*} defaultValue The default value. + * @returns {*} Returns the resolved value. + * @example + * + * _.defaultTo(1, 10); + * // => 1 + * + * _.defaultTo(undefined, 10); + * // => 10 + */ + function defaultTo(value, defaultValue) { + return (value == null || value !== value) ? defaultValue : value; + } + + return defaultTo; +}); diff --git a/defaults.js b/defaults.js index 48ab10866..5d661a5fd 100644 --- a/defaults.js +++ b/defaults.js @@ -1,4 +1,4 @@ -define(['./_apply', './_assignInDefaults', './assignInWith', './rest'], function(apply, assignInDefaults, assignInWith, rest) { +define(['./_apply', './_assignInDefaults', './assignInWith', './_baseRest'], function(apply, assignInDefaults, assignInWith, baseRest) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -21,10 +21,10 @@ define(['./_apply', './_assignInDefaults', './assignInWith', './rest'], function * @see _.defaultsDeep * @example * - * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); - * // => { 'user': 'barney', 'age': 36 } + * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); + * // => { 'a': 1, 'b': 2 } */ - var defaults = rest(function(args) { + var defaults = baseRest(function(args) { args.push(undefined, assignInDefaults); return apply(assignInWith, undefined, args); }); diff --git a/defaultsDeep.js b/defaultsDeep.js index 8ef77f116..51eba8f4f 100644 --- a/defaultsDeep.js +++ b/defaultsDeep.js @@ -1,4 +1,4 @@ -define(['./_apply', './_mergeDefaults', './mergeWith', './rest'], function(apply, mergeDefaults, mergeWith, rest) { +define(['./_apply', './_baseRest', './_mergeDefaults', './mergeWith'], function(apply, baseRest, mergeDefaults, mergeWith) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -19,11 +19,10 @@ define(['./_apply', './_mergeDefaults', './mergeWith', './rest'], function(apply * @see _.defaults * @example * - * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } }); - * // => { 'user': { 'name': 'barney', 'age': 36 } } - * + * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }); + * // => { 'a': { 'b': 2, 'c': 3 } } */ - var defaultsDeep = rest(function(args) { + var defaultsDeep = baseRest(function(args) { args.push(undefined, mergeDefaults); return apply(mergeWith, undefined, args); }); diff --git a/defer.js b/defer.js index 557170813..f65ec31f6 100644 --- a/defer.js +++ b/defer.js @@ -1,4 +1,4 @@ -define(['./_baseDelay', './rest'], function(baseDelay, rest) { +define(['./_baseDelay', './_baseRest'], function(baseDelay, baseRest) { /** * Defers invoking the `func` until the current call stack has cleared. Any @@ -18,7 +18,7 @@ define(['./_baseDelay', './rest'], function(baseDelay, rest) { * }, 'deferred'); * // => Logs 'deferred' after one or more milliseconds. */ - var defer = rest(function(func, args) { + var defer = baseRest(function(func, args) { return baseDelay(func, 1, args); }); diff --git a/delay.js b/delay.js index 4092527a5..381cb670a 100644 --- a/delay.js +++ b/delay.js @@ -1,4 +1,4 @@ -define(['./_baseDelay', './rest', './toNumber'], function(baseDelay, rest, toNumber) { +define(['./_baseDelay', './_baseRest', './toNumber'], function(baseDelay, baseRest, toNumber) { /** * Invokes `func` after `wait` milliseconds. Any additional arguments are @@ -19,7 +19,7 @@ define(['./_baseDelay', './rest', './toNumber'], function(baseDelay, rest, toNum * }, 1000, 'later'); * // => Logs 'later' after one second. */ - var delay = rest(function(func, wait, args) { + var delay = baseRest(function(func, wait, args) { return baseDelay(func, toNumber(wait) || 0, args); }); diff --git a/difference.js b/difference.js index 97113f43f..862d89549 100644 --- a/difference.js +++ b/difference.js @@ -1,11 +1,13 @@ -define(['./_baseDifference', './_baseFlatten', './isArrayLikeObject', './rest'], function(baseDifference, baseFlatten, isArrayLikeObject, rest) { +define(['./_baseDifference', './_baseFlatten', './_baseRest', './isArrayLikeObject'], function(baseDifference, baseFlatten, baseRest, isArrayLikeObject) { /** - * Creates an array of unique `array` values not included in the other given - * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) + * Creates an array of `array` values not included in the other given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * for equality comparisons. The order of result values is determined by the * order they occur in the first array. * + * **Note:** Unlike `_.pullAll`, this method returns a new array. + * * @static * @memberOf _ * @since 0.1.0 @@ -19,7 +21,7 @@ define(['./_baseDifference', './_baseFlatten', './isArrayLikeObject', './rest'], * _.difference([2, 1], [2, 3]); * // => [1] */ - var difference = rest(function(array, values) { + var difference = baseRest(function(array, values) { return isArrayLikeObject(array) ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) : []; diff --git a/differenceBy.js b/differenceBy.js index 6809b637d..416092e3d 100644 --- a/differenceBy.js +++ b/differenceBy.js @@ -1,4 +1,4 @@ -define(['./_baseDifference', './_baseFlatten', './_baseIteratee', './isArrayLikeObject', './last', './rest'], function(baseDifference, baseFlatten, baseIteratee, isArrayLikeObject, last, rest) { +define(['./_baseDifference', './_baseFlatten', './_baseIteratee', './_baseRest', './isArrayLikeObject', './last'], function(baseDifference, baseFlatten, baseIteratee, baseRest, isArrayLikeObject, last) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -9,14 +9,15 @@ define(['./_baseDifference', './_baseFlatten', './_baseIteratee', './isArrayLike * by which they're compared. Result values are chosen from the first array. * The iteratee is invoked with one argument: (value). * + * **Note:** Unlike `_.pullAllBy`, this method returns a new array. + * * @static * @memberOf _ * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @param {...Array} [values] The values to exclude. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns the new array of filtered values. * @example * @@ -27,13 +28,13 @@ define(['./_baseDifference', './_baseFlatten', './_baseIteratee', './isArrayLike * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); * // => [{ 'x': 2 }] */ - var differenceBy = rest(function(array, values) { + var differenceBy = baseRest(function(array, values) { var iteratee = last(values); if (isArrayLikeObject(iteratee)) { iteratee = undefined; } return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), baseIteratee(iteratee)) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), baseIteratee(iteratee, 2)) : []; }); diff --git a/differenceWith.js b/differenceWith.js index 6ce42902e..40f8719f9 100644 --- a/differenceWith.js +++ b/differenceWith.js @@ -1,4 +1,4 @@ -define(['./_baseDifference', './_baseFlatten', './isArrayLikeObject', './last', './rest'], function(baseDifference, baseFlatten, isArrayLikeObject, last, rest) { +define(['./_baseDifference', './_baseFlatten', './_baseRest', './isArrayLikeObject', './last'], function(baseDifference, baseFlatten, baseRest, isArrayLikeObject, last) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -9,6 +9,8 @@ define(['./_baseDifference', './_baseFlatten', './isArrayLikeObject', './last', * are chosen from the first array. The comparator is invoked with two arguments: * (arrVal, othVal). * + * **Note:** Unlike `_.pullAllWith`, this method returns a new array. + * * @static * @memberOf _ * @since 4.0.0 @@ -24,7 +26,7 @@ define(['./_baseDifference', './_baseFlatten', './isArrayLikeObject', './last', * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); * // => [{ 'x': 2, 'y': 1 }] */ - var differenceWith = rest(function(array, values) { + var differenceWith = baseRest(function(array, values) { var comparator = last(values); if (isArrayLikeObject(comparator)) { comparator = undefined; diff --git a/divide.js b/divide.js index 921c329a5..7ec2edc70 100644 --- a/divide.js +++ b/divide.js @@ -17,7 +17,7 @@ define(['./_createMathOperation'], function(createMathOperation) { */ var divide = createMathOperation(function(dividend, divisor) { return dividend / divisor; - }); + }, 1); return divide; }); diff --git a/dropRightWhile.js b/dropRightWhile.js index c45298bec..d248b12b5 100644 --- a/dropRightWhile.js +++ b/dropRightWhile.js @@ -10,8 +10,7 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/dropWhile.js b/dropWhile.js index 8be33cbf2..0d96bde69 100644 --- a/dropWhile.js +++ b/dropWhile.js @@ -10,7 +10,7 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example diff --git a/endsWith.js b/endsWith.js index 3b74e2743..306c56815 100644 --- a/endsWith.js +++ b/endsWith.js @@ -35,8 +35,9 @@ define(['./_baseClamp', './_baseToString', './toInteger', './toString'], functio ? length : baseClamp(toInteger(position), 0, length); + var end = position; position -= target.length; - return position >= 0 && string.indexOf(target, position) == position; + return position >= 0 && string.slice(position, end) == target; } return endsWith; diff --git a/eq.js b/eq.js index 1a687217a..0c5a2d712 100644 --- a/eq.js +++ b/eq.js @@ -14,8 +14,8 @@ define([], function() { * @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @example * - * var object = { 'user': 'fred' }; - * var other = { 'user': 'fred' }; + * var object = { 'a': 1 }; + * var other = { 'a': 1 }; * * _.eq(object, object); * // => true diff --git a/every.js b/every.js index 1614d4d58..80b70a316 100644 --- a/every.js +++ b/every.js @@ -13,7 +13,7 @@ define(['./_arrayEvery', './_baseEvery', './_baseIteratee', './isArray', './_isI * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {boolean} Returns `true` if all elements pass the predicate check, diff --git a/filter.js b/filter.js index dd2372f90..81f93843a 100644 --- a/filter.js +++ b/filter.js @@ -5,12 +5,14 @@ define(['./_arrayFilter', './_baseFilter', './_baseIteratee', './isArray'], func * `predicate` returns truthy for. The predicate is invoked with three * arguments: (value, index|key, collection). * + * **Note:** Unlike `_.remove`, this method returns a new array. + * * @static * @memberOf _ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the new filtered array. * @see _.reject diff --git a/find.js b/find.js index 9d3cc8e4c..dcd76261b 100644 --- a/find.js +++ b/find.js @@ -10,7 +10,7 @@ define(['./_createFind', './findIndex'], function(createFind, findIndex) { * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to search. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. * @returns {*} Returns the matched element, else `undefined`. diff --git a/findIndex.js b/findIndex.js index 531fb5847..24f58958e 100644 --- a/findIndex.js +++ b/findIndex.js @@ -12,7 +12,7 @@ define(['./_baseFindIndex', './_baseIteratee', './toInteger'], function(baseFind * @since 1.1.0 * @category Array * @param {Array} array The array to search. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. * @returns {number} Returns the index of the found element, else `-1`. diff --git a/findKey.js b/findKey.js index 1442d2c5a..711449940 100644 --- a/findKey.js +++ b/findKey.js @@ -9,8 +9,7 @@ define(['./_baseFindKey', './_baseForOwn', './_baseIteratee'], function(baseFind * @since 1.1.0 * @category Object * @param {Object} object The object to search. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {string|undefined} Returns the key of the matched element, * else `undefined`. * @example diff --git a/findLast.js b/findLast.js index e7de6ddb8..6d8f94e9d 100644 --- a/findLast.js +++ b/findLast.js @@ -9,7 +9,7 @@ define(['./_createFind', './findLastIndex'], function(createFind, findLastIndex) * @since 2.0.0 * @category Collection * @param {Array|Object} collection The collection to search. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=collection.length-1] The index to search from. * @returns {*} Returns the matched element, else `undefined`. diff --git a/findLastIndex.js b/findLastIndex.js index 3e6b61c72..d9724a37f 100644 --- a/findLastIndex.js +++ b/findLastIndex.js @@ -16,7 +16,7 @@ define(['./_baseFindIndex', './_baseIteratee', './toInteger'], function(baseFind * @since 2.0.0 * @category Array * @param {Array} array The array to search. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=array.length-1] The index to search from. * @returns {number} Returns the index of the found element, else `-1`. diff --git a/findLastKey.js b/findLastKey.js index e7a28c73a..19cc53fa5 100644 --- a/findLastKey.js +++ b/findLastKey.js @@ -9,8 +9,7 @@ define(['./_baseFindKey', './_baseForOwnRight', './_baseIteratee'], function(bas * @since 2.0.0 * @category Object * @param {Object} object The object to search. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {string|undefined} Returns the key of the matched element, * else `undefined`. * @example diff --git a/flatMap.js b/flatMap.js index 7d34a1d66..8ef3a244a 100644 --- a/flatMap.js +++ b/flatMap.js @@ -10,7 +10,7 @@ define(['./_baseFlatten', './map'], function(baseFlatten, map) { * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The function invoked per iteration. * @returns {Array} Returns the new flattened array. * @example diff --git a/flatMapDeep.js b/flatMapDeep.js index c139d2f9b..35a866db1 100644 --- a/flatMapDeep.js +++ b/flatMapDeep.js @@ -12,7 +12,7 @@ define(['./_baseFlatten', './map'], function(baseFlatten, map) { * @since 4.7.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The function invoked per iteration. * @returns {Array} Returns the new flattened array. * @example diff --git a/flatMapDepth.js b/flatMapDepth.js index 382f05c51..278ed7c01 100644 --- a/flatMapDepth.js +++ b/flatMapDepth.js @@ -12,7 +12,7 @@ define(['./_baseFlatten', './map', './toInteger'], function(baseFlatten, map, to * @since 4.7.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The function invoked per iteration. * @param {number} [depth=1] The maximum recursion depth. * @returns {Array} Returns the new flattened array. diff --git a/flip.js b/flip.js index c4d5c3d75..33969dd12 100644 --- a/flip.js +++ b/flip.js @@ -1,6 +1,6 @@ -define(['./_createWrapper'], function(createWrapper) { +define(['./_createWrap'], function(createWrap) { - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var FLIP_FLAG = 512; /** @@ -22,7 +22,7 @@ define(['./_createWrapper'], function(createWrapper) { * // => ['d', 'c', 'b', 'a'] */ function flip(func) { - return createWrapper(func, FLIP_FLAG); + return createWrap(func, FLIP_FLAG); } return flip; diff --git a/flow.js b/flow.js index 5e264079b..870e30016 100644 --- a/flow.js +++ b/flow.js @@ -9,7 +9,7 @@ define(['./_createFlow'], function(createFlow) { * @memberOf _ * @since 3.0.0 * @category Util - * @param {...(Function|Function[])} [funcs] Functions to invoke. + * @param {...(Function|Function[])} [funcs] The functions to invoke. * @returns {Function} Returns the new composite function. * @see _.flowRight * @example diff --git a/flowRight.js b/flowRight.js index 21d6b36c3..3affb96dc 100644 --- a/flowRight.js +++ b/flowRight.js @@ -8,7 +8,7 @@ define(['./_createFlow'], function(createFlow) { * @since 3.0.0 * @memberOf _ * @category Util - * @param {...(Function|Function[])} [funcs] Functions to invoke. + * @param {...(Function|Function[])} [funcs] The functions to invoke. * @returns {Function} Returns the new composite function. * @see _.flow * @example diff --git a/fromPairs.js b/fromPairs.js index 2a08889e4..822f07ac5 100644 --- a/fromPairs.js +++ b/fromPairs.js @@ -12,8 +12,8 @@ define([], function() { * @returns {Object} Returns the new object. * @example * - * _.fromPairs([['fred', 30], ['barney', 40]]); - * // => { 'fred': 30, 'barney': 40 } + * _.fromPairs([['a', 1], ['b', 2]]); + * // => { 'a': 1, 'b': 2 } */ function fromPairs(pairs) { var index = -1, diff --git a/get.js b/get.js index 18dd1cc43..a22955b68 100644 --- a/get.js +++ b/get.js @@ -5,7 +5,7 @@ define(['./_baseGet'], function(baseGet) { /** * Gets the value at `path` of `object`. If the resolved value is - * `undefined`, the `defaultValue` is used in its place. + * `undefined`, the `defaultValue` is returned in its place. * * @static * @memberOf _ diff --git a/groupBy.js b/groupBy.js index ea76ce3f2..fc930bb46 100644 --- a/groupBy.js +++ b/groupBy.js @@ -18,7 +18,7 @@ define(['./_createAggregator'], function(createAggregator) { * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example diff --git a/identity.js b/identity.js index 9a00d700d..c2ff3e2d9 100644 --- a/identity.js +++ b/identity.js @@ -1,7 +1,7 @@ define([], function() { /** - * This method returns the first argument given to it. + * This method returns the first argument it receives. * * @static * @since 0.1.0 @@ -11,7 +11,7 @@ define([], function() { * @returns {*} Returns `value`. * @example * - * var object = { 'user': 'fred' }; + * var object = { 'a': 1 }; * * console.log(_.identity(object) === object); * // => true diff --git a/includes.js b/includes.js index 4beac82e6..e244655ba 100644 --- a/includes.js +++ b/includes.js @@ -27,10 +27,10 @@ define(['./_baseIndexOf', './isArrayLike', './isString', './toInteger', './value * _.includes([1, 2, 3], 1, 2); * // => false * - * _.includes({ 'user': 'fred', 'age': 40 }, 'fred'); + * _.includes({ 'a': 1, 'b': 2 }, 1); * // => true * - * _.includes('pebbles', 'eb'); + * _.includes('abcd', 'bc'); * // => true */ function includes(collection, value, fromIndex, guard) { diff --git a/intersection.js b/intersection.js index ccea0f40a..6b8a69fdf 100644 --- a/intersection.js +++ b/intersection.js @@ -1,4 +1,4 @@ -define(['./_arrayMap', './_baseIntersection', './_castArrayLikeObject', './rest'], function(arrayMap, baseIntersection, castArrayLikeObject, rest) { +define(['./_arrayMap', './_baseIntersection', './_baseRest', './_castArrayLikeObject'], function(arrayMap, baseIntersection, baseRest, castArrayLikeObject) { /** * Creates an array of unique values that are included in all given arrays @@ -17,7 +17,7 @@ define(['./_arrayMap', './_baseIntersection', './_castArrayLikeObject', './rest' * _.intersection([2, 1], [2, 3]); * // => [2] */ - var intersection = rest(function(arrays) { + var intersection = baseRest(function(arrays) { var mapped = arrayMap(arrays, castArrayLikeObject); return (mapped.length && mapped[0] === arrays[0]) ? baseIntersection(mapped) diff --git a/intersectionBy.js b/intersectionBy.js index 9b1d233c9..28caa5285 100644 --- a/intersectionBy.js +++ b/intersectionBy.js @@ -1,4 +1,4 @@ -define(['./_arrayMap', './_baseIntersection', './_baseIteratee', './_castArrayLikeObject', './last', './rest'], function(arrayMap, baseIntersection, baseIteratee, castArrayLikeObject, last, rest) { +define(['./_arrayMap', './_baseIntersection', './_baseIteratee', './_baseRest', './_castArrayLikeObject', './last'], function(arrayMap, baseIntersection, baseIteratee, baseRest, castArrayLikeObject, last) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -14,8 +14,7 @@ define(['./_arrayMap', './_baseIntersection', './_baseIteratee', './_castArrayLi * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns the new array of intersecting values. * @example * @@ -26,7 +25,7 @@ define(['./_arrayMap', './_baseIntersection', './_baseIteratee', './_castArrayLi * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }] */ - var intersectionBy = rest(function(arrays) { + var intersectionBy = baseRest(function(arrays) { var iteratee = last(arrays), mapped = arrayMap(arrays, castArrayLikeObject); @@ -36,7 +35,7 @@ define(['./_arrayMap', './_baseIntersection', './_baseIteratee', './_castArrayLi mapped.pop(); } return (mapped.length && mapped[0] === arrays[0]) - ? baseIntersection(mapped, baseIteratee(iteratee)) + ? baseIntersection(mapped, baseIteratee(iteratee, 2)) : []; }); diff --git a/intersectionWith.js b/intersectionWith.js index c04567e33..6f3dfcfa9 100644 --- a/intersectionWith.js +++ b/intersectionWith.js @@ -1,4 +1,4 @@ -define(['./_arrayMap', './_baseIntersection', './_castArrayLikeObject', './last', './rest'], function(arrayMap, baseIntersection, castArrayLikeObject, last, rest) { +define(['./_arrayMap', './_baseIntersection', './_baseRest', './_castArrayLikeObject', './last'], function(arrayMap, baseIntersection, baseRest, castArrayLikeObject, last) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -24,7 +24,7 @@ define(['./_arrayMap', './_baseIntersection', './_castArrayLikeObject', './last' * _.intersectionWith(objects, others, _.isEqual); * // => [{ 'x': 1, 'y': 2 }] */ - var intersectionWith = rest(function(arrays) { + var intersectionWith = baseRest(function(arrays) { var comparator = last(arrays), mapped = arrayMap(arrays, castArrayLikeObject); diff --git a/invertBy.js b/invertBy.js index 180a4047a..739ae1de0 100644 --- a/invertBy.js +++ b/invertBy.js @@ -18,8 +18,7 @@ define(['./_baseIteratee', './_createInverter'], function(baseIteratee, createIn * @since 4.1.0 * @category Object * @param {Object} object The object to invert. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Object} Returns the new inverted object. * @example * diff --git a/invoke.js b/invoke.js index b8cd7c9ec..dabf354dd 100644 --- a/invoke.js +++ b/invoke.js @@ -1,4 +1,4 @@ -define(['./_baseInvoke', './rest'], function(baseInvoke, rest) { +define(['./_baseInvoke', './_baseRest'], function(baseInvoke, baseRest) { /** * Invokes the method at `path` of `object`. @@ -18,7 +18,7 @@ define(['./_baseInvoke', './rest'], function(baseInvoke, rest) { * _.invoke(object, 'a[0].b.c.slice', 1, 3); * // => [2, 3] */ - var invoke = rest(baseInvoke); + var invoke = baseRest(baseInvoke); return invoke; }); diff --git a/invokeMap.js b/invokeMap.js index 5cc83c8f3..3c5b02817 100644 --- a/invokeMap.js +++ b/invokeMap.js @@ -1,4 +1,4 @@ -define(['./_apply', './_baseEach', './_baseInvoke', './isArrayLike', './_isKey', './rest'], function(apply, baseEach, baseInvoke, isArrayLike, isKey, rest) { +define(['./_apply', './_baseEach', './_baseInvoke', './_baseRest', './isArrayLike', './_isKey'], function(apply, baseEach, baseInvoke, baseRest, isArrayLike, isKey) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -6,8 +6,8 @@ define(['./_apply', './_baseEach', './_baseInvoke', './isArrayLike', './_isKey', /** * Invokes the method at `path` of each element in `collection`, returning * an array of the results of each invoked method. Any additional arguments - * are provided to each invoked method. If `methodName` is a function, it's - * invoked for and `this` bound to, each element in `collection`. + * are provided to each invoked method. If `path` is a function, it's invoked + * for, and `this` bound to, each element in `collection`. * * @static * @memberOf _ @@ -26,7 +26,7 @@ define(['./_apply', './_baseEach', './_baseInvoke', './isArrayLike', './_isKey', * _.invokeMap([123, 456], String.prototype.split, ''); * // => [['1', '2', '3'], ['4', '5', '6']] */ - var invokeMap = rest(function(collection, path, args) { + var invokeMap = baseRest(function(collection, path, args) { var index = -1, isFunc = typeof path == 'function', isProp = isKey(path), diff --git a/isArguments.js b/isArguments.js index 7b488b662..d6b4150a3 100644 --- a/isArguments.js +++ b/isArguments.js @@ -27,7 +27,7 @@ define(['./isArrayLikeObject'], function(isArrayLikeObject) { * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, + * @returns {boolean} Returns `true` if `value` is an `arguments` object, * else `false`. * @example * diff --git a/isArray.js b/isArray.js index 28b7a7eab..f65ab2575 100644 --- a/isArray.js +++ b/isArray.js @@ -6,11 +6,9 @@ define([], function() { * @static * @memberOf _ * @since 0.1.0 - * @type {Function} * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is an array, else `false`. * @example * * _.isArray([1, 2, 3]); diff --git a/isArrayBuffer.js b/isArrayBuffer.js index 9503f84b9..674af1320 100644 --- a/isArrayBuffer.js +++ b/isArrayBuffer.js @@ -1,16 +1,7 @@ -define(['./isObjectLike'], function(isObjectLike) { +define(['./_baseIsArrayBuffer', './_baseUnary', './_nodeUtil'], function(baseIsArrayBuffer, baseUnary, nodeUtil) { - var arrayBufferTag = '[object ArrayBuffer]'; - - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; + /* Node.js helper references. */ + var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer; /** * Checks if `value` is classified as an `ArrayBuffer` object. @@ -20,8 +11,7 @@ define(['./isObjectLike'], function(isObjectLike) { * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. * @example * * _.isArrayBuffer(new ArrayBuffer(2)); @@ -30,9 +20,7 @@ define(['./isObjectLike'], function(isObjectLike) { * _.isArrayBuffer(new Array(2)); * // => false */ - function isArrayBuffer(value) { - return isObjectLike(value) && objectToString.call(value) == arrayBufferTag; - } + var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer; return isArrayBuffer; }); diff --git a/isBoolean.js b/isBoolean.js index 17db3af49..22d848b06 100644 --- a/isBoolean.js +++ b/isBoolean.js @@ -21,8 +21,7 @@ define(['./isObjectLike'], function(isObjectLike) { * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a boolean, else `false`. * @example * * _.isBoolean(false); diff --git a/isBuffer.js b/isBuffer.js index 800209ff3..fa2cc9091 100644 --- a/isBuffer.js +++ b/isBuffer.js @@ -1,10 +1,10 @@ -define(['./_root', './stubFalse'], function(root, stubFalse) { +define(['./_freeGlobal', './_root', './stubFalse'], function(freeGlobal, root, stubFalse) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; /** Detect free variable `exports`. */ - var freeExports = typeof exports == 'object' && exports; + var freeExports = freeGlobal && typeof exports == 'object' && exports; /** Detect free variable `module`. */ var freeModule = freeExports && typeof module == 'object' && module; @@ -15,6 +15,9 @@ define(['./_root', './stubFalse'], function(root, stubFalse) { /** Built-in value references. */ var Buffer = moduleExports ? root.Buffer : undefined; + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined; + /** * Checks if `value` is a buffer. * @@ -32,9 +35,7 @@ define(['./_root', './stubFalse'], function(root, stubFalse) { * _.isBuffer(new Uint8Array(2)); * // => false */ - var isBuffer = !Buffer ? stubFalse : function(value) { - return value instanceof Buffer; - }; + var isBuffer = nativeIsBuffer || stubFalse; return isBuffer; }); diff --git a/isDate.js b/isDate.js index 4850ed8fc..16103dd70 100644 --- a/isDate.js +++ b/isDate.js @@ -1,17 +1,7 @@ -define(['./isObjectLike'], function(isObjectLike) { +define(['./_baseIsDate', './_baseUnary', './_nodeUtil'], function(baseIsDate, baseUnary, nodeUtil) { - /** `Object#toString` result references. */ - var dateTag = '[object Date]'; - - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; + /* Node.js helper references. */ + var nodeIsDate = nodeUtil && nodeUtil.isDate; /** * Checks if `value` is classified as a `Date` object. @@ -21,8 +11,7 @@ define(['./isObjectLike'], function(isObjectLike) { * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a date object, else `false`. * @example * * _.isDate(new Date); @@ -31,9 +20,7 @@ define(['./isObjectLike'], function(isObjectLike) { * _.isDate('Mon April 23 2012'); * // => false */ - function isDate(value) { - return isObjectLike(value) && objectToString.call(value) == dateTag; - } + var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate; return isDate; }); diff --git a/isEqual.js b/isEqual.js index 32e672ed1..c53bff31f 100644 --- a/isEqual.js +++ b/isEqual.js @@ -20,8 +20,8 @@ define(['./_baseIsEqual'], function(baseIsEqual) { * else `false`. * @example * - * var object = { 'user': 'fred' }; - * var other = { 'user': 'fred' }; + * var object = { 'a': 1 }; + * var other = { 'a': 1 }; * * _.isEqual(object, other); * // => true diff --git a/isFunction.js b/isFunction.js index a3872ae77..4d3667fb5 100644 --- a/isFunction.js +++ b/isFunction.js @@ -22,8 +22,7 @@ define(['./isObject'], function(isObject) { * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. * @example * * _.isFunction(_); diff --git a/isMap.js b/isMap.js index c0cce4d4f..9f7b4f744 100644 --- a/isMap.js +++ b/isMap.js @@ -1,7 +1,7 @@ -define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { +define(['./_baseIsMap', './_baseUnary', './_nodeUtil'], function(baseIsMap, baseUnary, nodeUtil) { - /** `Object#toString` result references. */ - var mapTag = '[object Map]'; + /* Node.js helper references. */ + var nodeIsMap = nodeUtil && nodeUtil.isMap; /** * Checks if `value` is classified as a `Map` object. @@ -11,8 +11,7 @@ define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a map, else `false`. * @example * * _.isMap(new Map); @@ -21,9 +20,7 @@ define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { * _.isMap(new WeakMap); * // => false */ - function isMap(value) { - return isObjectLike(value) && getTag(value) == mapTag; - } + var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap; return isMap; }); diff --git a/isMatch.js b/isMatch.js index 765476af1..7bac32ec8 100644 --- a/isMatch.js +++ b/isMatch.js @@ -16,12 +16,12 @@ define(['./_baseIsMatch', './_getMatchData'], function(baseIsMatch, getMatchData * @returns {boolean} Returns `true` if `object` is a match, else `false`. * @example * - * var object = { 'user': 'fred', 'age': 40 }; + * var object = { 'a': 1, 'b': 2 }; * - * _.isMatch(object, { 'age': 40 }); + * _.isMatch(object, { 'b': 2 }); * // => true * - * _.isMatch(object, { 'age': 36 }); + * _.isMatch(object, { 'b': 1 }); * // => false */ function isMatch(object, source) { diff --git a/isNative.js b/isNative.js index 041f8adcb..f66f5f30d 100644 --- a/isNative.js +++ b/isNative.js @@ -3,13 +3,13 @@ define(['./_baseIsNative', './_isMaskable'], function(baseIsNative, isMaskable) /** * Checks if `value` is a pristine native function. * - * **Note:** This method can't reliably detect native functions in the - * presence of the `core-js` package because `core-js` circumvents this kind - * of detection. Despite multiple requests, the `core-js` maintainer has made - * it clear: any attempt to fix the detection will be obstructed. As a result, - * we're left with little choice but to throw an error. Unfortunately, this - * also affects packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill), - * which rely on `core-js`. + * **Note:** This method can't reliably detect native functions in the presence + * of the core-js package because core-js circumvents this kind of detection. + * Despite multiple requests, the core-js maintainer has made it clear: any + * attempt to fix the detection will be obstructed. As a result, we're left + * with little choice but to throw an error. Unfortunately, this also affects + * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill), + * which rely on core-js. * * @static * @memberOf _ @@ -28,7 +28,7 @@ define(['./_baseIsNative', './_isMaskable'], function(baseIsNative, isMaskable) */ function isNative(value) { if (isMaskable(value)) { - throw new Error('This method is not supported with `core-js`. Try https://github.com/es-shims.'); + throw new Error('This method is not supported with core-js. Try https://github.com/es-shims.'); } return baseIsNative(value); } diff --git a/isNumber.js b/isNumber.js index bedd47d13..f276a2438 100644 --- a/isNumber.js +++ b/isNumber.js @@ -24,8 +24,7 @@ define(['./isObjectLike'], function(isObjectLike) { * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a number, else `false`. * @example * * _.isNumber(3); diff --git a/isRegExp.js b/isRegExp.js index 63556bd93..d0469a4d7 100644 --- a/isRegExp.js +++ b/isRegExp.js @@ -1,17 +1,7 @@ -define(['./isObject'], function(isObject) { +define(['./_baseIsRegExp', './_baseUnary', './_nodeUtil'], function(baseIsRegExp, baseUnary, nodeUtil) { - /** `Object#toString` result references. */ - var regexpTag = '[object RegExp]'; - - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; + /* Node.js helper references. */ + var nodeIsRegExp = nodeUtil && nodeUtil.isRegExp; /** * Checks if `value` is classified as a `RegExp` object. @@ -21,8 +11,7 @@ define(['./isObject'], function(isObject) { * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. * @example * * _.isRegExp(/abc/); @@ -31,9 +20,7 @@ define(['./isObject'], function(isObject) { * _.isRegExp('/abc/'); * // => false */ - function isRegExp(value) { - return isObject(value) && objectToString.call(value) == regexpTag; - } + var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp; return isRegExp; }); diff --git a/isSet.js b/isSet.js index 4e49e2869..8932cd296 100644 --- a/isSet.js +++ b/isSet.js @@ -1,7 +1,7 @@ -define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { +define(['./_baseIsSet', './_baseUnary', './_nodeUtil'], function(baseIsSet, baseUnary, nodeUtil) { - /** `Object#toString` result references. */ - var setTag = '[object Set]'; + /* Node.js helper references. */ + var nodeIsSet = nodeUtil && nodeUtil.isSet; /** * Checks if `value` is classified as a `Set` object. @@ -11,8 +11,7 @@ define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a set, else `false`. * @example * * _.isSet(new Set); @@ -21,9 +20,7 @@ define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { * _.isSet(new WeakSet); * // => false */ - function isSet(value) { - return isObjectLike(value) && getTag(value) == setTag; - } + var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet; return isSet; }); diff --git a/isString.js b/isString.js index 8226201c8..4ab503f7c 100644 --- a/isString.js +++ b/isString.js @@ -21,8 +21,7 @@ define(['./isArray', './isObjectLike'], function(isArray, isObjectLike) { * @memberOf _ * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a string, else `false`. * @example * * _.isString('abc'); diff --git a/isSymbol.js b/isSymbol.js index ba3648a41..da9d9856f 100644 --- a/isSymbol.js +++ b/isSymbol.js @@ -21,8 +21,7 @@ define(['./isObjectLike'], function(isObjectLike) { * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. * @example * * _.isSymbol(Symbol.iterator); diff --git a/isTypedArray.js b/isTypedArray.js index 0f455823e..2ef703c63 100644 --- a/isTypedArray.js +++ b/isTypedArray.js @@ -1,57 +1,7 @@ -define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { +define(['./_baseIsTypedArray', './_baseUnary', './_nodeUtil'], function(baseIsTypedArray, baseUnary, nodeUtil) { - /** `Object#toString` result references. */ - var argsTag = '[object Arguments]', - arrayTag = '[object Array]', - boolTag = '[object Boolean]', - dateTag = '[object Date]', - errorTag = '[object Error]', - funcTag = '[object Function]', - mapTag = '[object Map]', - numberTag = '[object Number]', - objectTag = '[object Object]', - regexpTag = '[object RegExp]', - setTag = '[object Set]', - stringTag = '[object String]', - weakMapTag = '[object WeakMap]'; - - var arrayBufferTag = '[object ArrayBuffer]', - dataViewTag = '[object DataView]', - float32Tag = '[object Float32Array]', - float64Tag = '[object Float64Array]', - int8Tag = '[object Int8Array]', - int16Tag = '[object Int16Array]', - int32Tag = '[object Int32Array]', - uint8Tag = '[object Uint8Array]', - uint8ClampedTag = '[object Uint8ClampedArray]', - uint16Tag = '[object Uint16Array]', - uint32Tag = '[object Uint32Array]'; - - /** Used to identify `toStringTag` values of typed arrays. */ - var typedArrayTags = {}; - typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = - typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = - typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = - typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = - typedArrayTags[uint32Tag] = true; - typedArrayTags[argsTag] = typedArrayTags[arrayTag] = - typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = - typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = - typedArrayTags[errorTag] = typedArrayTags[funcTag] = - typedArrayTags[mapTag] = typedArrayTags[numberTag] = - typedArrayTags[objectTag] = typedArrayTags[regexpTag] = - typedArrayTags[setTag] = typedArrayTags[stringTag] = - typedArrayTags[weakMapTag] = false; - - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; + /* Node.js helper references. */ + var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; /** * Checks if `value` is classified as a typed array. @@ -61,8 +11,7 @@ define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { * @since 3.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. * @example * * _.isTypedArray(new Uint8Array); @@ -71,10 +20,7 @@ define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { * _.isTypedArray([]); * // => false */ - function isTypedArray(value) { - return isObjectLike(value) && - isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; - } + var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; return isTypedArray; }); diff --git a/isWeakMap.js b/isWeakMap.js index dda1cdef8..6050a4b54 100644 --- a/isWeakMap.js +++ b/isWeakMap.js @@ -11,8 +11,7 @@ define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a weak map, else `false`. * @example * * _.isWeakMap(new WeakMap); diff --git a/isWeakSet.js b/isWeakSet.js index 29f751f19..bd594cde8 100644 --- a/isWeakSet.js +++ b/isWeakSet.js @@ -21,8 +21,7 @@ define(['./isObjectLike'], function(isObjectLike) { * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a weak set, else `false`. * @example * * _.isWeakSet(new WeakSet); diff --git a/keyBy.js b/keyBy.js index f36fc49bf..dc2496676 100644 --- a/keyBy.js +++ b/keyBy.js @@ -11,7 +11,7 @@ define(['./_createAggregator'], function(createAggregator) { * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example diff --git a/lang.js b/lang.js index a9ba91dc0..7e3630bb0 100644 --- a/lang.js +++ b/lang.js @@ -1,10 +1,11 @@ -define(['./castArray', './clone', './cloneDeep', './cloneDeepWith', './cloneWith', './eq', './gt', './gte', './isArguments', './isArray', './isArrayBuffer', './isArrayLike', './isArrayLikeObject', './isBoolean', './isBuffer', './isDate', './isElement', './isEmpty', './isEqual', './isEqualWith', './isError', './isFinite', './isFunction', './isInteger', './isLength', './isMap', './isMatch', './isMatchWith', './isNaN', './isNative', './isNil', './isNull', './isNumber', './isObject', './isObjectLike', './isPlainObject', './isRegExp', './isSafeInteger', './isSet', './isString', './isSymbol', './isTypedArray', './isUndefined', './isWeakMap', './isWeakSet', './lt', './lte', './toArray', './toFinite', './toInteger', './toLength', './toNumber', './toPlainObject', './toSafeInteger', './toString'], function(castArray, clone, cloneDeep, cloneDeepWith, cloneWith, eq, gt, gte, isArguments, isArray, isArrayBuffer, isArrayLike, isArrayLikeObject, isBoolean, isBuffer, isDate, isElement, isEmpty, isEqual, isEqualWith, isError, isFinite, isFunction, isInteger, isLength, isMap, isMatch, isMatchWith, isNaN, isNative, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, lt, lte, toArray, toFinite, toInteger, toLength, toNumber, toPlainObject, toSafeInteger, toString) { +define(['./castArray', './clone', './cloneDeep', './cloneDeepWith', './cloneWith', './conformsTo', './eq', './gt', './gte', './isArguments', './isArray', './isArrayBuffer', './isArrayLike', './isArrayLikeObject', './isBoolean', './isBuffer', './isDate', './isElement', './isEmpty', './isEqual', './isEqualWith', './isError', './isFinite', './isFunction', './isInteger', './isLength', './isMap', './isMatch', './isMatchWith', './isNaN', './isNative', './isNil', './isNull', './isNumber', './isObject', './isObjectLike', './isPlainObject', './isRegExp', './isSafeInteger', './isSet', './isString', './isSymbol', './isTypedArray', './isUndefined', './isWeakMap', './isWeakSet', './lt', './lte', './toArray', './toFinite', './toInteger', './toLength', './toNumber', './toPlainObject', './toSafeInteger', './toString'], function(castArray, clone, cloneDeep, cloneDeepWith, cloneWith, conformsTo, eq, gt, gte, isArguments, isArray, isArrayBuffer, isArrayLike, isArrayLikeObject, isBoolean, isBuffer, isDate, isElement, isEmpty, isEqual, isEqualWith, isError, isFinite, isFunction, isInteger, isLength, isMap, isMatch, isMatchWith, isNaN, isNative, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, lt, lte, toArray, toFinite, toInteger, toLength, toNumber, toPlainObject, toSafeInteger, toString) { return { 'castArray': castArray, 'clone': clone, 'cloneDeep': cloneDeep, 'cloneDeepWith': cloneDeepWith, 'cloneWith': cloneWith, + 'conformsTo': conformsTo, 'eq': eq, 'gt': gt, 'gte': gte, diff --git a/lastIndexOf.js b/lastIndexOf.js index d9c26a331..5a51faa03 100644 --- a/lastIndexOf.js +++ b/lastIndexOf.js @@ -1,4 +1,4 @@ -define(['./_indexOfNaN', './toInteger'], function(indexOfNaN, toInteger) { +define(['./_baseFindIndex', './_baseIsNaN', './toInteger'], function(baseFindIndex, baseIsNaN, toInteger) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -43,7 +43,7 @@ define(['./_indexOfNaN', './toInteger'], function(indexOfNaN, toInteger) { ) + 1; } if (value !== value) { - return indexOfNaN(array, index - 1, true); + return baseFindIndex(array, baseIsNaN, index - 1, true); } while (index--) { if (array[index] === value) { diff --git a/main.js b/main.js index 04ca61977..3c62a92c3 100644 --- a/main.js +++ b/main.js @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.13.1'; + var VERSION = '4.14.0'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -27,7 +27,7 @@ /** Used as the internal argument placeholder. */ var PLACEHOLDER = '__lodash_placeholder__'; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1, BIND_KEY_FLAG = 2, CURRY_BOUND_FLAG = 4, @@ -67,6 +67,19 @@ MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; + /** Used to associate wrap methods with their bit flags. */ + var wrapFlags = [ + ['ary', ARY_FLAG], + ['bind', BIND_FLAG], + ['bindKey', BIND_KEY_FLAG], + ['curry', CURRY_FLAG], + ['curryRight', CURRY_RIGHT_FLAG], + ['flip', FLIP_FLAG], + ['partial', PARTIAL_FLAG], + ['partialRight', PARTIAL_RIGHT_FLAG], + ['rearg', REARG_FLAG] + ]; + /** `Object#toString` result references. */ var argsTag = '[object Arguments]', arrayTag = '[object Array]', @@ -131,6 +144,11 @@ reTrimStart = /^\s+/, reTrimEnd = /\s+$/; + /** Used to match wrap detail comments. */ + var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/, + reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, + reSplitDetails = /,? & /; + /** Used to match non-compound words composed of alphanumeric characters. */ var reBasicWord = /[a-zA-Z0-9]+/g; @@ -250,7 +268,7 @@ 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object', 'Promise', 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', - '_', 'isFinite', 'parseInt', 'setTimeout' + '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' ]; /** Used to make template sourceURLs easier to identify. */ @@ -343,8 +361,17 @@ var freeParseFloat = parseFloat, freeParseInt = parseInt; + /** Detect free variable `global` from Node.js. */ + var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; + + /** Detect free variable `self`. */ + var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + + /** Used as a reference to the global object. */ + var root = freeGlobal || freeSelf || Function('return this')(); + /** Detect free variable `exports`. */ - var freeExports = typeof exports == 'object' && exports; + var freeExports = freeGlobal && typeof exports == 'object' && exports; /** Detect free variable `module`. */ var freeModule = freeExports && typeof module == 'object' && module; @@ -352,17 +379,23 @@ /** Detect the popular CommonJS extension `module.exports`. */ var moduleExports = freeModule && freeModule.exports === freeExports; - /** Detect free variable `global` from Node.js. */ - var freeGlobal = checkGlobal(typeof global == 'object' && global); + /** Detect free variable `process` from Node.js. */ + var freeProcess = moduleExports && freeGlobal.process; - /** Detect free variable `self`. */ - var freeSelf = checkGlobal(typeof self == 'object' && self); + /** Used to access faster Node.js helpers. */ + var nodeUtil = (function() { + try { + return freeProcess && freeProcess.binding('util'); + } catch (e) {} + }()); - /** Detect `this` as the global object. */ - var thisGlobal = checkGlobal(typeof this == 'object' && this); - - /** Used as a reference to the global object. */ - var root = freeGlobal || freeSelf || thisGlobal || Function('return this')(); + /* Node.js helper references. */ + var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer, + nodeIsDate = nodeUtil && nodeUtil.isDate, + nodeIsMap = nodeUtil && nodeUtil.isMap, + nodeIsRegExp = nodeUtil && nodeUtil.isRegExp, + nodeIsSet = nodeUtil && nodeUtil.isSet, + nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; /*--------------------------------------------------------------------------*/ @@ -375,7 +408,7 @@ * @returns {Object} Returns `map`. */ function addMapEntry(map, pair) { - // Don't return `Map#set` because it doesn't return the map instance in IE 11. + // Don't return `map.set` because it's not chainable in IE 11. map.set(pair[0], pair[1]); return map; } @@ -389,6 +422,7 @@ * @returns {Object} Returns `set`. */ function addSetEntry(set, value) { + // Don't return `set.add` because it's not chainable in IE 11. set.add(value); return set; } @@ -404,8 +438,7 @@ * @returns {*} Returns the result of `func`. */ function apply(func, thisArg, args) { - var length = args.length; - switch (length) { + switch (args.length) { case 0: return func.call(thisArg); case 1: return func.call(thisArg, args[0]); case 2: return func.call(thisArg, args[0], args[1]); @@ -722,7 +755,7 @@ */ function baseIndexOf(array, value, fromIndex) { if (value !== value) { - return indexOfNaN(array, fromIndex); + return baseFindIndex(array, baseIsNaN, fromIndex); } var index = fromIndex - 1, length = array.length; @@ -757,6 +790,17 @@ return -1; } + /** + * The base implementation of `_.isNaN` without support for number objects. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. + */ + function baseIsNaN(value) { + return value !== value; + } + /** * The base implementation of `_.mean` and `_.meanBy` without support for * iteratee shorthands. @@ -771,6 +815,32 @@ return length ? (baseSum(array, iteratee) / length) : NAN; } + /** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new accessor function. + */ + function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; + } + + /** + * The base implementation of `_.propertyOf` without support for deep paths. + * + * @private + * @param {Object} object The object to query. + * @returns {Function} Returns the new accessor function. + */ + function basePropertyOf(object) { + return function(key) { + return object == null ? undefined : object[key]; + }; + } + /** * The base implementation of `_.reduce` and `_.reduceRight`, without support * for iteratee shorthands, which iterates over `collection` using `eachFunc`. @@ -871,7 +941,7 @@ } /** - * The base implementation of `_.unary` without support for storing wrapper metadata. + * The base implementation of `_.unary` without support for storing metadata. * * @private * @param {Function} func The function to cap arguments for. @@ -944,17 +1014,6 @@ return index; } - /** - * Checks if `value` is a global object. - * - * @private - * @param {*} value The value to check. - * @returns {null|Object} Returns `value` if it's a global object, else `null`. - */ - function checkGlobal(value) { - return (value && value.Object === Object) ? value : null; - } - /** * Gets the number of `placeholder` occurrences in `array`. * @@ -982,9 +1041,7 @@ * @param {string} letter The matched letter to deburr. * @returns {string} Returns the deburred letter. */ - function deburrLetter(letter) { - return deburredLetters[letter]; - } + var deburrLetter = basePropertyOf(deburredLetters); /** * Used by `_.escape` to convert characters to HTML entities. @@ -993,9 +1050,7 @@ * @param {string} chr The matched character to escape. * @returns {string} Returns the escaped character. */ - function escapeHtmlChar(chr) { - return htmlEscapes[chr]; - } + var escapeHtmlChar = basePropertyOf(htmlEscapes); /** * Used by `_.template` to escape characters for inclusion in compiled string literals. @@ -1020,28 +1075,6 @@ return object == null ? undefined : object[key]; } - /** - * Gets the index at which the first occurrence of `NaN` is found in `array`. - * - * @private - * @param {Array} array The array to search. - * @param {number} fromIndex The index to search from. - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {number} Returns the index of the matched `NaN`, else `-1`. - */ - function indexOfNaN(array, fromIndex, fromRight) { - var length = array.length, - index = fromIndex + (fromRight ? 1 : -1); - - while ((fromRight ? index-- : ++index < length)) { - var other = array[index]; - if (other !== other) { - return index; - } - } - return -1; - } - /** * Checks if `value` is a host object in IE < 9. * @@ -1095,6 +1128,20 @@ return result; } + /** + * Creates a function that invokes `func` with its first argument transformed. + * + * @private + * @param {Function} func The function to wrap. + * @param {Function} transform The argument transform. + * @returns {Function} Returns the new function. + */ + function overArg(func, transform) { + return function(arg) { + return func(transform(arg)); + }; + } + /** * Replaces all `placeholder` elements in `array` with an internal placeholder * and returns an array of their indexes. @@ -1190,9 +1237,7 @@ * @param {string} chr The matched character to unescape. * @returns {string} Returns the unescaped character. */ - function unescapeHtmlChar(chr) { - return htmlUnescapes[chr]; - } + var unescapeHtmlChar = basePropertyOf(htmlUnescapes); /*--------------------------------------------------------------------------*/ @@ -1236,7 +1281,8 @@ context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root; /** Built-in constructor references. */ - var Date = context.Date, + var Array = context.Array, + Date = context.Date, Error = context.Error, Math = context.Math, RegExp = context.RegExp, @@ -1290,19 +1336,22 @@ Symbol = context.Symbol, Uint8Array = context.Uint8Array, enumerate = Reflect ? Reflect.enumerate : undefined, - getOwnPropertySymbols = Object.getOwnPropertySymbols, - iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined, - objectCreate = Object.create, + iteratorSymbol = Symbol ? Symbol.iterator : undefined, + objectCreate = context.Object.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, - splice = arrayProto.splice; + splice = arrayProto.splice, + spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; /** Built-in method references that are mockable. */ - var setTimeout = function(func, wait) { return context.setTimeout.call(root, func, wait); }; + var clearTimeout = function(id) { return context.clearTimeout.call(root, id); }, + setTimeout = function(func, wait) { return context.setTimeout.call(root, func, wait); }; /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeCeil = Math.ceil, nativeFloor = Math.floor, nativeGetPrototype = Object.getPrototypeOf, + nativeGetSymbols = Object.getOwnPropertySymbols, + nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = Object.keys, @@ -1320,7 +1369,15 @@ Promise = getNative(context, 'Promise'), Set = getNative(context, 'Set'), WeakMap = getNative(context, 'WeakMap'), - nativeCreate = getNative(Object, 'create'); + nativeCreate = getNative(context.Object, 'create'); + + /* Used to set `toString` methods. */ + var defineProperty = (function() { + var func = getNative(context.Object, 'defineProperty'), + name = getNative.name; + + return (name && name.length > 2) ? func : undefined; + }()); /** Used to store function metadata. */ var metaMap = WeakMap && new WeakMap; @@ -1411,16 +1468,16 @@ * * The wrapper methods that are **not** chainable by default are: * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, - * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `divide`, `each`, - * `eachRight`, `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`, - * `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`, - * `floor`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, - * `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`, - * `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`, - * `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`, - * `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, - * `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`, - * `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, + * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`, + * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`, + * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`, + * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`, + * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, + * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, + * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, + * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, + * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, + * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`, * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`, @@ -2123,8 +2180,13 @@ */ function stackSet(key, value) { var cache = this.__data__; - if (cache instanceof ListCache && cache.__data__.length == LARGE_ARRAY_SIZE) { - cache = this.__data__ = new MapCache(cache.__data__); + if (cache instanceof ListCache) { + var pairs = cache.__data__; + if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) { + pairs.push([key, value]); + return this; + } + cache = this.__data__ = new MapCache(pairs); } cache.set(key, value); return this; @@ -2261,7 +2323,7 @@ } /** - * The base implementation of `_.clamp` which doesn't coerce arguments to numbers. + * The base implementation of `_.clamp` which doesn't coerce arguments. * * @private * @param {number} number The number to clamp. @@ -2345,14 +2407,17 @@ if (!isArr) { var props = isFull ? getAllKeys(value) : keys(value); } - // Recursively populate clone (susceptible to call stack limits). arrayEach(props || value, function(subValue, key) { if (props) { key = subValue; subValue = value[key]; } + // Recursively populate clone (susceptible to call stack limits). assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack)); }); + if (!isFull) { + stack['delete'](value); + } return result; } @@ -2364,28 +2429,39 @@ * @returns {Function} Returns the new spec function. */ function baseConforms(source) { - var props = keys(source), - length = props.length; - + var props = keys(source); return function(object) { - if (object == null) { - return !length; - } - var index = length; - while (index--) { - var key = props[index], - predicate = source[key], - value = object[key]; - - if ((value === undefined && - !(key in Object(object))) || !predicate(value)) { - return false; - } - } - return true; + return baseConformsTo(object, source, props); }; } + /** + * The base implementation of `_.conformsTo` which accepts `props` to check. + * + * @private + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + */ + function baseConformsTo(object, source, props) { + var length = props.length; + if (object == null) { + return !length; + } + var index = length; + while (index--) { + var key = props[index], + predicate = source[key], + value = object[key]; + + if ((value === undefined && + !(key in Object(object))) || !predicate(value)) { + return false; + } + } + return true; + } + /** * The base implementation of `_.create` without support for assigning * properties to the created object. @@ -2399,13 +2475,13 @@ } /** - * The base implementation of `_.delay` and `_.defer` which accepts an array - * of `func` arguments. + * The base implementation of `_.delay` and `_.defer` which accepts `args` + * to provide to `func`. * * @private * @param {Function} func The function to delay. * @param {number} wait The number of milliseconds to delay invocation. - * @param {Object} args The arguments to provide to `func`. + * @param {Array} args The arguments to provide to `func`. * @returns {number} Returns the timer id. */ function baseDelay(func, wait, args) { @@ -2719,7 +2795,18 @@ } /** - * The base implementation of `_.gt` which doesn't coerce arguments to numbers. + * The base implementation of `getTag`. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + function baseGetTag(value) { + return objectToString.call(value); + } + + /** + * The base implementation of `_.gt` which doesn't coerce arguments. * * @private * @param {*} value The value to compare. @@ -2761,7 +2848,7 @@ } /** - * The base implementation of `_.inRange` which doesn't coerce arguments to numbers. + * The base implementation of `_.inRange` which doesn't coerce arguments. * * @private * @param {number} number The number to check. @@ -2874,6 +2961,28 @@ return func == null ? undefined : apply(func, object, args); } + /** + * The base implementation of `_.isArrayBuffer` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. + */ + function baseIsArrayBuffer(value) { + return isObjectLike(value) && objectToString.call(value) == arrayBufferTag; + } + + /** + * The base implementation of `_.isDate` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a date object, else `false`. + */ + function baseIsDate(value) { + return isObjectLike(value) && objectToString.call(value) == dateTag; + } + /** * The base implementation of `_.isEqual` which supports partial comparisons * and tracks traversed objects. @@ -2957,6 +3066,17 @@ return equalObjects(object, other, equalFunc, customizer, bitmask, stack); } + /** + * The base implementation of `_.isMap` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a map, else `false`. + */ + function baseIsMap(value) { + return isObjectLike(value) && getTag(value) == mapTag; + } + /** * The base implementation of `_.isMatch` without support for iteratee shorthands. * @@ -3027,6 +3147,40 @@ return pattern.test(toSource(value)); } + /** + * The base implementation of `_.isRegExp` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. + */ + function baseIsRegExp(value) { + return isObject(value) && objectToString.call(value) == regexpTag; + } + + /** + * The base implementation of `_.isSet` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a set, else `false`. + */ + function baseIsSet(value) { + return isObjectLike(value) && getTag(value) == setTag; + } + + /** + * The base implementation of `_.isTypedArray` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. + */ + function baseIsTypedArray(value) { + return isObjectLike(value) && + isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; + } + /** * The base implementation of `_.iteratee`. * @@ -3059,9 +3213,7 @@ * @param {Object} object The object to query. * @returns {Array} Returns the array of property names. */ - function baseKeys(object) { - return nativeKeys(Object(object)); - } + var baseKeys = overArg(nativeKeys, Object); /** * The base implementation of `_.keysIn` which doesn't skip the constructor @@ -3089,7 +3241,7 @@ } /** - * The base implementation of `_.lt` which doesn't coerce arguments to numbers. + * The base implementation of `_.lt` which doesn't coerce arguments. * * @private * @param {*} value The value to compare. @@ -3256,18 +3408,17 @@ isCommon = false; } } - stack.set(srcValue, newValue); - if (isCommon) { // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, newValue); mergeFunc(newValue, srcValue, srcIndex, customizer, stack); + stack['delete'](srcValue); } - stack['delete'](srcValue); assignMergeValue(object, key, newValue); } /** - * The base implementation of `_.nth` which doesn't coerce `n` to an integer. + * The base implementation of `_.nth` which doesn't coerce arguments. * * @private * @param {Array} array The array to query. @@ -3319,12 +3470,9 @@ */ function basePick(object, props) { object = Object(object); - return arrayReduce(props, function(result, key) { - if (key in object) { - result[key] = object[key]; - } - return result; - }, {}); + return basePickBy(object, props, function(value, key) { + return key in object; + }); } /** @@ -3332,12 +3480,12 @@ * * @private * @param {Object} object The source object. + * @param {string[]} props The property identifiers to pick from. * @param {Function} predicate The function invoked per property. * @returns {Object} Returns the new object. */ - function basePickBy(object, predicate) { + function basePickBy(object, props, predicate) { var index = -1, - props = getAllKeysIn(object), length = props.length, result = {}; @@ -3352,19 +3500,6 @@ return result; } - /** - * The base implementation of `_.property` without support for deep paths. - * - * @private - * @param {string} key The key of the property to get. - * @returns {Function} Returns the new accessor function. - */ - function baseProperty(key) { - return function(object) { - return object == null ? undefined : object[key]; - }; - } - /** * A specialized version of `baseProperty` which supports deep paths. * @@ -3467,7 +3602,7 @@ /** * The base implementation of `_.range` and `_.rangeRight` which doesn't - * coerce arguments to numbers. + * coerce arguments. * * @private * @param {number} start The start of the range. @@ -3516,6 +3651,35 @@ return result; } + /** + * The base implementation of `_.rest` which doesn't validate or coerce arguments. + * + * @private + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @returns {Function} Returns the new function. + */ + function baseRest(func, start) { + start = nativeMax(start === undefined ? (func.length - 1) : start, 0); + return function() { + var args = arguments, + index = -1, + length = nativeMax(args.length - start, 0), + array = Array(length); + + while (++index < length) { + array[index] = args[start + index]; + } + index = -1; + var otherArgs = Array(start + 1); + while (++index < start) { + otherArgs[index] = args[index]; + } + otherArgs[start] = array; + return apply(func, this, otherArgs); + }; + } + /** * The base implementation of `_.set`. * @@ -4295,9 +4459,9 @@ var newValue = customizer ? customizer(object[key], source[key], key, object, source) - : source[key]; + : undefined; - assignValue(object, key, newValue); + assignValue(object, key, newValue === undefined ? source[key] : newValue); } return object; } @@ -4327,7 +4491,7 @@ var func = isArray(collection) ? arrayAggregator : baseAggregator, accumulator = initializer ? initializer() : {}; - return func(collection, setter, getIteratee(iteratee), accumulator); + return func(collection, setter, getIteratee(iteratee, 2), accumulator); }; } @@ -4339,7 +4503,7 @@ * @returns {Function} Returns the new assigner function. */ function createAssigner(assigner) { - return rest(function(object, sources) { + return baseRest(function(object, sources) { var index = -1, length = sources.length, customizer = length > 1 ? sources[length - 1] : undefined, @@ -4423,14 +4587,13 @@ * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` - * for more details. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {*} [thisArg] The `this` binding of `func`. * @returns {Function} Returns the new wrapped function. */ - function createBaseWrapper(func, bitmask, thisArg) { + function createBind(func, bitmask, thisArg) { var isBind = bitmask & BIND_FLAG, - Ctor = createCtorWrapper(func); + Ctor = createCtor(func); function wrapper() { var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; @@ -4487,7 +4650,7 @@ * @param {Function} Ctor The constructor to wrap. * @returns {Function} Returns the new wrapped function. */ - function createCtorWrapper(Ctor) { + function createCtor(Ctor) { return function() { // Use a `switch` statement to work with class constructors. See // http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist @@ -4517,13 +4680,12 @@ * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` - * for more details. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {number} arity The arity of `func`. * @returns {Function} Returns the new wrapped function. */ - function createCurryWrapper(func, bitmask, arity) { - var Ctor = createCtorWrapper(func); + function createCurry(func, bitmask, arity) { + var Ctor = createCtor(func); function wrapper() { var length = arguments.length, @@ -4540,8 +4702,8 @@ length -= holders.length; if (length < arity) { - return createRecurryWrapper( - func, bitmask, createHybridWrapper, wrapper.placeholder, undefined, + return createRecurry( + func, bitmask, createHybrid, wrapper.placeholder, undefined, args, holders, undefined, undefined, arity - length); } var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; @@ -4560,18 +4722,13 @@ function createFind(findIndexFunc) { return function(collection, predicate, fromIndex) { var iterable = Object(collection); - predicate = getIteratee(predicate, 3); if (!isArrayLike(collection)) { - var props = keys(collection); + var iteratee = getIteratee(predicate, 3); + collection = keys(collection); + predicate = function(key) { return iteratee(iterable[key], key, iterable); }; } - var index = findIndexFunc(props || collection, function(value, key) { - if (props) { - key = value; - value = iterable[key]; - } - return predicate(value, key, iterable); - }, fromIndex); - return index > -1 ? collection[props ? props[index] : index] : undefined; + var index = findIndexFunc(collection, predicate, fromIndex); + return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined; }; } @@ -4583,7 +4740,7 @@ * @returns {Function} Returns the new flow function. */ function createFlow(fromRight) { - return rest(function(funcs) { + return baseRest(function(funcs) { funcs = baseFlatten(funcs, 1); var length = funcs.length, @@ -4645,8 +4802,7 @@ * * @private * @param {Function|string} func The function or method name to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` - * for more details. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {*} [thisArg] The `this` binding of `func`. * @param {Array} [partials] The arguments to prepend to those provided to * the new function. @@ -4659,13 +4815,13 @@ * @param {number} [arity] The arity of `func`. * @returns {Function} Returns the new wrapped function. */ - function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { + function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { var isAry = bitmask & ARY_FLAG, isBind = bitmask & BIND_FLAG, isBindKey = bitmask & BIND_KEY_FLAG, isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG), isFlip = bitmask & FLIP_FLAG, - Ctor = isBindKey ? undefined : createCtorWrapper(func); + Ctor = isBindKey ? undefined : createCtor(func); function wrapper() { var length = arguments.length, @@ -4688,8 +4844,8 @@ length -= holdersCount; if (isCurried && length < arity) { var newHolders = replaceHolders(args, placeholder); - return createRecurryWrapper( - func, bitmask, createHybridWrapper, wrapper.placeholder, thisArg, + return createRecurry( + func, bitmask, createHybrid, wrapper.placeholder, thisArg, args, newHolders, argPos, ary, arity - length ); } @@ -4706,7 +4862,7 @@ args.length = ary; } if (this && this !== root && this instanceof wrapper) { - fn = Ctor || createCtorWrapper(fn); + fn = Ctor || createCtor(fn); } return fn.apply(thisBinding, args); } @@ -4732,13 +4888,14 @@ * * @private * @param {Function} operator The function to perform the operation. + * @param {number} [defaultValue] The value used for `undefined` arguments. * @returns {Function} Returns the new mathematical operation function. */ - function createMathOperation(operator) { + function createMathOperation(operator, defaultValue) { return function(value, other) { var result; if (value === undefined && other === undefined) { - return 0; + return defaultValue; } if (value !== undefined) { result = value; @@ -4768,12 +4925,12 @@ * @returns {Function} Returns the new over function. */ function createOver(arrayFunc) { - return rest(function(iteratees) { + return baseRest(function(iteratees) { iteratees = (iteratees.length == 1 && isArray(iteratees[0])) ? arrayMap(iteratees[0], baseUnary(getIteratee())) - : arrayMap(baseFlatten(iteratees, 1, isFlattenableIteratee), baseUnary(getIteratee())); + : arrayMap(baseFlatten(iteratees, 1), baseUnary(getIteratee())); - return rest(function(args) { + return baseRest(function(args) { var thisArg = this; return arrayFunc(iteratees, function(iteratee) { return apply(iteratee, thisArg, args); @@ -4810,16 +4967,15 @@ * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` - * for more details. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {*} thisArg The `this` binding of `func`. * @param {Array} partials The arguments to prepend to those provided to * the new function. * @returns {Function} Returns the new wrapped function. */ - function createPartialWrapper(func, bitmask, thisArg, partials) { + function createPartial(func, bitmask, thisArg, partials) { var isBind = bitmask & BIND_FLAG, - Ctor = createCtorWrapper(func); + Ctor = createCtor(func); function wrapper() { var argsIndex = -1, @@ -4888,8 +5044,7 @@ * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` - * for more details. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {Function} wrapFunc The function to create the `func` wrapper. * @param {*} placeholder The placeholder value. * @param {*} [thisArg] The `this` binding of `func`. @@ -4901,7 +5056,7 @@ * @param {number} [arity] The arity of `func`. * @returns {Function} Returns the new wrapped function. */ - function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { + function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { var isCurry = bitmask & CURRY_FLAG, newHolders = isCurry ? holders : undefined, newHoldersRight = isCurry ? undefined : holders, @@ -4924,7 +5079,7 @@ setData(result, newData); } result.placeholder = placeholder; - return result; + return setWrapToString(result, func, bitmask); } /** @@ -4953,7 +5108,7 @@ } /** - * Creates a set of `values`. + * Creates a set object of `values`. * * @private * @param {Array} values The values to add to the set. @@ -4989,7 +5144,7 @@ * * @private * @param {Function|string} func The function or method name to wrap. - * @param {number} bitmask The bitmask of wrapper flags. + * @param {number} bitmask The bitmask flags. * The bitmask may be composed of the following flags: * 1 - `_.bind` * 2 - `_.bindKey` @@ -5009,7 +5164,7 @@ * @param {number} [arity] The arity of `func`. * @returns {Function} Returns the new wrapped function. */ - function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { + function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { var isBindKey = bitmask & BIND_KEY_FLAG; if (!isBindKey && typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); @@ -5052,16 +5207,16 @@ bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG); } if (!bitmask || bitmask == BIND_FLAG) { - var result = createBaseWrapper(func, bitmask, thisArg); + var result = createBind(func, bitmask, thisArg); } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) { - result = createCurryWrapper(func, bitmask, arity); + result = createCurry(func, bitmask, arity); } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) { - result = createPartialWrapper(func, bitmask, thisArg, partials); + result = createPartial(func, bitmask, thisArg, partials); } else { - result = createHybridWrapper.apply(undefined, newData); + result = createHybrid.apply(undefined, newData); } var setter = data ? baseSetData : setData; - return setter(result, newData); + return setWrapToString(setter(result, newData), func, bitmask); } /** @@ -5088,7 +5243,7 @@ } // Assume cyclic values are equal. var stacked = stack.get(array); - if (stacked) { + if (stacked && stack.get(other)) { return stacked == other; } var index = -1, @@ -5096,6 +5251,7 @@ seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined; stack.set(array, other); + stack.set(other, array); // Ignore non-index properties. while (++index < arrLength) { @@ -5174,18 +5330,14 @@ case boolTag: case dateTag: - // Coerce dates and booleans to numbers, dates to milliseconds and - // booleans to `1` or `0` treating invalid dates coerced to `NaN` as - // not equal. - return +object == +other; + case numberTag: + // Coerce booleans to `1` or `0` and dates to milliseconds. + // Invalid dates are coerced to `NaN`. + return eq(+object, +other); case errorTag: return object.name == other.name && object.message == other.message; - case numberTag: - // Treat `NaN` vs. `NaN` as equal. - return (object != +object) ? other != +other : object == +other; - case regexpTag: case stringTag: // Coerce regexes to strings and treat strings, primitives and objects, @@ -5209,10 +5361,12 @@ return stacked == other; } bitmask |= UNORDERED_COMPARE_FLAG; - stack.set(object, other); // Recursively compare objects (susceptible to call stack limits). - return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack); + stack.set(object, other); + var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack); + stack['delete'](object); + return result; case symbolTag: if (symbolValueOf) { @@ -5255,11 +5409,12 @@ } // Assume cyclic values are equal. var stacked = stack.get(object); - if (stacked) { + if (stacked && stack.get(other)) { return stacked == other; } var result = true; stack.set(object, other); + stack.set(other, object); var skipCtor = isPartial; while (++index < objLength) { @@ -5451,9 +5606,7 @@ * @param {*} value The value to query. * @returns {null|Object} Returns the `[[Prototype]]`. */ - function getPrototype(value) { - return nativeGetPrototype(Object(value)); - } + var getPrototype = overArg(nativeGetPrototype, Object); /** * Creates an array of the own enumerable symbol properties of `object`. @@ -5462,16 +5615,7 @@ * @param {Object} object The object to query. * @returns {Array} Returns the array of symbols. */ - function getSymbols(object) { - // Coerce `object` to an object to avoid non-object errors in V8. - // See https://bugs.chromium.org/p/v8/issues/detail?id=3443 for more details. - return getOwnPropertySymbols(Object(object)); - } - - // Fallback for IE < 11. - if (!getOwnPropertySymbols) { - getSymbols = stubArray; - } + var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray; /** * Creates an array of the own and inherited enumerable symbol properties @@ -5481,7 +5625,7 @@ * @param {Object} object The object to query. * @returns {Array} Returns the array of symbols. */ - var getSymbolsIn = !getOwnPropertySymbols ? getSymbols : function(object) { + var getSymbolsIn = !nativeGetSymbols ? getSymbols : function(object) { var result = []; while (object) { arrayPush(result, getSymbols(object)); @@ -5497,9 +5641,7 @@ * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ - function getTag(value) { - return objectToString.call(value); - } + var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11, // for data views in Edge, and promises in Node.js. @@ -5554,6 +5696,18 @@ return { 'start': start, 'end': end }; } + /** + * Extracts wrapper details from the `source` body comment. + * + * @private + * @param {string} source The source to inspect. + * @returns {Array} Returns the wrapper details. + */ + function getWrapDetails(source) { + var match = source.match(reWrapDetails); + return match ? match[1].split(reSplitDetails) : []; + } + /** * Checks if `path` exists on `object`. * @@ -5683,6 +5837,23 @@ return null; } + /** + * Inserts wrapper `details` in a comment at the top of the `source` body. + * + * @private + * @param {string} source The source to modify. + * @returns {Array} details The details to insert. + * @returns {string} Returns the modified source. + */ + function insertWrapDetails(source, details) { + var length = details.length, + lastIndex = length - 1; + + details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex]; + details = details.join(length > 2 ? ', ' : ' '); + return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n'); + } + /** * Checks if `value` is a flattenable `arguments` object or array. * @@ -5691,19 +5862,8 @@ * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. */ function isFlattenable(value) { - return isArray(value) || isArguments(value); - } - - /** - * Checks if `value` is a flattenable array and not a `_.matchesProperty` - * iteratee shorthand. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. - */ - function isFlattenableIteratee(value) { - return isArray(value) && !(value.length == 2 && !isFunction(value[0])); + return isArray(value) || isArguments(value) || + !!(spreadableSymbol && value && value[spreadableSymbol]) } /** @@ -5953,7 +6113,10 @@ */ function mergeDefaults(objValue, srcValue, key, object, source, stack) { if (isObject(objValue) && isObject(srcValue)) { - baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue)); + // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, objValue); + baseMerge(objValue, srcValue, undefined, mergeDefaults, stack); + stack['delete'](srcValue); } return objValue; } @@ -6026,6 +6189,25 @@ }; }()); + /** + * Sets the `toString` method of `wrapper` to mimic the source of `reference` + * with wrapper details in a comment at the top of the source body. + * + * @private + * @param {Function} wrapper The function to modify. + * @param {Function} reference The reference function. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @returns {Function} Returns `wrapper`. + */ + var setWrapToString = !defineProperty ? identity : function(wrapper, reference, bitmask) { + var source = (reference + ''); + return defineProperty(wrapper, 'toString', { + 'configurable': true, + 'enumerable': false, + 'value': constant(insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask))) + }); + }; + /** * Converts `string` to a property path array. * @@ -6075,6 +6257,24 @@ return ''; } + /** + * Updates wrapper `details` based on `bitmask` flags. + * + * @private + * @returns {Array} details The details to modify. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @returns {Array} Returns `details`. + */ + function updateWrapDetails(details, bitmask) { + arrayEach(wrapFlags, function(pair) { + var value = '_.' + pair[0]; + if ((bitmask & pair[1]) && !arrayIncludes(details, value)) { + details.push(value); + } + }); + return details.sort(); + } + /** * Creates a clone of `wrapper`. * @@ -6203,11 +6403,13 @@ } /** - * Creates an array of unique `array` values not included in the other given - * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) + * Creates an array of `array` values not included in the other given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * for equality comparisons. The order of result values is determined by the * order they occur in the first array. * + * **Note:** Unlike `_.pullAll`, this method returns a new array. + * * @static * @memberOf _ * @since 0.1.0 @@ -6221,7 +6423,7 @@ * _.difference([2, 1], [2, 3]); * // => [1] */ - var difference = rest(function(array, values) { + var difference = baseRest(function(array, values) { return isArrayLikeObject(array) ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) : []; @@ -6233,14 +6435,15 @@ * by which they're compared. Result values are chosen from the first array. * The iteratee is invoked with one argument: (value). * + * **Note:** Unlike `_.pullAllBy`, this method returns a new array. + * * @static * @memberOf _ * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @param {...Array} [values] The values to exclude. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns the new array of filtered values. * @example * @@ -6251,13 +6454,13 @@ * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); * // => [{ 'x': 2 }] */ - var differenceBy = rest(function(array, values) { + var differenceBy = baseRest(function(array, values) { var iteratee = last(values); if (isArrayLikeObject(iteratee)) { iteratee = undefined; } return isArrayLikeObject(array) - ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee)) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)) : []; }); @@ -6267,6 +6470,8 @@ * are chosen from the first array. The comparator is invoked with two arguments: * (arrVal, othVal). * + * **Note:** Unlike `_.pullAllWith`, this method returns a new array. + * * @static * @memberOf _ * @since 4.0.0 @@ -6282,7 +6487,7 @@ * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); * // => [{ 'x': 2, 'y': 1 }] */ - var differenceWith = rest(function(array, values) { + var differenceWith = baseRest(function(array, values) { var comparator = last(values); if (isArrayLikeObject(comparator)) { comparator = undefined; @@ -6371,8 +6576,7 @@ * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * @@ -6413,7 +6617,7 @@ * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example @@ -6495,7 +6699,7 @@ * @since 1.1.0 * @category Array * @param {Array} array The array to search. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. * @returns {number} Returns the index of the found element, else `-1`. @@ -6543,7 +6747,7 @@ * @since 2.0.0 * @category Array * @param {Array} array The array to search. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=array.length-1] The index to search from. * @returns {number} Returns the index of the found element, else `-1`. @@ -6664,8 +6868,8 @@ * @returns {Object} Returns the new object. * @example * - * _.fromPairs([['fred', 30], ['barney', 40]]); - * // => { 'fred': 30, 'barney': 40 } + * _.fromPairs([['a', 1], ['b', 2]]); + * // => { 'a': 1, 'b': 2 } */ function fromPairs(pairs) { var index = -1, @@ -6771,7 +6975,7 @@ * _.intersection([2, 1], [2, 3]); * // => [2] */ - var intersection = rest(function(arrays) { + var intersection = baseRest(function(arrays) { var mapped = arrayMap(arrays, castArrayLikeObject); return (mapped.length && mapped[0] === arrays[0]) ? baseIntersection(mapped) @@ -6789,8 +6993,7 @@ * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns the new array of intersecting values. * @example * @@ -6801,7 +7004,7 @@ * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }] */ - var intersectionBy = rest(function(arrays) { + var intersectionBy = baseRest(function(arrays) { var iteratee = last(arrays), mapped = arrayMap(arrays, castArrayLikeObject); @@ -6811,7 +7014,7 @@ mapped.pop(); } return (mapped.length && mapped[0] === arrays[0]) - ? baseIntersection(mapped, getIteratee(iteratee)) + ? baseIntersection(mapped, getIteratee(iteratee, 2)) : []; }); @@ -6836,7 +7039,7 @@ * _.intersectionWith(objects, others, _.isEqual); * // => [{ 'x': 1, 'y': 2 }] */ - var intersectionWith = rest(function(arrays) { + var intersectionWith = baseRest(function(arrays) { var comparator = last(arrays), mapped = arrayMap(arrays, castArrayLikeObject); @@ -6924,7 +7127,7 @@ ) + 1; } if (value !== value) { - return indexOfNaN(array, index - 1, true); + return baseFindIndex(array, baseIsNaN, index - 1, true); } while (index--) { if (array[index] === value) { @@ -6982,7 +7185,7 @@ * console.log(array); * // => ['b', 'b'] */ - var pull = rest(pullAll); + var pull = baseRest(pullAll); /** * This method is like `_.pull` except that it accepts an array of values to remove. @@ -7023,7 +7226,7 @@ * @category Array * @param {Array} array The array to modify. * @param {Array} values The values to remove. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {Array} Returns `array`. * @example @@ -7036,7 +7239,7 @@ */ function pullAllBy(array, values, iteratee) { return (array && array.length && values && values.length) - ? basePullAll(array, values, getIteratee(iteratee)) + ? basePullAll(array, values, getIteratee(iteratee, 2)) : array; } @@ -7093,7 +7296,7 @@ * console.log(pulled); * // => ['b', 'd'] */ - var pullAt = rest(function(array, indexes) { + var pullAt = baseRest(function(array, indexes) { indexes = baseFlatten(indexes, 1); var length = array ? array.length : 0, @@ -7119,7 +7322,7 @@ * @since 2.0.0 * @category Array * @param {Array} array The array to modify. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the new array of removed elements. * @example @@ -7247,7 +7450,7 @@ * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {number} Returns the index at which `value` should be inserted * into `array`. @@ -7263,7 +7466,7 @@ * // => 0 */ function sortedIndexBy(array, value, iteratee) { - return baseSortedIndexBy(array, value, getIteratee(iteratee)); + return baseSortedIndexBy(array, value, getIteratee(iteratee, 2)); } /** @@ -7326,7 +7529,7 @@ * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {number} Returns the index at which `value` should be inserted * into `array`. @@ -7342,7 +7545,7 @@ * // => 1 */ function sortedLastIndexBy(array, value, iteratee) { - return baseSortedIndexBy(array, value, getIteratee(iteratee), true); + return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true); } /** @@ -7411,7 +7614,7 @@ */ function sortedUniqBy(array, iteratee) { return (array && array.length) - ? baseSortedUniq(array, getIteratee(iteratee)) + ? baseSortedUniq(array, getIteratee(iteratee, 2)) : []; } @@ -7511,7 +7714,7 @@ * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example @@ -7553,7 +7756,7 @@ * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example @@ -7601,14 +7804,15 @@ * _.union([2], [1, 2]); * // => [2, 1] */ - var union = rest(function(arrays) { + var union = baseRest(function(arrays) { return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); }); /** * This method is like `_.union` except that it accepts `iteratee` which is * invoked for each element of each `arrays` to generate the criterion by - * which uniqueness is computed. The iteratee is invoked with one argument: + * which uniqueness is computed. Result values are chosen from the first + * array in which the value occurs. The iteratee is invoked with one argument: * (value). * * @static @@ -7616,7 +7820,7 @@ * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {Array} Returns the new array of combined values. * @example @@ -7628,17 +7832,18 @@ * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }, { 'x': 2 }] */ - var unionBy = rest(function(arrays) { + var unionBy = baseRest(function(arrays) { var iteratee = last(arrays); if (isArrayLikeObject(iteratee)) { iteratee = undefined; } - return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee)); + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)); }); /** * This method is like `_.union` except that it accepts `comparator` which - * is invoked to compare elements of `arrays`. The comparator is invoked + * is invoked to compare elements of `arrays`. Result values are chosen from + * the first array in which the value occurs. The comparator is invoked * with two arguments: (arrVal, othVal). * * @static @@ -7656,7 +7861,7 @@ * _.unionWith(objects, others, _.isEqual); * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] */ - var unionWith = rest(function(arrays) { + var unionWith = baseRest(function(arrays) { var comparator = last(arrays); if (isArrayLikeObject(comparator)) { comparator = undefined; @@ -7697,7 +7902,7 @@ * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {Array} Returns the new duplicate free array. * @example @@ -7711,7 +7916,7 @@ */ function uniqBy(array, iteratee) { return (array && array.length) - ? baseUniq(array, getIteratee(iteratee)) + ? baseUniq(array, getIteratee(iteratee, 2)) : []; } @@ -7753,11 +7958,11 @@ * @returns {Array} Returns the new array of regrouped elements. * @example * - * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]); - * // => [['fred', 30, true], ['barney', 40, false]] + * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]); + * // => [['a', 1, true], ['b', 2, false]] * * _.unzip(zipped); - * // => [['fred', 'barney'], [30, 40], [true, false]] + * // => [['a', 'b'], [1, 2], [true, false]] */ function unzip(array) { if (!(array && array.length)) { @@ -7814,6 +8019,8 @@ * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * for equality comparisons. * + * **Note:** Unlike `_.pull`, this method returns a new array. + * * @static * @memberOf _ * @since 0.1.0 @@ -7827,7 +8034,7 @@ * _.without([2, 1, 2, 3], 1, 2); * // => [3] */ - var without = rest(function(array, values) { + var without = baseRest(function(array, values) { return isArrayLikeObject(array) ? baseDifference(array, values) : []; @@ -7851,7 +8058,7 @@ * _.xor([2, 1], [2, 3]); * // => [1, 3] */ - var xor = rest(function(arrays) { + var xor = baseRest(function(arrays) { return baseXor(arrayFilter(arrays, isArrayLikeObject)); }); @@ -7866,7 +8073,7 @@ * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {Array} Returns the new array of filtered values. * @example @@ -7878,12 +8085,12 @@ * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 2 }] */ - var xorBy = rest(function(arrays) { + var xorBy = baseRest(function(arrays) { var iteratee = last(arrays); if (isArrayLikeObject(iteratee)) { iteratee = undefined; } - return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee)); + return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2)); }); /** @@ -7906,7 +8113,7 @@ * _.xorWith(objects, others, _.isEqual); * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] */ - var xorWith = rest(function(arrays) { + var xorWith = baseRest(function(arrays) { var comparator = last(arrays); if (isArrayLikeObject(comparator)) { comparator = undefined; @@ -7927,10 +8134,10 @@ * @returns {Array} Returns the new array of grouped elements. * @example * - * _.zip(['fred', 'barney'], [30, 40], [true, false]); - * // => [['fred', 30, true], ['barney', 40, false]] + * _.zip(['a', 'b'], [1, 2], [true, false]); + * // => [['a', 1, true], ['b', 2, false]] */ - var zip = rest(unzip); + var zip = baseRest(unzip); /** * This method is like `_.fromPairs` except that it accepts two arrays, @@ -7990,7 +8197,7 @@ * }); * // => [111, 222] */ - var zipWith = rest(function(arrays) { + var zipWith = baseRest(function(arrays) { var length = arrays.length, iteratee = length > 1 ? arrays[length - 1] : undefined; @@ -8106,7 +8313,7 @@ * _(object).at(['a[0].b.c', 'a[1]']).value(); * // => [3, 4] */ - var wrapperAt = rest(function(paths) { + var wrapperAt = baseRest(function(paths) { paths = baseFlatten(paths, 1); var length = paths.length, start = length ? paths[0] : 0, @@ -8359,7 +8566,7 @@ * @since 0.5.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example @@ -8385,7 +8592,7 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {boolean} Returns `true` if all elements pass the predicate check, @@ -8425,12 +8632,14 @@ * `predicate` returns truthy for. The predicate is invoked with three * arguments: (value, index|key, collection). * + * **Note:** Unlike `_.remove`, this method returns a new array. + * * @static * @memberOf _ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the new filtered array. * @see _.reject @@ -8471,7 +8680,7 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to search. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. * @returns {*} Returns the matched element, else `undefined`. @@ -8509,7 +8718,7 @@ * @since 2.0.0 * @category Collection * @param {Array|Object} collection The collection to search. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=collection.length-1] The index to search from. * @returns {*} Returns the matched element, else `undefined`. @@ -8532,7 +8741,7 @@ * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The function invoked per iteration. * @returns {Array} Returns the new flattened array. * @example @@ -8557,7 +8766,7 @@ * @since 4.7.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The function invoked per iteration. * @returns {Array} Returns the new flattened array. * @example @@ -8582,7 +8791,7 @@ * @since 4.7.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The function invoked per iteration. * @param {number} [depth=1] The maximum recursion depth. * @returns {Array} Returns the new flattened array. @@ -8672,7 +8881,7 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example @@ -8716,10 +8925,10 @@ * _.includes([1, 2, 3], 1, 2); * // => false * - * _.includes({ 'user': 'fred', 'age': 40 }, 'fred'); + * _.includes({ 'a': 1, 'b': 2 }, 1); * // => true * - * _.includes('pebbles', 'eb'); + * _.includes('abcd', 'bc'); * // => true */ function includes(collection, value, fromIndex, guard) { @@ -8738,8 +8947,8 @@ /** * Invokes the method at `path` of each element in `collection`, returning * an array of the results of each invoked method. Any additional arguments - * are provided to each invoked method. If `methodName` is a function, it's - * invoked for and `this` bound to, each element in `collection`. + * are provided to each invoked method. If `path` is a function, it's invoked + * for, and `this` bound to, each element in `collection`. * * @static * @memberOf _ @@ -8758,7 +8967,7 @@ * _.invokeMap([123, 456], String.prototype.split, ''); * // => [['1', '2', '3'], ['4', '5', '6']] */ - var invokeMap = rest(function(collection, path, args) { + var invokeMap = baseRest(function(collection, path, args) { var index = -1, isFunc = typeof path == 'function', isProp = isKey(path), @@ -8782,7 +8991,7 @@ * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example @@ -8823,8 +9032,7 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Array} Returns the new mapped array. * @example * @@ -8906,8 +9114,7 @@ * @since 3.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the array of grouped elements. * @example * @@ -9018,8 +9225,7 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the new filtered array. * @see _.filter * @example @@ -9046,10 +9252,7 @@ */ function reject(collection, predicate) { var func = isArray(collection) ? arrayFilter : baseFilter; - predicate = getIteratee(predicate, 3); - return func(collection, function(value, index, collection) { - return !predicate(value, index, collection); - }); + return func(collection, negate(getIteratee(predicate, 3))); } /** @@ -9182,8 +9385,7 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {boolean} Returns `true` if any element passes the predicate check, * else `false`. @@ -9228,8 +9430,8 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [iteratees=[_.identity]] The iteratees to sort by. + * @param {...(Function|Function[])} [iteratees=[_.identity]] + * The iteratees to sort by. * @returns {Array} Returns the new sorted array. * @example * @@ -9251,7 +9453,7 @@ * }); * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] */ - var sortBy = rest(function(collection, iteratees) { + var sortBy = baseRest(function(collection, iteratees) { if (collection == null) { return []; } @@ -9261,11 +9463,7 @@ } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { iteratees = [iteratees[0]]; } - iteratees = (iteratees.length == 1 && isArray(iteratees[0])) - ? iteratees[0] - : baseFlatten(iteratees, 1, isFlattenableIteratee); - - return baseOrderBy(collection, iteratees, []); + return baseOrderBy(collection, baseFlatten(iteratees, 1), []); }); /*------------------------------------------------------------------------*/ @@ -9348,7 +9546,7 @@ function ary(func, n, guard) { n = guard ? undefined : n; n = (func && n == null) ? func.length : n; - return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n); + return createWrap(func, ARY_FLAG, undefined, undefined, undefined, undefined, n); } /** @@ -9366,7 +9564,7 @@ * @example * * jQuery(element).on('click', _.before(5, addContactToList)); - * // => allows adding up to 4 contacts to the list + * // => Allows adding up to 4 contacts to the list. */ function before(n, func) { var result; @@ -9405,9 +9603,9 @@ * @returns {Function} Returns the new bound function. * @example * - * var greet = function(greeting, punctuation) { + * function greet(greeting, punctuation) { * return greeting + ' ' + this.user + punctuation; - * }; + * } * * var object = { 'user': 'fred' }; * @@ -9420,13 +9618,13 @@ * bound('hi'); * // => 'hi fred!' */ - var bind = rest(function(func, thisArg, partials) { + var bind = baseRest(function(func, thisArg, partials) { var bitmask = BIND_FLAG; if (partials.length) { var holders = replaceHolders(partials, getHolder(bind)); bitmask |= PARTIAL_FLAG; } - return createWrapper(func, bitmask, thisArg, partials, holders); + return createWrap(func, bitmask, thisArg, partials, holders); }); /** @@ -9474,13 +9672,13 @@ * bound('hi'); * // => 'hiya fred!' */ - var bindKey = rest(function(object, key, partials) { + var bindKey = baseRest(function(object, key, partials) { var bitmask = BIND_FLAG | BIND_KEY_FLAG; if (partials.length) { var holders = replaceHolders(partials, getHolder(bindKey)); bitmask |= PARTIAL_FLAG; } - return createWrapper(key, bitmask, object, partials, holders); + return createWrap(key, bitmask, object, partials, holders); }); /** @@ -9526,7 +9724,7 @@ */ function curry(func, arity, guard) { arity = guard ? undefined : arity; - var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); + var result = createWrap(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); result.placeholder = curry.placeholder; return result; } @@ -9571,7 +9769,7 @@ */ function curryRight(func, arity, guard) { arity = guard ? undefined : arity; - var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); + var result = createWrap(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); result.placeholder = curryRight.placeholder; return result; } @@ -9709,6 +9907,9 @@ } function cancel() { + if (timerId !== undefined) { + clearTimeout(timerId); + } lastInvokeTime = 0; lastArgs = lastCallTime = lastThis = timerId = undefined; } @@ -9763,7 +9964,7 @@ * }, 'deferred'); * // => Logs 'deferred' after one or more milliseconds. */ - var defer = rest(function(func, args) { + var defer = baseRest(function(func, args) { return baseDelay(func, 1, args); }); @@ -9786,7 +9987,7 @@ * }, 1000, 'later'); * // => Logs 'later' after one second. */ - var delay = rest(function(func, wait, args) { + var delay = baseRest(function(func, wait, args) { return baseDelay(func, toNumber(wait) || 0, args); }); @@ -9809,7 +10010,7 @@ * // => ['d', 'c', 'b', 'a'] */ function flip(func) { - return createWrapper(func, FLIP_FLAG); + return createWrap(func, FLIP_FLAG); } /** @@ -9904,7 +10105,14 @@ throw new TypeError(FUNC_ERROR_TEXT); } return function() { - return !predicate.apply(this, arguments); + var args = arguments; + switch (args.length) { + case 0: return !predicate.call(this); + case 1: return !predicate.call(this, args[0]); + case 2: return !predicate.call(this, args[0], args[1]); + case 3: return !predicate.call(this, args[0], args[1], args[2]); + } + return !predicate.apply(this, args); }; } @@ -9924,23 +10132,22 @@ * var initialize = _.once(createApplication); * initialize(); * initialize(); - * // `initialize` invokes `createApplication` once + * // => `createApplication` is invoked once */ function once(func) { return before(2, func); } /** - * Creates a function that invokes `func` with arguments transformed by - * corresponding `transforms`. + * Creates a function that invokes `func` with its arguments transformed. * * @static * @since 4.0.0 * @memberOf _ * @category Function * @param {Function} func The function to wrap. - * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [transforms[_.identity]] The functions to transform. + * @param {...(Function|Function[])} [transforms=[_.identity]] + * The argument transforms. * @returns {Function} Returns the new function. * @example * @@ -9962,13 +10169,13 @@ * func(10, 5); * // => [100, 10] */ - var overArgs = rest(function(func, transforms) { + var overArgs = baseRest(function(func, transforms) { transforms = (transforms.length == 1 && isArray(transforms[0])) ? arrayMap(transforms[0], baseUnary(getIteratee())) - : arrayMap(baseFlatten(transforms, 1, isFlattenableIteratee), baseUnary(getIteratee())); + : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee())); var funcsLength = transforms.length; - return rest(function(args) { + return baseRest(function(args) { var index = -1, length = nativeMin(args.length, funcsLength); @@ -9999,9 +10206,9 @@ * @returns {Function} Returns the new partially applied function. * @example * - * var greet = function(greeting, name) { + * function greet(greeting, name) { * return greeting + ' ' + name; - * }; + * } * * var sayHelloTo = _.partial(greet, 'hello'); * sayHelloTo('fred'); @@ -10012,9 +10219,9 @@ * greetFred('hi'); * // => 'hi fred' */ - var partial = rest(function(func, partials) { + var partial = baseRest(function(func, partials) { var holders = replaceHolders(partials, getHolder(partial)); - return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders); + return createWrap(func, PARTIAL_FLAG, undefined, partials, holders); }); /** @@ -10036,9 +10243,9 @@ * @returns {Function} Returns the new partially applied function. * @example * - * var greet = function(greeting, name) { + * function greet(greeting, name) { * return greeting + ' ' + name; - * }; + * } * * var greetFred = _.partialRight(greet, 'fred'); * greetFred('hi'); @@ -10049,9 +10256,9 @@ * sayHelloTo('fred'); * // => 'hello fred' */ - var partialRight = rest(function(func, partials) { + var partialRight = baseRest(function(func, partials) { var holders = replaceHolders(partials, getHolder(partialRight)); - return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders); + return createWrap(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders); }); /** @@ -10076,8 +10283,8 @@ * rearged('b', 'c', 'a') * // => ['a', 'b', 'c'] */ - var rearg = rest(function(func, indexes) { - return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1)); + var rearg = baseRest(function(func, indexes) { + return createWrap(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1)); }); /** @@ -10109,29 +10316,8 @@ if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } - start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0); - return function() { - var args = arguments, - index = -1, - length = nativeMax(args.length - start, 0), - array = Array(length); - - while (++index < length) { - array[index] = args[start + index]; - } - switch (start) { - case 0: return func.call(this, array); - case 1: return func.call(this, args[0], array); - case 2: return func.call(this, args[0], args[1], array); - } - var otherArgs = Array(start + 1); - index = -1; - while (++index < start) { - otherArgs[index] = args[index]; - } - otherArgs[start] = array; - return apply(func, this, otherArgs); - }; + start = start === undefined ? start : toInteger(start); + return baseRest(func, start); } /** @@ -10173,7 +10359,7 @@ throw new TypeError(FUNC_ERROR_TEXT); } start = start === undefined ? 0 : nativeMax(toInteger(start), 0); - return rest(function(args) { + return baseRest(function(args) { var array = args[start], otherArgs = castSlice(args, 0, start); @@ -10263,10 +10449,10 @@ } /** - * Creates a function that provides `value` to the wrapper function as its - * first argument. Any additional arguments provided to the function are - * appended to those provided to the wrapper function. The wrapper is invoked - * with the `this` binding of the created function. + * Creates a function that provides `value` to `wrapper` as its first + * argument. Any additional arguments provided to the function are appended + * to those provided to the `wrapper`. The wrapper is invoked with the `this` + * binding of the created function. * * @static * @memberOf _ @@ -10451,6 +10637,32 @@ return baseClone(value, true, true, customizer); } + /** + * Checks if `object` conforms to `source` by invoking the predicate properties + * of `source` with the corresponding property values of `object`. This method + * is equivalent to a `_.conforms` function when `source` is partially applied. + * + * @static + * @memberOf _ + * @since 4.14.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + * @example + * + * var object = { 'a': 1, 'b': 2 }; + * + * _.conformsTo(object, { 'b': function(n) { return n > 1; } }); + * // => true + * + * _.conformsTo(object, { 'b': function(n) { return n > 2; } }); + * // => false + */ + function conformsTo(object, source) { + return source == null || baseConformsTo(object, source, keys(source)); + } + /** * Performs a * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) @@ -10465,8 +10677,8 @@ * @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @example * - * var object = { 'user': 'fred' }; - * var other = { 'user': 'fred' }; + * var object = { 'a': 1 }; + * var other = { 'a': 1 }; * * _.eq(object, object); * // => true @@ -10547,7 +10759,7 @@ * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, + * @returns {boolean} Returns `true` if `value` is an `arguments` object, * else `false`. * @example * @@ -10569,11 +10781,9 @@ * @static * @memberOf _ * @since 0.1.0 - * @type {Function} * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is an array, else `false`. * @example * * _.isArray([1, 2, 3]); @@ -10598,8 +10808,7 @@ * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. * @example * * _.isArrayBuffer(new ArrayBuffer(2)); @@ -10608,9 +10817,7 @@ * _.isArrayBuffer(new Array(2)); * // => false */ - function isArrayBuffer(value) { - return isObjectLike(value) && objectToString.call(value) == arrayBufferTag; - } + var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer; /** * Checks if `value` is array-like. A value is considered array-like if it's @@ -10678,8 +10885,7 @@ * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a boolean, else `false`. * @example * * _.isBoolean(false); @@ -10710,9 +10916,7 @@ * _.isBuffer(new Uint8Array(2)); * // => false */ - var isBuffer = !Buffer ? stubFalse : function(value) { - return value instanceof Buffer; - }; + var isBuffer = nativeIsBuffer || stubFalse; /** * Checks if `value` is classified as a `Date` object. @@ -10722,8 +10926,7 @@ * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a date object, else `false`. * @example * * _.isDate(new Date); @@ -10732,9 +10935,7 @@ * _.isDate('Mon April 23 2012'); * // => false */ - function isDate(value) { - return isObjectLike(value) && objectToString.call(value) == dateTag; - } + var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate; /** * Checks if `value` is likely a DOM element. @@ -10831,8 +11032,8 @@ * else `false`. * @example * - * var object = { 'user': 'fred' }; - * var other = { 'user': 'fred' }; + * var object = { 'a': 1 }; + * var other = { 'a': 1 }; * * _.isEqual(object, other); * // => true @@ -10949,8 +11150,7 @@ * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. * @example * * _.isFunction(_); @@ -11095,8 +11295,7 @@ * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a map, else `false`. * @example * * _.isMap(new Map); @@ -11105,9 +11304,7 @@ * _.isMap(new WeakMap); * // => false */ - function isMap(value) { - return isObjectLike(value) && getTag(value) == mapTag; - } + var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap; /** * Performs a partial deep comparison between `object` and `source` to @@ -11125,12 +11322,12 @@ * @returns {boolean} Returns `true` if `object` is a match, else `false`. * @example * - * var object = { 'user': 'fred', 'age': 40 }; + * var object = { 'a': 1, 'b': 2 }; * - * _.isMatch(object, { 'age': 40 }); + * _.isMatch(object, { 'b': 2 }); * // => true * - * _.isMatch(object, { 'age': 36 }); + * _.isMatch(object, { 'b': 1 }); * // => false */ function isMatch(object, source) { @@ -11212,13 +11409,13 @@ /** * Checks if `value` is a pristine native function. * - * **Note:** This method can't reliably detect native functions in the - * presence of the `core-js` package because `core-js` circumvents this kind - * of detection. Despite multiple requests, the `core-js` maintainer has made - * it clear: any attempt to fix the detection will be obstructed. As a result, - * we're left with little choice but to throw an error. Unfortunately, this - * also affects packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill), - * which rely on `core-js`. + * **Note:** This method can't reliably detect native functions in the presence + * of the core-js package because core-js circumvents this kind of detection. + * Despite multiple requests, the core-js maintainer has made it clear: any + * attempt to fix the detection will be obstructed. As a result, we're left + * with little choice but to throw an error. Unfortunately, this also affects + * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill), + * which rely on core-js. * * @static * @memberOf _ @@ -11237,7 +11434,7 @@ */ function isNative(value) { if (isMaskable(value)) { - throw new Error('This method is not supported with `core-js`. Try https://github.com/es-shims.'); + throw new Error('This method is not supported with core-js. Try https://github.com/es-shims.'); } return baseIsNative(value); } @@ -11298,8 +11495,7 @@ * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a number, else `false`. * @example * * _.isNumber(3); @@ -11370,8 +11566,7 @@ * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. * @example * * _.isRegExp(/abc/); @@ -11380,9 +11575,7 @@ * _.isRegExp('/abc/'); * // => false */ - function isRegExp(value) { - return isObject(value) && objectToString.call(value) == regexpTag; - } + var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp; /** * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754 @@ -11424,8 +11617,7 @@ * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a set, else `false`. * @example * * _.isSet(new Set); @@ -11434,9 +11626,7 @@ * _.isSet(new WeakSet); * // => false */ - function isSet(value) { - return isObjectLike(value) && getTag(value) == setTag; - } + var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet; /** * Checks if `value` is classified as a `String` primitive or object. @@ -11446,8 +11636,7 @@ * @memberOf _ * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a string, else `false`. * @example * * _.isString('abc'); @@ -11469,8 +11658,7 @@ * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. * @example * * _.isSymbol(Symbol.iterator); @@ -11492,8 +11680,7 @@ * @since 3.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. * @example * * _.isTypedArray(new Uint8Array); @@ -11502,10 +11689,7 @@ * _.isTypedArray([]); * // => false */ - function isTypedArray(value) { - return isObjectLike(value) && - isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; - } + var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; /** * Checks if `value` is `undefined`. @@ -11536,8 +11720,7 @@ * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a weak map, else `false`. * @example * * _.isWeakMap(new WeakMap); @@ -11558,8 +11741,7 @@ * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a weak set, else `false`. * @example * * _.isWeakSet(new WeakSet); @@ -11908,18 +12090,18 @@ * @example * * function Foo() { - * this.c = 3; + * this.a = 1; * } * * function Bar() { - * this.e = 5; + * this.c = 3; * } * - * Foo.prototype.d = 4; - * Bar.prototype.f = 6; + * Foo.prototype.b = 2; + * Bar.prototype.d = 4; * - * _.assign({ 'a': 1 }, new Foo, new Bar); - * // => { 'a': 1, 'c': 3, 'e': 5 } + * _.assign({ 'a': 0 }, new Foo, new Bar); + * // => { 'a': 1, 'c': 3 } */ var assign = createAssigner(function(object, source) { if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) { @@ -11951,18 +12133,18 @@ * @example * * function Foo() { - * this.b = 2; + * this.a = 1; * } * * function Bar() { - * this.d = 4; + * this.c = 3; * } * - * Foo.prototype.c = 3; - * Bar.prototype.e = 5; + * Foo.prototype.b = 2; + * Bar.prototype.d = 4; * - * _.assignIn({ 'a': 1 }, new Foo, new Bar); - * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 } + * _.assignIn({ 'a': 0 }, new Foo, new Bar); + * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } */ var assignIn = createAssigner(function(object, source) { if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) { @@ -12056,7 +12238,7 @@ * _.at(object, ['a[0].b.c', 'a[1]']); * // => [3, 4] */ - var at = rest(function(object, paths) { + var at = baseRest(function(object, paths) { return baseAt(object, baseFlatten(paths, 1)); }); @@ -12117,10 +12299,10 @@ * @see _.defaultsDeep * @example * - * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); - * // => { 'user': 'barney', 'age': 36 } + * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); + * // => { 'a': 1, 'b': 2 } */ - var defaults = rest(function(args) { + var defaults = baseRest(function(args) { args.push(undefined, assignInDefaults); return apply(assignInWith, undefined, args); }); @@ -12141,11 +12323,10 @@ * @see _.defaults * @example * - * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } }); - * // => { 'user': { 'name': 'barney', 'age': 36 } } - * + * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }); + * // => { 'a': { 'b': 2, 'c': 3 } } */ - var defaultsDeep = rest(function(args) { + var defaultsDeep = baseRest(function(args) { args.push(undefined, mergeDefaults); return apply(mergeWith, undefined, args); }); @@ -12159,8 +12340,7 @@ * @since 1.1.0 * @category Object * @param {Object} object The object to search. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {string|undefined} Returns the key of the matched element, * else `undefined`. * @example @@ -12199,8 +12379,7 @@ * @since 2.0.0 * @category Object * @param {Object} object The object to search. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {string|undefined} Returns the key of the matched element, * else `undefined`. * @example @@ -12414,7 +12593,7 @@ /** * Gets the value at `path` of `object`. If the resolved value is - * `undefined`, the `defaultValue` is used in its place. + * `undefined`, the `defaultValue` is returned in its place. * * @static * @memberOf _ @@ -12537,8 +12716,7 @@ * @since 4.1.0 * @category Object * @param {Object} object The object to invert. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Object} Returns the new inverted object. * @example * @@ -12578,7 +12756,7 @@ * _.invoke(object, 'a[0].b.c.slice', 1, 3); * // => [2, 3] */ - var invoke = rest(baseInvoke); + var invoke = baseRest(baseInvoke); /** * Creates an array of the own enumerable property names of `object`. @@ -12682,8 +12860,7 @@ * @since 3.8.0 * @category Object * @param {Object} object The object to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Object} Returns the new mapped object. * @see _.mapValues * @example @@ -12714,8 +12891,7 @@ * @since 2.4.0 * @category Object * @param {Object} object The object to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Object} Returns the new mapped object. * @see _.mapKeys * @example @@ -12762,16 +12938,16 @@ * @returns {Object} Returns `object`. * @example * - * var users = { - * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }] + * var object = { + * 'a': [{ 'b': 2 }, { 'd': 4 }] * }; * - * var ages = { - * 'data': [{ 'age': 36 }, { 'age': 40 }] + * var other = { + * 'a': [{ 'c': 3 }, { 'e': 5 }] * }; * - * _.merge(users, ages); - * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] } + * _.merge(object, other); + * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } */ var merge = createAssigner(function(object, source, srcIndex) { baseMerge(object, source, srcIndex); @@ -12802,18 +12978,11 @@ * } * } * - * var object = { - * 'fruits': ['apple'], - * 'vegetables': ['beet'] - * }; - * - * var other = { - * 'fruits': ['banana'], - * 'vegetables': ['carrot'] - * }; + * var object = { 'a': [1], 'b': [2] }; + * var other = { 'a': [3], 'b': [4] }; * * _.mergeWith(object, other, customizer); - * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] } + * // => { 'a': [1, 3], 'b': [2, 4] } */ var mergeWith = createAssigner(function(object, source, srcIndex, customizer) { baseMerge(object, source, srcIndex, customizer); @@ -12838,7 +13007,7 @@ * _.omit(object, ['a', 'c']); * // => { 'b': '2' } */ - var omit = rest(function(object, props) { + var omit = baseRest(function(object, props) { if (object == null) { return {}; } @@ -12857,8 +13026,7 @@ * @since 4.0.0 * @category Object * @param {Object} object The source object. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per property. + * @param {Function} [predicate=_.identity] The function invoked per property. * @returns {Object} Returns the new object. * @example * @@ -12868,10 +13036,7 @@ * // => { 'b': '2' } */ function omitBy(object, predicate) { - predicate = getIteratee(predicate); - return basePickBy(object, function(value, key) { - return !predicate(value, key); - }); + return pickBy(object, negate(getIteratee(predicate))); } /** @@ -12891,7 +13056,7 @@ * _.pick(object, ['a', 'c']); * // => { 'a': 1, 'c': 3 } */ - var pick = rest(function(object, props) { + var pick = baseRest(function(object, props) { return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey)); }); @@ -12904,8 +13069,7 @@ * @since 4.0.0 * @category Object * @param {Object} object The source object. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per property. + * @param {Function} [predicate=_.identity] The function invoked per property. * @returns {Object} Returns the new object. * @example * @@ -12915,7 +13079,7 @@ * // => { 'a': 1, 'c': 3 } */ function pickBy(object, predicate) { - return object == null ? {} : basePickBy(object, getIteratee(predicate)); + return object == null ? {} : basePickBy(object, getAllKeysIn(object), getIteratee(predicate)); } /** @@ -13540,8 +13704,9 @@ ? length : baseClamp(toInteger(position), 0, length); + var end = position; position -= target.length; - return position >= 0 && string.indexOf(target, position) == position; + return position >= 0 && string.slice(position, end) == target; } /** @@ -13989,7 +14154,8 @@ function startsWith(string, target, position) { string = toString(string); position = baseClamp(toInteger(position), 0, string.length); - return string.lastIndexOf(baseToString(target), position) == position; + target = baseToString(target); + return string.slice(position, position + target.length) == target; } /** @@ -14572,7 +14738,7 @@ * elements = []; * } */ - var attempt = rest(function(func, args) { + var attempt = baseRest(function(func, args) { try { return apply(func, undefined, args); } catch (e) { @@ -14597,16 +14763,16 @@ * * var view = { * 'label': 'docs', - * 'onClick': function() { + * 'click': function() { * console.log('clicked ' + this.label); * } * }; * - * _.bindAll(view, ['onClick']); - * jQuery(element).on('click', view.onClick); + * _.bindAll(view, ['click']); + * jQuery(element).on('click', view.click); * // => Logs 'clicked docs' when clicked. */ - var bindAll = rest(function(object, methodNames) { + var bindAll = baseRest(function(object, methodNames) { arrayEach(baseFlatten(methodNames, 1), function(key) { key = toKey(key); object[key] = bind(object[key], object); @@ -14631,7 +14797,7 @@ * var func = _.cond([ * [_.matches({ 'a': 1 }), _.constant('matches A')], * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')], - * [_.constant(true), _.constant('no match')] + * [_.stubTrue, _.constant('no match')] * ]); * * func({ 'a': 1, 'b': 2 }); @@ -14654,7 +14820,7 @@ return [toIteratee(pair[0]), pair[1]]; }); - return rest(function(args) { + return baseRest(function(args) { var index = -1; while (++index < length) { var pair = pairs[index]; @@ -14678,13 +14844,13 @@ * @returns {Function} Returns the new spec function. * @example * - * var users = [ - * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 40 } + * var objects = [ + * { 'a': 2, 'b': 1 }, + * { 'a': 1, 'b': 2 } * ]; * - * _.filter(users, _.conforms({ 'age': function(n) { return n > 38; } })); - * // => [{ 'user': 'fred', 'age': 40 }] + * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } })); + * // => [{ 'a': 1, 'b': 2 }] */ function conforms(source) { return baseConforms(baseClone(source, true)); @@ -14715,6 +14881,30 @@ }; } + /** + * Checks `value` to determine whether a default value should be returned in + * its place. The `defaultValue` is returned if `value` is `NaN`, `null`, + * or `undefined`. + * + * @static + * @memberOf _ + * @since 4.14.0 + * @category Util + * @param {*} value The value to check. + * @param {*} defaultValue The default value. + * @returns {*} Returns the resolved value. + * @example + * + * _.defaultTo(1, 10); + * // => 1 + * + * _.defaultTo(undefined, 10); + * // => 10 + */ + function defaultTo(value, defaultValue) { + return (value == null || value !== value) ? defaultValue : value; + } + /** * Creates a function that returns the result of invoking the given functions * with the `this` binding of the created function, where each successive @@ -14724,7 +14914,7 @@ * @memberOf _ * @since 3.0.0 * @category Util - * @param {...(Function|Function[])} [funcs] Functions to invoke. + * @param {...(Function|Function[])} [funcs] The functions to invoke. * @returns {Function} Returns the new composite function. * @see _.flowRight * @example @@ -14747,7 +14937,7 @@ * @since 3.0.0 * @memberOf _ * @category Util - * @param {...(Function|Function[])} [funcs] Functions to invoke. + * @param {...(Function|Function[])} [funcs] The functions to invoke. * @returns {Function} Returns the new composite function. * @see _.flow * @example @@ -14763,7 +14953,7 @@ var flowRight = createFlow(true); /** - * This method returns the first argument given to it. + * This method returns the first argument it receives. * * @static * @since 0.1.0 @@ -14773,7 +14963,7 @@ * @returns {*} Returns `value`. * @example * - * var object = { 'user': 'fred' }; + * var object = { 'a': 1 }; * * console.log(_.identity(object) === object); * // => true @@ -14844,13 +15034,13 @@ * @returns {Function} Returns the new spec function. * @example * - * var users = [ - * { 'user': 'barney', 'age': 36, 'active': true }, - * { 'user': 'fred', 'age': 40, 'active': false } + * var objects = [ + * { 'a': 1, 'b': 2, 'c': 3 }, + * { 'a': 4, 'b': 5, 'c': 6 } * ]; * - * _.filter(users, _.matches({ 'age': 40, 'active': false })); - * // => [{ 'user': 'fred', 'age': 40, 'active': false }] + * _.filter(objects, _.matches({ 'a': 4, 'c': 6 })); + * // => [{ 'a': 4, 'b': 5, 'c': 6 }] */ function matches(source) { return baseMatches(baseClone(source, true)); @@ -14872,13 +15062,13 @@ * @returns {Function} Returns the new spec function. * @example * - * var users = [ - * { 'user': 'barney' }, - * { 'user': 'fred' } + * var objects = [ + * { 'a': 1, 'b': 2, 'c': 3 }, + * { 'a': 4, 'b': 5, 'c': 6 } * ]; * - * _.find(users, _.matchesProperty('user', 'fred')); - * // => { 'user': 'fred' } + * _.find(objects, _.matchesProperty('a', 4)); + * // => { 'a': 4, 'b': 5, 'c': 6 } */ function matchesProperty(path, srcValue) { return baseMatchesProperty(path, baseClone(srcValue, true)); @@ -14908,7 +15098,7 @@ * _.map(objects, _.method(['a', 'b'])); * // => [2, 1] */ - var method = rest(function(path, args) { + var method = baseRest(function(path, args) { return function(object) { return baseInvoke(object, path, args); }; @@ -14937,7 +15127,7 @@ * _.map([['a', '2'], ['c', '0']], _.methodOf(object)); * // => [2, 0] */ - var methodOf = rest(function(object, args) { + var methodOf = baseRest(function(object, args) { return function(path) { return baseInvoke(object, path, args); }; @@ -15036,7 +15226,7 @@ } /** - * A method that returns `undefined`. + * This method returns `undefined`. * * @static * @memberOf _ @@ -15073,7 +15263,7 @@ */ function nthArg(n) { n = toInteger(n); - return rest(function(args) { + return baseRest(function(args) { return baseNth(args, n); }); } @@ -15086,8 +15276,8 @@ * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [iteratees=[_.identity]] The iteratees to invoke. + * @param {...(Function|Function[])} [iteratees=[_.identity]] + * The iteratees to invoke. * @returns {Function} Returns the new function. * @example * @@ -15106,8 +15296,8 @@ * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [predicates=[_.identity]] The predicates to check. + * @param {...(Function|Function[])} [predicates=[_.identity]] + * The predicates to check. * @returns {Function} Returns the new function. * @example * @@ -15132,8 +15322,8 @@ * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [predicates=[_.identity]] The predicates to check. + * @param {...(Function|Function[])} [predicates=[_.identity]] + * The predicates to check. * @returns {Function} Returns the new function. * @example * @@ -15285,7 +15475,7 @@ var rangeRight = createRange(true); /** - * A method that returns a new empty array. + * This method returns a new empty array. * * @static * @memberOf _ @@ -15307,7 +15497,7 @@ } /** - * A method that returns `false`. + * This method returns `false`. * * @static * @memberOf _ @@ -15324,7 +15514,7 @@ } /** - * A method that returns a new empty object. + * This method returns a new empty object. * * @static * @memberOf _ @@ -15346,7 +15536,7 @@ } /** - * A method that returns an empty string. + * This method returns an empty string. * * @static * @memberOf _ @@ -15363,7 +15553,7 @@ } /** - * A method that returns `true`. + * This method returns `true`. * * @static * @memberOf _ @@ -15481,7 +15671,7 @@ */ var add = createMathOperation(function(augend, addend) { return augend + addend; - }); + }, 0); /** * Computes `number` rounded up to `precision`. @@ -15523,7 +15713,7 @@ */ var divide = createMathOperation(function(dividend, divisor) { return dividend / divisor; - }); + }, 1); /** * Computes `number` rounded down to `precision`. @@ -15582,8 +15772,7 @@ * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {*} Returns the maximum value. * @example * @@ -15598,7 +15787,7 @@ */ function maxBy(array, iteratee) { return (array && array.length) - ? baseExtremum(array, getIteratee(iteratee), baseGt) + ? baseExtremum(array, getIteratee(iteratee, 2), baseGt) : undefined; } @@ -15630,8 +15819,7 @@ * @since 4.7.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {number} Returns the mean. * @example * @@ -15645,7 +15833,7 @@ * // => 5 */ function meanBy(array, iteratee) { - return baseMean(array, getIteratee(iteratee)); + return baseMean(array, getIteratee(iteratee, 2)); } /** @@ -15682,8 +15870,7 @@ * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {*} Returns the minimum value. * @example * @@ -15698,7 +15885,7 @@ */ function minBy(array, iteratee) { return (array && array.length) - ? baseExtremum(array, getIteratee(iteratee), baseLt) + ? baseExtremum(array, getIteratee(iteratee, 2), baseLt) : undefined; } @@ -15719,7 +15906,7 @@ */ var multiply = createMathOperation(function(multiplier, multiplicand) { return multiplier * multiplicand; - }); + }, 1); /** * Computes `number` rounded to `precision`. @@ -15761,7 +15948,7 @@ */ var subtract = createMathOperation(function(minuend, subtrahend) { return minuend - subtrahend; - }); + }, 0); /** * Computes the sum of the values in `array`. @@ -15793,8 +15980,7 @@ * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {number} Returns the sum. * @example * @@ -15809,7 +15995,7 @@ */ function sumBy(array, iteratee) { return (array && array.length) - ? baseSum(array, getIteratee(iteratee)) + ? baseSum(array, getIteratee(iteratee, 2)) : 0; } @@ -15988,7 +16174,9 @@ lodash.cloneDeep = cloneDeep; lodash.cloneDeepWith = cloneDeepWith; lodash.cloneWith = cloneWith; + lodash.conformsTo = conformsTo; lodash.deburr = deburr; + lodash.defaultTo = defaultTo; lodash.divide = divide; lodash.endsWith = endsWith; lodash.eq = eq; @@ -16229,7 +16417,7 @@ return this.reverse().find(predicate); }; - LazyWrapper.prototype.invokeMap = rest(function(path, args) { + LazyWrapper.prototype.invokeMap = baseRest(function(path, args) { if (typeof path == 'function') { return new LazyWrapper(this); } @@ -16239,10 +16427,7 @@ }); LazyWrapper.prototype.reject = function(predicate) { - predicate = getIteratee(predicate, 3); - return this.filter(function(value) { - return !predicate(value); - }); + return this.filter(negate(getIteratee(predicate))); }; LazyWrapper.prototype.slice = function(start, end) { @@ -16346,7 +16531,7 @@ } }); - realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ + realNames[createHybrid(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }]; @@ -16365,6 +16550,9 @@ lodash.prototype.reverse = wrapperReverse; lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue; + // Add lazy aliases. + lodash.prototype.first = lodash.prototype.head; + if (iteratorSymbol) { lodash.prototype[iteratorSymbol] = wrapperToIterator; } @@ -16376,7 +16564,7 @@ // Export lodash. var _ = runInContext(); - // Some AMD build optimizers like r.js check for condition patterns like the following: + // Some AMD build optimizers, like r.js, check for condition patterns like: if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { // Define as an anonymous module so, through path mapping, it can be // referenced as the "underscore" module. diff --git a/map.js b/map.js index 32780cc15..3fd265b5f 100644 --- a/map.js +++ b/map.js @@ -19,8 +19,7 @@ define(['./_arrayMap', './_baseIteratee', './_baseMap', './isArray'], function(a * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Array} Returns the new mapped array. * @example * diff --git a/mapKeys.js b/mapKeys.js index 18808948c..5eade74ac 100644 --- a/mapKeys.js +++ b/mapKeys.js @@ -11,8 +11,7 @@ define(['./_baseForOwn', './_baseIteratee'], function(baseForOwn, baseIteratee) * @since 3.8.0 * @category Object * @param {Object} object The object to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Object} Returns the new mapped object. * @see _.mapValues * @example diff --git a/mapValues.js b/mapValues.js index 5406aeb32..997eec8c9 100644 --- a/mapValues.js +++ b/mapValues.js @@ -11,8 +11,7 @@ define(['./_baseForOwn', './_baseIteratee'], function(baseForOwn, baseIteratee) * @since 2.4.0 * @category Object * @param {Object} object The object to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Object} Returns the new mapped object. * @see _.mapKeys * @example diff --git a/matches.js b/matches.js index 95976e202..8487fe63c 100644 --- a/matches.js +++ b/matches.js @@ -16,13 +16,13 @@ define(['./_baseClone', './_baseMatches'], function(baseClone, baseMatches) { * @returns {Function} Returns the new spec function. * @example * - * var users = [ - * { 'user': 'barney', 'age': 36, 'active': true }, - * { 'user': 'fred', 'age': 40, 'active': false } + * var objects = [ + * { 'a': 1, 'b': 2, 'c': 3 }, + * { 'a': 4, 'b': 5, 'c': 6 } * ]; * - * _.filter(users, _.matches({ 'age': 40, 'active': false })); - * // => [{ 'user': 'fred', 'age': 40, 'active': false }] + * _.filter(objects, _.matches({ 'a': 4, 'c': 6 })); + * // => [{ 'a': 4, 'b': 5, 'c': 6 }] */ function matches(source) { return baseMatches(baseClone(source, true)); diff --git a/matchesProperty.js b/matchesProperty.js index 0ad8573d7..930e19eb7 100644 --- a/matchesProperty.js +++ b/matchesProperty.js @@ -16,13 +16,13 @@ define(['./_baseClone', './_baseMatchesProperty'], function(baseClone, baseMatch * @returns {Function} Returns the new spec function. * @example * - * var users = [ - * { 'user': 'barney' }, - * { 'user': 'fred' } + * var objects = [ + * { 'a': 1, 'b': 2, 'c': 3 }, + * { 'a': 4, 'b': 5, 'c': 6 } * ]; * - * _.find(users, _.matchesProperty('user', 'fred')); - * // => { 'user': 'fred' } + * _.find(objects, _.matchesProperty('a', 4)); + * // => { 'a': 4, 'b': 5, 'c': 6 } */ function matchesProperty(path, srcValue) { return baseMatchesProperty(path, baseClone(srcValue, true)); diff --git a/maxBy.js b/maxBy.js index 36230a3f8..7a82ac00a 100644 --- a/maxBy.js +++ b/maxBy.js @@ -13,8 +13,7 @@ define(['./_baseExtremum', './_baseGt', './_baseIteratee'], function(baseExtremu * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {*} Returns the maximum value. * @example * @@ -29,7 +28,7 @@ define(['./_baseExtremum', './_baseGt', './_baseIteratee'], function(baseExtremu */ function maxBy(array, iteratee) { return (array && array.length) - ? baseExtremum(array, baseIteratee(iteratee), baseGt) + ? baseExtremum(array, baseIteratee(iteratee, 2), baseGt) : undefined; } diff --git a/meanBy.js b/meanBy.js index 567258316..fe3b83dce 100644 --- a/meanBy.js +++ b/meanBy.js @@ -10,8 +10,7 @@ define(['./_baseIteratee', './_baseMean'], function(baseIteratee, baseMean) { * @since 4.7.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {number} Returns the mean. * @example * @@ -25,7 +24,7 @@ define(['./_baseIteratee', './_baseMean'], function(baseIteratee, baseMean) { * // => 5 */ function meanBy(array, iteratee) { - return baseMean(array, baseIteratee(iteratee)); + return baseMean(array, baseIteratee(iteratee, 2)); } return meanBy; diff --git a/merge.js b/merge.js index 301fc3061..daea7bf0b 100644 --- a/merge.js +++ b/merge.js @@ -20,16 +20,16 @@ define(['./_baseMerge', './_createAssigner'], function(baseMerge, createAssigner * @returns {Object} Returns `object`. * @example * - * var users = { - * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }] + * var object = { + * 'a': [{ 'b': 2 }, { 'd': 4 }] * }; * - * var ages = { - * 'data': [{ 'age': 36 }, { 'age': 40 }] + * var other = { + * 'a': [{ 'c': 3 }, { 'e': 5 }] * }; * - * _.merge(users, ages); - * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] } + * _.merge(object, other); + * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } */ var merge = createAssigner(function(object, source, srcIndex) { baseMerge(object, source, srcIndex); diff --git a/mergeWith.js b/mergeWith.js index 5c3470fd8..b4da681f9 100644 --- a/mergeWith.js +++ b/mergeWith.js @@ -25,18 +25,11 @@ define(['./_baseMerge', './_createAssigner'], function(baseMerge, createAssigner * } * } * - * var object = { - * 'fruits': ['apple'], - * 'vegetables': ['beet'] - * }; - * - * var other = { - * 'fruits': ['banana'], - * 'vegetables': ['carrot'] - * }; + * var object = { 'a': [1], 'b': [2] }; + * var other = { 'a': [3], 'b': [4] }; * * _.mergeWith(object, other, customizer); - * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] } + * // => { 'a': [1, 3], 'b': [2, 4] } */ var mergeWith = createAssigner(function(object, source, srcIndex, customizer) { baseMerge(object, source, srcIndex, customizer); diff --git a/method.js b/method.js index 010733023..c538942f7 100644 --- a/method.js +++ b/method.js @@ -1,4 +1,4 @@ -define(['./_baseInvoke', './rest'], function(baseInvoke, rest) { +define(['./_baseInvoke', './_baseRest'], function(baseInvoke, baseRest) { /** * Creates a function that invokes the method at `path` of a given object. @@ -24,7 +24,7 @@ define(['./_baseInvoke', './rest'], function(baseInvoke, rest) { * _.map(objects, _.method(['a', 'b'])); * // => [2, 1] */ - var method = rest(function(path, args) { + var method = baseRest(function(path, args) { return function(object) { return baseInvoke(object, path, args); }; diff --git a/methodOf.js b/methodOf.js index 79222fb87..76bd6431e 100644 --- a/methodOf.js +++ b/methodOf.js @@ -1,4 +1,4 @@ -define(['./_baseInvoke', './rest'], function(baseInvoke, rest) { +define(['./_baseInvoke', './_baseRest'], function(baseInvoke, baseRest) { /** * The opposite of `_.method`; this method creates a function that invokes @@ -23,7 +23,7 @@ define(['./_baseInvoke', './rest'], function(baseInvoke, rest) { * _.map([['a', '2'], ['c', '0']], _.methodOf(object)); * // => [2, 0] */ - var methodOf = rest(function(object, args) { + var methodOf = baseRest(function(object, args) { return function(path) { return baseInvoke(object, path, args); }; diff --git a/minBy.js b/minBy.js index 9b74a4ade..1fe8e7c86 100644 --- a/minBy.js +++ b/minBy.js @@ -13,8 +13,7 @@ define(['./_baseExtremum', './_baseIteratee', './_baseLt'], function(baseExtremu * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {*} Returns the minimum value. * @example * @@ -29,7 +28,7 @@ define(['./_baseExtremum', './_baseIteratee', './_baseLt'], function(baseExtremu */ function minBy(array, iteratee) { return (array && array.length) - ? baseExtremum(array, baseIteratee(iteratee), baseLt) + ? baseExtremum(array, baseIteratee(iteratee, 2), baseLt) : undefined; } diff --git a/multiply.js b/multiply.js index 3967deca1..11eacb4d9 100644 --- a/multiply.js +++ b/multiply.js @@ -17,7 +17,7 @@ define(['./_createMathOperation'], function(createMathOperation) { */ var multiply = createMathOperation(function(multiplier, multiplicand) { return multiplier * multiplicand; - }); + }, 1); return multiply; }); diff --git a/negate.js b/negate.js index 036045a08..53a6c94e7 100644 --- a/negate.js +++ b/negate.js @@ -28,7 +28,14 @@ define([], function() { throw new TypeError(FUNC_ERROR_TEXT); } return function() { - return !predicate.apply(this, arguments); + var args = arguments; + switch (args.length) { + case 0: return !predicate.call(this); + case 1: return !predicate.call(this, args[0]); + case 2: return !predicate.call(this, args[0], args[1]); + case 3: return !predicate.call(this, args[0], args[1], args[2]); + } + return !predicate.apply(this, args); }; } diff --git a/noop.js b/noop.js index 368703430..1d16e385f 100644 --- a/noop.js +++ b/noop.js @@ -1,7 +1,7 @@ define([], function() { /** - * A method that returns `undefined`. + * This method returns `undefined`. * * @static * @memberOf _ diff --git a/nthArg.js b/nthArg.js index 44486893b..3e70fa91e 100644 --- a/nthArg.js +++ b/nthArg.js @@ -1,4 +1,4 @@ -define(['./_baseNth', './rest', './toInteger'], function(baseNth, rest, toInteger) { +define(['./_baseNth', './_baseRest', './toInteger'], function(baseNth, baseRest, toInteger) { /** * Creates a function that gets the argument at index `n`. If `n` is negative, @@ -22,7 +22,7 @@ define(['./_baseNth', './rest', './toInteger'], function(baseNth, rest, toIntege */ function nthArg(n) { n = toInteger(n); - return rest(function(args) { + return baseRest(function(args) { return baseNth(args, n); }); } diff --git a/object.js b/object.js index d3e63db36..5fa5025f2 100644 --- a/object.js +++ b/object.js @@ -1,9 +1,10 @@ -define(['./assign', './assignIn', './assignInWith', './assignWith', './create', './defaults', './defaultsDeep', './entries', './entriesIn', './extend', './extendWith', './findKey', './findLastKey', './forIn', './forInRight', './forOwn', './forOwnRight', './functions', './functionsIn', './get', './has', './hasIn', './invert', './invertBy', './invoke', './keys', './keysIn', './mapKeys', './mapValues', './merge', './mergeWith', './omit', './omitBy', './pick', './pickBy', './result', './set', './setWith', './toPairs', './toPairsIn', './transform', './unset', './update', './updateWith', './values', './valuesIn'], function(assign, assignIn, assignInWith, assignWith, create, defaults, defaultsDeep, entries, entriesIn, extend, extendWith, findKey, findLastKey, forIn, forInRight, forOwn, forOwnRight, functions, functionsIn, get, has, hasIn, invert, invertBy, invoke, keys, keysIn, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, result, set, setWith, toPairs, toPairsIn, transform, unset, update, updateWith, values, valuesIn) { +define(['./assign', './assignIn', './assignInWith', './assignWith', './at', './create', './defaults', './defaultsDeep', './entries', './entriesIn', './extend', './extendWith', './findKey', './findLastKey', './forIn', './forInRight', './forOwn', './forOwnRight', './functions', './functionsIn', './get', './has', './hasIn', './invert', './invertBy', './invoke', './keys', './keysIn', './mapKeys', './mapValues', './merge', './mergeWith', './omit', './omitBy', './pick', './pickBy', './result', './set', './setWith', './toPairs', './toPairsIn', './transform', './unset', './update', './updateWith', './values', './valuesIn'], function(assign, assignIn, assignInWith, assignWith, at, create, defaults, defaultsDeep, entries, entriesIn, extend, extendWith, findKey, findLastKey, forIn, forInRight, forOwn, forOwnRight, functions, functionsIn, get, has, hasIn, invert, invertBy, invoke, keys, keysIn, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, result, set, setWith, toPairs, toPairsIn, transform, unset, update, updateWith, values, valuesIn) { return { 'assign': assign, 'assignIn': assignIn, 'assignInWith': assignInWith, 'assignWith': assignWith, + 'at': at, 'create': create, 'defaults': defaults, 'defaultsDeep': defaultsDeep, diff --git a/omit.js b/omit.js index 304dc822d..fdebc8704 100644 --- a/omit.js +++ b/omit.js @@ -1,4 +1,4 @@ -define(['./_arrayMap', './_baseDifference', './_baseFlatten', './_basePick', './_getAllKeysIn', './rest', './_toKey'], function(arrayMap, baseDifference, baseFlatten, basePick, getAllKeysIn, rest, toKey) { +define(['./_arrayMap', './_baseDifference', './_baseFlatten', './_basePick', './_baseRest', './_getAllKeysIn', './_toKey'], function(arrayMap, baseDifference, baseFlatten, basePick, baseRest, getAllKeysIn, toKey) { /** * The opposite of `_.pick`; this method creates an object composed of the @@ -19,7 +19,7 @@ define(['./_arrayMap', './_baseDifference', './_baseFlatten', './_basePick', './ * _.omit(object, ['a', 'c']); * // => { 'b': '2' } */ - var omit = rest(function(object, props) { + var omit = baseRest(function(object, props) { if (object == null) { return {}; } diff --git a/omitBy.js b/omitBy.js index 0fe502c83..4c44323e2 100644 --- a/omitBy.js +++ b/omitBy.js @@ -1,4 +1,4 @@ -define(['./_baseIteratee', './_basePickBy'], function(baseIteratee, basePickBy) { +define(['./_baseIteratee', './negate', './pickBy'], function(baseIteratee, negate, pickBy) { /** * The opposite of `_.pickBy`; this method creates an object composed of @@ -11,8 +11,7 @@ define(['./_baseIteratee', './_basePickBy'], function(baseIteratee, basePickBy) * @since 4.0.0 * @category Object * @param {Object} object The source object. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per property. + * @param {Function} [predicate=_.identity] The function invoked per property. * @returns {Object} Returns the new object. * @example * @@ -22,10 +21,7 @@ define(['./_baseIteratee', './_basePickBy'], function(baseIteratee, basePickBy) * // => { 'b': '2' } */ function omitBy(object, predicate) { - predicate = baseIteratee(predicate); - return basePickBy(object, function(value, key) { - return !predicate(value, key); - }); + return pickBy(object, negate(baseIteratee(predicate))); } return omitBy; diff --git a/once.js b/once.js index 22c0aff46..d21e0304c 100644 --- a/once.js +++ b/once.js @@ -16,7 +16,7 @@ define(['./before'], function(before) { * var initialize = _.once(createApplication); * initialize(); * initialize(); - * // `initialize` invokes `createApplication` once + * // => `createApplication` is invoked once */ function once(func) { return before(2, func); diff --git a/over.js b/over.js index 8a1989a5f..f870f56a6 100644 --- a/over.js +++ b/over.js @@ -8,8 +8,8 @@ define(['./_arrayMap', './_createOver'], function(arrayMap, createOver) { * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [iteratees=[_.identity]] The iteratees to invoke. + * @param {...(Function|Function[])} [iteratees=[_.identity]] + * The iteratees to invoke. * @returns {Function} Returns the new function. * @example * diff --git a/overArgs.js b/overArgs.js index 486ad4b3c..9e8ba0597 100644 --- a/overArgs.js +++ b/overArgs.js @@ -1,19 +1,18 @@ -define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_baseUnary', './isArray', './_isFlattenableIteratee', './rest'], function(apply, arrayMap, baseFlatten, baseIteratee, baseUnary, isArray, isFlattenableIteratee, rest) { +define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_baseRest', './_baseUnary', './isArray'], function(apply, arrayMap, baseFlatten, baseIteratee, baseRest, baseUnary, isArray) { /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeMin = Math.min; /** - * Creates a function that invokes `func` with arguments transformed by - * corresponding `transforms`. + * Creates a function that invokes `func` with its arguments transformed. * * @static * @since 4.0.0 * @memberOf _ * @category Function * @param {Function} func The function to wrap. - * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [transforms[_.identity]] The functions to transform. + * @param {...(Function|Function[])} [transforms=[_.identity]] + * The argument transforms. * @returns {Function} Returns the new function. * @example * @@ -35,13 +34,13 @@ define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_base * func(10, 5); * // => [100, 10] */ - var overArgs = rest(function(func, transforms) { + var overArgs = baseRest(function(func, transforms) { transforms = (transforms.length == 1 && isArray(transforms[0])) ? arrayMap(transforms[0], baseUnary(baseIteratee)) - : arrayMap(baseFlatten(transforms, 1, isFlattenableIteratee), baseUnary(baseIteratee)); + : arrayMap(baseFlatten(transforms, 1), baseUnary(baseIteratee)); var funcsLength = transforms.length; - return rest(function(args) { + return baseRest(function(args) { var index = -1, length = nativeMin(args.length, funcsLength); diff --git a/overEvery.js b/overEvery.js index ed7bb258f..32e3b24d8 100644 --- a/overEvery.js +++ b/overEvery.js @@ -8,8 +8,8 @@ define(['./_arrayEvery', './_createOver'], function(arrayEvery, createOver) { * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [predicates=[_.identity]] The predicates to check. + * @param {...(Function|Function[])} [predicates=[_.identity]] + * The predicates to check. * @returns {Function} Returns the new function. * @example * diff --git a/overSome.js b/overSome.js index 1b3edcf81..6721803f8 100644 --- a/overSome.js +++ b/overSome.js @@ -8,8 +8,8 @@ define(['./_arraySome', './_createOver'], function(arraySome, createOver) { * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [predicates=[_.identity]] The predicates to check. + * @param {...(Function|Function[])} [predicates=[_.identity]] + * The predicates to check. * @returns {Function} Returns the new function. * @example * diff --git a/package.json b/package.json index 82bd5857c..8b4665154 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-amd", - "version": "4.13.1", + "version": "4.14.0", "description": "Lodash exported as AMD modules.", "keywords": "amd, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds", diff --git a/partial.js b/partial.js index cf061e572..a1272d5b9 100644 --- a/partial.js +++ b/partial.js @@ -1,9 +1,9 @@ -define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], function(createWrapper, getHolder, replaceHolders, rest) { +define(['./_baseRest', './_createWrap', './_getHolder', './_replaceHolders'], function(baseRest, createWrap, getHolder, replaceHolders) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var PARTIAL_FLAG = 32; /** @@ -26,9 +26,9 @@ define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], func * @returns {Function} Returns the new partially applied function. * @example * - * var greet = function(greeting, name) { + * function greet(greeting, name) { * return greeting + ' ' + name; - * }; + * } * * var sayHelloTo = _.partial(greet, 'hello'); * sayHelloTo('fred'); @@ -39,9 +39,9 @@ define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], func * greetFred('hi'); * // => 'hi fred' */ - var partial = rest(function(func, partials) { + var partial = baseRest(function(func, partials) { var holders = replaceHolders(partials, getHolder(partial)); - return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders); + return createWrap(func, PARTIAL_FLAG, undefined, partials, holders); }); // Assign default placeholders. diff --git a/partialRight.js b/partialRight.js index 1474cd52c..ae851f848 100644 --- a/partialRight.js +++ b/partialRight.js @@ -1,9 +1,9 @@ -define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], function(createWrapper, getHolder, replaceHolders, rest) { +define(['./_baseRest', './_createWrap', './_getHolder', './_replaceHolders'], function(baseRest, createWrap, getHolder, replaceHolders) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var PARTIAL_RIGHT_FLAG = 64; /** @@ -25,9 +25,9 @@ define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], func * @returns {Function} Returns the new partially applied function. * @example * - * var greet = function(greeting, name) { + * function greet(greeting, name) { * return greeting + ' ' + name; - * }; + * } * * var greetFred = _.partialRight(greet, 'fred'); * greetFred('hi'); @@ -38,9 +38,9 @@ define(['./_createWrapper', './_getHolder', './_replaceHolders', './rest'], func * sayHelloTo('fred'); * // => 'hello fred' */ - var partialRight = rest(function(func, partials) { + var partialRight = baseRest(function(func, partials) { var holders = replaceHolders(partials, getHolder(partialRight)); - return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders); + return createWrap(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders); }); // Assign default placeholders. diff --git a/partition.js b/partition.js index 01475c64c..05e9df6b3 100644 --- a/partition.js +++ b/partition.js @@ -11,8 +11,7 @@ define(['./_createAggregator'], function(createAggregator) { * @since 3.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the array of grouped elements. * @example * diff --git a/pick.js b/pick.js index c3e9694a8..392218c3e 100644 --- a/pick.js +++ b/pick.js @@ -1,4 +1,4 @@ -define(['./_arrayMap', './_baseFlatten', './_basePick', './rest', './_toKey'], function(arrayMap, baseFlatten, basePick, rest, toKey) { +define(['./_arrayMap', './_baseFlatten', './_basePick', './_baseRest', './_toKey'], function(arrayMap, baseFlatten, basePick, baseRest, toKey) { /** * Creates an object composed of the picked `object` properties. @@ -17,7 +17,7 @@ define(['./_arrayMap', './_baseFlatten', './_basePick', './rest', './_toKey'], f * _.pick(object, ['a', 'c']); * // => { 'a': 1, 'c': 3 } */ - var pick = rest(function(object, props) { + var pick = baseRest(function(object, props) { return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey)); }); diff --git a/pickBy.js b/pickBy.js index d184cb878..b527a3eef 100644 --- a/pickBy.js +++ b/pickBy.js @@ -1,4 +1,4 @@ -define(['./_baseIteratee', './_basePickBy'], function(baseIteratee, basePickBy) { +define(['./_baseIteratee', './_basePickBy', './_getAllKeysIn'], function(baseIteratee, basePickBy, getAllKeysIn) { /** * Creates an object composed of the `object` properties `predicate` returns @@ -9,8 +9,7 @@ define(['./_baseIteratee', './_basePickBy'], function(baseIteratee, basePickBy) * @since 4.0.0 * @category Object * @param {Object} object The source object. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per property. + * @param {Function} [predicate=_.identity] The function invoked per property. * @returns {Object} Returns the new object. * @example * @@ -20,7 +19,7 @@ define(['./_baseIteratee', './_basePickBy'], function(baseIteratee, basePickBy) * // => { 'a': 1, 'c': 3 } */ function pickBy(object, predicate) { - return object == null ? {} : basePickBy(object, baseIteratee(predicate)); + return object == null ? {} : basePickBy(object, getAllKeysIn(object), baseIteratee(predicate)); } return pickBy; diff --git a/pull.js b/pull.js index 0d7d8e06a..abdcbdf80 100644 --- a/pull.js +++ b/pull.js @@ -1,4 +1,4 @@ -define(['./pullAll', './rest'], function(pullAll, rest) { +define(['./_baseRest', './pullAll'], function(baseRest, pullAll) { /** * Removes all given values from `array` using @@ -23,7 +23,7 @@ define(['./pullAll', './rest'], function(pullAll, rest) { * console.log(array); * // => ['b', 'b'] */ - var pull = rest(pullAll); + var pull = baseRest(pullAll); return pull; }); diff --git a/pullAllBy.js b/pullAllBy.js index 4e610bd5d..1d60da248 100644 --- a/pullAllBy.js +++ b/pullAllBy.js @@ -13,7 +13,7 @@ define(['./_baseIteratee', './_basePullAll'], function(baseIteratee, basePullAll * @category Array * @param {Array} array The array to modify. * @param {Array} values The values to remove. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {Array} Returns `array`. * @example @@ -26,7 +26,7 @@ define(['./_baseIteratee', './_basePullAll'], function(baseIteratee, basePullAll */ function pullAllBy(array, values, iteratee) { return (array && array.length && values && values.length) - ? basePullAll(array, values, baseIteratee(iteratee)) + ? basePullAll(array, values, baseIteratee(iteratee, 2)) : array; } diff --git a/pullAt.js b/pullAt.js index cd8f19736..fde274d31 100644 --- a/pullAt.js +++ b/pullAt.js @@ -1,4 +1,4 @@ -define(['./_arrayMap', './_baseAt', './_baseFlatten', './_basePullAt', './_compareAscending', './_isIndex', './rest'], function(arrayMap, baseAt, baseFlatten, basePullAt, compareAscending, isIndex, rest) { +define(['./_arrayMap', './_baseAt', './_baseFlatten', './_basePullAt', './_baseRest', './_compareAscending', './_isIndex'], function(arrayMap, baseAt, baseFlatten, basePullAt, baseRest, compareAscending, isIndex) { /** * Removes elements from `array` corresponding to `indexes` and returns an @@ -24,7 +24,7 @@ define(['./_arrayMap', './_baseAt', './_baseFlatten', './_basePullAt', './_compa * console.log(pulled); * // => ['b', 'd'] */ - var pullAt = rest(function(array, indexes) { + var pullAt = baseRest(function(array, indexes) { indexes = baseFlatten(indexes, 1); var length = array ? array.length : 0, diff --git a/rearg.js b/rearg.js index d47968d48..ac39ced34 100644 --- a/rearg.js +++ b/rearg.js @@ -1,9 +1,9 @@ -define(['./_baseFlatten', './_createWrapper', './rest'], function(baseFlatten, createWrapper, rest) { +define(['./_baseFlatten', './_baseRest', './_createWrap'], function(baseFlatten, baseRest, createWrap) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used to compose bitmasks for wrapper metadata. */ + /** Used to compose bitmasks for function metadata. */ var REARG_FLAG = 256; /** @@ -28,8 +28,8 @@ define(['./_baseFlatten', './_createWrapper', './rest'], function(baseFlatten, c * rearged('b', 'c', 'a') * // => ['a', 'b', 'c'] */ - var rearg = rest(function(func, indexes) { - return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1)); + var rearg = baseRest(function(func, indexes) { + return createWrap(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1)); }); return rearg; diff --git a/reject.js b/reject.js index 8c3678ef6..20455283f 100644 --- a/reject.js +++ b/reject.js @@ -1,4 +1,4 @@ -define(['./_arrayFilter', './_baseFilter', './_baseIteratee', './isArray'], function(arrayFilter, baseFilter, baseIteratee, isArray) { +define(['./_arrayFilter', './_baseFilter', './_baseIteratee', './isArray', './negate'], function(arrayFilter, baseFilter, baseIteratee, isArray, negate) { /** * The opposite of `_.filter`; this method returns the elements of `collection` @@ -9,8 +9,7 @@ define(['./_arrayFilter', './_baseFilter', './_baseIteratee', './isArray'], func * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the new filtered array. * @see _.filter * @example @@ -37,10 +36,7 @@ define(['./_arrayFilter', './_baseFilter', './_baseIteratee', './isArray'], func */ function reject(collection, predicate) { var func = isArray(collection) ? arrayFilter : baseFilter; - predicate = baseIteratee(predicate, 3); - return func(collection, function(value, index, collection) { - return !predicate(value, index, collection); - }); + return func(collection, negate(baseIteratee(predicate, 3))); } return reject; diff --git a/remove.js b/remove.js index 3b383036d..f136e43ab 100644 --- a/remove.js +++ b/remove.js @@ -13,7 +13,7 @@ define(['./_baseIteratee', './_basePullAt'], function(baseIteratee, basePullAt) * @since 2.0.0 * @category Array * @param {Array} array The array to modify. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the new array of removed elements. * @example diff --git a/rest.js b/rest.js index b358555da..c910372b2 100644 --- a/rest.js +++ b/rest.js @@ -1,4 +1,4 @@ -define(['./_apply', './toInteger'], function(apply, toInteger) { +define(['./_baseRest', './toInteger'], function(baseRest, toInteger) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -6,9 +6,6 @@ define(['./_apply', './toInteger'], function(apply, toInteger) { /** Used as the `TypeError` message for "Functions" methods. */ var FUNC_ERROR_TEXT = 'Expected a function'; - /* Built-in method references for those with the same name as other `lodash` methods. */ - var nativeMax = Math.max; - /** * Creates a function that invokes `func` with the `this` binding of the * created function and arguments from `start` and beyond provided as @@ -38,29 +35,8 @@ define(['./_apply', './toInteger'], function(apply, toInteger) { if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } - start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0); - return function() { - var args = arguments, - index = -1, - length = nativeMax(args.length - start, 0), - array = Array(length); - - while (++index < length) { - array[index] = args[start + index]; - } - switch (start) { - case 0: return func.call(this, array); - case 1: return func.call(this, args[0], array); - case 2: return func.call(this, args[0], args[1], array); - } - var otherArgs = Array(start + 1); - index = -1; - while (++index < start) { - otherArgs[index] = args[index]; - } - otherArgs[start] = array; - return apply(func, this, otherArgs); - }; + start = start === undefined ? start : toInteger(start); + return baseRest(func, start); } return rest; diff --git a/some.js b/some.js index 9c515fb41..c06cd8de0 100644 --- a/some.js +++ b/some.js @@ -13,8 +13,7 @@ define(['./_arraySome', './_baseIteratee', './_baseSome', './isArray', './_isIte * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Array|Function|Object|string} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {boolean} Returns `true` if any element passes the predicate check, * else `false`. diff --git a/sortBy.js b/sortBy.js index becc5f262..8592da28b 100644 --- a/sortBy.js +++ b/sortBy.js @@ -1,4 +1,4 @@ -define(['./_baseFlatten', './_baseOrderBy', './isArray', './_isFlattenableIteratee', './_isIterateeCall', './rest'], function(baseFlatten, baseOrderBy, isArray, isFlattenableIteratee, isIterateeCall, rest) { +define(['./_baseFlatten', './_baseOrderBy', './_baseRest', './_isIterateeCall'], function(baseFlatten, baseOrderBy, baseRest, isIterateeCall) { /** * Creates an array of elements, sorted in ascending order by the results of @@ -11,8 +11,8 @@ define(['./_baseFlatten', './_baseOrderBy', './isArray', './_isFlattenableIterat * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [iteratees=[_.identity]] The iteratees to sort by. + * @param {...(Function|Function[])} [iteratees=[_.identity]] + * The iteratees to sort by. * @returns {Array} Returns the new sorted array. * @example * @@ -34,7 +34,7 @@ define(['./_baseFlatten', './_baseOrderBy', './isArray', './_isFlattenableIterat * }); * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] */ - var sortBy = rest(function(collection, iteratees) { + var sortBy = baseRest(function(collection, iteratees) { if (collection == null) { return []; } @@ -44,11 +44,7 @@ define(['./_baseFlatten', './_baseOrderBy', './isArray', './_isFlattenableIterat } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { iteratees = [iteratees[0]]; } - iteratees = (iteratees.length == 1 && isArray(iteratees[0])) - ? iteratees[0] - : baseFlatten(iteratees, 1, isFlattenableIteratee); - - return baseOrderBy(collection, iteratees, []); + return baseOrderBy(collection, baseFlatten(iteratees, 1), []); }); return sortBy; diff --git a/sortedIndexBy.js b/sortedIndexBy.js index daceb428b..e0d50dcfc 100644 --- a/sortedIndexBy.js +++ b/sortedIndexBy.js @@ -11,7 +11,7 @@ define(['./_baseIteratee', './_baseSortedIndexBy'], function(baseIteratee, baseS * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {number} Returns the index at which `value` should be inserted * into `array`. @@ -27,7 +27,7 @@ define(['./_baseIteratee', './_baseSortedIndexBy'], function(baseIteratee, baseS * // => 0 */ function sortedIndexBy(array, value, iteratee) { - return baseSortedIndexBy(array, value, baseIteratee(iteratee)); + return baseSortedIndexBy(array, value, baseIteratee(iteratee, 2)); } return sortedIndexBy; diff --git a/sortedLastIndexBy.js b/sortedLastIndexBy.js index 2c175536e..1362689db 100644 --- a/sortedLastIndexBy.js +++ b/sortedLastIndexBy.js @@ -11,7 +11,7 @@ define(['./_baseIteratee', './_baseSortedIndexBy'], function(baseIteratee, baseS * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {number} Returns the index at which `value` should be inserted * into `array`. @@ -27,7 +27,7 @@ define(['./_baseIteratee', './_baseSortedIndexBy'], function(baseIteratee, baseS * // => 1 */ function sortedLastIndexBy(array, value, iteratee) { - return baseSortedIndexBy(array, value, baseIteratee(iteratee), true); + return baseSortedIndexBy(array, value, baseIteratee(iteratee, 2), true); } return sortedLastIndexBy; diff --git a/sortedUniqBy.js b/sortedUniqBy.js index 39d3e8d4b..0e85f0b95 100644 --- a/sortedUniqBy.js +++ b/sortedUniqBy.js @@ -18,7 +18,7 @@ define(['./_baseIteratee', './_baseSortedUniq'], function(baseIteratee, baseSort */ function sortedUniqBy(array, iteratee) { return (array && array.length) - ? baseSortedUniq(array, baseIteratee(iteratee)) + ? baseSortedUniq(array, baseIteratee(iteratee, 2)) : []; } diff --git a/spread.js b/spread.js index c98c9a7b5..047fa6a7d 100644 --- a/spread.js +++ b/spread.js @@ -1,4 +1,4 @@ -define(['./_apply', './_arrayPush', './_castSlice', './rest', './toInteger'], function(apply, arrayPush, castSlice, rest, toInteger) { +define(['./_apply', './_arrayPush', './_baseRest', './_castSlice', './toInteger'], function(apply, arrayPush, baseRest, castSlice, toInteger) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -48,7 +48,7 @@ define(['./_apply', './_arrayPush', './_castSlice', './rest', './toInteger'], fu throw new TypeError(FUNC_ERROR_TEXT); } start = start === undefined ? 0 : nativeMax(toInteger(start), 0); - return rest(function(args) { + return baseRest(function(args) { var array = args[start], otherArgs = castSlice(args, 0, start); diff --git a/startsWith.js b/startsWith.js index 35eb46ecc..537796aaf 100644 --- a/startsWith.js +++ b/startsWith.js @@ -26,7 +26,8 @@ define(['./_baseClamp', './_baseToString', './toInteger', './toString'], functio function startsWith(string, target, position) { string = toString(string); position = baseClamp(toInteger(position), 0, string.length); - return string.lastIndexOf(baseToString(target), position) == position; + target = baseToString(target); + return string.slice(position, position + target.length) == target; } return startsWith; diff --git a/stubArray.js b/stubArray.js index f0ab83ed4..baf06517d 100644 --- a/stubArray.js +++ b/stubArray.js @@ -1,7 +1,7 @@ define([], function() { /** - * A method that returns a new empty array. + * This method returns a new empty array. * * @static * @memberOf _ diff --git a/stubFalse.js b/stubFalse.js index 9e0b9ab2e..05ae19b58 100644 --- a/stubFalse.js +++ b/stubFalse.js @@ -1,7 +1,7 @@ define([], function() { /** - * A method that returns `false`. + * This method returns `false`. * * @static * @memberOf _ diff --git a/stubObject.js b/stubObject.js index 4fe89a9f0..17a3b7997 100644 --- a/stubObject.js +++ b/stubObject.js @@ -1,7 +1,7 @@ define([], function() { /** - * A method that returns a new empty object. + * This method returns a new empty object. * * @static * @memberOf _ diff --git a/stubString.js b/stubString.js index bcd69a394..b439e7e62 100644 --- a/stubString.js +++ b/stubString.js @@ -1,7 +1,7 @@ define([], function() { /** - * A method that returns an empty string. + * This method returns an empty string. * * @static * @memberOf _ diff --git a/stubTrue.js b/stubTrue.js index 96cba7d83..d7a8d59ec 100644 --- a/stubTrue.js +++ b/stubTrue.js @@ -1,7 +1,7 @@ define([], function() { /** - * A method that returns `true`. + * This method returns `true`. * * @static * @memberOf _ diff --git a/subtract.js b/subtract.js index 6039aec8f..b4fd55c50 100644 --- a/subtract.js +++ b/subtract.js @@ -17,7 +17,7 @@ define(['./_createMathOperation'], function(createMathOperation) { */ var subtract = createMathOperation(function(minuend, subtrahend) { return minuend - subtrahend; - }); + }, 0); return subtract; }); diff --git a/sumBy.js b/sumBy.js index c306ca5b7..01196b024 100644 --- a/sumBy.js +++ b/sumBy.js @@ -10,8 +10,7 @@ define(['./_baseIteratee', './_baseSum'], function(baseIteratee, baseSum) { * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Array|Function|Object|string} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {number} Returns the sum. * @example * @@ -26,7 +25,7 @@ define(['./_baseIteratee', './_baseSum'], function(baseIteratee, baseSum) { */ function sumBy(array, iteratee) { return (array && array.length) - ? baseSum(array, baseIteratee(iteratee)) + ? baseSum(array, baseIteratee(iteratee, 2)) : 0; } diff --git a/takeRightWhile.js b/takeRightWhile.js index 4aa80bdad..05506f3cb 100644 --- a/takeRightWhile.js +++ b/takeRightWhile.js @@ -10,7 +10,7 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example diff --git a/takeWhile.js b/takeWhile.js index 6babf2ca8..49fa20ef8 100644 --- a/takeWhile.js +++ b/takeWhile.js @@ -10,7 +10,7 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Array|Function|Object|string} [predicate=_.identity] + * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example diff --git a/toArray.js b/toArray.js index 3fc5ea392..f2f1bce1b 100644 --- a/toArray.js +++ b/toArray.js @@ -8,7 +8,7 @@ define(['./_Symbol', './_copyArray', './_getTag', './isArrayLike', './isString', setTag = '[object Set]'; /** Built-in value references. */ - var iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined; + var iteratorSymbol = Symbol ? Symbol.iterator : undefined; /** * Converts `value` to an array. diff --git a/union.js b/union.js index c1dbe1346..f517eed29 100644 --- a/union.js +++ b/union.js @@ -1,4 +1,4 @@ -define(['./_baseFlatten', './_baseUniq', './isArrayLikeObject', './rest'], function(baseFlatten, baseUniq, isArrayLikeObject, rest) { +define(['./_baseFlatten', './_baseRest', './_baseUniq', './isArrayLikeObject'], function(baseFlatten, baseRest, baseUniq, isArrayLikeObject) { /** * Creates an array of unique values, in order, from all given arrays using @@ -16,7 +16,7 @@ define(['./_baseFlatten', './_baseUniq', './isArrayLikeObject', './rest'], funct * _.union([2], [1, 2]); * // => [2, 1] */ - var union = rest(function(arrays) { + var union = baseRest(function(arrays) { return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); }); diff --git a/unionBy.js b/unionBy.js index 9ab5348a9..627017550 100644 --- a/unionBy.js +++ b/unionBy.js @@ -1,4 +1,4 @@ -define(['./_baseFlatten', './_baseIteratee', './_baseUniq', './isArrayLikeObject', './last', './rest'], function(baseFlatten, baseIteratee, baseUniq, isArrayLikeObject, last, rest) { +define(['./_baseFlatten', './_baseIteratee', './_baseRest', './_baseUniq', './isArrayLikeObject', './last'], function(baseFlatten, baseIteratee, baseRest, baseUniq, isArrayLikeObject, last) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -6,7 +6,8 @@ define(['./_baseFlatten', './_baseIteratee', './_baseUniq', './isArrayLikeObject /** * This method is like `_.union` except that it accepts `iteratee` which is * invoked for each element of each `arrays` to generate the criterion by - * which uniqueness is computed. The iteratee is invoked with one argument: + * which uniqueness is computed. Result values are chosen from the first + * array in which the value occurs. The iteratee is invoked with one argument: * (value). * * @static @@ -14,7 +15,7 @@ define(['./_baseFlatten', './_baseIteratee', './_baseUniq', './isArrayLikeObject * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {Array} Returns the new array of combined values. * @example @@ -26,12 +27,12 @@ define(['./_baseFlatten', './_baseIteratee', './_baseUniq', './isArrayLikeObject * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }, { 'x': 2 }] */ - var unionBy = rest(function(arrays) { + var unionBy = baseRest(function(arrays) { var iteratee = last(arrays); if (isArrayLikeObject(iteratee)) { iteratee = undefined; } - return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), baseIteratee(iteratee)); + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), baseIteratee(iteratee, 2)); }); return unionBy; diff --git a/unionWith.js b/unionWith.js index b40c85577..48e1a0c26 100644 --- a/unionWith.js +++ b/unionWith.js @@ -1,11 +1,12 @@ -define(['./_baseFlatten', './_baseUniq', './isArrayLikeObject', './last', './rest'], function(baseFlatten, baseUniq, isArrayLikeObject, last, rest) { +define(['./_baseFlatten', './_baseRest', './_baseUniq', './isArrayLikeObject', './last'], function(baseFlatten, baseRest, baseUniq, isArrayLikeObject, last) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; /** * This method is like `_.union` except that it accepts `comparator` which - * is invoked to compare elements of `arrays`. The comparator is invoked + * is invoked to compare elements of `arrays`. Result values are chosen from + * the first array in which the value occurs. The comparator is invoked * with two arguments: (arrVal, othVal). * * @static @@ -23,7 +24,7 @@ define(['./_baseFlatten', './_baseUniq', './isArrayLikeObject', './last', './res * _.unionWith(objects, others, _.isEqual); * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] */ - var unionWith = rest(function(arrays) { + var unionWith = baseRest(function(arrays) { var comparator = last(arrays); if (isArrayLikeObject(comparator)) { comparator = undefined; diff --git a/uniqBy.js b/uniqBy.js index 641717ee7..dbd4d5f31 100644 --- a/uniqBy.js +++ b/uniqBy.js @@ -10,7 +10,7 @@ define(['./_baseIteratee', './_baseUniq'], function(baseIteratee, baseUniq) { * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {Array} Returns the new duplicate free array. * @example @@ -24,7 +24,7 @@ define(['./_baseIteratee', './_baseUniq'], function(baseIteratee, baseUniq) { */ function uniqBy(array, iteratee) { return (array && array.length) - ? baseUniq(array, baseIteratee(iteratee)) + ? baseUniq(array, baseIteratee(iteratee, 2)) : []; } diff --git a/unzip.js b/unzip.js index 6ba80e270..1a56253c9 100644 --- a/unzip.js +++ b/unzip.js @@ -16,11 +16,11 @@ define(['./_arrayFilter', './_arrayMap', './_baseProperty', './_baseTimes', './i * @returns {Array} Returns the new array of regrouped elements. * @example * - * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]); - * // => [['fred', 30, true], ['barney', 40, false]] + * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]); + * // => [['a', 1, true], ['b', 2, false]] * * _.unzip(zipped); - * // => [['fred', 'barney'], [30, 40], [true, false]] + * // => [['a', 'b'], [1, 2], [true, false]] */ function unzip(array) { if (!(array && array.length)) { diff --git a/util.js b/util.js index ea3cee3f3..b02120202 100644 --- a/util.js +++ b/util.js @@ -1,10 +1,11 @@ -define(['./attempt', './bindAll', './cond', './conforms', './constant', './flow', './flowRight', './identity', './iteratee', './matches', './matchesProperty', './method', './methodOf', './mixin', './noop', './nthArg', './over', './overEvery', './overSome', './property', './propertyOf', './range', './rangeRight', './stubArray', './stubFalse', './stubObject', './stubString', './stubTrue', './times', './toPath', './uniqueId'], function(attempt, bindAll, cond, conforms, constant, flow, flowRight, identity, iteratee, matches, matchesProperty, method, methodOf, mixin, noop, nthArg, over, overEvery, overSome, property, propertyOf, range, rangeRight, stubArray, stubFalse, stubObject, stubString, stubTrue, times, toPath, uniqueId) { +define(['./attempt', './bindAll', './cond', './conforms', './constant', './defaultTo', './flow', './flowRight', './identity', './iteratee', './matches', './matchesProperty', './method', './methodOf', './mixin', './noop', './nthArg', './over', './overEvery', './overSome', './property', './propertyOf', './range', './rangeRight', './stubArray', './stubFalse', './stubObject', './stubString', './stubTrue', './times', './toPath', './uniqueId'], function(attempt, bindAll, cond, conforms, constant, defaultTo, flow, flowRight, identity, iteratee, matches, matchesProperty, method, methodOf, mixin, noop, nthArg, over, overEvery, overSome, property, propertyOf, range, rangeRight, stubArray, stubFalse, stubObject, stubString, stubTrue, times, toPath, uniqueId) { return { 'attempt': attempt, 'bindAll': bindAll, 'cond': cond, 'conforms': conforms, 'constant': constant, + 'defaultTo': defaultTo, 'flow': flow, 'flowRight': flowRight, 'identity': identity, diff --git a/without.js b/without.js index 6c06394c1..b6dcc53cd 100644 --- a/without.js +++ b/without.js @@ -1,10 +1,12 @@ -define(['./_baseDifference', './isArrayLikeObject', './rest'], function(baseDifference, isArrayLikeObject, rest) { +define(['./_baseDifference', './_baseRest', './isArrayLikeObject'], function(baseDifference, baseRest, isArrayLikeObject) { /** * Creates an array excluding all given values using * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * for equality comparisons. * + * **Note:** Unlike `_.pull`, this method returns a new array. + * * @static * @memberOf _ * @since 0.1.0 @@ -18,7 +20,7 @@ define(['./_baseDifference', './isArrayLikeObject', './rest'], function(baseDiff * _.without([2, 1, 2, 3], 1, 2); * // => [3] */ - var without = rest(function(array, values) { + var without = baseRest(function(array, values) { return isArrayLikeObject(array) ? baseDifference(array, values) : []; diff --git a/wrap.js b/wrap.js index 3bededca1..77323cc4e 100644 --- a/wrap.js +++ b/wrap.js @@ -1,10 +1,10 @@ define(['./identity', './partial'], function(identity, partial) { /** - * Creates a function that provides `value` to the wrapper function as its - * first argument. Any additional arguments provided to the function are - * appended to those provided to the wrapper function. The wrapper is invoked - * with the `this` binding of the created function. + * Creates a function that provides `value` to `wrapper` as its first + * argument. Any additional arguments provided to the function are appended + * to those provided to the `wrapper`. The wrapper is invoked with the `this` + * binding of the created function. * * @static * @memberOf _ diff --git a/wrapperAt.js b/wrapperAt.js index 344136d27..a28296e5c 100644 --- a/wrapperAt.js +++ b/wrapperAt.js @@ -1,4 +1,4 @@ -define(['./_LazyWrapper', './_LodashWrapper', './_baseAt', './_baseFlatten', './_isIndex', './rest', './thru'], function(LazyWrapper, LodashWrapper, baseAt, baseFlatten, isIndex, rest, thru) { +define(['./_LazyWrapper', './_LodashWrapper', './_baseAt', './_baseFlatten', './_baseRest', './_isIndex', './thru'], function(LazyWrapper, LodashWrapper, baseAt, baseFlatten, baseRest, isIndex, thru) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -19,7 +19,7 @@ define(['./_LazyWrapper', './_LodashWrapper', './_baseAt', './_baseFlatten', './ * _(object).at(['a[0].b.c', 'a[1]']).value(); * // => [3, 4] */ - var wrapperAt = rest(function(paths) { + var wrapperAt = baseRest(function(paths) { paths = baseFlatten(paths, 1); var length = paths.length, start = length ? paths[0] : 0, diff --git a/wrapperLodash.js b/wrapperLodash.js index 6ac684d52..040b45dc6 100644 --- a/wrapperLodash.js +++ b/wrapperLodash.js @@ -72,16 +72,16 @@ define(['./_LazyWrapper', './_LodashWrapper', './_baseLodash', './isArray', './i * * The wrapper methods that are **not** chainable by default are: * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, - * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `divide`, `each`, - * `eachRight`, `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`, - * `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`, - * `floor`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, - * `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`, - * `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`, - * `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`, - * `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, - * `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`, - * `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, + * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`, + * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`, + * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`, + * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`, + * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, + * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, + * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, + * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, + * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, + * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`, * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`, diff --git a/xor.js b/xor.js index 113704b01..4654d5404 100644 --- a/xor.js +++ b/xor.js @@ -1,4 +1,4 @@ -define(['./_arrayFilter', './_baseXor', './isArrayLikeObject', './rest'], function(arrayFilter, baseXor, isArrayLikeObject, rest) { +define(['./_arrayFilter', './_baseRest', './_baseXor', './isArrayLikeObject'], function(arrayFilter, baseRest, baseXor, isArrayLikeObject) { /** * Creates an array of unique values that is the @@ -18,7 +18,7 @@ define(['./_arrayFilter', './_baseXor', './isArrayLikeObject', './rest'], functi * _.xor([2, 1], [2, 3]); * // => [1, 3] */ - var xor = rest(function(arrays) { + var xor = baseRest(function(arrays) { return baseXor(arrayFilter(arrays, isArrayLikeObject)); }); diff --git a/xorBy.js b/xorBy.js index 8453aa587..b34ee9c44 100644 --- a/xorBy.js +++ b/xorBy.js @@ -1,4 +1,4 @@ -define(['./_arrayFilter', './_baseIteratee', './_baseXor', './isArrayLikeObject', './last', './rest'], function(arrayFilter, baseIteratee, baseXor, isArrayLikeObject, last, rest) { +define(['./_arrayFilter', './_baseIteratee', './_baseRest', './_baseXor', './isArrayLikeObject', './last'], function(arrayFilter, baseIteratee, baseRest, baseXor, isArrayLikeObject, last) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -14,7 +14,7 @@ define(['./_arrayFilter', './_baseIteratee', './_baseXor', './isArrayLikeObject' * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Array|Function|Object|string} [iteratee=_.identity] + * @param {Function} [iteratee=_.identity] * The iteratee invoked per element. * @returns {Array} Returns the new array of filtered values. * @example @@ -26,12 +26,12 @@ define(['./_arrayFilter', './_baseIteratee', './_baseXor', './isArrayLikeObject' * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 2 }] */ - var xorBy = rest(function(arrays) { + var xorBy = baseRest(function(arrays) { var iteratee = last(arrays); if (isArrayLikeObject(iteratee)) { iteratee = undefined; } - return baseXor(arrayFilter(arrays, isArrayLikeObject), baseIteratee(iteratee)); + return baseXor(arrayFilter(arrays, isArrayLikeObject), baseIteratee(iteratee, 2)); }); return xorBy; diff --git a/xorWith.js b/xorWith.js index fcaaa1e35..eb2519449 100644 --- a/xorWith.js +++ b/xorWith.js @@ -1,4 +1,4 @@ -define(['./_arrayFilter', './_baseXor', './isArrayLikeObject', './last', './rest'], function(arrayFilter, baseXor, isArrayLikeObject, last, rest) { +define(['./_arrayFilter', './_baseRest', './_baseXor', './isArrayLikeObject', './last'], function(arrayFilter, baseRest, baseXor, isArrayLikeObject, last) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -23,7 +23,7 @@ define(['./_arrayFilter', './_baseXor', './isArrayLikeObject', './last', './rest * _.xorWith(objects, others, _.isEqual); * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] */ - var xorWith = rest(function(arrays) { + var xorWith = baseRest(function(arrays) { var comparator = last(arrays); if (isArrayLikeObject(comparator)) { comparator = undefined; diff --git a/zip.js b/zip.js index 8b47d8446..686ab1828 100644 --- a/zip.js +++ b/zip.js @@ -1,4 +1,4 @@ -define(['./rest', './unzip'], function(rest, unzip) { +define(['./_baseRest', './unzip'], function(baseRest, unzip) { /** * Creates an array of grouped elements, the first of which contains the @@ -13,10 +13,10 @@ define(['./rest', './unzip'], function(rest, unzip) { * @returns {Array} Returns the new array of grouped elements. * @example * - * _.zip(['fred', 'barney'], [30, 40], [true, false]); - * // => [['fred', 30, true], ['barney', 40, false]] + * _.zip(['a', 'b'], [1, 2], [true, false]); + * // => [['a', 1, true], ['b', 2, false]] */ - var zip = rest(unzip); + var zip = baseRest(unzip); return zip; }); diff --git a/zipWith.js b/zipWith.js index 4d5b4f0b4..371d7ccbb 100644 --- a/zipWith.js +++ b/zipWith.js @@ -1,4 +1,4 @@ -define(['./rest', './unzipWith'], function(rest, unzipWith) { +define(['./_baseRest', './unzipWith'], function(baseRest, unzipWith) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -22,7 +22,7 @@ define(['./rest', './unzipWith'], function(rest, unzipWith) { * }); * // => [111, 222] */ - var zipWith = rest(function(arrays) { + var zipWith = baseRest(function(arrays) { var length = arrays.length, iteratee = length > 1 ? arrays[length - 1] : undefined;