diff --git a/README.md b/README.md index 3d1a4c360..3230bcac1 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# lodash-es v4.7.0 +# lodash-es v4.8.0 -The [lodash](https://lodash.com/) library exported as [ES](http://www.ecma-international.org/ecma-262/6.0/) modules. +The [Lodash](https://lodash.com/) library exported as [ES](http://www.ecma-international.org/ecma-262/6.0/) modules. Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli): ```bash $ lodash modularize exports=es -o ./ ``` -See the [package source](https://github.com/lodash/lodash/tree/4.7.0-es) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.8.0-es) for more details. diff --git a/_apply.js b/_apply.js index 341315948..479688583 100644 --- a/_apply.js +++ b/_apply.js @@ -5,7 +5,7 @@ * @private * @param {Function} func The function to invoke. * @param {*} thisArg The `this` binding of `func`. - * @param {...*} args The arguments to invoke `func` with. + * @param {Array} args The arguments to invoke `func` with. * @returns {*} Returns the result of `func`. */ function apply(func, thisArg, args) { diff --git a/_baseMatches.js b/_baseMatches.js index b1d237be7..6cbb044a8 100644 --- a/_baseMatches.js +++ b/_baseMatches.js @@ -1,5 +1,6 @@ import baseIsMatch from './_baseIsMatch'; import getMatchData from './_getMatchData'; +import matchesStrictComparable from './_matchesStrictComparable'; /** * The base implementation of `_.matches` which doesn't clone `source`. @@ -11,16 +12,7 @@ import getMatchData from './_getMatchData'; function baseMatches(source) { var matchData = getMatchData(source); if (matchData.length == 1 && matchData[0][2]) { - var key = matchData[0][0], - value = matchData[0][1]; - - return function(object) { - if (object == null) { - return false; - } - return object[key] === value && - (value !== undefined || (key in Object(object))); - }; + return matchesStrictComparable(matchData[0][0], matchData[0][1]); } return function(object) { return object === source || baseIsMatch(object, source, matchData); diff --git a/_baseMatchesProperty.js b/_baseMatchesProperty.js index b7fe5b5de..8728cfd08 100644 --- a/_baseMatchesProperty.js +++ b/_baseMatchesProperty.js @@ -1,6 +1,9 @@ import baseIsEqual from './_baseIsEqual'; import get from './get'; import hasIn from './hasIn'; +import isKey from './_isKey'; +import isStrictComparable from './_isStrictComparable'; +import matchesStrictComparable from './_matchesStrictComparable'; /** Used to compose bitmasks for comparison styles. */ var UNORDERED_COMPARE_FLAG = 1, @@ -15,6 +18,9 @@ var UNORDERED_COMPARE_FLAG = 1, * @returns {Function} Returns the new function. */ function baseMatchesProperty(path, srcValue) { + if (isKey(path) && isStrictComparable(srcValue)) { + return matchesStrictComparable(path, srcValue); + } return function(object) { var objValue = get(object, path); return (objValue === undefined && objValue === srcValue) diff --git a/_createCtorWrapper.js b/_createCtorWrapper.js index 132991941..a1159a2c1 100644 --- a/_createCtorWrapper.js +++ b/_createCtorWrapper.js @@ -11,8 +11,8 @@ import isObject from './isObject'; */ function createCtorWrapper(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 + // 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 // for more details. var args = arguments; switch (args.length) { diff --git a/_createOver.js b/_createOver.js index c24b36cfe..07260b263 100644 --- a/_createOver.js +++ b/_createOver.js @@ -1,6 +1,5 @@ import apply from './_apply'; import arrayMap from './_arrayMap'; -import baseFlatten from './_baseFlatten'; import baseIteratee from './_baseIteratee'; import rest from './rest'; @@ -13,7 +12,7 @@ import rest from './rest'; */ function createOver(arrayFunc) { return rest(function(iteratees) { - iteratees = arrayMap(baseFlatten(iteratees, 1), baseIteratee); + iteratees = arrayMap(iteratees, baseIteratee); return rest(function(args) { var thisArg = this; return arrayFunc(iteratees, function(iteratee) { diff --git a/_createPartialWrapper.js b/_createPartialWrapper.js index 22b86d0a2..8a472926a 100644 --- a/_createPartialWrapper.js +++ b/_createPartialWrapper.js @@ -6,9 +6,8 @@ import root from './_root'; var BIND_FLAG = 1; /** - * Creates a function that wraps `func` to invoke it with the optional `this` - * binding of `thisArg` and the `partials` prepended to those provided to - * the wrapper. + * Creates a function that wraps `func` to invoke it with the `this` binding + * of `thisArg` and `partials` prepended to the arguments it receives. * * @private * @param {Function} func The function to wrap. diff --git a/_equalByTag.js b/_equalByTag.js index 036d8d28f..d7ba39775 100644 --- a/_equalByTag.js +++ b/_equalByTag.js @@ -78,7 +78,8 @@ function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) { case regexpTag: case stringTag: // Coerce regexes to strings and treat strings, primitives and objects, - // as equal. See https://es5.github.io/#x15.10.6.4 for more details. + // as equal. See http://www.ecma-international.org/ecma-262/6.0/#sec-regexp.prototype.tostring + // for more details. return object == (other + ''); case mapTag: diff --git a/_getTag.js b/_getTag.js index 9ddb3f85c..663ac5fa6 100644 --- a/_getTag.js +++ b/_getTag.js @@ -3,6 +3,7 @@ import Map from './_Map'; import Promise from './_Promise'; import Set from './_Set'; import WeakMap from './_WeakMap'; +import toSource from './_toSource'; /** `Object#toString` result references. */ var mapTag = '[object Map]', @@ -16,21 +17,19 @@ var dataViewTag = '[object DataView]'; /** Used for built-in method references. */ var objectProto = Object.prototype; -/** Used to resolve the decompiled source of functions. */ -var funcToString = Function.prototype.toString; - /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; /** Used to detect maps, sets, and weakmaps. */ -var dataViewCtorString = DataView ? (DataView + '') : '', - mapCtorString = Map ? funcToString.call(Map) : '', - promiseCtorString = Promise ? funcToString.call(Promise) : '', - setCtorString = Set ? funcToString.call(Set) : '', - weakMapCtorString = WeakMap ? funcToString.call(WeakMap) : ''; +var dataViewCtorString = toSource(DataView), + mapCtorString = toSource(Map), + promiseCtorString = toSource(Promise), + setCtorString = toSource(Set), + weakMapCtorString = toSource(WeakMap); /** * Gets the `toStringTag` of `value`. @@ -53,7 +52,7 @@ if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || getTag = function(value) { var result = objectToString.call(value), Ctor = result == objectTag ? value.constructor : null, - ctorString = typeof Ctor == 'function' ? funcToString.call(Ctor) : ''; + ctorString = toSource(Ctor); if (ctorString) { switch (ctorString) { diff --git a/_hasPath.js b/_hasPath.js index cdded4a9e..901750cbc 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -16,29 +16,25 @@ import isString from './isString'; * @returns {boolean} Returns `true` if `path` exists, else `false`. */ function hasPath(object, path, hasFunc) { - if (object == null) { - return false; - } - var result = hasFunc(object, path); - if (!result && !isKey(path)) { - path = baseCastPath(path); + path = isKey(path, object) ? [path] : baseCastPath(path); - var index = -1, - length = path.length; + var result, + index = -1, + length = path.length; - while (object != null && ++index < length) { - var key = path[index]; - if (!(result = hasFunc(object, key))) { - break; - } - object = object[key]; + while (++index < length) { + var key = path[index]; + if (!(result = object != null && hasFunc(object, key))) { + break; } + object = object[key]; } - var length = object ? object.length : undefined; - return result || ( - !!length && isLength(length) && isIndex(path, length) && - (isArray(object) || isString(object) || isArguments(object)) - ); + if (result) { + return result; + } + var length = object ? object.length : 0; + return !!length && isLength(length) && isIndex(key, length) && + (isArray(object) || isString(object) || isArguments(object)); } export default hasPath; diff --git a/_matchesStrictComparable.js b/_matchesStrictComparable.js new file mode 100644 index 000000000..a9dd8af95 --- /dev/null +++ b/_matchesStrictComparable.js @@ -0,0 +1,20 @@ +/** + * A specialized version of `matchesProperty` for source values suitable + * for strict equality comparisons, i.e. `===`. + * + * @private + * @param {string} key The key of the property to get. + * @param {*} srcValue The value to match. + * @returns {Function} Returns the new function. + */ +function matchesStrictComparable(key, srcValue) { + return function(object) { + if (object == null) { + return false; + } + return object[key] === srcValue && + (srcValue !== undefined || (key in Object(object))); + }; +} + +export default matchesStrictComparable; diff --git a/_toSource.js b/_toSource.js new file mode 100644 index 000000000..dd11d2fe3 --- /dev/null +++ b/_toSource.js @@ -0,0 +1,23 @@ +import isFunction from './isFunction'; +import toString from './toString'; + +/** Used to resolve the decompiled source of functions. */ +var funcToString = Function.prototype.toString; + +/** + * Converts `func` to its source code. + * + * @private + * @param {Function} func The function to process. + * @returns {string} Returns the source code. + */ +function toSource(func) { + if (isFunction(func)) { + try { + return funcToString.call(func); + } catch (e) {} + } + return toString(func); +} + +export default toSource; diff --git a/ary.js b/ary.js index 8e3d3d751..2d5abc1bb 100644 --- a/ary.js +++ b/ary.js @@ -4,8 +4,8 @@ import createWrapper from './_createWrapper'; var ARY_FLAG = 128; /** - * Creates a function that accepts up to `n` arguments, ignoring any - * additional arguments. + * Creates a function that invokes `func`, with up to `n` arguments, + * ignoring any additional arguments. * * @static * @memberOf _ diff --git a/bind.js b/bind.js index cdf551d93..947dbedaa 100644 --- a/bind.js +++ b/bind.js @@ -9,8 +9,7 @@ var BIND_FLAG = 1, /** * Creates a function that invokes `func` with the `this` binding of `thisArg` - * and prepends any additional `_.bind` arguments to those provided to the - * bound function. + * and `partials` prepended to the arguments it receives. * * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, * may be used as a placeholder for partially applied arguments. diff --git a/bindKey.js b/bindKey.js index e5ebe44eb..ef3bd6ed6 100644 --- a/bindKey.js +++ b/bindKey.js @@ -9,8 +9,8 @@ var BIND_FLAG = 1, PARTIAL_FLAG = 32; /** - * Creates a function that invokes the method at `object[key]` and prepends - * any additional `_.bindKey` arguments to those provided to the bound function. + * Creates a function that invokes the method at `object[key]` with `partials` + * prepended to the arguments it receives. * * This method differs from `_.bind` by allowing bound functions to reference * methods that may be redefined or don't yet exist. See diff --git a/chunk.js b/chunk.js index bf202884f..700b0e619 100644 --- a/chunk.js +++ b/chunk.js @@ -1,4 +1,5 @@ import baseSlice from './_baseSlice'; +import isIterateeCall from './_isIterateeCall'; import toInteger from './toInteger'; /* Built-in method references for those with the same name as other `lodash` methods. */ @@ -15,7 +16,8 @@ var nativeCeil = Math.ceil, * @since 3.0.0 * @category Array * @param {Array} array The array to process. - * @param {number} [size=0] The length of each chunk. + * @param {number} [size=1] The length of each chunk + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the new array containing chunks. * @example * @@ -25,9 +27,12 @@ var nativeCeil = Math.ceil, * _.chunk(['a', 'b', 'c', 'd'], 3); * // => [['a', 'b', 'c'], ['d']] */ -function chunk(array, size) { - size = nativeMax(toInteger(size), 0); - +function chunk(array, size, guard) { + if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) { + size = 1; + } else { + size = nativeMax(toInteger(size), 0); + } var length = array ? array.length : 0; if (!length || size < 1) { return []; diff --git a/countBy.js b/countBy.js index 67056d805..70d61fbe6 100644 --- a/countBy.js +++ b/countBy.js @@ -8,9 +8,9 @@ var hasOwnProperty = objectProto.hasOwnProperty; /** * Creates an object composed of keys generated from the results of running - * each element of `collection` through `iteratee`. The corresponding value - * of each key is the number of times the key was returned by `iteratee`. - * The iteratee is invoked with one argument: (value). + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the number of times the key was returned by `iteratee`. The + * iteratee is invoked with one argument: (value). * * @static * @memberOf _ diff --git a/escapeRegExp.js b/escapeRegExp.js index fb3941db2..aad60d1bf 100644 --- a/escapeRegExp.js +++ b/escapeRegExp.js @@ -1,6 +1,9 @@ import toString from './toString'; -/** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */ +/** + * Used to match `RegExp` + * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). + */ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g, reHasRegExpChar = RegExp(reRegExpChar.source); diff --git a/flatMap.js b/flatMap.js index 11e0ce010..c261691fe 100644 --- a/flatMap.js +++ b/flatMap.js @@ -3,8 +3,8 @@ import map from './map'; /** * Creates a flattened array of values by running each element in `collection` - * through `iteratee` and flattening the mapped results. The iteratee is - * invoked with three arguments: (value, index|key, collection). + * thru `iteratee` and flattening the mapped results. The iteratee is invoked + * with three arguments: (value, index|key, collection). * * @static * @memberOf _ diff --git a/groupBy.js b/groupBy.js index 6a0c5f78b..38e4ab4cf 100644 --- a/groupBy.js +++ b/groupBy.js @@ -8,9 +8,9 @@ var hasOwnProperty = objectProto.hasOwnProperty; /** * Creates an object composed of keys generated from the results of running - * each element of `collection` through `iteratee`. The corresponding value - * of each key is an array of elements responsible for generating the key. - * The iteratee is invoked with one argument: (value). + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is an array of elements responsible for generating the key. The + * iteratee is invoked with one argument: (value). * * @static * @memberOf _ diff --git a/has.js b/has.js index dcdda8a18..5e0b461bc 100644 --- a/has.js +++ b/has.js @@ -29,7 +29,7 @@ import hasPath from './_hasPath'; * // => false */ function has(object, path) { - return hasPath(object, path, baseHas); + return object != null && hasPath(object, path, baseHas); } export default has; diff --git a/hasIn.js b/hasIn.js index f8e4b511e..ae43c336f 100644 --- a/hasIn.js +++ b/hasIn.js @@ -28,7 +28,7 @@ import hasPath from './_hasPath'; * // => false */ function hasIn(object, path) { - return hasPath(object, path, baseHasIn); + return object != null && hasPath(object, path, baseHasIn); } export default hasIn; diff --git a/invertBy.js b/invertBy.js index b096f8dc0..3fa2fd773 100644 --- a/invertBy.js +++ b/invertBy.js @@ -9,8 +9,8 @@ var hasOwnProperty = objectProto.hasOwnProperty; /** * This method is like `_.invert` except that the inverted object is generated - * from the results of running each element of `object` through `iteratee`. - * The corresponding inverted value of each inverted key is an array of keys + * from the results of running each element of `object` thru `iteratee`. The + * corresponding inverted value of each inverted key is an array of keys * responsible for generating the inverted value. The iteratee is invoked * with one argument: (value). * diff --git a/isArguments.js b/isArguments.js index 579c0e088..1f4cf8e37 100644 --- a/isArguments.js +++ b/isArguments.js @@ -10,7 +10,8 @@ var objectProto = Object.prototype; var hasOwnProperty = objectProto.hasOwnProperty; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isArrayBuffer.js b/isArrayBuffer.js index b603d0eac..9170868fe 100644 --- a/isArrayBuffer.js +++ b/isArrayBuffer.js @@ -6,7 +6,8 @@ var arrayBufferTag = '[object ArrayBuffer]'; var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isBoolean.js b/isBoolean.js index 0b3991a6e..fc06ac5e8 100644 --- a/isBoolean.js +++ b/isBoolean.js @@ -7,7 +7,8 @@ var boolTag = '[object Boolean]'; var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isDate.js b/isDate.js index 8c100147b..0496e463c 100644 --- a/isDate.js +++ b/isDate.js @@ -7,7 +7,8 @@ var dateTag = '[object Date]'; var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isError.js b/isError.js index 156548e91..5ad5e7e74 100644 --- a/isError.js +++ b/isError.js @@ -7,7 +7,8 @@ var errorTag = '[object Error]'; var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isFunction.js b/isFunction.js index 7144ea119..093161320 100644 --- a/isFunction.js +++ b/isFunction.js @@ -8,7 +8,8 @@ var funcTag = '[object Function]', var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isNaN.js b/isNaN.js index 8489779c3..90e83bf55 100644 --- a/isNaN.js +++ b/isNaN.js @@ -3,9 +3,10 @@ import isNumber from './isNumber'; /** * Checks if `value` is `NaN`. * - * **Note:** This method is not the same as - * [`isNaN`](https://es5.github.io/#x15.1.2.4) which returns `true` for - * `undefined` and other non-numeric values. + * **Note:** This method is based on + * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as + * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for + * `undefined` and other non-number values. * * @static * @memberOf _ diff --git a/isNative.js b/isNative.js index 5a3478572..d7641c0b2 100644 --- a/isNative.js +++ b/isNative.js @@ -1,8 +1,12 @@ import isFunction from './isFunction'; import isHostObject from './_isHostObject'; -import isObjectLike from './isObjectLike'; +import isObject from './isObject'; +import toSource from './_toSource'; -/** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */ +/** + * Used to match `RegExp` + * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). + */ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; /** Used to detect host constructors (Safari). */ @@ -42,14 +46,11 @@ var reIsNative = RegExp('^' + * // => false */ function isNative(value) { - if (value == null) { + if (!isObject(value)) { return false; } - if (isFunction(value)) { - return reIsNative.test(funcToString.call(value)); - } - return isObjectLike(value) && - (isHostObject(value) ? reIsNative : reIsHostCtor).test(value); + var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor; + return pattern.test(toSource(value)); } export default isNative; diff --git a/isNumber.js b/isNumber.js index 1ad99f843..4b3a66933 100644 --- a/isNumber.js +++ b/isNumber.js @@ -7,7 +7,8 @@ var numberTag = '[object Number]'; var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isObject.js b/isObject.js index 1488b7a99..ccce8c3c6 100644 --- a/isObject.js +++ b/isObject.js @@ -1,6 +1,7 @@ /** - * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. - * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) * * @static * @memberOf _ diff --git a/isPlainObject.js b/isPlainObject.js index 9a0701549..8dab09ef4 100644 --- a/isPlainObject.js +++ b/isPlainObject.js @@ -18,7 +18,8 @@ var hasOwnProperty = objectProto.hasOwnProperty; var objectCtorString = funcToString.call(Object); /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isRegExp.js b/isRegExp.js index b1bac4a07..a52d2159a 100644 --- a/isRegExp.js +++ b/isRegExp.js @@ -7,7 +7,8 @@ var regexpTag = '[object RegExp]'; var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isString.js b/isString.js index c01208a98..de9d971ea 100644 --- a/isString.js +++ b/isString.js @@ -8,7 +8,8 @@ var stringTag = '[object String]'; var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isSymbol.js b/isSymbol.js index e35477d16..d068b3862 100644 --- a/isSymbol.js +++ b/isSymbol.js @@ -7,7 +7,8 @@ var symbolTag = '[object Symbol]'; var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isTypedArray.js b/isTypedArray.js index 88191bc34..34cdc702e 100644 --- a/isTypedArray.js +++ b/isTypedArray.js @@ -48,7 +48,8 @@ typedArrayTags[weakMapTag] = false; var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/isWeakSet.js b/isWeakSet.js index 9199caf70..70ee0c3ec 100644 --- a/isWeakSet.js +++ b/isWeakSet.js @@ -7,7 +7,8 @@ var weakSetTag = '[object WeakSet]'; var objectProto = Object.prototype; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; diff --git a/keyBy.js b/keyBy.js index 3b22866dd..771a0d8a8 100644 --- a/keyBy.js +++ b/keyBy.js @@ -2,8 +2,8 @@ import createAggregator from './_createAggregator'; /** * Creates an object composed of keys generated from the results of running - * each element of `collection` through `iteratee`. The corresponding value - * of each key is the last element responsible for generating the key. The + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the last element responsible for generating the key. The * iteratee is invoked with one argument: (value). * * @static diff --git a/lodash.default.js b/lodash.default.js index ab9ecec26..47bcbbeaa 100644 --- a/lodash.default.js +++ b/lodash.default.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.7.0 (Custom Build) + * lodash 4.8.0 (Custom Build) * Build: `lodash modularize exports="es" -o ./` * Copyright jQuery Foundation and other contributors * Released under MIT license @@ -44,7 +44,7 @@ import toInteger from './toInteger'; import lodash from './wrapperLodash'; /** Used as the semantic version number. */ -var VERSION = '4.7.0'; +var VERSION = '4.8.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_KEY_FLAG = 2; diff --git a/lodash.js b/lodash.js index 12d6aa0d4..074f82add 100644 --- a/lodash.js +++ b/lodash.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.7.0 (Custom Build) + * lodash 4.8.0 (Custom Build) * Build: `lodash modularize exports="es" -o ./` * Copyright jQuery Foundation and other contributors * Released under MIT license diff --git a/map.js b/map.js index d46806efe..9fb895872 100644 --- a/map.js +++ b/map.js @@ -4,7 +4,7 @@ import baseMap from './_baseMap'; import isArray from './isArray'; /** - * Creates an array of values by running each element in `collection` through + * Creates an array of values by running each element in `collection` thru * `iteratee`. The iteratee is invoked with three arguments: * (value, index|key, collection). * @@ -12,10 +12,10 @@ import isArray from './isArray'; * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. * * The guarded methods are: - * `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`, - * `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`, - * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`, - * and `words` + * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, + * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`, + * `sampleSize`, `slice`, `some`, `sortBy`, `take`, `takeRight`, `template`, + * `trim`, `trimEnd`, `trimStart`, and `words` * * @static * @memberOf _ diff --git a/mapKeys.js b/mapKeys.js index 114dc9570..ad06c0f76 100644 --- a/mapKeys.js +++ b/mapKeys.js @@ -4,8 +4,8 @@ import baseIteratee from './_baseIteratee'; /** * The opposite of `_.mapValues`; this method creates an object with the * same values as `object` and keys generated by running each own enumerable - * string keyed property of `object` through `iteratee`. The iteratee is - * invoked with three arguments: (value, key, object). + * string keyed property of `object` thru `iteratee`. The iteratee is invoked + * with three arguments: (value, key, object). * * @static * @memberOf _ diff --git a/mapValues.js b/mapValues.js index 9d144182a..298b7ae80 100644 --- a/mapValues.js +++ b/mapValues.js @@ -2,8 +2,8 @@ import baseForOwn from './_baseForOwn'; import baseIteratee from './_baseIteratee'; /** - * Creates an object with the same keys as `object` and values generated by - * running each own enumerable string keyed property of `object` through + * Creates an object with the same keys as `object` and values generated + * by running each own enumerable string keyed property of `object` thru * `iteratee`. The iteratee is invoked with three arguments: * (value, key, object). * diff --git a/over.js b/over.js index dd592d32c..4245c371e 100644 --- a/over.js +++ b/over.js @@ -2,14 +2,14 @@ import arrayMap from './_arrayMap'; import createOver from './_createOver'; /** - * Creates a function that invokes `iteratees` with the arguments provided - * to the created function and returns their results. + * Creates a function that invokes `iteratees` with the arguments it receives + * and returns their results. * * @static * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Function|Function[])} iteratees The iteratees to invoke. + * @param {...Function} iteratees The iteratees to invoke. * @returns {Function} Returns the new function. * @example * diff --git a/overArgs.js b/overArgs.js index 083961bb7..251d1a82e 100644 --- a/overArgs.js +++ b/overArgs.js @@ -1,6 +1,5 @@ import apply from './_apply'; import arrayMap from './_arrayMap'; -import baseFlatten from './_baseFlatten'; import baseIteratee from './_baseIteratee'; import rest from './rest'; @@ -16,7 +15,7 @@ var nativeMin = Math.min; * @memberOf _ * @category Function * @param {Function} func The function to wrap. - * @param {...(Function|Function[])} [transforms] The functions to transform + * @param {...Function} [transforms] The functions to transform * arguments, specified individually or in arrays. * @returns {Function} Returns the new function. * @example @@ -40,7 +39,7 @@ var nativeMin = Math.min; * // => [100, 10] */ var overArgs = rest(function(func, transforms) { - transforms = arrayMap(baseFlatten(transforms, 1), baseIteratee); + transforms = arrayMap(transforms, baseIteratee); var funcsLength = transforms.length; return rest(function(args) { diff --git a/overEvery.js b/overEvery.js index cadde1e9c..0a7991a56 100644 --- a/overEvery.js +++ b/overEvery.js @@ -3,13 +3,13 @@ import createOver from './_createOver'; /** * Creates a function that checks if **all** of the `predicates` return - * truthy when invoked with the arguments provided to the created function. + * truthy when invoked with the arguments it receives. * * @static * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Function|Function[])} predicates The predicates to check. + * @param {...Function} predicates The predicates to check. * @returns {Function} Returns the new function. * @example * diff --git a/overSome.js b/overSome.js index 813b5e235..55d3c7af9 100644 --- a/overSome.js +++ b/overSome.js @@ -3,13 +3,13 @@ import createOver from './_createOver'; /** * Creates a function that checks if **any** of the `predicates` return - * truthy when invoked with the arguments provided to the created function. + * truthy when invoked with the arguments it receives. * * @static * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Function|Function[])} predicates The predicates to check. + * @param {...Function} predicates The predicates to check. * @returns {Function} Returns the new function. * @example * diff --git a/package.json b/package.json index 973e3be62..d19f94d66 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "lodash-es", - "version": "4.7.0", + "version": "4.8.0", "description": "Lodash exported as ES modules.", "homepage": "https://lodash.com/custom-builds", "license": "MIT", + "private": true, "jsnext:main": "lodash.js", "main": "lodash.js", - "private": true, "keywords": "es6, modules, stdlib, util", "author": "John-David Dalton (http://allyoucanleet.com/)", "contributors": [ diff --git a/partial.js b/partial.js index e548bf57f..a7789fe8e 100644 --- a/partial.js +++ b/partial.js @@ -7,9 +7,9 @@ import rest from './rest'; var PARTIAL_FLAG = 32; /** - * Creates a function that invokes `func` with `partial` arguments prepended - * to those provided to the new function. This method is like `_.bind` except - * it does **not** alter the `this` binding. + * Creates a function that invokes `func` with `partials` prepended to the + * arguments it receives. This method is like `_.bind` except it does **not** + * alter the `this` binding. * * The `_.partial.placeholder` value, which defaults to `_` in monolithic * builds, may be used as a placeholder for partially applied arguments. diff --git a/partialRight.js b/partialRight.js index c98456b60..0d1b9e975 100644 --- a/partialRight.js +++ b/partialRight.js @@ -8,7 +8,7 @@ var PARTIAL_RIGHT_FLAG = 64; /** * This method is like `_.partial` except that partially applied arguments - * are appended to those provided to the new function. + * are appended to the arguments it receives. * * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic * builds, may be used as a placeholder for partially applied arguments. diff --git a/rearg.js b/rearg.js index 6a0aef35f..8990017c9 100644 --- a/rearg.js +++ b/rearg.js @@ -7,7 +7,7 @@ var REARG_FLAG = 256; /** * Creates a function that invokes `func` with arguments arranged according - * to the specified indexes where the argument value at the first index is + * to the specified `indexes` where the argument value at the first index is * provided as the first argument, the argument value at the second index is * provided as the second argument, and so on. * diff --git a/reduce.js b/reduce.js index 096300e79..187cfd8db 100644 --- a/reduce.js +++ b/reduce.js @@ -6,7 +6,7 @@ import isArray from './isArray'; /** * Reduces `collection` to a value which is the accumulated result of running - * each element in `collection` through `iteratee`, where each successive + * each element in `collection` thru `iteratee`, where each successive * invocation is supplied the return value of the previous. If `accumulator` * is not given the first element of `collection` is used as the initial * value. The iteratee is invoked with four arguments: diff --git a/repeat.js b/repeat.js index 967d0c060..c32683497 100644 --- a/repeat.js +++ b/repeat.js @@ -1,4 +1,5 @@ import baseRepeat from './_baseRepeat'; +import isIterateeCall from './_isIterateeCall'; import toInteger from './toInteger'; import toString from './toString'; @@ -10,7 +11,8 @@ import toString from './toString'; * @since 3.0.0 * @category String * @param {string} [string=''] The string to repeat. - * @param {number} [n=0] The number of times to repeat the string. + * @param {number} [n=1] The number of times to repeat the string. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {string} Returns the repeated string. * @example * @@ -23,8 +25,13 @@ import toString from './toString'; * _.repeat('abc', 0); * // => '' */ -function repeat(string, n) { - return baseRepeat(toString(string), toInteger(n)); +function repeat(string, n, guard) { + if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) { + n = 1; + } else { + n = toInteger(n); + } + return baseRepeat(toString(string), n); } export default repeat; diff --git a/sampleSize.js b/sampleSize.js index fcb4f0219..c65453e86 100644 --- a/sampleSize.js +++ b/sampleSize.js @@ -1,5 +1,6 @@ import baseClamp from './_baseClamp'; import baseRandom from './_baseRandom'; +import isIterateeCall from './_isIterateeCall'; import toArray from './toArray'; import toInteger from './toInteger'; @@ -12,7 +13,8 @@ import toInteger from './toInteger'; * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to sample. - * @param {number} [n=0] The number of elements to sample. + * @param {number} [n=1] The number of elements to sample. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the random elements. * @example * @@ -22,13 +24,17 @@ import toInteger from './toInteger'; * _.sampleSize([1, 2, 3], 4); * // => [2, 3, 1] */ -function sampleSize(collection, n) { +function sampleSize(collection, n, guard) { var index = -1, result = toArray(collection), length = result.length, lastIndex = length - 1; - n = baseClamp(toInteger(n), 0, length); + if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) { + n = 1; + } else { + n = baseClamp(toInteger(n), 0, length); + } while (++index < n) { var rand = baseRandom(index, lastIndex), value = result[rand]; diff --git a/set.js b/set.js index 967d2030b..f7581832c 100644 --- a/set.js +++ b/set.js @@ -24,7 +24,7 @@ import baseSet from './_baseSet'; * console.log(object.a[0].b.c); * // => 4 * - * _.set(object, 'x[0].y.z', 5); + * _.set(object, ['x', '0', 'y', 'z'], 5); * console.log(object.x[0].y.z); * // => 5 */ diff --git a/sortBy.js b/sortBy.js index 437061904..edb45a3b9 100644 --- a/sortBy.js +++ b/sortBy.js @@ -5,7 +5,7 @@ import rest from './rest'; /** * Creates an array of elements, sorted in ascending order by the results of - * running each element in a collection through each iteratee. This method + * running each element in a collection thru each iteratee. This method * performs a stable sort, that is, it preserves the original sort order of * equal elements. The iteratees are invoked with one argument: (value). * diff --git a/spread.js b/spread.js index 69fdfbcd2..debde0b4d 100644 --- a/spread.js +++ b/spread.js @@ -12,7 +12,7 @@ var nativeMax = Math.max; /** * Creates a function that invokes `func` with the `this` binding of the * create function and an array of arguments much like - * [`Function#apply`](https://es5.github.io/#x15.3.4.3). + * [`Function#apply`](http://www.ecma-international.org/ecma-262/6.0/#sec-function.prototype.apply). * * **Note:** This method is based on the * [spread operator](https://mdn.io/spread_operator). diff --git a/template.js b/template.js index 7bcce914f..11662425e 100644 --- a/template.js +++ b/template.js @@ -15,7 +15,10 @@ var reEmptyStringLeading = /\b__p \+= '';/g, reEmptyStringMiddle = /\b(__p \+=) '' \+/g, reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; -/** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */ +/** + * Used to match + * [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). + */ var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; /** Used to ensure capturing order of template delimiters. */ diff --git a/toNumber.js b/toNumber.js index b0f0816d1..5917c9d99 100644 --- a/toNumber.js +++ b/toNumber.js @@ -55,7 +55,7 @@ function toNumber(value) { value = isObject(other) ? (other + '') : other; } if (typeof value != 'string') { - return value === 0 ? value : +value; + return value === 0 ? value : +value; } value = value.replace(reTrim, ''); var isBinary = reIsBinary.test(value); diff --git a/transform.js b/transform.js index c2e00473f..f681d9659 100644 --- a/transform.js +++ b/transform.js @@ -10,11 +10,11 @@ import isTypedArray from './isTypedArray'; /** * An alternative to `_.reduce`; this method transforms `object` to a new - * `accumulator` object which is the result of running each of its own enumerable - * string keyed properties through `iteratee`, with each invocation potentially - * mutating the `accumulator` object. The iteratee is invoked with four arguments: - * (accumulator, value, key, object). Iteratee functions may exit iteration - * early by explicitly returning `false`. + * `accumulator` object which is the result of running each of its own + * enumerable string keyed properties thru `iteratee`, with each invocation + * potentially mutating the `accumulator` object. The iteratee is invoked + * with four arguments: (accumulator, value, key, object). Iteratee functions + * may exit iteration early by explicitly returning `false`. * * @static * @memberOf _ diff --git a/unset.js b/unset.js index b2fd7f7a6..5c2aa10c7 100644 --- a/unset.js +++ b/unset.js @@ -21,7 +21,7 @@ import baseUnset from './_baseUnset'; * console.log(object); * // => { 'a': [{ 'b': {} }] }; * - * _.unset(object, 'a[0].b.c'); + * _.unset(object, ['a', '0', 'b', 'c']); * // => true * * console.log(object);