From 51ed7e7707047aae23433bebaf461064787b006a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 24 Jul 2016 09:52:22 -0700 Subject: [PATCH] Bump to v4.14.0. --- README.md | 4 +- _addMapEntry.js | 2 +- _addSetEntry.js | 1 + _apply.js | 3 +- _baseClamp.js | 2 +- _baseClone.js | 5 +- _baseConforms.js | 21 +----- _baseConformsTo.js | 28 ++++++++ _baseDelay.js | 6 +- _baseGetTag.js | 22 ++++++ _baseGt.js | 2 +- _baseInRange.js | 2 +- _baseIndexOf.js | 5 +- _baseIsArrayBuffer.js | 26 +++++++ _baseIsDate.js | 27 ++++++++ _baseIsMap.js | 18 +++++ _baseIsNaN.js | 12 ++++ _baseIsRegExp.js | 27 ++++++++ _baseIsSet.js | 18 +++++ _baseIsTypedArray.js | 69 +++++++++++++++++++ _baseKeys.js | 6 +- _baseLt.js | 2 +- _baseMergeDeep.js | 5 +- _baseNth.js | 2 +- _basePick.js | 11 ++- _basePickBy.js | 6 +- _basePropertyOf.js | 14 ++++ _baseRange.js | 2 +- _baseRest.js | 35 ++++++++++ _baseUnary.js | 2 +- _checkGlobal.js | 12 ---- _copyObject.js | 4 +- _createAggregator.js | 2 +- _createAssigner.js | 4 +- _createBaseWrapper.js => _createBind.js | 13 ++-- _createCtorWrapper.js => _createCtor.js | 4 +- _createCurryWrapper.js => _createCurry.js | 19 +++-- _createFind.js | 15 ++-- _createFlow.js | 6 +- _createHybridWrapper.js => _createHybrid.js | 21 +++--- _createMathOperation.js | 5 +- _createOver.js | 9 ++- _createPartialWrapper.js => _createPartial.js | 13 ++-- _createRecurryWrapper.js => _createRecurry.js | 12 ++-- _createSet.js | 2 +- _createWrapper.js => _createWrap.js | 27 ++++---- _deburrLetter.js | 6 +- _defineProperty.js | 11 +++ _equalArrays.js | 3 +- _equalByTag.js | 19 +++-- _equalObjects.js | 3 +- _escapeHtmlChar.js | 6 +- _freeGlobal.js | 4 ++ _getPrototype.js | 6 +- _getSymbols.js | 16 ++--- _getSymbolsIn.js | 6 +- _getTag.js | 5 +- _getWrapDetails.js | 17 +++++ _indexOfNaN.js | 23 ------- _insertWrapDetails.js | 21 ++++++ _isFlattenable.js | 7 +- _isFlattenableIteratee.js | 16 ----- _mergeData.js | 2 +- _mergeDefaults.js | 5 +- _nodeUtil.js | 22 ++++++ _overArg.js | 15 ++++ _root.js | 12 +--- _setWrapToString.js | 27 ++++++++ _stackSet.js | 10 ++- _unescapeHtmlChar.js | 6 +- _updateWrapDetails.js | 46 +++++++++++++ add.js | 2 +- array.js | 2 +- ary.js | 6 +- assign.js | 12 ++-- assignIn.js | 12 ++-- at.js | 4 +- attempt.js | 4 +- before.js | 2 +- bind.js | 14 ++-- bindAll.js | 10 +-- bindKey.js | 10 +-- collection.default.js | 13 ++-- collection.js | 3 +- cond.js | 6 +- conforms.js | 10 +-- conformsTo.js | 30 ++++++++ countBy.js | 2 +- curry.js | 6 +- curryRight.js | 6 +- date.js | 2 +- debounce.js | 3 + defaultTo.js | 25 +++++++ defaults.js | 8 +-- defaultsDeep.js | 9 ++- defer.js | 4 +- delay.js | 4 +- difference.js | 10 +-- differenceBy.js | 11 +-- differenceWith.js | 6 +- divide.js | 2 +- dropRightWhile.js | 3 +- dropWhile.js | 2 +- endsWith.js | 3 +- eq.js | 4 +- every.js | 2 +- filter.js | 4 +- find.js | 2 +- findIndex.js | 2 +- findKey.js | 3 +- findLast.js | 2 +- findLastIndex.js | 2 +- findLastKey.js | 3 +- flatMap.js | 2 +- flatMapDeep.js | 2 +- flatMapDepth.js | 2 +- flip.js | 6 +- flow.js | 2 +- flowRight.js | 2 +- fromPairs.js | 4 +- function.js | 2 +- get.js | 2 +- groupBy.js | 2 +- identity.js | 4 +- includes.js | 4 +- intersection.js | 4 +- intersectionBy.js | 9 ++- intersectionWith.js | 4 +- invertBy.js | 3 +- invoke.js | 4 +- invokeMap.js | 8 +-- isArguments.js | 2 +- isArray.js | 4 +- isArrayBuffer.js | 24 ++----- isBoolean.js | 3 +- isBuffer.js | 10 +-- isDate.js | 25 ++----- isEqual.js | 4 +- isFunction.js | 3 +- isMap.js | 16 ++--- isMatch.js | 6 +- isNative.js | 16 ++--- isNumber.js | 3 +- isRegExp.js | 25 ++----- isSet.js | 16 ++--- isString.js | 3 +- isSymbol.js | 3 +- isTypedArray.js | 67 ++---------------- isWeakMap.js | 3 +- isWeakSet.js | 3 +- keyBy.js | 2 +- lang.default.js | 22 +++--- lang.js | 3 +- lastIndexOf.js | 5 +- lodash.default.js | 31 +++++---- lodash.js | 4 +- map.js | 3 +- mapKeys.js | 3 +- mapValues.js | 3 +- matches.js | 10 +-- matchesProperty.js | 10 +-- math.js | 2 +- maxBy.js | 5 +- meanBy.js | 5 +- merge.js | 12 ++-- mergeWith.js | 13 +--- method.js | 4 +- methodOf.js | 4 +- minBy.js | 5 +- multiply.js | 2 +- negate.js | 9 ++- noop.js | 2 +- nthArg.js | 4 +- number.js | 2 +- object.default.js | 21 +++--- object.js | 3 +- omit.js | 4 +- omitBy.js | 11 ++- once.js | 2 +- over.js | 4 +- overArgs.js | 16 ++--- overEvery.js | 4 +- overSome.js | 4 +- package.json | 2 +- partial.js | 14 ++-- partialRight.js | 14 ++-- partition.js | 3 +- pick.js | 4 +- pickBy.js | 6 +- pull.js | 4 +- pullAllBy.js | 4 +- pullAt.js | 4 +- rearg.js | 10 +-- reject.js | 9 +-- remove.js | 2 +- rest.js | 30 +------- seq.js | 2 +- some.js | 3 +- sortBy.js | 16 ++--- sortedIndexBy.js | 4 +- sortedLastIndexBy.js | 4 +- sortedUniqBy.js | 2 +- spread.js | 4 +- startsWith.js | 3 +- string.js | 2 +- stubArray.js | 2 +- stubFalse.js | 2 +- stubObject.js | 2 +- stubString.js | 2 +- stubTrue.js | 2 +- subtract.js | 2 +- sumBy.js | 5 +- takeRightWhile.js | 2 +- takeWhile.js | 2 +- toArray.js | 2 +- union.js | 4 +- unionBy.js | 11 +-- unionWith.js | 7 +- uniqBy.js | 4 +- unzip.js | 6 +- util.default.js | 13 ++-- util.js | 3 +- without.js | 6 +- wrap.js | 8 +-- wrapperAt.js | 4 +- wrapperLodash.js | 20 +++--- xor.js | 4 +- xorBy.js | 8 +-- xorWith.js | 4 +- zip.js | 8 +-- zipWith.js | 4 +- 231 files changed, 1136 insertions(+), 820 deletions(-) create mode 100644 _baseConformsTo.js create mode 100644 _baseGetTag.js create mode 100644 _baseIsArrayBuffer.js create mode 100644 _baseIsDate.js create mode 100644 _baseIsMap.js create mode 100644 _baseIsNaN.js create mode 100644 _baseIsRegExp.js create mode 100644 _baseIsSet.js create mode 100644 _baseIsTypedArray.js create mode 100644 _basePropertyOf.js create mode 100644 _baseRest.js delete mode 100644 _checkGlobal.js rename _createBaseWrapper.js => _createBind.js (62%) rename _createCtorWrapper.js => _createCtor.js (95%) rename _createCurryWrapper.js => _createCurry.js (66%) rename _createHybridWrapper.js => _createHybrid.js (80%) rename _createPartialWrapper.js => _createPartial.js (75%) rename _createRecurryWrapper.js => _createRecurry.js (81%) rename _createWrapper.js => _createWrap.js (79%) create mode 100644 _defineProperty.js create mode 100644 _freeGlobal.js create mode 100644 _getWrapDetails.js delete mode 100644 _indexOfNaN.js create mode 100644 _insertWrapDetails.js delete mode 100644 _isFlattenableIteratee.js create mode 100644 _nodeUtil.js create mode 100644 _overArg.js create mode 100644 _setWrapToString.js create mode 100644 _updateWrapDetails.js create mode 100644 conformsTo.js create mode 100644 defaultTo.js diff --git a/README.md b/README.md index b9cb70eb4..a18f4c0c4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-es v4.13.1 +# lodash-es v4.14.0 The [Lodash](https://lodash.com/) library exported as [ES](http://www.ecma-international.org/ecma-262/6.0/) modules. @@ -7,4 +7,4 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli): $ lodash modularize exports=es -o ./ ``` -See the [package source](https://github.com/lodash/lodash/tree/4.13.1-es) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.14.0-es) for more details. diff --git a/_addMapEntry.js b/_addMapEntry.js index a5094faf0..33f57a259 100644 --- a/_addMapEntry.js +++ b/_addMapEntry.js @@ -7,7 +7,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; } diff --git a/_addSetEntry.js b/_addSetEntry.js index a999aed9c..c02b5ccf7 100644 --- a/_addSetEntry.js +++ b/_addSetEntry.js @@ -7,6 +7,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; } diff --git a/_apply.js b/_apply.js index 479688583..a92f5a88c 100644 --- a/_apply.js +++ b/_apply.js @@ -9,8 +9,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]); diff --git a/_baseClamp.js b/_baseClamp.js index bb05ec270..bf9a927c7 100644 --- a/_baseClamp.js +++ b/_baseClamp.js @@ -1,5 +1,5 @@ /** - * 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 124c1f163..e4fd8f36b 100644 --- a/_baseClone.js +++ b/_baseClone.js @@ -125,14 +125,17 @@ function baseClone(value, isDeep, isFull, customizer, key, object, stack) { 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 103c9f4cb..d7633c130 100644 --- a/_baseConforms.js +++ b/_baseConforms.js @@ -1,3 +1,4 @@ +import baseConformsTo from './_baseConformsTo.js'; import keys from './keys.js'; /** @@ -8,25 +9,9 @@ import keys from './keys.js'; * @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..3dc05d01f --- /dev/null +++ b/_baseConformsTo.js @@ -0,0 +1,28 @@ +/** + * 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; +} + +export default baseConformsTo; diff --git a/_baseDelay.js b/_baseDelay.js index a0ca3892b..489835411 100644 --- a/_baseDelay.js +++ b/_baseDelay.js @@ -2,13 +2,13 @@ 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..70211645c --- /dev/null +++ b/_baseGetTag.js @@ -0,0 +1,22 @@ +/** 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); +} + +export default baseGetTag; diff --git a/_baseGt.js b/_baseGt.js index a237f3dab..998cf158c 100644 --- a/_baseGt.js +++ b/_baseGt.js @@ -1,5 +1,5 @@ /** - * 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 82636b272..4b249a55b 100644 --- a/_baseInRange.js +++ b/_baseInRange.js @@ -3,7 +3,7 @@ var nativeMax = Math.max, 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 f8477a9ae..9152c3edc 100644 --- a/_baseIndexOf.js +++ b/_baseIndexOf.js @@ -1,4 +1,5 @@ -import indexOfNaN from './_indexOfNaN.js'; +import baseFindIndex from './_baseFindIndex.js'; +import baseIsNaN from './_baseIsNaN.js'; /** * The base implementation of `_.indexOf` without `fromIndex` bounds checks. @@ -11,7 +12,7 @@ import indexOfNaN from './_indexOfNaN.js'; */ 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..3903613ec --- /dev/null +++ b/_baseIsArrayBuffer.js @@ -0,0 +1,26 @@ +import isObjectLike from './isObjectLike.js'; + +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; +} + +export default baseIsArrayBuffer; diff --git a/_baseIsDate.js b/_baseIsDate.js new file mode 100644 index 000000000..6483d0527 --- /dev/null +++ b/_baseIsDate.js @@ -0,0 +1,27 @@ +import isObjectLike from './isObjectLike.js'; + +/** `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; +} + +export default baseIsDate; diff --git a/_baseIsMap.js b/_baseIsMap.js new file mode 100644 index 000000000..6438d2b03 --- /dev/null +++ b/_baseIsMap.js @@ -0,0 +1,18 @@ +import getTag from './_getTag.js'; +import isObjectLike from './isObjectLike.js'; + +/** `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; +} + +export default baseIsMap; diff --git a/_baseIsNaN.js b/_baseIsNaN.js new file mode 100644 index 000000000..7a36d0ee3 --- /dev/null +++ b/_baseIsNaN.js @@ -0,0 +1,12 @@ +/** + * 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; +} + +export default baseIsNaN; diff --git a/_baseIsRegExp.js b/_baseIsRegExp.js new file mode 100644 index 000000000..3ce35c8f5 --- /dev/null +++ b/_baseIsRegExp.js @@ -0,0 +1,27 @@ +import isObject from './isObject.js'; + +/** `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; +} + +export default baseIsRegExp; diff --git a/_baseIsSet.js b/_baseIsSet.js new file mode 100644 index 000000000..bee4a8e4b --- /dev/null +++ b/_baseIsSet.js @@ -0,0 +1,18 @@ +import getTag from './_getTag.js'; +import isObjectLike from './isObjectLike.js'; + +/** `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; +} + +export default baseIsSet; diff --git a/_baseIsTypedArray.js b/_baseIsTypedArray.js new file mode 100644 index 000000000..913dcb9a7 --- /dev/null +++ b/_baseIsTypedArray.js @@ -0,0 +1,69 @@ +import isLength from './isLength.js'; +import isObjectLike from './isObjectLike.js'; + +/** `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)]; +} + +export default baseIsTypedArray; diff --git a/_baseKeys.js b/_baseKeys.js index 7e3b31eb6..913a2ecfb 100644 --- a/_baseKeys.js +++ b/_baseKeys.js @@ -1,3 +1,5 @@ +import overArg from './_overArg.js'; + /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeKeys = Object.keys; @@ -9,8 +11,6 @@ var nativeKeys = Object.keys; * @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); export default baseKeys; diff --git a/_baseLt.js b/_baseLt.js index 1ba6745a9..e70ad2d55 100644 --- a/_baseLt.js +++ b/_baseLt.js @@ -1,5 +1,5 @@ /** - * 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 3e0e0ef00..96433f6f0 100644 --- a/_baseMergeDeep.js +++ b/_baseMergeDeep.js @@ -70,13 +70,12 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, sta 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 df0874135..0a6e9998b 100644 --- a/_baseNth.js +++ b/_baseNth.js @@ -1,7 +1,7 @@ import isIndex from './_isIndex.js'; /** - * 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 36528b77b..afdf4b2c3 100644 --- a/_basePick.js +++ b/_basePick.js @@ -1,4 +1,4 @@ -import arrayReduce from './_arrayReduce.js'; +import basePickBy from './_basePickBy.js'; /** * The base implementation of `_.pick` without support for individual @@ -11,12 +11,9 @@ import arrayReduce from './_arrayReduce.js'; */ 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; + }); } export default basePick; diff --git a/_basePickBy.js b/_basePickBy.js index 22d8aa905..5352a3b7e 100644 --- a/_basePickBy.js +++ b/_basePickBy.js @@ -1,16 +1,14 @@ -import getAllKeysIn from './_getAllKeysIn.js'; - /** * 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..e0ec2b860 --- /dev/null +++ b/_basePropertyOf.js @@ -0,0 +1,14 @@ +/** + * 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]; + }; +} + +export default basePropertyOf; diff --git a/_baseRange.js b/_baseRange.js index f179f14e8..12e48b031 100644 --- a/_baseRange.js +++ b/_baseRange.js @@ -4,7 +4,7 @@ var nativeCeil = Math.ceil, /** * 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..6ca3256c6 --- /dev/null +++ b/_baseRest.js @@ -0,0 +1,35 @@ +import apply from './_apply.js'; + +/* 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); + }; +} + +export default baseRest; diff --git a/_baseUnary.js b/_baseUnary.js index 23a25e32d..e756a3222 100644 --- a/_baseUnary.js +++ b/_baseUnary.js @@ -1,5 +1,5 @@ /** - * 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 523609a94..000000000 --- a/_checkGlobal.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * 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; -} - -export default checkGlobal; diff --git a/_copyObject.js b/_copyObject.js index 03d6a671f..7bd5f77b0 100644 --- a/_copyObject.js +++ b/_copyObject.js @@ -21,9 +21,9 @@ function copyObject(source, props, object, customizer) { 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 dafa4c107..578c0ae7b 100644 --- a/_createAggregator.js +++ b/_createAggregator.js @@ -16,7 +16,7 @@ function createAggregator(setter, initializer) { 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 f309b2f35..67dc499b5 100644 --- a/_createAssigner.js +++ b/_createAssigner.js @@ -1,5 +1,5 @@ +import baseRest from './_baseRest.js'; import isIterateeCall from './_isIterateeCall.js'; -import rest from './rest.js'; /** * Creates a function like `_.assign`. @@ -9,7 +9,7 @@ import rest from './rest.js'; * @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 62% rename from _createBaseWrapper.js rename to _createBind.js index 9e968d62d..b16c99b45 100644 --- a/_createBaseWrapper.js +++ b/_createBind.js @@ -1,7 +1,7 @@ -import createCtorWrapper from './_createCtorWrapper.js'; +import createCtor from './_createCtor.js'; import root from './_root.js'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1; /** @@ -10,14 +10,13 @@ var BIND_FLAG = 1; * * @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; @@ -26,4 +25,4 @@ function createBaseWrapper(func, bitmask, thisArg) { return wrapper; } -export default createBaseWrapper; +export default createBind; diff --git a/_createCtorWrapper.js b/_createCtor.js similarity index 95% rename from _createCtorWrapper.js rename to _createCtor.js index d57b5818d..14a123292 100644 --- a/_createCtorWrapper.js +++ b/_createCtor.js @@ -9,7 +9,7 @@ import isObject from './isObject.js'; * @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 @@ -34,4 +34,4 @@ function createCtorWrapper(Ctor) { }; } -export default createCtorWrapper; +export default createCtor; diff --git a/_createCurryWrapper.js b/_createCurry.js similarity index 66% rename from _createCurryWrapper.js rename to _createCurry.js index ccb39b297..cae7f9343 100644 --- a/_createCurryWrapper.js +++ b/_createCurry.js @@ -1,7 +1,7 @@ import apply from './_apply.js'; -import createCtorWrapper from './_createCtorWrapper.js'; -import createHybridWrapper from './_createHybridWrapper.js'; -import createRecurryWrapper from './_createRecurryWrapper.js'; +import createCtor from './_createCtor.js'; +import createHybrid from './_createHybrid.js'; +import createRecurry from './_createRecurry.js'; import getHolder from './_getHolder.js'; import replaceHolders from './_replaceHolders.js'; import root from './_root.js'; @@ -11,13 +11,12 @@ import root from './_root.js'; * * @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, @@ -34,8 +33,8 @@ function createCurryWrapper(func, bitmask, arity) { 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; @@ -44,4 +43,4 @@ function createCurryWrapper(func, bitmask, arity) { return wrapper; } -export default createCurryWrapper; +export default createCurry; diff --git a/_createFind.js b/_createFind.js index 8d8986aa3..d3f8bd55f 100644 --- a/_createFind.js +++ b/_createFind.js @@ -12,18 +12,13 @@ import keys from './keys.js'; 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 b4ae81768..c2e5e2fe7 100644 --- a/_createFlow.js +++ b/_createFlow.js @@ -1,10 +1,10 @@ import LodashWrapper from './_LodashWrapper.js'; import baseFlatten from './_baseFlatten.js'; +import baseRest from './_baseRest.js'; import getData from './_getData.js'; import getFuncName from './_getFuncName.js'; import isArray from './isArray.js'; import isLaziable from './_isLaziable.js'; -import rest from './rest.js'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -12,7 +12,7 @@ var LARGE_ARRAY_SIZE = 200; /** 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, @@ -26,7 +26,7 @@ var CURRY_FLAG = 8, * @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 80% rename from _createHybridWrapper.js rename to _createHybrid.js index bb20e8b2c..ab2cd856b 100644 --- a/_createHybridWrapper.js +++ b/_createHybrid.js @@ -1,14 +1,14 @@ import composeArgs from './_composeArgs.js'; import composeArgsRight from './_composeArgsRight.js'; import countHolders from './_countHolders.js'; -import createCtorWrapper from './_createCtorWrapper.js'; -import createRecurryWrapper from './_createRecurryWrapper.js'; +import createCtor from './_createCtor.js'; +import createRecurry from './_createRecurry.js'; import getHolder from './_getHolder.js'; import reorder from './_reorder.js'; import replaceHolders from './_replaceHolders.js'; import root from './_root.js'; -/** 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, @@ -22,8 +22,7 @@ var BIND_FLAG = 1, * * @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. @@ -36,13 +35,13 @@ var BIND_FLAG = 1, * @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, @@ -65,8 +64,8 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials 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 ); } @@ -83,11 +82,11 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials 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; } -export default createHybridWrapper; +export default createHybrid; diff --git a/_createMathOperation.js b/_createMathOperation.js index 1a9bbf8e9..cffe75d85 100644 --- a/_createMathOperation.js +++ b/_createMathOperation.js @@ -6,13 +6,14 @@ import baseToString from './_baseToString.js'; * * @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 e915e9390..2c842bef6 100644 --- a/_createOver.js +++ b/_createOver.js @@ -2,10 +2,9 @@ import apply from './_apply.js'; import arrayMap from './_arrayMap.js'; import baseFlatten from './_baseFlatten.js'; import baseIteratee from './_baseIteratee.js'; +import baseRest from './_baseRest.js'; import baseUnary from './_baseUnary.js'; import isArray from './isArray.js'; -import isFlattenableIteratee from './_isFlattenableIteratee.js'; -import rest from './rest.js'; /** * Creates a function like `_.over`. @@ -15,12 +14,12 @@ import rest from './rest.js'; * @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 75% rename from _createPartialWrapper.js rename to _createPartial.js index 3eef9bac4..036d557ec 100644 --- a/_createPartialWrapper.js +++ b/_createPartial.js @@ -1,8 +1,8 @@ import apply from './_apply.js'; -import createCtorWrapper from './_createCtorWrapper.js'; +import createCtor from './_createCtor.js'; import root from './_root.js'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1; /** @@ -11,16 +11,15 @@ var BIND_FLAG = 1; * * @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, @@ -41,4 +40,4 @@ function createPartialWrapper(func, bitmask, thisArg, partials) { return wrapper; } -export default createPartialWrapper; +export default createPartial; diff --git a/_createRecurryWrapper.js b/_createRecurry.js similarity index 81% rename from _createRecurryWrapper.js rename to _createRecurry.js index 2d647cda3..73195844d 100644 --- a/_createRecurryWrapper.js +++ b/_createRecurry.js @@ -1,7 +1,8 @@ import isLaziable from './_isLaziable.js'; import setData from './_setData.js'; +import setWrapToString from './_setWrapToString.js'; -/** 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, @@ -14,8 +15,7 @@ var BIND_FLAG = 1, * * @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`. @@ -27,7 +27,7 @@ var BIND_FLAG = 1, * @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, @@ -50,7 +50,7 @@ function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, par setData(result, newData); } result.placeholder = placeholder; - return result; + return setWrapToString(result, func, bitmask); } -export default createRecurryWrapper; +export default createRecurry; diff --git a/_createSet.js b/_createSet.js index f6062e5b3..ead1dd70d 100644 --- a/_createSet.js +++ b/_createSet.js @@ -6,7 +6,7 @@ import setToArray from './_setToArray.js'; 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 79% rename from _createWrapper.js rename to _createWrap.js index b5b219f5e..997b825db 100644 --- a/_createWrapper.js +++ b/_createWrap.js @@ -1,17 +1,18 @@ import baseSetData from './_baseSetData.js'; -import createBaseWrapper from './_createBaseWrapper.js'; -import createCurryWrapper from './_createCurryWrapper.js'; -import createHybridWrapper from './_createHybridWrapper.js'; -import createPartialWrapper from './_createPartialWrapper.js'; +import createBind from './_createBind.js'; +import createCurry from './_createCurry.js'; +import createHybrid from './_createHybrid.js'; +import createPartial from './_createPartial.js'; import getData from './_getData.js'; import mergeData from './_mergeData.js'; import setData from './_setData.js'; +import setWrapToString from './_setWrapToString.js'; import toInteger from './toInteger.js'; /** 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, @@ -28,7 +29,7 @@ var nativeMax = Math.max; * * @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` @@ -48,7 +49,7 @@ var nativeMax = Math.max; * @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); @@ -91,16 +92,16 @@ function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, a 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); } -export default createWrapper; +export default createWrap; diff --git a/_deburrLetter.js b/_deburrLetter.js index a0eab9f06..fe6a3ab90 100644 --- a/_deburrLetter.js +++ b/_deburrLetter.js @@ -1,3 +1,5 @@ +import basePropertyOf from './_basePropertyOf.js'; + /** Used to map latin-1 supplementary letters to basic latin letters. */ var deburredLetters = { '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', @@ -26,8 +28,6 @@ var deburredLetters = { * @param {string} letter The matched letter to deburr. * @returns {string} Returns the deburred letter. */ -function deburrLetter(letter) { - return deburredLetters[letter]; -} +var deburrLetter = basePropertyOf(deburredLetters); export default deburrLetter; diff --git a/_defineProperty.js b/_defineProperty.js new file mode 100644 index 000000000..fcab11552 --- /dev/null +++ b/_defineProperty.js @@ -0,0 +1,11 @@ +import getNative from './_getNative.js'; + +/* Used to set `toString` methods. */ +var defineProperty = (function() { + var func = getNative(Object, 'defineProperty'), + name = getNative.name; + + return (name && name.length > 2) ? func : undefined; +}()); + +export default defineProperty; diff --git a/_equalArrays.js b/_equalArrays.js index 4ed5fcb1f..b851a2904 100644 --- a/_equalArrays.js +++ b/_equalArrays.js @@ -29,7 +29,7 @@ function equalArrays(array, other, equalFunc, customizer, bitmask, stack) { } // Assume cyclic values are equal. var stacked = stack.get(array); - if (stacked) { + if (stacked && stack.get(other)) { return stacked == other; } var index = -1, @@ -37,6 +37,7 @@ function equalArrays(array, other, equalFunc, customizer, bitmask, stack) { 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 334769de7..c12862dd0 100644 --- a/_equalByTag.js +++ b/_equalByTag.js @@ -1,5 +1,6 @@ import Symbol from './_Symbol.js'; import Uint8Array from './_Uint8Array.js'; +import eq from './eq.js'; import equalArrays from './_equalArrays.js'; import mapToArray from './_mapToArray.js'; import setToArray from './_setToArray.js'; @@ -63,18 +64,14 @@ function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) { 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, @@ -98,10 +95,12 @@ function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) { 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 93facbc10..fbd4b3a2a 100644 --- a/_equalObjects.js +++ b/_equalObjects.js @@ -37,11 +37,12 @@ function equalObjects(object, other, equalFunc, customizer, bitmask, stack) { } // 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 58e9f4ac8..6535d1a12 100644 --- a/_escapeHtmlChar.js +++ b/_escapeHtmlChar.js @@ -1,3 +1,5 @@ +import basePropertyOf from './_basePropertyOf.js'; + /** Used to map characters to HTML entities. */ var htmlEscapes = { '&': '&', @@ -15,8 +17,6 @@ var htmlEscapes = { * @param {string} chr The matched character to escape. * @returns {string} Returns the escaped character. */ -function escapeHtmlChar(chr) { - return htmlEscapes[chr]; -} +var escapeHtmlChar = basePropertyOf(htmlEscapes); export default escapeHtmlChar; diff --git a/_freeGlobal.js b/_freeGlobal.js new file mode 100644 index 000000000..5e383a14c --- /dev/null +++ b/_freeGlobal.js @@ -0,0 +1,4 @@ +/** Detect free variable `global` from Node.js. */ +var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; + +export default freeGlobal; diff --git a/_getPrototype.js b/_getPrototype.js index 445a0231f..bdd536231 100644 --- a/_getPrototype.js +++ b/_getPrototype.js @@ -1,3 +1,5 @@ +import overArg from './_overArg.js'; + /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeGetPrototype = Object.getPrototypeOf; @@ -8,8 +10,6 @@ var nativeGetPrototype = Object.getPrototypeOf; * @param {*} value The value to query. * @returns {null|Object} Returns the `[[Prototype]]`. */ -function getPrototype(value) { - return nativeGetPrototype(Object(value)); -} +var getPrototype = overArg(nativeGetPrototype, Object); export default getPrototype; diff --git a/_getSymbols.js b/_getSymbols.js index cdb107c4f..b748002d6 100644 --- a/_getSymbols.js +++ b/_getSymbols.js @@ -1,7 +1,8 @@ +import overArg from './_overArg.js'; import stubArray from './stubArray.js'; -/** 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,15 +11,6 @@ var getOwnPropertySymbols = Object.getOwnPropertySymbols; * @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; export default getSymbols; diff --git a/_getSymbolsIn.js b/_getSymbolsIn.js index 27bb01c73..a4c3b1aa9 100644 --- a/_getSymbolsIn.js +++ b/_getSymbolsIn.js @@ -2,8 +2,8 @@ import arrayPush from './_arrayPush.js'; import getPrototype from './_getPrototype.js'; import getSymbols from './_getSymbols.js'; -/** 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 @@ -13,7 +13,7 @@ var getOwnPropertySymbols = Object.getOwnPropertySymbols; * @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 8b1abd4ef..c583966f7 100644 --- a/_getTag.js +++ b/_getTag.js @@ -3,6 +3,7 @@ import Map from './_Map.js'; import Promise from './_Promise.js'; import Set from './_Set.js'; import WeakMap from './_WeakMap.js'; +import baseGetTag from './_baseGetTag.js'; import toSource from './_toSource.js'; /** `Object#toString` result references. */ @@ -38,9 +39,7 @@ var dataViewCtorString = toSource(DataView), * @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..1de838d81 --- /dev/null +++ b/_getWrapDetails.js @@ -0,0 +1,17 @@ +/** 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) : []; +} + +export default getWrapDetails; diff --git a/_indexOfNaN.js b/_indexOfNaN.js deleted file mode 100644 index 5a8f0225e..000000000 --- a/_indexOfNaN.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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; -} - -export default indexOfNaN; diff --git a/_insertWrapDetails.js b/_insertWrapDetails.js new file mode 100644 index 000000000..3ac974c00 --- /dev/null +++ b/_insertWrapDetails.js @@ -0,0 +1,21 @@ +/** 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'); +} + +export default insertWrapDetails; diff --git a/_isFlattenable.js b/_isFlattenable.js index 3fbb434dc..854147fe1 100644 --- a/_isFlattenable.js +++ b/_isFlattenable.js @@ -1,6 +1,10 @@ +import Symbol from './_Symbol.js'; import isArguments from './isArguments.js'; import isArray from './isArray.js'; +/** Built-in value references. */ +var spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; + /** * Checks if `value` is a flattenable `arguments` object or array. * @@ -9,7 +13,8 @@ import isArray from './isArray.js'; * @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]) } export default isFlattenable; diff --git a/_isFlattenableIteratee.js b/_isFlattenableIteratee.js deleted file mode 100644 index 63359df44..000000000 --- a/_isFlattenableIteratee.js +++ /dev/null @@ -1,16 +0,0 @@ -import isArray from './isArray.js'; -import isFunction from './isFunction.js'; - -/** - * 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])); -} - -export default isFlattenableIteratee; diff --git a/_mergeData.js b/_mergeData.js index c22fbd996..c8f012e64 100644 --- a/_mergeData.js +++ b/_mergeData.js @@ -5,7 +5,7 @@ import replaceHolders from './_replaceHolders.js'; /** 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 b262d18f2..1e3b7b5a1 100644 --- a/_mergeDefaults.js +++ b/_mergeDefaults.js @@ -16,7 +16,10 @@ import isObject from './isObject.js'; */ 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..b4a9b47b0 --- /dev/null +++ b/_nodeUtil.js @@ -0,0 +1,22 @@ +import freeGlobal from './_freeGlobal.js'; + +/** 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) {} +}()); + +export default nodeUtil; diff --git a/_overArg.js b/_overArg.js new file mode 100644 index 000000000..637d06c82 --- /dev/null +++ b/_overArg.js @@ -0,0 +1,15 @@ +/** + * 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)); + }; +} + +export default overArg; diff --git a/_root.js b/_root.js index 45b72b891..281f81280 100644 --- a/_root.js +++ b/_root.js @@ -1,15 +1,9 @@ -import checkGlobal from './_checkGlobal.js'; - -/** Detect free variable `global` from Node.js. */ -var freeGlobal = checkGlobal(typeof global == 'object' && global); +import freeGlobal from './_freeGlobal.js'; /** 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')(); export default root; diff --git a/_setWrapToString.js b/_setWrapToString.js new file mode 100644 index 000000000..85f44b3f8 --- /dev/null +++ b/_setWrapToString.js @@ -0,0 +1,27 @@ +import constant from './constant.js'; +import defineProperty from './_defineProperty.js'; +import getWrapDetails from './_getWrapDetails.js'; +import identity from './identity.js'; +import insertWrapDetails from './_insertWrapDetails.js'; +import updateWrapDetails from './_updateWrapDetails.js'; + +/** + * 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))) + }); +}; + +export default setWrapToString; diff --git a/_stackSet.js b/_stackSet.js index 719f20b2b..000735cd3 100644 --- a/_stackSet.js +++ b/_stackSet.js @@ -1,4 +1,5 @@ import ListCache from './_ListCache.js'; +import Map from './_Map.js'; import MapCache from './_MapCache.js'; /** Used as the size to enable large array optimizations. */ @@ -16,8 +17,13 @@ var LARGE_ARRAY_SIZE = 200; */ 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 ab3171e25..d3dbcecb2 100644 --- a/_unescapeHtmlChar.js +++ b/_unescapeHtmlChar.js @@ -1,3 +1,5 @@ +import basePropertyOf from './_basePropertyOf.js'; + /** Used to map HTML entities to characters. */ var htmlUnescapes = { '&': '&', @@ -15,8 +17,6 @@ var htmlUnescapes = { * @param {string} chr The matched character to unescape. * @returns {string} Returns the unescaped character. */ -function unescapeHtmlChar(chr) { - return htmlUnescapes[chr]; -} +var unescapeHtmlChar = basePropertyOf(htmlUnescapes); export default unescapeHtmlChar; diff --git a/_updateWrapDetails.js b/_updateWrapDetails.js new file mode 100644 index 000000000..9032d308a --- /dev/null +++ b/_updateWrapDetails.js @@ -0,0 +1,46 @@ +import arrayEach from './_arrayEach.js'; +import arrayIncludes from './_arrayIncludes.js'; + +/** 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(); +} + +export default updateWrapDetails; diff --git a/add.js b/add.js index 7c7e74970..b17f10771 100644 --- a/add.js +++ b/add.js @@ -17,6 +17,6 @@ import createMathOperation from './_createMathOperation.js'; */ var add = createMathOperation(function(augend, addend) { return augend + addend; -}); +}, 0); export default add; diff --git a/array.js b/array.js index acb4afacd..b579b5c98 100644 --- a/array.js +++ b/array.js @@ -63,4 +63,4 @@ export { default as zip } from './zip.js'; export { default as zipObject } from './zipObject.js'; export { default as zipObjectDeep } from './zipObjectDeep.js'; export { default as zipWith } from './zipWith.js'; -export { default as default } from './array.default'; +export { default } from './array.default.js'; diff --git a/ary.js b/ary.js index 592cc8a2a..76a95cb7d 100644 --- a/ary.js +++ b/ary.js @@ -1,6 +1,6 @@ -import createWrapper from './_createWrapper.js'; +import createWrap from './_createWrap.js'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var ARY_FLAG = 128; /** @@ -23,7 +23,7 @@ var ARY_FLAG = 128; 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); } export default ary; diff --git a/assign.js b/assign.js index 07e639494..fe485002b 100644 --- a/assign.js +++ b/assign.js @@ -36,18 +36,18 @@ var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf'); * @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 4d673f6e0..644107adf 100644 --- a/assignIn.js +++ b/assignIn.js @@ -32,18 +32,18 @@ var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf'); * @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 0033ed8c1..92c317338 100644 --- a/at.js +++ b/at.js @@ -1,6 +1,6 @@ import baseAt from './_baseAt.js'; import baseFlatten from './_baseFlatten.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; /** * Creates an array of values corresponding to `paths` of `object`. @@ -19,7 +19,7 @@ import rest from './rest.js'; * _.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 019d352b3..ff4df2813 100644 --- a/attempt.js +++ b/attempt.js @@ -1,6 +1,6 @@ import apply from './_apply.js'; +import baseRest from './_baseRest.js'; import isError from './isError.js'; -import rest from './rest.js'; /** * Attempts to invoke `func`, returning either the result or the caught error @@ -24,7 +24,7 @@ import rest from './rest.js'; * 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 3e49da548..b854ca762 100644 --- a/before.js +++ b/before.js @@ -18,7 +18,7 @@ var FUNC_ERROR_TEXT = 'Expected a function'; * @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 b6e4ab6b5..ca8f7174b 100644 --- a/bind.js +++ b/bind.js @@ -1,9 +1,9 @@ -import createWrapper from './_createWrapper.js'; +import baseRest from './_baseRest.js'; +import createWrap from './_createWrap.js'; import getHolder from './_getHolder.js'; import replaceHolders from './_replaceHolders.js'; -import rest from './rest.js'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var BIND_FLAG = 1, PARTIAL_FLAG = 32; @@ -27,9 +27,9 @@ var BIND_FLAG = 1, * @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' }; * @@ -42,13 +42,13 @@ var BIND_FLAG = 1, * 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 04e3492c8..05864a24f 100644 --- a/bindAll.js +++ b/bindAll.js @@ -1,7 +1,7 @@ import arrayEach from './_arrayEach.js'; import baseFlatten from './_baseFlatten.js'; +import baseRest from './_baseRest.js'; import bind from './bind.js'; -import rest from './rest.js'; import toKey from './_toKey.js'; /** @@ -21,16 +21,16 @@ import toKey from './_toKey.js'; * * 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 51778db85..f18f426a8 100644 --- a/bindKey.js +++ b/bindKey.js @@ -1,9 +1,9 @@ -import createWrapper from './_createWrapper.js'; +import baseRest from './_baseRest.js'; +import createWrap from './_createWrap.js'; import getHolder from './_getHolder.js'; import replaceHolders from './_replaceHolders.js'; -import rest from './rest.js'; -/** 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; @@ -53,13 +53,13 @@ var BIND_FLAG = 1, * 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.default.js b/collection.default.js index ff56c45a6..2f262bfd7 100644 --- a/collection.default.js +++ b/collection.default.js @@ -1,4 +1,3 @@ -import at from './at.js'; import countBy from './countBy.js'; import each from './each.js'; import eachRight from './eachRight.js'; @@ -29,10 +28,10 @@ import some from './some.js'; import sortBy from './sortBy.js'; export default { - 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 + 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 }; diff --git a/collection.js b/collection.js index 307d94490..2c9fab977 100644 --- a/collection.js +++ b/collection.js @@ -1,4 +1,3 @@ -export { default as at } from './at.js'; export { default as countBy } from './countBy.js'; export { default as each } from './each.js'; export { default as eachRight } from './eachRight.js'; @@ -27,4 +26,4 @@ export { default as shuffle } from './shuffle.js'; export { default as size } from './size.js'; export { default as some } from './some.js'; export { default as sortBy } from './sortBy.js'; -export { default as default } from './collection.default'; +export { default } from './collection.default.js'; diff --git a/cond.js b/cond.js index dec7766df..ae53c78ca 100644 --- a/cond.js +++ b/cond.js @@ -1,7 +1,7 @@ import apply from './_apply.js'; import arrayMap from './_arrayMap.js'; import baseIteratee from './_baseIteratee.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; /** Used as the `TypeError` message for "Functions" methods. */ var FUNC_ERROR_TEXT = 'Expected a function'; @@ -23,7 +23,7 @@ var FUNC_ERROR_TEXT = 'Expected a function'; * 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 }); @@ -46,7 +46,7 @@ function cond(pairs) { 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 79afafd7e..6b24146b3 100644 --- a/conforms.js +++ b/conforms.js @@ -14,13 +14,13 @@ import baseConforms from './_baseConforms.js'; * @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..fbd377fcb --- /dev/null +++ b/conformsTo.js @@ -0,0 +1,30 @@ +import baseConformsTo from './_baseConformsTo.js'; +import keys from './keys.js'; + +/** + * 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)); +} + +export default conformsTo; diff --git a/countBy.js b/countBy.js index acbdd19c4..3d3ea1546 100644 --- a/countBy.js +++ b/countBy.js @@ -17,7 +17,7 @@ var hasOwnProperty = objectProto.hasOwnProperty; * @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 38228fda9..c269536d5 100644 --- a/curry.js +++ b/curry.js @@ -1,6 +1,6 @@ -import createWrapper from './_createWrapper.js'; +import createWrap from './_createWrap.js'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var CURRY_FLAG = 8; /** @@ -46,7 +46,7 @@ var CURRY_FLAG = 8; */ 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 ea08d0be1..8aab2d103 100644 --- a/curryRight.js +++ b/curryRight.js @@ -1,6 +1,6 @@ -import createWrapper from './_createWrapper.js'; +import createWrap from './_createWrap.js'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var CURRY_RIGHT_FLAG = 16; /** @@ -43,7 +43,7 @@ var CURRY_RIGHT_FLAG = 16; */ 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/date.js b/date.js index 56c92bcf2..bea18b62e 100644 --- a/date.js +++ b/date.js @@ -1,2 +1,2 @@ export { default as now } from './now.js'; -export { default as default } from './date.default'; +export { default } from './date.default.js'; diff --git a/debounce.js b/debounce.js index 1a7ca7234..29599b8bb 100644 --- a/debounce.js +++ b/debounce.js @@ -142,6 +142,9 @@ function debounce(func, wait, options) { } 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..2fafeacb5 --- /dev/null +++ b/defaultTo.js @@ -0,0 +1,25 @@ +/** + * 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; +} + +export default defaultTo; diff --git a/defaults.js b/defaults.js index 614b2c6a9..a460e454a 100644 --- a/defaults.js +++ b/defaults.js @@ -1,7 +1,7 @@ import apply from './_apply.js'; import assignInDefaults from './_assignInDefaults.js'; import assignInWith from './assignInWith.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; /** * Assigns own and inherited enumerable string keyed properties of source @@ -21,10 +21,10 @@ import rest from './rest.js'; * @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 1320536e3..10863925e 100644 --- a/defaultsDeep.js +++ b/defaultsDeep.js @@ -1,7 +1,7 @@ import apply from './_apply.js'; +import baseRest from './_baseRest.js'; import mergeDefaults from './_mergeDefaults.js'; import mergeWith from './mergeWith.js'; -import rest from './rest.js'; /** * This method is like `_.defaults` except that it recursively assigns @@ -19,11 +19,10 @@ import rest from './rest.js'; * @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 a8a42f141..45ae53ffe 100644 --- a/defer.js +++ b/defer.js @@ -1,5 +1,5 @@ import baseDelay from './_baseDelay.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; /** * Defers invoking the `func` until the current call stack has cleared. Any @@ -19,7 +19,7 @@ import rest from './rest.js'; * }, '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 308d3e002..d9b5eb468 100644 --- a/delay.js +++ b/delay.js @@ -1,5 +1,5 @@ import baseDelay from './_baseDelay.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; import toNumber from './toNumber.js'; /** @@ -21,7 +21,7 @@ import toNumber from './toNumber.js'; * }, 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 12540cbfc..eb7fd6954 100644 --- a/difference.js +++ b/difference.js @@ -1,14 +1,16 @@ import baseDifference from './_baseDifference.js'; import baseFlatten from './_baseFlatten.js'; +import baseRest from './_baseRest.js'; import isArrayLikeObject from './isArrayLikeObject.js'; -import rest from './rest.js'; /** - * 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 @@ -22,7 +24,7 @@ import rest from './rest.js'; * _.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 9af817d6a..30149e56c 100644 --- a/differenceBy.js +++ b/differenceBy.js @@ -1,9 +1,9 @@ import baseDifference from './_baseDifference.js'; import baseFlatten from './_baseFlatten.js'; import baseIteratee from './_baseIteratee.js'; +import baseRest from './_baseRest.js'; import isArrayLikeObject from './isArrayLikeObject.js'; import last from './last.js'; -import rest from './rest.js'; /** * This method is like `_.difference` except that it accepts `iteratee` which @@ -11,14 +11,15 @@ import rest from './rest.js'; * 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 * @@ -29,13 +30,13 @@ import rest from './rest.js'; * _.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 e8d5a133d..ab5014e13 100644 --- a/differenceWith.js +++ b/differenceWith.js @@ -1,8 +1,8 @@ import baseDifference from './_baseDifference.js'; import baseFlatten from './_baseFlatten.js'; +import baseRest from './_baseRest.js'; import isArrayLikeObject from './isArrayLikeObject.js'; import last from './last.js'; -import rest from './rest.js'; /** * This method is like `_.difference` except that it accepts `comparator` @@ -10,6 +10,8 @@ import rest from './rest.js'; * 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 @@ -25,7 +27,7 @@ import rest from './rest.js'; * _.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 2ef7e9185..f281786e7 100644 --- a/divide.js +++ b/divide.js @@ -17,6 +17,6 @@ import createMathOperation from './_createMathOperation.js'; */ var divide = createMathOperation(function(dividend, divisor) { return dividend / divisor; -}); +}, 1); export default divide; diff --git a/dropRightWhile.js b/dropRightWhile.js index d76b76cdb..c5cdbc6c1 100644 --- a/dropRightWhile.js +++ b/dropRightWhile.js @@ -11,8 +11,7 @@ import baseWhile from './_baseWhile.js'; * @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 f638cd4ce..d9b718ee9 100644 --- a/dropWhile.js +++ b/dropWhile.js @@ -11,7 +11,7 @@ import baseWhile from './_baseWhile.js'; * @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 505566953..65fe0a646 100644 --- a/endsWith.js +++ b/endsWith.js @@ -35,8 +35,9 @@ function endsWith(string, target, position) { ? 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; } export default endsWith; diff --git a/eq.js b/eq.js index c0c9d1099..002c991db 100644 --- a/eq.js +++ b/eq.js @@ -12,8 +12,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 diff --git a/every.js b/every.js index f64a4a4f1..3514a1d84 100644 --- a/every.js +++ b/every.js @@ -14,7 +14,7 @@ import isIterateeCall from './_isIterateeCall.js'; * @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 26ceb01ab..451f63fa7 100644 --- a/filter.js +++ b/filter.js @@ -8,12 +8,14 @@ import isArray from './isArray.js'; * `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 b12fa5b9b..7084c3f2d 100644 --- a/find.js +++ b/find.js @@ -11,7 +11,7 @@ import findIndex from './findIndex.js'; * @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 5aea01ecd..b14022522 100644 --- a/findIndex.js +++ b/findIndex.js @@ -14,7 +14,7 @@ var nativeMax = Math.max; * @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 e7d1b4a82..6e2519511 100644 --- a/findKey.js +++ b/findKey.js @@ -11,8 +11,7 @@ import baseIteratee from './_baseIteratee.js'; * @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 6e3d2e40d..d353213e7 100644 --- a/findLast.js +++ b/findLast.js @@ -10,7 +10,7 @@ import findLastIndex from './findLastIndex.js'; * @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 afedd2725..3c39a6c07 100644 --- a/findLastIndex.js +++ b/findLastIndex.js @@ -15,7 +15,7 @@ var nativeMax = Math.max, * @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 0658a13e5..67c8b2893 100644 --- a/findLastKey.js +++ b/findLastKey.js @@ -11,8 +11,7 @@ import baseIteratee from './_baseIteratee.js'; * @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 431ebe9a7..e65beb1c4 100644 --- a/flatMap.js +++ b/flatMap.js @@ -11,7 +11,7 @@ import map from './map.js'; * @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 78667dd82..125049ce6 100644 --- a/flatMapDeep.js +++ b/flatMapDeep.js @@ -13,7 +13,7 @@ var INFINITY = 1 / 0; * @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 b6f7e818a..141ebf3ad 100644 --- a/flatMapDepth.js +++ b/flatMapDepth.js @@ -11,7 +11,7 @@ import toInteger from './toInteger.js'; * @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 24a83b7d7..3cf0eeb79 100644 --- a/flip.js +++ b/flip.js @@ -1,6 +1,6 @@ -import createWrapper from './_createWrapper.js'; +import createWrap from './_createWrap.js'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var FLIP_FLAG = 512; /** @@ -22,7 +22,7 @@ var FLIP_FLAG = 512; * // => ['d', 'c', 'b', 'a'] */ function flip(func) { - return createWrapper(func, FLIP_FLAG); + return createWrap(func, FLIP_FLAG); } export default flip; diff --git a/flow.js b/flow.js index b6506bfdc..0a3e633e9 100644 --- a/flow.js +++ b/flow.js @@ -9,7 +9,7 @@ import createFlow from './_createFlow.js'; * @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 f363509a7..cec0b80ef 100644 --- a/flowRight.js +++ b/flowRight.js @@ -8,7 +8,7 @@ import createFlow from './_createFlow.js'; * @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 6da3b8be9..3fe428d21 100644 --- a/fromPairs.js +++ b/fromPairs.js @@ -10,8 +10,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, diff --git a/function.js b/function.js index fb924abb5..7c1dddfba 100644 --- a/function.js +++ b/function.js @@ -21,4 +21,4 @@ export { default as spread } from './spread.js'; export { default as throttle } from './throttle.js'; export { default as unary } from './unary.js'; export { default as wrap } from './wrap.js'; -export { default as default } from './function.default'; +export { default } from './function.default.js'; diff --git a/get.js b/get.js index a953c56a4..551783500 100644 --- a/get.js +++ b/get.js @@ -2,7 +2,7 @@ import baseGet from './_baseGet.js'; /** * 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 4dae6bb19..4b55760ee 100644 --- a/groupBy.js +++ b/groupBy.js @@ -18,7 +18,7 @@ var hasOwnProperty = objectProto.hasOwnProperty; * @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 bb6d97d36..ed074d8c8 100644 --- a/identity.js +++ b/identity.js @@ -1,5 +1,5 @@ /** - * This method returns the first argument given to it. + * This method returns the first argument it receives. * * @static * @since 0.1.0 @@ -9,7 +9,7 @@ * @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 a4f2561b6..d1b29cfa3 100644 --- a/includes.js +++ b/includes.js @@ -31,10 +31,10 @@ var nativeMax = Math.max; * _.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 40a0e896b..acccbde2d 100644 --- a/intersection.js +++ b/intersection.js @@ -1,7 +1,7 @@ import arrayMap from './_arrayMap.js'; import baseIntersection from './_baseIntersection.js'; +import baseRest from './_baseRest.js'; import castArrayLikeObject from './_castArrayLikeObject.js'; -import rest from './rest.js'; /** * Creates an array of unique values that are included in all given arrays @@ -20,7 +20,7 @@ import rest from './rest.js'; * _.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 96f2ba57d..f4627374a 100644 --- a/intersectionBy.js +++ b/intersectionBy.js @@ -1,9 +1,9 @@ import arrayMap from './_arrayMap.js'; import baseIntersection from './_baseIntersection.js'; import baseIteratee from './_baseIteratee.js'; +import baseRest from './_baseRest.js'; import castArrayLikeObject from './_castArrayLikeObject.js'; import last from './last.js'; -import rest from './rest.js'; /** * This method is like `_.intersection` except that it accepts `iteratee` @@ -16,8 +16,7 @@ import rest from './rest.js'; * @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 * @@ -28,7 +27,7 @@ import rest from './rest.js'; * _.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); @@ -38,7 +37,7 @@ var intersectionBy = rest(function(arrays) { 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 205aadc88..2a7b32c5f 100644 --- a/intersectionWith.js +++ b/intersectionWith.js @@ -1,8 +1,8 @@ import arrayMap from './_arrayMap.js'; import baseIntersection from './_baseIntersection.js'; +import baseRest from './_baseRest.js'; import castArrayLikeObject from './_castArrayLikeObject.js'; import last from './last.js'; -import rest from './rest.js'; /** * This method is like `_.intersection` except that it accepts `comparator` @@ -25,7 +25,7 @@ import rest from './rest.js'; * _.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 d645303c3..e29fc9d12 100644 --- a/invertBy.js +++ b/invertBy.js @@ -19,8 +19,7 @@ var hasOwnProperty = objectProto.hasOwnProperty; * @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 7840164f2..a21208bd4 100644 --- a/invoke.js +++ b/invoke.js @@ -1,5 +1,5 @@ import baseInvoke from './_baseInvoke.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; /** * Invokes the method at `path` of `object`. @@ -19,6 +19,6 @@ import rest from './rest.js'; * _.invoke(object, 'a[0].b.c.slice', 1, 3); * // => [2, 3] */ -var invoke = rest(baseInvoke); +var invoke = baseRest(baseInvoke); export default invoke; diff --git a/invokeMap.js b/invokeMap.js index 0ff5c8c86..4e23387b2 100644 --- a/invokeMap.js +++ b/invokeMap.js @@ -1,15 +1,15 @@ import apply from './_apply.js'; import baseEach from './_baseEach.js'; import baseInvoke from './_baseInvoke.js'; +import baseRest from './_baseRest.js'; import isArrayLike from './isArrayLike.js'; import isKey from './_isKey.js'; -import rest from './rest.js'; /** * 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 _ @@ -28,7 +28,7 @@ import rest from './rest.js'; * _.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 293130db7..9460adbad 100644 --- a/isArguments.js +++ b/isArguments.js @@ -27,7 +27,7 @@ var propertyIsEnumerable = objectProto.propertyIsEnumerable; * @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 316f36733..5643c1983 100644 --- a/isArray.js +++ b/isArray.js @@ -4,11 +4,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]); diff --git a/isArrayBuffer.js b/isArrayBuffer.js index bec8bbac9..32f91ac52 100644 --- a/isArrayBuffer.js +++ b/isArrayBuffer.js @@ -1,16 +1,9 @@ -import isObjectLike from './isObjectLike.js'; +import baseIsArrayBuffer from './_baseIsArrayBuffer.js'; +import baseUnary from './_baseUnary.js'; +import nodeUtil from './_nodeUtil.js'; -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 +13,7 @@ var objectToString = objectProto.toString; * @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,8 +22,6 @@ var objectToString = objectProto.toString; * _.isArrayBuffer(new Array(2)); * // => false */ -function isArrayBuffer(value) { - return isObjectLike(value) && objectToString.call(value) == arrayBufferTag; -} +var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer; export default isArrayBuffer; diff --git a/isBoolean.js b/isBoolean.js index a2a9f12f3..ad18810c5 100644 --- a/isBoolean.js +++ b/isBoolean.js @@ -21,8 +21,7 @@ var objectToString = objectProto.toString; * @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 1db2c70cf..f140301fe 100644 --- a/isBuffer.js +++ b/isBuffer.js @@ -1,8 +1,9 @@ +import freeGlobal from './_freeGlobal.js'; import root from './_root.js'; import stubFalse from './stubFalse.js'; /** 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; @@ -13,6 +14,9 @@ var moduleExports = freeModule && freeModule.exports === freeExports; /** 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. * @@ -30,8 +34,6 @@ var Buffer = moduleExports ? root.Buffer : undefined; * _.isBuffer(new Uint8Array(2)); * // => false */ -var isBuffer = !Buffer ? stubFalse : function(value) { - return value instanceof Buffer; -}; +var isBuffer = nativeIsBuffer || stubFalse; export default isBuffer; diff --git a/isDate.js b/isDate.js index dee638a9b..d586c5125 100644 --- a/isDate.js +++ b/isDate.js @@ -1,17 +1,9 @@ -import isObjectLike from './isObjectLike.js'; +import baseIsDate from './_baseIsDate.js'; +import baseUnary from './_baseUnary.js'; +import nodeUtil from './_nodeUtil.js'; -/** `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 +13,7 @@ var objectToString = objectProto.toString; * @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,8 +22,6 @@ var objectToString = objectProto.toString; * _.isDate('Mon April 23 2012'); * // => false */ -function isDate(value) { - return isObjectLike(value) && objectToString.call(value) == dateTag; -} +var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate; export default isDate; diff --git a/isEqual.js b/isEqual.js index 292dd4f48..0eb776051 100644 --- a/isEqual.js +++ b/isEqual.js @@ -20,8 +20,8 @@ import baseIsEqual from './_baseIsEqual.js'; * 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 0c4adefdd..1a288bba4 100644 --- a/isFunction.js +++ b/isFunction.js @@ -22,8 +22,7 @@ var objectToString = objectProto.toString; * @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 8c1578c7d..d867dfa85 100644 --- a/isMap.js +++ b/isMap.js @@ -1,8 +1,9 @@ -import getTag from './_getTag.js'; -import isObjectLike from './isObjectLike.js'; +import baseIsMap from './_baseIsMap.js'; +import baseUnary from './_baseUnary.js'; +import nodeUtil from './_nodeUtil.js'; -/** `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. @@ -12,8 +13,7 @@ var mapTag = '[object Map]'; * @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); @@ -22,8 +22,6 @@ var mapTag = '[object Map]'; * _.isMap(new WeakMap); * // => false */ -function isMap(value) { - return isObjectLike(value) && getTag(value) == mapTag; -} +var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap; export default isMap; diff --git a/isMatch.js b/isMatch.js index f45e69101..74ab75d26 100644 --- a/isMatch.js +++ b/isMatch.js @@ -17,12 +17,12 @@ import getMatchData from './_getMatchData.js'; * @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 564b7aca7..13f93542e 100644 --- a/isNative.js +++ b/isNative.js @@ -4,13 +4,13 @@ import isMaskable from './_isMaskable.js'; /** * 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 _ @@ -29,7 +29,7 @@ import isMaskable from './_isMaskable.js'; */ 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 608378a31..25b10e907 100644 --- a/isNumber.js +++ b/isNumber.js @@ -24,8 +24,7 @@ var objectToString = objectProto.toString; * @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 d60258466..19580dbba 100644 --- a/isRegExp.js +++ b/isRegExp.js @@ -1,17 +1,9 @@ -import isObject from './isObject.js'; +import baseIsRegExp from './_baseIsRegExp.js'; +import baseUnary from './_baseUnary.js'; +import nodeUtil from './_nodeUtil.js'; -/** `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 +13,7 @@ var objectToString = objectProto.toString; * @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,8 +22,6 @@ var objectToString = objectProto.toString; * _.isRegExp('/abc/'); * // => false */ -function isRegExp(value) { - return isObject(value) && objectToString.call(value) == regexpTag; -} +var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp; export default isRegExp; diff --git a/isSet.js b/isSet.js index 9089847b2..78c8198ee 100644 --- a/isSet.js +++ b/isSet.js @@ -1,8 +1,9 @@ -import getTag from './_getTag.js'; -import isObjectLike from './isObjectLike.js'; +import baseIsSet from './_baseIsSet.js'; +import baseUnary from './_baseUnary.js'; +import nodeUtil from './_nodeUtil.js'; -/** `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. @@ -12,8 +13,7 @@ var setTag = '[object Set]'; * @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); @@ -22,8 +22,6 @@ var setTag = '[object Set]'; * _.isSet(new WeakSet); * // => false */ -function isSet(value) { - return isObjectLike(value) && getTag(value) == setTag; -} +var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet; export default isSet; diff --git a/isString.js b/isString.js index 1c82368e4..9b2b6ad08 100644 --- a/isString.js +++ b/isString.js @@ -22,8 +22,7 @@ var objectToString = objectProto.toString; * @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 c32bb5b48..12b8b2621 100644 --- a/isSymbol.js +++ b/isSymbol.js @@ -21,8 +21,7 @@ var objectToString = objectProto.toString; * @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 087d6152c..8cffbef95 100644 --- a/isTypedArray.js +++ b/isTypedArray.js @@ -1,58 +1,9 @@ -import isLength from './isLength.js'; -import isObjectLike from './isObjectLike.js'; +import baseIsTypedArray from './_baseIsTypedArray.js'; +import baseUnary from './_baseUnary.js'; +import nodeUtil from './_nodeUtil.js'; -/** `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. @@ -62,8 +13,7 @@ var objectToString = objectProto.toString; * @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); @@ -72,9 +22,6 @@ var objectToString = objectProto.toString; * _.isTypedArray([]); * // => false */ -function isTypedArray(value) { - return isObjectLike(value) && - isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; -} +var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; export default isTypedArray; diff --git a/isWeakMap.js b/isWeakMap.js index 1a440c807..a85307f04 100644 --- a/isWeakMap.js +++ b/isWeakMap.js @@ -12,8 +12,7 @@ var weakMapTag = '[object WeakMap]'; * @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 e20d9b5fd..47f100ce2 100644 --- a/isWeakSet.js +++ b/isWeakSet.js @@ -21,8 +21,7 @@ var objectToString = objectProto.toString; * @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 3b140095c..1bf20cffa 100644 --- a/keyBy.js +++ b/keyBy.js @@ -11,7 +11,7 @@ import createAggregator from './_createAggregator.js'; * @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.default.js b/lang.default.js index e51ba3aa0..8fd434d12 100644 --- a/lang.default.js +++ b/lang.default.js @@ -3,6 +3,7 @@ import clone from './clone.js'; import cloneDeep from './cloneDeep.js'; import cloneDeepWith from './cloneDeepWith.js'; import cloneWith from './cloneWith.js'; +import conformsTo from './conformsTo.js'; import eq from './eq.js'; import gt from './gt.js'; import gte from './gte.js'; @@ -56,14 +57,15 @@ import toString from './toString.js'; export default { 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 + 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 }; diff --git a/lang.js b/lang.js index 6490eb4ec..eb837d9bd 100644 --- a/lang.js +++ b/lang.js @@ -3,6 +3,7 @@ export { default as clone } from './clone.js'; export { default as cloneDeep } from './cloneDeep.js'; export { default as cloneDeepWith } from './cloneDeepWith.js'; export { default as cloneWith } from './cloneWith.js'; +export { default as conformsTo } from './conformsTo.js'; export { default as eq } from './eq.js'; export { default as gt } from './gt.js'; export { default as gte } from './gte.js'; @@ -53,4 +54,4 @@ export { default as toNumber } from './toNumber.js'; export { default as toPlainObject } from './toPlainObject.js'; export { default as toSafeInteger } from './toSafeInteger.js'; export { default as toString } from './toString.js'; -export { default as default } from './lang.default'; +export { default } from './lang.default.js'; diff --git a/lastIndexOf.js b/lastIndexOf.js index e90ce3078..43a53a378 100644 --- a/lastIndexOf.js +++ b/lastIndexOf.js @@ -1,4 +1,5 @@ -import indexOfNaN from './_indexOfNaN.js'; +import baseFindIndex from './_baseFindIndex.js'; +import baseIsNaN from './_baseIsNaN.js'; import toInteger from './toInteger.js'; /* Built-in method references for those with the same name as other `lodash` methods. */ @@ -41,7 +42,7 @@ function lastIndexOf(array, value, fromIndex) { ) + 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/lodash.default.js b/lodash.default.js index c32ba1bcb..641672357 100644 --- a/lodash.default.js +++ b/lodash.default.js @@ -27,7 +27,8 @@ import baseForOwn from './_baseForOwn.js'; import baseFunctions from './_baseFunctions.js'; import baseInvoke from './_baseInvoke.js'; import baseIteratee from './_baseIteratee.js'; -import createHybridWrapper from './_createHybridWrapper.js'; +import baseRest from './_baseRest.js'; +import createHybrid from './_createHybrid.js'; import identity from './identity.js'; import isArray from './isArray.js'; import isObject from './isObject.js'; @@ -37,16 +38,16 @@ import lazyClone from './_lazyClone.js'; import lazyReverse from './_lazyReverse.js'; import lazyValue from './_lazyValue.js'; import _mixin from './mixin.js'; +import negate from './negate.js'; import realNames from './_realNames.js'; -import rest from './rest.js'; import thru from './thru.js'; import toInteger from './toInteger.js'; import lodash from './wrapperLodash.js'; /** Used as the semantic version number. */ -var VERSION = '4.13.1'; +var VERSION = '4.14.0'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var BIND_KEY_FLAG = 2; /** Used to indicate the type of lazy iteratees. */ @@ -64,7 +65,7 @@ var arrayProto = Array.prototype, var hasOwnProperty = objectProto.hasOwnProperty; /** Built-in value references. */ -var iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined; +var iteratorSymbol = Symbol ? Symbol.iterator : undefined; /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeMax = Math.max, @@ -95,7 +96,7 @@ lodash.assign = object.assign; lodash.assignIn = object.assignIn; lodash.assignInWith = object.assignInWith; lodash.assignWith = object.assignWith; -lodash.at = collection.at; +lodash.at = object.at; lodash.before = func.before; lodash.bind = func.bind; lodash.bindAll = util.bindAll; @@ -161,7 +162,7 @@ lodash.mergeWith = object.mergeWith; lodash.method = util.method; lodash.methodOf = util.methodOf; lodash.mixin = mixin; -lodash.negate = func.negate; +lodash.negate = negate; lodash.nthArg = util.nthArg; lodash.omit = object.omit; lodash.omitBy = object.omitBy; @@ -188,7 +189,7 @@ lodash.rangeRight = util.rangeRight; lodash.rearg = func.rearg; lodash.reject = collection.reject; lodash.remove = array.remove; -lodash.rest = rest; +lodash.rest = func.rest; lodash.reverse = array.reverse; lodash.sampleSize = collection.sampleSize; lodash.set = object.set; @@ -259,7 +260,9 @@ lodash.clone = lang.clone; lodash.cloneDeep = lang.cloneDeep; lodash.cloneDeepWith = lang.cloneDeepWith; lodash.cloneWith = lang.cloneWith; +lodash.conformsTo = lang.conformsTo; lodash.deburr = string.deburr; +lodash.defaultTo = util.defaultTo; lodash.divide = math.divide; lodash.endsWith = string.endsWith; lodash.eq = lang.eq; @@ -497,7 +500,7 @@ LazyWrapper.prototype.findLast = function(predicate) { 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); } @@ -507,10 +510,7 @@ LazyWrapper.prototype.invokeMap = rest(function(path, args) { }); LazyWrapper.prototype.reject = function(predicate) { - predicate = baseIteratee(predicate, 3); - return this.filter(function(value) { - return !predicate(value); - }); + return this.filter(negate(baseIteratee(predicate))); }; LazyWrapper.prototype.slice = function(start, end) { @@ -614,7 +614,7 @@ baseForOwn(LazyWrapper.prototype, function(func, methodName) { } }); -realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ +realNames[createHybrid(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }]; @@ -633,6 +633,9 @@ lodash.prototype.plant = seq.plant; lodash.prototype.reverse = seq.reverse; lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = seq.value; +// Add lazy aliases. +lodash.prototype.first = lodash.prototype.head; + if (iteratorSymbol) { lodash.prototype[iteratorSymbol] = seq.toIterator; } diff --git a/lodash.js b/lodash.js index 56af7f7d4..c02d382d5 100644 --- a/lodash.js +++ b/lodash.js @@ -36,6 +36,7 @@ export { default as compact } from './compact.js'; export { default as concat } from './concat.js'; export { default as cond } from './cond.js'; export { default as conforms } from './conforms.js'; +export { default as conformsTo } from './conformsTo.js'; export { default as constant } from './constant.js'; export { default as countBy } from './countBy.js'; export { default as create } from './create.js'; @@ -43,6 +44,7 @@ export { default as curry } from './curry.js'; export { default as curryRight } from './curryRight.js'; export { default as debounce } from './debounce.js'; export { default as deburr } from './deburr.js'; +export { default as defaultTo } from './defaultTo.js'; export { default as defaults } from './defaults.js'; export { default as defaultsDeep } from './defaultsDeep.js'; export { default as defer } from './defer.js'; @@ -326,4 +328,4 @@ export { default as zip } from './zip.js'; export { default as zipObject } from './zipObject.js'; export { default as zipObjectDeep } from './zipObjectDeep.js'; export { default as zipWith } from './zipWith.js'; -export { default as default } from './lodash.default'; +export { default } from './lodash.default.js'; diff --git a/map.js b/map.js index 8c2af401f..36139f96b 100644 --- a/map.js +++ b/map.js @@ -22,8 +22,7 @@ import isArray from './isArray.js'; * @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 d8b9eae24..ac563eb69 100644 --- a/mapKeys.js +++ b/mapKeys.js @@ -12,8 +12,7 @@ import baseIteratee from './_baseIteratee.js'; * @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 d5aae9b68..123930701 100644 --- a/mapValues.js +++ b/mapValues.js @@ -12,8 +12,7 @@ import baseIteratee from './_baseIteratee.js'; * @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 c0cd96504..72c2aed44 100644 --- a/matches.js +++ b/matches.js @@ -17,13 +17,13 @@ import baseMatches from './_baseMatches.js'; * @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 95ea8ba01..f8ea0029a 100644 --- a/matchesProperty.js +++ b/matchesProperty.js @@ -17,13 +17,13 @@ import baseMatchesProperty from './_baseMatchesProperty.js'; * @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/math.js b/math.js index 772759a48..8be0338fa 100644 --- a/math.js +++ b/math.js @@ -13,4 +13,4 @@ export { default as round } from './round.js'; export { default as subtract } from './subtract.js'; export { default as sum } from './sum.js'; export { default as sumBy } from './sumBy.js'; -export { default as default } from './math.default'; +export { default } from './math.default.js'; diff --git a/maxBy.js b/maxBy.js index c94b93594..6cbd1ceea 100644 --- a/maxBy.js +++ b/maxBy.js @@ -12,8 +12,7 @@ import baseIteratee from './_baseIteratee.js'; * @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 * @@ -28,7 +27,7 @@ import baseIteratee from './_baseIteratee.js'; */ 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 2cb1c7232..4a29ebdc9 100644 --- a/meanBy.js +++ b/meanBy.js @@ -11,8 +11,7 @@ import baseMean from './_baseMean.js'; * @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 * @@ -26,7 +25,7 @@ import baseMean from './_baseMean.js'; * // => 5 */ function meanBy(array, iteratee) { - return baseMean(array, baseIteratee(iteratee)); + return baseMean(array, baseIteratee(iteratee, 2)); } export default meanBy; diff --git a/merge.js b/merge.js index 0dfd0583e..9aab6283a 100644 --- a/merge.js +++ b/merge.js @@ -21,16 +21,16 @@ import createAssigner from './_createAssigner.js'; * @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 feec5a7b2..1961e6915 100644 --- a/mergeWith.js +++ b/mergeWith.js @@ -26,18 +26,11 @@ import createAssigner from './_createAssigner.js'; * } * } * - * 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 dbba0c38d..9daed7881 100644 --- a/method.js +++ b/method.js @@ -1,5 +1,5 @@ import baseInvoke from './_baseInvoke.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; /** * Creates a function that invokes the method at `path` of a given object. @@ -25,7 +25,7 @@ import rest from './rest.js'; * _.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 e24c73709..1a4d98de7 100644 --- a/methodOf.js +++ b/methodOf.js @@ -1,5 +1,5 @@ import baseInvoke from './_baseInvoke.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; /** * The opposite of `_.method`; this method creates a function that invokes @@ -24,7 +24,7 @@ import rest from './rest.js'; * _.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 b08f182af..2d810a840 100644 --- a/minBy.js +++ b/minBy.js @@ -12,8 +12,7 @@ import baseLt from './_baseLt.js'; * @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 * @@ -28,7 +27,7 @@ import baseLt from './_baseLt.js'; */ 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 05b06aa5e..19aba7251 100644 --- a/multiply.js +++ b/multiply.js @@ -17,6 +17,6 @@ import createMathOperation from './_createMathOperation.js'; */ var multiply = createMathOperation(function(multiplier, multiplicand) { return multiplier * multiplicand; -}); +}, 1); export default multiply; diff --git a/negate.js b/negate.js index 242eaf558..4353137bc 100644 --- a/negate.js +++ b/negate.js @@ -26,7 +26,14 @@ function negate(predicate) { 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 bafa45851..6b4847c11 100644 --- a/noop.js +++ b/noop.js @@ -1,5 +1,5 @@ /** - * A method that returns `undefined`. + * This method returns `undefined`. * * @static * @memberOf _ diff --git a/nthArg.js b/nthArg.js index 64706724c..be3a4cccc 100644 --- a/nthArg.js +++ b/nthArg.js @@ -1,5 +1,5 @@ import baseNth from './_baseNth.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; import toInteger from './toInteger.js'; /** @@ -24,7 +24,7 @@ import toInteger from './toInteger.js'; */ function nthArg(n) { n = toInteger(n); - return rest(function(args) { + return baseRest(function(args) { return baseNth(args, n); }); } diff --git a/number.js b/number.js index 77b17822b..2ff09e35f 100644 --- a/number.js +++ b/number.js @@ -1,4 +1,4 @@ export { default as clamp } from './clamp.js'; export { default as inRange } from './inRange.js'; export { default as random } from './random.js'; -export { default as default } from './number.default'; +export { default } from './number.default.js'; diff --git a/object.default.js b/object.default.js index 128cdec4a..931ac0e39 100644 --- a/object.default.js +++ b/object.default.js @@ -2,6 +2,7 @@ import assign from './assign.js'; import assignIn from './assignIn.js'; import assignInWith from './assignInWith.js'; import assignWith from './assignWith.js'; +import at from './at.js'; import create from './create.js'; import defaults from './defaults.js'; import defaultsDeep from './defaultsDeep.js'; @@ -46,14 +47,14 @@ import values from './values.js'; import valuesIn from './valuesIn.js'; export default { - 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 + 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 }; diff --git a/object.js b/object.js index 23c705acb..aa7ce3d1c 100644 --- a/object.js +++ b/object.js @@ -2,6 +2,7 @@ export { default as assign } from './assign.js'; export { default as assignIn } from './assignIn.js'; export { default as assignInWith } from './assignInWith.js'; export { default as assignWith } from './assignWith.js'; +export { default as at } from './at.js'; export { default as create } from './create.js'; export { default as defaults } from './defaults.js'; export { default as defaultsDeep } from './defaultsDeep.js'; @@ -44,4 +45,4 @@ export { default as update } from './update.js'; export { default as updateWith } from './updateWith.js'; export { default as values } from './values.js'; export { default as valuesIn } from './valuesIn.js'; -export { default as default } from './object.default'; +export { default } from './object.default.js'; diff --git a/omit.js b/omit.js index 2d6bf944d..2be1b6016 100644 --- a/omit.js +++ b/omit.js @@ -2,8 +2,8 @@ import arrayMap from './_arrayMap.js'; import baseDifference from './_baseDifference.js'; import baseFlatten from './_baseFlatten.js'; import basePick from './_basePick.js'; +import baseRest from './_baseRest.js'; import getAllKeysIn from './_getAllKeysIn.js'; -import rest from './rest.js'; import toKey from './_toKey.js'; /** @@ -25,7 +25,7 @@ import toKey from './_toKey.js'; * _.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 309bde47e..cab01bdbc 100644 --- a/omitBy.js +++ b/omitBy.js @@ -1,5 +1,6 @@ import baseIteratee from './_baseIteratee.js'; -import basePickBy from './_basePickBy.js'; +import negate from './negate.js'; +import pickBy from './pickBy.js'; /** * The opposite of `_.pickBy`; this method creates an object composed of @@ -12,8 +13,7 @@ import basePickBy from './_basePickBy.js'; * @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 * @@ -23,10 +23,7 @@ import basePickBy from './_basePickBy.js'; * // => { '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))); } export default omitBy; diff --git a/once.js b/once.js index ed274fedb..603c73ee3 100644 --- a/once.js +++ b/once.js @@ -16,7 +16,7 @@ import before from './before.js'; * 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 52fa180fb..51b6339d1 100644 --- a/over.js +++ b/over.js @@ -9,8 +9,8 @@ import createOver from './_createOver.js'; * @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 ee8ebcef7..4a47b61d2 100644 --- a/overArgs.js +++ b/overArgs.js @@ -2,25 +2,23 @@ import apply from './_apply.js'; import arrayMap from './_arrayMap.js'; import baseFlatten from './_baseFlatten.js'; import baseIteratee from './_baseIteratee.js'; +import baseRest from './_baseRest.js'; import baseUnary from './_baseUnary.js'; import isArray from './isArray.js'; -import isFlattenableIteratee from './_isFlattenableIteratee.js'; -import rest from './rest.js'; /* 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 * @@ -42,13 +40,13 @@ var nativeMin = Math.min; * 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 f8cff8584..6b262d8b3 100644 --- a/overEvery.js +++ b/overEvery.js @@ -9,8 +9,8 @@ import createOver from './_createOver.js'; * @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 f70e59c81..9893ba670 100644 --- a/overSome.js +++ b/overSome.js @@ -9,8 +9,8 @@ import createOver from './_createOver.js'; * @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 292a05d96..e73875cd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-es", - "version": "4.13.1", + "version": "4.14.0", "description": "Lodash exported as ES modules.", "keywords": "es6, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds", diff --git a/partial.js b/partial.js index 22d561874..7c5889d34 100644 --- a/partial.js +++ b/partial.js @@ -1,9 +1,9 @@ -import createWrapper from './_createWrapper.js'; +import baseRest from './_baseRest.js'; +import createWrap from './_createWrap.js'; import getHolder from './_getHolder.js'; import replaceHolders from './_replaceHolders.js'; -import rest from './rest.js'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var PARTIAL_FLAG = 32; /** @@ -26,9 +26,9 @@ var PARTIAL_FLAG = 32; * @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 @@ var PARTIAL_FLAG = 32; * 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 9345102b9..ba89ea0bd 100644 --- a/partialRight.js +++ b/partialRight.js @@ -1,9 +1,9 @@ -import createWrapper from './_createWrapper.js'; +import baseRest from './_baseRest.js'; +import createWrap from './_createWrap.js'; import getHolder from './_getHolder.js'; import replaceHolders from './_replaceHolders.js'; -import rest from './rest.js'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var PARTIAL_RIGHT_FLAG = 64; /** @@ -25,9 +25,9 @@ var PARTIAL_RIGHT_FLAG = 64; * @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 @@ var PARTIAL_RIGHT_FLAG = 64; * 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 3122d1236..a58b6de4f 100644 --- a/partition.js +++ b/partition.js @@ -11,8 +11,7 @@ import createAggregator from './_createAggregator.js'; * @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 d5b5b68a3..1c812a03b 100644 --- a/pick.js +++ b/pick.js @@ -1,7 +1,7 @@ import arrayMap from './_arrayMap.js'; import baseFlatten from './_baseFlatten.js'; import basePick from './_basePick.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; import toKey from './_toKey.js'; /** @@ -21,7 +21,7 @@ import toKey from './_toKey.js'; * _.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 19331d682..a92abc955 100644 --- a/pickBy.js +++ b/pickBy.js @@ -1,5 +1,6 @@ import baseIteratee from './_baseIteratee.js'; import basePickBy from './_basePickBy.js'; +import getAllKeysIn from './_getAllKeysIn.js'; /** * Creates an object composed of the `object` properties `predicate` returns @@ -10,8 +11,7 @@ import basePickBy from './_basePickBy.js'; * @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 * @@ -21,7 +21,7 @@ import basePickBy from './_basePickBy.js'; * // => { 'a': 1, 'c': 3 } */ function pickBy(object, predicate) { - return object == null ? {} : basePickBy(object, baseIteratee(predicate)); + return object == null ? {} : basePickBy(object, getAllKeysIn(object), baseIteratee(predicate)); } export default pickBy; diff --git a/pull.js b/pull.js index 4bdf24a90..5d73a2230 100644 --- a/pull.js +++ b/pull.js @@ -1,5 +1,5 @@ +import baseRest from './_baseRest.js'; import pullAll from './pullAll.js'; -import rest from './rest.js'; /** * Removes all given values from `array` using @@ -24,6 +24,6 @@ import rest from './rest.js'; * console.log(array); * // => ['b', 'b'] */ -var pull = rest(pullAll); +var pull = baseRest(pullAll); export default pull; diff --git a/pullAllBy.js b/pullAllBy.js index c4c9a4417..b98c973fd 100644 --- a/pullAllBy.js +++ b/pullAllBy.js @@ -14,7 +14,7 @@ import basePullAll from './_basePullAll.js'; * @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 @@ -27,7 +27,7 @@ import basePullAll from './_basePullAll.js'; */ 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 7fb436cf0..303705bc2 100644 --- a/pullAt.js +++ b/pullAt.js @@ -2,9 +2,9 @@ import arrayMap from './_arrayMap.js'; import baseAt from './_baseAt.js'; import baseFlatten from './_baseFlatten.js'; import basePullAt from './_basePullAt.js'; +import baseRest from './_baseRest.js'; import compareAscending from './_compareAscending.js'; import isIndex from './_isIndex.js'; -import rest from './rest.js'; /** * Removes elements from `array` corresponding to `indexes` and returns an @@ -30,7 +30,7 @@ import rest from './rest.js'; * 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 c58611c9e..6ee849a16 100644 --- a/rearg.js +++ b/rearg.js @@ -1,8 +1,8 @@ import baseFlatten from './_baseFlatten.js'; -import createWrapper from './_createWrapper.js'; -import rest from './rest.js'; +import baseRest from './_baseRest.js'; +import createWrap from './_createWrap.js'; -/** Used to compose bitmasks for wrapper metadata. */ +/** Used to compose bitmasks for function metadata. */ var REARG_FLAG = 256; /** @@ -27,8 +27,8 @@ var REARG_FLAG = 256; * 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)); }); export default rearg; diff --git a/reject.js b/reject.js index e8bbed251..f3a1c55d8 100644 --- a/reject.js +++ b/reject.js @@ -2,6 +2,7 @@ import arrayFilter from './_arrayFilter.js'; import baseFilter from './_baseFilter.js'; import baseIteratee from './_baseIteratee.js'; import isArray from './isArray.js'; +import negate from './negate.js'; /** * The opposite of `_.filter`; this method returns the elements of `collection` @@ -12,8 +13,7 @@ import isArray from './isArray.js'; * @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 @@ -40,10 +40,7 @@ import isArray from './isArray.js'; */ 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))); } export default reject; diff --git a/remove.js b/remove.js index de7fdd2b1..631249724 100644 --- a/remove.js +++ b/remove.js @@ -14,7 +14,7 @@ import basePullAt from './_basePullAt.js'; * @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 136e71204..75cb08ba4 100644 --- a/rest.js +++ b/rest.js @@ -1,12 +1,9 @@ -import apply from './_apply.js'; +import baseRest from './_baseRest.js'; import toInteger from './toInteger.js'; /** 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 @@ -36,29 +33,8 @@ function rest(func, start) { 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); } export default rest; diff --git a/seq.js b/seq.js index d4dca73fe..f679d3054 100644 --- a/seq.js +++ b/seq.js @@ -12,4 +12,4 @@ export { default as toJSON } from './toJSON.js'; export { default as value } from './wrapperValue.js'; export { default as valueOf } from './valueOf.js'; export { default as wrapperChain } from './wrapperChain.js'; -export { default as default } from './seq.default'; +export { default } from './seq.default.js'; diff --git a/some.js b/some.js index 85f2afcb0..27f1996e1 100644 --- a/some.js +++ b/some.js @@ -14,8 +14,7 @@ import isIterateeCall from './_isIterateeCall.js'; * @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 48d5fa17d..99cc078d3 100644 --- a/sortBy.js +++ b/sortBy.js @@ -1,9 +1,7 @@ import baseFlatten from './_baseFlatten.js'; import baseOrderBy from './_baseOrderBy.js'; -import isArray from './isArray.js'; -import isFlattenableIteratee from './_isFlattenableIteratee.js'; +import baseRest from './_baseRest.js'; import isIterateeCall from './_isIterateeCall.js'; -import rest from './rest.js'; /** * Creates an array of elements, sorted in ascending order by the results of @@ -16,8 +14,8 @@ import rest from './rest.js'; * @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 * @@ -39,7 +37,7 @@ import rest from './rest.js'; * }); * // => 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 []; } @@ -49,11 +47,7 @@ var sortBy = rest(function(collection, iteratees) { } 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), []); }); export default sortBy; diff --git a/sortedIndexBy.js b/sortedIndexBy.js index 87a07aae1..dc42fb081 100644 --- a/sortedIndexBy.js +++ b/sortedIndexBy.js @@ -12,7 +12,7 @@ import baseSortedIndexBy from './_baseSortedIndexBy.js'; * @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`. @@ -28,7 +28,7 @@ import baseSortedIndexBy from './_baseSortedIndexBy.js'; * // => 0 */ function sortedIndexBy(array, value, iteratee) { - return baseSortedIndexBy(array, value, baseIteratee(iteratee)); + return baseSortedIndexBy(array, value, baseIteratee(iteratee, 2)); } export default sortedIndexBy; diff --git a/sortedLastIndexBy.js b/sortedLastIndexBy.js index f45c380d9..e7752327a 100644 --- a/sortedLastIndexBy.js +++ b/sortedLastIndexBy.js @@ -12,7 +12,7 @@ import baseSortedIndexBy from './_baseSortedIndexBy.js'; * @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`. @@ -28,7 +28,7 @@ import baseSortedIndexBy from './_baseSortedIndexBy.js'; * // => 1 */ function sortedLastIndexBy(array, value, iteratee) { - return baseSortedIndexBy(array, value, baseIteratee(iteratee), true); + return baseSortedIndexBy(array, value, baseIteratee(iteratee, 2), true); } export default sortedLastIndexBy; diff --git a/sortedUniqBy.js b/sortedUniqBy.js index 41fe08451..48894fe51 100644 --- a/sortedUniqBy.js +++ b/sortedUniqBy.js @@ -19,7 +19,7 @@ import baseSortedUniq from './_baseSortedUniq.js'; */ 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 c2a33cadb..819d8c8bd 100644 --- a/spread.js +++ b/spread.js @@ -1,7 +1,7 @@ import apply from './_apply.js'; import arrayPush from './_arrayPush.js'; +import baseRest from './_baseRest.js'; import castSlice from './_castSlice.js'; -import rest from './rest.js'; import toInteger from './toInteger.js'; /** Used as the `TypeError` message for "Functions" methods. */ @@ -49,7 +49,7 @@ function spread(func, start) { 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 38fc0081c..cc67a4934 100644 --- a/startsWith.js +++ b/startsWith.js @@ -29,7 +29,8 @@ import toString from './toString.js'; 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; } export default startsWith; diff --git a/string.js b/string.js index 8b9be91e0..2534e7c71 100644 --- a/string.js +++ b/string.js @@ -29,4 +29,4 @@ export { default as unescape } from './unescape.js'; export { default as upperCase } from './upperCase.js'; export { default as upperFirst } from './upperFirst.js'; export { default as words } from './words.js'; -export { default as default } from './string.default'; +export { default } from './string.default.js'; diff --git a/stubArray.js b/stubArray.js index 7de7be9a4..b2b5503ce 100644 --- a/stubArray.js +++ b/stubArray.js @@ -1,5 +1,5 @@ /** - * 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 5598e0c9a..c569c25df 100644 --- a/stubFalse.js +++ b/stubFalse.js @@ -1,5 +1,5 @@ /** - * A method that returns `false`. + * This method returns `false`. * * @static * @memberOf _ diff --git a/stubObject.js b/stubObject.js index 5cc8d8ce4..f634824dd 100644 --- a/stubObject.js +++ b/stubObject.js @@ -1,5 +1,5 @@ /** - * 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 5cc375d9a..783b57c1c 100644 --- a/stubString.js +++ b/stubString.js @@ -1,5 +1,5 @@ /** - * A method that returns an empty string. + * This method returns an empty string. * * @static * @memberOf _ diff --git a/stubTrue.js b/stubTrue.js index ec604f78e..405a29da1 100644 --- a/stubTrue.js +++ b/stubTrue.js @@ -1,5 +1,5 @@ /** - * A method that returns `true`. + * This method returns `true`. * * @static * @memberOf _ diff --git a/subtract.js b/subtract.js index c0a6a56b3..c2ca69123 100644 --- a/subtract.js +++ b/subtract.js @@ -17,6 +17,6 @@ import createMathOperation from './_createMathOperation.js'; */ var subtract = createMathOperation(function(minuend, subtrahend) { return minuend - subtrahend; -}); +}, 0); export default subtract; diff --git a/sumBy.js b/sumBy.js index fdf093609..6828c16b7 100644 --- a/sumBy.js +++ b/sumBy.js @@ -11,8 +11,7 @@ import baseSum from './_baseSum.js'; * @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 * @@ -27,7 +26,7 @@ import baseSum from './_baseSum.js'; */ 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 c4cf744ea..fe234db13 100644 --- a/takeRightWhile.js +++ b/takeRightWhile.js @@ -11,7 +11,7 @@ import baseWhile from './_baseWhile.js'; * @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 41fc5fee3..cacb766cd 100644 --- a/takeWhile.js +++ b/takeWhile.js @@ -11,7 +11,7 @@ import baseWhile from './_baseWhile.js'; * @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 09a774813..9fcc1273b 100644 --- a/toArray.js +++ b/toArray.js @@ -14,7 +14,7 @@ var mapTag = '[object Map]', 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 3b019f6d0..41d72e400 100644 --- a/union.js +++ b/union.js @@ -1,7 +1,7 @@ import baseFlatten from './_baseFlatten.js'; +import baseRest from './_baseRest.js'; import baseUniq from './_baseUniq.js'; import isArrayLikeObject from './isArrayLikeObject.js'; -import rest from './rest.js'; /** * Creates an array of unique values, in order, from all given arrays using @@ -19,7 +19,7 @@ import rest from './rest.js'; * _.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 2de20dafc..5a2451ee6 100644 --- a/unionBy.js +++ b/unionBy.js @@ -1,14 +1,15 @@ import baseFlatten from './_baseFlatten.js'; import baseIteratee from './_baseIteratee.js'; +import baseRest from './_baseRest.js'; import baseUniq from './_baseUniq.js'; import isArrayLikeObject from './isArrayLikeObject.js'; import last from './last.js'; -import rest from './rest.js'; /** * 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 @@ -16,7 +17,7 @@ import rest from './rest.js'; * @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 @@ -28,12 +29,12 @@ import rest from './rest.js'; * _.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)); }); export default unionBy; diff --git a/unionWith.js b/unionWith.js index 5c84b0a4b..ff690d113 100644 --- a/unionWith.js +++ b/unionWith.js @@ -1,12 +1,13 @@ import baseFlatten from './_baseFlatten.js'; +import baseRest from './_baseRest.js'; import baseUniq from './_baseUniq.js'; import isArrayLikeObject from './isArrayLikeObject.js'; import last from './last.js'; -import rest from './rest.js'; /** * 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 @@ -24,7 +25,7 @@ import rest from './rest.js'; * _.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 11aaafc0a..d828b6dad 100644 --- a/uniqBy.js +++ b/uniqBy.js @@ -11,7 +11,7 @@ import baseUniq from './_baseUniq.js'; * @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 @@ -25,7 +25,7 @@ import baseUniq from './_baseUniq.js'; */ 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 7e09d1c93..e3f7a604a 100644 --- a/unzip.js +++ b/unzip.js @@ -20,11 +20,11 @@ var nativeMax = Math.max; * @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.default.js b/util.default.js index 7a399506d..c0795946e 100644 --- a/util.default.js +++ b/util.default.js @@ -3,6 +3,7 @@ import bindAll from './bindAll.js'; import cond from './cond.js'; import conforms from './conforms.js'; import constant from './constant.js'; +import defaultTo from './defaultTo.js'; import flow from './flow.js'; import flowRight from './flowRight.js'; import identity from './identity.js'; @@ -32,10 +33,10 @@ import uniqueId from './uniqueId.js'; export default { 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 + 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 }; diff --git a/util.js b/util.js index 1ea853117..d03885882 100644 --- a/util.js +++ b/util.js @@ -3,6 +3,7 @@ export { default as bindAll } from './bindAll.js'; export { default as cond } from './cond.js'; export { default as conforms } from './conforms.js'; export { default as constant } from './constant.js'; +export { default as defaultTo } from './defaultTo.js'; export { default as flow } from './flow.js'; export { default as flowRight } from './flowRight.js'; export { default as identity } from './identity.js'; @@ -29,4 +30,4 @@ export { default as stubTrue } from './stubTrue.js'; export { default as times } from './times.js'; export { default as toPath } from './toPath.js'; export { default as uniqueId } from './uniqueId.js'; -export { default as default } from './util.default'; +export { default } from './util.default.js'; diff --git a/without.js b/without.js index 16aa304c4..3d1e12c54 100644 --- a/without.js +++ b/without.js @@ -1,12 +1,14 @@ import baseDifference from './_baseDifference.js'; +import baseRest from './_baseRest.js'; import isArrayLikeObject from './isArrayLikeObject.js'; -import rest from './rest.js'; /** * 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 @@ -20,7 +22,7 @@ import rest from './rest.js'; * _.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 a43387fc4..2612efebc 100644 --- a/wrap.js +++ b/wrap.js @@ -2,10 +2,10 @@ import identity from './identity.js'; import partial from './partial.js'; /** - * 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 cead5d9c5..a508e907e 100644 --- a/wrapperAt.js +++ b/wrapperAt.js @@ -2,8 +2,8 @@ import LazyWrapper from './_LazyWrapper.js'; import LodashWrapper from './_LodashWrapper.js'; import baseAt from './_baseAt.js'; import baseFlatten from './_baseFlatten.js'; +import baseRest from './_baseRest.js'; import isIndex from './_isIndex.js'; -import rest from './rest.js'; import thru from './thru.js'; /** @@ -22,7 +22,7 @@ import thru from './thru.js'; * _(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 44771ec2a..dcd299a9c 100644 --- a/wrapperLodash.js +++ b/wrapperLodash.js @@ -77,16 +77,16 @@ var hasOwnProperty = objectProto.hasOwnProperty; * * 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 f107736e7..c406c48e2 100644 --- a/xor.js +++ b/xor.js @@ -1,7 +1,7 @@ import arrayFilter from './_arrayFilter.js'; +import baseRest from './_baseRest.js'; import baseXor from './_baseXor.js'; import isArrayLikeObject from './isArrayLikeObject.js'; -import rest from './rest.js'; /** * Creates an array of unique values that is the @@ -21,7 +21,7 @@ import rest from './rest.js'; * _.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 7d4f7c6ba..1e57f7949 100644 --- a/xorBy.js +++ b/xorBy.js @@ -1,9 +1,9 @@ import arrayFilter from './_arrayFilter.js'; import baseIteratee from './_baseIteratee.js'; +import baseRest from './_baseRest.js'; import baseXor from './_baseXor.js'; import isArrayLikeObject from './isArrayLikeObject.js'; import last from './last.js'; -import rest from './rest.js'; /** * This method is like `_.xor` except that it accepts `iteratee` which is @@ -16,7 +16,7 @@ import rest from './rest.js'; * @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 @@ -28,12 +28,12 @@ import rest from './rest.js'; * _.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)); }); export default xorBy; diff --git a/xorWith.js b/xorWith.js index 95a5fa20c..fef8f66ae 100644 --- a/xorWith.js +++ b/xorWith.js @@ -1,8 +1,8 @@ import arrayFilter from './_arrayFilter.js'; +import baseRest from './_baseRest.js'; import baseXor from './_baseXor.js'; import isArrayLikeObject from './isArrayLikeObject.js'; import last from './last.js'; -import rest from './rest.js'; /** * This method is like `_.xor` except that it accepts `comparator` which is @@ -24,7 +24,7 @@ import rest from './rest.js'; * _.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 05357fe48..c91052821 100644 --- a/zip.js +++ b/zip.js @@ -1,4 +1,4 @@ -import rest from './rest.js'; +import baseRest from './_baseRest.js'; import unzip from './unzip.js'; /** @@ -14,9 +14,9 @@ import unzip from './unzip.js'; * @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); export default zip; diff --git a/zipWith.js b/zipWith.js index 85c9fe558..03312e1b1 100644 --- a/zipWith.js +++ b/zipWith.js @@ -1,4 +1,4 @@ -import rest from './rest.js'; +import baseRest from './_baseRest.js'; import unzipWith from './unzipWith.js'; /** @@ -20,7 +20,7 @@ import unzipWith from './unzipWith.js'; * }); * // => [111, 222] */ -var zipWith = rest(function(arrays) { +var zipWith = baseRest(function(arrays) { var length = arrays.length, iteratee = length > 1 ? arrays[length - 1] : undefined;