diff --git a/README.md b/README.md index e005f0290..00c1551aa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# lodash-amd v4.7.0 +# lodash-amd v4.8.0 -The [lodash](https://lodash.com/) library exported as [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules. +The [Lodash](https://lodash.com/) library exported as [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules. Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli): ```bash @@ -27,4 +27,4 @@ require({ }); ``` -See the [package source](https://github.com/lodash/lodash/tree/4.7.0-amd) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.8.0-amd) for more details. diff --git a/_apply.js b/_apply.js index eea9fd562..b264e0a63 100644 --- a/_apply.js +++ b/_apply.js @@ -7,7 +7,7 @@ define([], function() { * @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 988df8436..28ce074c5 100644 --- a/_baseMatches.js +++ b/_baseMatches.js @@ -1,7 +1,4 @@ -define(['./_baseIsMatch', './_getMatchData'], function(baseIsMatch, getMatchData) { - - /** Used as a safe reference for `undefined` in pre-ES5 environments. */ - var undefined; +define(['./_baseIsMatch', './_getMatchData', './_matchesStrictComparable'], function(baseIsMatch, getMatchData, matchesStrictComparable) { /** * The base implementation of `_.matches` which doesn't clone `source`. @@ -13,16 +10,7 @@ define(['./_baseIsMatch', './_getMatchData'], function(baseIsMatch, 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 d93c10adf..76f3fabf0 100644 --- a/_baseMatchesProperty.js +++ b/_baseMatchesProperty.js @@ -1,4 +1,4 @@ -define(['./_baseIsEqual', './get', './hasIn'], function(baseIsEqual, get, hasIn) { +define(['./_baseIsEqual', './get', './hasIn', './_isKey', './_isStrictComparable', './_matchesStrictComparable'], function(baseIsEqual, get, hasIn, isKey, isStrictComparable, matchesStrictComparable) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -16,6 +16,9 @@ define(['./_baseIsEqual', './get', './hasIn'], function(baseIsEqual, get, hasIn) * @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 2bbbe2a6f..5b76869b2 100644 --- a/_createCtorWrapper.js +++ b/_createCtorWrapper.js @@ -10,8 +10,8 @@ define(['./_baseCreate', './isObject'], function(baseCreate, 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 ca834ba30..2ea2c5b34 100644 --- a/_createOver.js +++ b/_createOver.js @@ -1,4 +1,4 @@ -define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './rest'], function(apply, arrayMap, baseFlatten, baseIteratee, rest) { +define(['./_apply', './_arrayMap', './_baseIteratee', './rest'], function(apply, arrayMap, baseIteratee, rest) { /** * Creates a function like `_.over`. @@ -9,7 +9,7 @@ define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './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 b3f1d9762..055762326 100644 --- a/_createPartialWrapper.js +++ b/_createPartialWrapper.js @@ -4,9 +4,8 @@ define(['./_apply', './_createCtorWrapper', './_root'], function(apply, createCt 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 66a8834d1..4a9d234c2 100644 --- a/_equalByTag.js +++ b/_equalByTag.js @@ -77,7 +77,8 @@ define(['./_Symbol', './_Uint8Array', './_equalArrays', './_mapToArray', './_set 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 734b2e1cc..4ba142f0a 100644 --- a/_getTag.js +++ b/_getTag.js @@ -1,4 +1,4 @@ -define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap'], function(DataView, Map, Promise, Set, WeakMap) { +define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap', './_toSource'], function(DataView, Map, Promise, Set, WeakMap, toSource) { /** `Object#toString` result references. */ var mapTag = '[object Map]', @@ -12,21 +12,19 @@ define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap'], function /** 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`. @@ -49,7 +47,7 @@ define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap'], function 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 df0354391..4427d41e0 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -1,8 +1,5 @@ define(['./_baseCastPath', './isArguments', './isArray', './_isIndex', './_isKey', './isLength', './isString'], function(baseCastPath, isArguments, isArray, isIndex, isKey, isLength, isString) { - /** Used as a safe reference for `undefined` in pre-ES5 environments. */ - var undefined; - /** * Checks if `path` exists on `object`. * @@ -13,29 +10,25 @@ define(['./_baseCastPath', './isArguments', './isArray', './_isIndex', './_isKey * @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)); } return hasPath; diff --git a/_matchesStrictComparable.js b/_matchesStrictComparable.js new file mode 100644 index 000000000..4e1150e57 --- /dev/null +++ b/_matchesStrictComparable.js @@ -0,0 +1,26 @@ +define([], function() { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * 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))); + }; + } + + return matchesStrictComparable; +}); diff --git a/_toSource.js b/_toSource.js new file mode 100644 index 000000000..a7c389282 --- /dev/null +++ b/_toSource.js @@ -0,0 +1,23 @@ +define(['./isFunction', './toString'], function(isFunction, 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); + } + + return toSource; +}); diff --git a/ary.js b/ary.js index a7a7ca768..394788fa7 100644 --- a/ary.js +++ b/ary.js @@ -7,8 +7,8 @@ define(['./_createWrapper'], function(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 47081975f..7fa0b5cc9 100644 --- a/bind.js +++ b/bind.js @@ -6,8 +6,7 @@ define(['./_createWrapper', './_getPlaceholder', './_replaceHolders', './rest'], /** * 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 2b0fb4570..86e3f6932 100644 --- a/bindKey.js +++ b/bindKey.js @@ -6,8 +6,8 @@ define(['./_createWrapper', './_getPlaceholder', './_replaceHolders', './rest'], 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 85f2c7ef3..c96d41699 100644 --- a/chunk.js +++ b/chunk.js @@ -1,4 +1,7 @@ -define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { +define(['./_baseSlice', './_isIterateeCall', './toInteger'], function(baseSlice, isIterateeCall, toInteger) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeCeil = Math.ceil, @@ -14,7 +17,8 @@ define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { * @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 * @@ -24,9 +28,12 @@ define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { * _.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 b8d345929..90c0c47df 100644 --- a/countBy.js +++ b/countBy.js @@ -8,9 +8,9 @@ define(['./_createAggregator'], function(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 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 8f5901325..03d653aed 100644 --- a/escapeRegExp.js +++ b/escapeRegExp.js @@ -1,6 +1,9 @@ define(['./toString'], function(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 7d6f17d6d..7d34a1d66 100644 --- a/flatMap.js +++ b/flatMap.js @@ -2,8 +2,8 @@ define(['./_baseFlatten', './map'], function(baseFlatten, 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 feca22489..a8b08256c 100644 --- a/groupBy.js +++ b/groupBy.js @@ -8,9 +8,9 @@ define(['./_createAggregator'], function(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 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 aae94854a..5575cf8cf 100644 --- a/has.js +++ b/has.js @@ -28,7 +28,7 @@ define(['./_baseHas', './_hasPath'], function(baseHas, hasPath) { * // => false */ function has(object, path) { - return hasPath(object, path, baseHas); + return object != null && hasPath(object, path, baseHas); } return has; diff --git a/hasIn.js b/hasIn.js index 6c8153447..90b6952d6 100644 --- a/hasIn.js +++ b/hasIn.js @@ -27,7 +27,7 @@ define(['./_baseHasIn', './_hasPath'], function(baseHasIn, hasPath) { * // => false */ function hasIn(object, path) { - return hasPath(object, path, baseHasIn); + return object != null && hasPath(object, path, baseHasIn); } return hasIn; diff --git a/invertBy.js b/invertBy.js index 35a940369..180a4047a 100644 --- a/invertBy.js +++ b/invertBy.js @@ -8,8 +8,8 @@ define(['./_baseIteratee', './_createInverter'], function(baseIteratee, createIn /** * 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 fc112bef2..7b488b662 100644 --- a/isArguments.js +++ b/isArguments.js @@ -10,7 +10,8 @@ define(['./isArrayLikeObject'], function(isArrayLikeObject) { 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 f32588720..9503f84b9 100644 --- a/isArrayBuffer.js +++ b/isArrayBuffer.js @@ -6,7 +6,8 @@ define(['./isObjectLike'], function(isObjectLike) { 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 245475a65..17db3af49 100644 --- a/isBoolean.js +++ b/isBoolean.js @@ -7,7 +7,8 @@ define(['./isObjectLike'], function(isObjectLike) { 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 358ccdc9e..4850ed8fc 100644 --- a/isDate.js +++ b/isDate.js @@ -7,7 +7,8 @@ define(['./isObjectLike'], function(isObjectLike) { 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 b0f14b2b5..914544755 100644 --- a/isError.js +++ b/isError.js @@ -7,7 +7,8 @@ define(['./isObjectLike'], function(isObjectLike) { 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 2c445475f..a3872ae77 100644 --- a/isFunction.js +++ b/isFunction.js @@ -8,7 +8,8 @@ define(['./isObject'], function(isObject) { 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 542bfb82e..b12aab3e7 100644 --- a/isNaN.js +++ b/isNaN.js @@ -3,9 +3,10 @@ define(['./isNumber'], function(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 2a1b53358..9f821bfbb 100644 --- a/isNative.js +++ b/isNative.js @@ -1,6 +1,9 @@ -define(['./isFunction', './_isHostObject', './isObjectLike'], function(isFunction, isHostObject, isObjectLike) { +define(['./isFunction', './_isHostObject', './isObject', './_toSource'], function(isFunction, isHostObject, isObject, 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). */ @@ -40,14 +43,11 @@ define(['./isFunction', './_isHostObject', './isObjectLike'], function(isFunctio * // => 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)); } return isNative; diff --git a/isNumber.js b/isNumber.js index fd76ee700..bedd47d13 100644 --- a/isNumber.js +++ b/isNumber.js @@ -7,7 +7,8 @@ define(['./isObjectLike'], function(isObjectLike) { 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 78cf34876..1c760012c 100644 --- a/isObject.js +++ b/isObject.js @@ -1,8 +1,9 @@ define([], function() { /** - * 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 8f5760674..b97a432a8 100644 --- a/isPlainObject.js +++ b/isPlainObject.js @@ -16,7 +16,8 @@ define(['./_getPrototype', './_isHostObject', './isObjectLike'], function(getPro 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 88d018947..63556bd93 100644 --- a/isRegExp.js +++ b/isRegExp.js @@ -7,7 +7,8 @@ define(['./isObject'], function(isObject) { 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 17bf98f41..8226201c8 100644 --- a/isString.js +++ b/isString.js @@ -7,7 +7,8 @@ define(['./isArray', './isObjectLike'], function(isArray, isObjectLike) { 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 74ded64f9..ba3648a41 100644 --- a/isSymbol.js +++ b/isSymbol.js @@ -7,7 +7,8 @@ define(['./isObjectLike'], function(isObjectLike) { 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 1af5854cd..0f455823e 100644 --- a/isTypedArray.js +++ b/isTypedArray.js @@ -47,7 +47,8 @@ define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { 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 e6fe04ded..29f751f19 100644 --- a/isWeakSet.js +++ b/isWeakSet.js @@ -7,7 +7,8 @@ define(['./isObjectLike'], function(isObjectLike) { 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 874f38bd2..f36fc49bf 100644 --- a/keyBy.js +++ b/keyBy.js @@ -2,8 +2,8 @@ define(['./_createAggregator'], function(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/main.js b/main.js index d0cee56d0..64902db00 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.7.0 (Custom Build) + * lodash 4.8.0 (Custom Build) * Build: `lodash exports="amd" -d -o ./main.js` * Copyright jQuery Foundation and other contributors * Released under MIT license @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.7.0'; + var VERSION = '4.8.0'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -119,7 +119,10 @@ reIsPlainProp = /^\w*$/, rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g; - /** 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); @@ -131,7 +134,10 @@ /** Used to match backslashes in property paths. */ var reEscapeChar = /\\(\\)?/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 match `RegExp` flags from their coerced string values. */ @@ -410,7 +416,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) { @@ -1391,7 +1397,8 @@ 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; @@ -1450,11 +1457,11 @@ var realNames = {}; /** 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); /** Used to convert symbols to primitives and strings. */ var symbolProto = Symbol ? Symbol.prototype : undefined, @@ -3190,16 +3197,7 @@ 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); @@ -3215,6 +3213,9 @@ * @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) @@ -4386,8 +4387,8 @@ */ 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) { @@ -4608,7 +4609,7 @@ */ function createOver(arrayFunc) { return rest(function(iteratees) { - iteratees = arrayMap(baseFlatten(iteratees, 1), getIteratee()); + iteratees = arrayMap(iteratees, getIteratee()); return rest(function(args) { var thisArg = this; return arrayFunc(iteratees, function(iteratee) { @@ -4641,9 +4642,8 @@ } /** - * 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. @@ -4986,7 +4986,8 @@ 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: @@ -5153,7 +5154,7 @@ /** * Gets the appropriate "iteratee" function. If the `_.iteratee` method is * customized this function returns the custom method, otherwise it returns - * `baseIteratee`. If arguments are provided the chosen function is invoked + * `baseIteratee`. If arguments are provided, the chosen function is invoked * with them and its result is returned. * * @private @@ -5291,7 +5292,7 @@ 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) { @@ -5344,29 +5345,25 @@ * @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)); } /** @@ -5570,6 +5567,25 @@ return value === value && !isObject(value); } + /** + * 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))); + }; + } + /** * Merges the function metadata of `source` into `data`. * @@ -5744,6 +5760,22 @@ return result; }); + /** + * 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); + } + /** * Creates a clone of `wrapper`. * @@ -5774,7 +5806,8 @@ * @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 * @@ -5784,9 +5817,12 @@ * _.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 []; @@ -7968,9 +8004,9 @@ /** * 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 _ @@ -8152,8 +8188,8 @@ /** * 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 _ @@ -8290,9 +8326,9 @@ /** * 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 _ @@ -8400,8 +8436,8 @@ /** * 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 @@ -8432,7 +8468,7 @@ }); /** - * 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). * @@ -8440,10 +8476,10 @@ * `_.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 _ @@ -8565,7 +8601,7 @@ /** * 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: @@ -8706,7 +8742,8 @@ * @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 * @@ -8716,13 +8753,17 @@ * _.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]; @@ -8838,7 +8879,7 @@ /** * 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). * @@ -8944,8 +8985,8 @@ } /** - * 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 _ @@ -9002,8 +9043,7 @@ /** * 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. @@ -9046,8 +9086,8 @@ }); /** - * 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 @@ -9553,7 +9593,7 @@ * @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 @@ -9577,7 +9617,7 @@ * // => [100, 10] */ var overArgs = rest(function(func, transforms) { - transforms = arrayMap(baseFlatten(transforms, 1), getIteratee()); + transforms = arrayMap(transforms, getIteratee()); var funcsLength = transforms.length; return rest(function(args) { @@ -9592,9 +9632,9 @@ }); /** - * 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. @@ -9631,7 +9671,7 @@ /** * 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. @@ -9668,7 +9708,7 @@ /** * 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. * @@ -9750,7 +9790,7 @@ /** * 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). @@ -10639,8 +10679,9 @@ } /** - * 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 _ @@ -10785,9 +10826,10 @@ /** * 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 _ @@ -10835,14 +10877,11 @@ * // => 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)); } /** @@ -11371,7 +11410,7 @@ 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); @@ -12047,7 +12086,7 @@ * // => false */ function has(object, path) { - return hasPath(object, path, baseHas); + return object != null && hasPath(object, path, baseHas); } /** @@ -12077,7 +12116,7 @@ * // => false */ function hasIn(object, path) { - return hasPath(object, path, baseHasIn); + return object != null && hasPath(object, path, baseHasIn); } /** @@ -12104,8 +12143,8 @@ /** * 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). * @@ -12251,8 +12290,8 @@ /** * 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 _ @@ -12280,8 +12319,8 @@ } /** - * 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). * @@ -12570,7 +12609,7 @@ * 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 */ @@ -12663,11 +12702,11 @@ /** * 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 _ @@ -12733,7 +12772,7 @@ * console.log(object); * // => { 'a': [{ 'b': {} }] }; * - * _.unset(object, 'a[0].b.c'); + * _.unset(object, ['a', '0', 'b', 'c']); * // => true * * console.log(object); @@ -13401,7 +13440,8 @@ * @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 * @@ -13414,8 +13454,13 @@ * _.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); } /** @@ -14640,14 +14685,14 @@ } /** - * 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 * @@ -14660,13 +14705,13 @@ /** * 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 * @@ -14685,13 +14730,13 @@ /** * 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/map.js b/map.js index 35195cb96..eceb4e6c5 100644 --- a/map.js +++ b/map.js @@ -1,7 +1,7 @@ define(['./_arrayMap', './_baseIteratee', './_baseMap', './isArray'], function(arrayMap, baseIteratee, baseMap, 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). * @@ -9,10 +9,10 @@ define(['./_arrayMap', './_baseIteratee', './_baseMap', './isArray'], function(a * `_.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 efeb05917..a305d0f1d 100644 --- a/mapKeys.js +++ b/mapKeys.js @@ -3,8 +3,8 @@ define(['./_baseForOwn', './_baseIteratee'], function(baseForOwn, 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 e35fa7b4b..d24360775 100644 --- a/mapValues.js +++ b/mapValues.js @@ -1,8 +1,8 @@ define(['./_baseForOwn', './_baseIteratee'], function(baseForOwn, 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 b66f15bcd..ecf1cbd70 100644 --- a/over.js +++ b/over.js @@ -1,14 +1,14 @@ define(['./_arrayMap', './_createOver'], function(arrayMap, 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 99e8471d0..d633ceb7b 100644 --- a/overArgs.js +++ b/overArgs.js @@ -1,4 +1,4 @@ -define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './rest'], function(apply, arrayMap, baseFlatten, baseIteratee, rest) { +define(['./_apply', './_arrayMap', './_baseIteratee', './rest'], function(apply, arrayMap, baseIteratee, rest) { /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeMin = Math.min; @@ -12,7 +12,7 @@ define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './rest' * @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 @@ -36,7 +36,7 @@ define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './rest' * // => [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 b2f2f3be2..f4c187e20 100644 --- a/overEvery.js +++ b/overEvery.js @@ -2,13 +2,13 @@ define(['./_arrayEvery', './_createOver'], function(arrayEvery, 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 23bb7e23b..a8181e41b 100644 --- a/overSome.js +++ b/overSome.js @@ -2,13 +2,13 @@ define(['./_arraySome', './_createOver'], function(arraySome, 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 4cb5ed4d7..d2a2778ce 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "lodash-amd", - "version": "4.7.0", + "version": "4.8.0", "description": "Lodash exported as AMD modules.", "homepage": "https://lodash.com/custom-builds", "license": "MIT", - "main": "main.js", "private": true, + "main": "main.js", "keywords": "amd, modules, stdlib, util", "author": "John-David Dalton (http://allyoucanleet.com/)", "contributors": [ diff --git a/partial.js b/partial.js index 16fa6f294..bd5f5b327 100644 --- a/partial.js +++ b/partial.js @@ -7,9 +7,9 @@ define(['./_createWrapper', './_getPlaceholder', './_replaceHolders', './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 71d15acf3..2ef96245e 100644 --- a/partialRight.js +++ b/partialRight.js @@ -8,7 +8,7 @@ define(['./_createWrapper', './_getPlaceholder', './_replaceHolders', './rest'], /** * 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 5bddbe49f..0d2ce4c88 100644 --- a/rearg.js +++ b/rearg.js @@ -8,7 +8,7 @@ define(['./_baseFlatten', './_createWrapper', './rest'], function(baseFlatten, c /** * 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 906d2e02d..072a7c834 100644 --- a/reduce.js +++ b/reduce.js @@ -2,7 +2,7 @@ define(['./_arrayReduce', './_baseEach', './_baseIteratee', './_baseReduce', './ /** * 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 913987ebd..299fa8552 100644 --- a/repeat.js +++ b/repeat.js @@ -1,4 +1,7 @@ -define(['./_baseRepeat', './toInteger', './toString'], function(baseRepeat, toInteger, toString) { +define(['./_baseRepeat', './_isIterateeCall', './toInteger', './toString'], function(baseRepeat, isIterateeCall, toInteger, toString) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; /** * Repeats the given string `n` times. @@ -8,7 +11,8 @@ define(['./_baseRepeat', './toInteger', './toString'], function(baseRepeat, toIn * @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 * @@ -21,8 +25,13 @@ define(['./_baseRepeat', './toInteger', './toString'], function(baseRepeat, toIn * _.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); } return repeat; diff --git a/sampleSize.js b/sampleSize.js index 5e884eb69..14426bba0 100644 --- a/sampleSize.js +++ b/sampleSize.js @@ -1,4 +1,7 @@ -define(['./_baseClamp', './_baseRandom', './toArray', './toInteger'], function(baseClamp, baseRandom, toArray, toInteger) { +define(['./_baseClamp', './_baseRandom', './_isIterateeCall', './toArray', './toInteger'], function(baseClamp, baseRandom, isIterateeCall, toArray, toInteger) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; /** * Gets `n` random elements at unique keys from `collection` up to the @@ -9,7 +12,8 @@ define(['./_baseClamp', './_baseRandom', './toArray', './toInteger'], function(b * @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 * @@ -19,13 +23,17 @@ define(['./_baseClamp', './_baseRandom', './toArray', './toInteger'], function(b * _.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 4d530c8ef..35bc6dc3b 100644 --- a/set.js +++ b/set.js @@ -24,7 +24,7 @@ define(['./_baseSet'], function(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 c5ce90eb5..d5a24223b 100644 --- a/sortBy.js +++ b/sortBy.js @@ -2,7 +2,7 @@ define(['./_baseFlatten', './_baseOrderBy', './_isIterateeCall', './rest'], func /** * 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 fe9a743a2..8f4727644 100644 --- a/spread.js +++ b/spread.js @@ -12,7 +12,7 @@ define(['./_apply', './_arrayPush', './rest', './toInteger'], function(apply, ar /** * 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 def89bc82..65591f90c 100644 --- a/template.js +++ b/template.js @@ -8,7 +8,10 @@ define(['./_assignInDefaults', './assignInWith', './attempt', './_baseValues', ' 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 a0d47abe0..0b6fadc65 100644 --- a/toNumber.js +++ b/toNumber.js @@ -53,7 +53,7 @@ define(['./isFunction', './isObject', './isSymbol'], function(isFunction, isObje 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 9962c9262..c04e1fa15 100644 --- a/transform.js +++ b/transform.js @@ -2,11 +2,11 @@ define(['./_arrayEach', './_baseCreate', './_baseForOwn', './_baseIteratee', './ /** * 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 da26cbd63..899810717 100644 --- a/unset.js +++ b/unset.js @@ -21,7 +21,7 @@ define(['./_baseUnset'], function(baseUnset) { * console.log(object); * // => { 'a': [{ 'b': {} }] }; * - * _.unset(object, 'a[0].b.c'); + * _.unset(object, ['a', '0', 'b', 'c']); * // => true * * console.log(object);