From ab95e7dde7e0d664a0836dd1bc0d122df7ace400 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 25 Sep 2016 13:40:14 -0700 Subject: [PATCH] Bump to v4.16.2. --- README.md | 4 ++-- _arraySample.js | 3 +-- _arraySampleSize.js | 8 +++----- _baseCreate.js | 20 ++++++++++++++++---- _baseDelay.js | 2 +- _baseSample.js | 15 +++++++++++++++ _baseSampleSize.js | 16 ++++++++++++++++ _baseShuffle.js | 15 +++++++++++++++ _cloneBuffer.js | 19 ++++++++++++++++++- _createFlow.js | 2 +- _createWrap.js | 2 +- _shuffleSelf.js | 10 +++++++--- after.js | 2 +- before.js | 2 +- cond.js | 2 +- debounce.js | 2 +- isNative.js | 5 ++++- lodash.default.js | 2 +- memoize.js | 2 +- negate.js | 2 +- package.json | 2 +- parseInt.js | 5 ++++- rest.js | 2 +- sample.js | 7 ++++--- sampleSize.js | 7 ++++--- shuffle.js | 13 +++++-------- spread.js | 2 +- throttle.js | 2 +- 28 files changed, 128 insertions(+), 47 deletions(-) create mode 100644 _baseSample.js create mode 100644 _baseSampleSize.js create mode 100644 _baseShuffle.js diff --git a/README.md b/README.md index bccb4bb85..188111571 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-es v4.16.1 +# lodash-es v4.16.2 The [Lodash](https://lodash.com/) library exported as [ES](http://www.ecma-international.org/ecma-262/6.0/) modules. @@ -7,4 +7,4 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli): $ lodash modularize exports=es -o ./ ``` -See the [package source](https://github.com/lodash/lodash/tree/4.16.1-es) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.16.2-es) for more details. diff --git a/_arraySample.js b/_arraySample.js index 2b555967d..008596fc9 100644 --- a/_arraySample.js +++ b/_arraySample.js @@ -1,8 +1,7 @@ import baseRandom from './_baseRandom.js'; /** - * A specialized version of `_.sample` for arrays without support for iteratee - * shorthands. + * A specialized version of `_.sample` for arrays. * * @private * @param {Array} array The array to sample. diff --git a/_arraySampleSize.js b/_arraySampleSize.js index 9fede136e..c361700f5 100644 --- a/_arraySampleSize.js +++ b/_arraySampleSize.js @@ -1,5 +1,5 @@ -import arrayShuffle from './_arrayShuffle.js'; -import baseClamp from './_baseClamp.js'; +import copyArray from './_copyArray.js'; +import shuffleSelf from './_shuffleSelf.js'; /** * A specialized version of `_.sampleSize` for arrays. @@ -10,9 +10,7 @@ import baseClamp from './_baseClamp.js'; * @returns {Array} Returns the random elements. */ function arraySampleSize(array, n) { - var result = arrayShuffle(array); - result.length = baseClamp(n, 0, result.length); - return result; + return shuffleSelf(copyArray(array), n); } export default arraySampleSize; diff --git a/_baseCreate.js b/_baseCreate.js index db9679b95..6a8d95548 100644 --- a/_baseCreate.js +++ b/_baseCreate.js @@ -8,11 +8,23 @@ var objectCreate = Object.create; * properties to the created object. * * @private - * @param {Object} prototype The object to inherit from. + * @param {Object} proto The object to inherit from. * @returns {Object} Returns the new object. */ -function baseCreate(proto) { - return isObject(proto) ? objectCreate(proto) : {}; -} +var baseCreate = (function() { + function object() {} + return function(proto) { + if (!isObject(proto)) { + return {}; + } + if (objectCreate) { + return objectCreate(proto); + } + object.prototype = prototype; + var result = new object; + object.prototype = undefined; + return result; + }; +}()); export default baseCreate; diff --git a/_baseDelay.js b/_baseDelay.js index 12f2fea53..8cc5e27a2 100644 --- a/_baseDelay.js +++ b/_baseDelay.js @@ -1,4 +1,4 @@ -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /** diff --git a/_baseSample.js b/_baseSample.js new file mode 100644 index 000000000..7b96c062f --- /dev/null +++ b/_baseSample.js @@ -0,0 +1,15 @@ +import arraySample from './_arraySample.js'; +import values from './values.js'; + +/** + * The base implementation of `_.sample`. + * + * @private + * @param {Array|Object} collection The collection to sample. + * @returns {*} Returns the random element. + */ +function baseSample(collection) { + return arraySample(values(collection)); +} + +export default baseSample; diff --git a/_baseSampleSize.js b/_baseSampleSize.js new file mode 100644 index 000000000..7e2f32b12 --- /dev/null +++ b/_baseSampleSize.js @@ -0,0 +1,16 @@ +import shuffleSelf from './_shuffleSelf.js'; +import values from './values.js'; + +/** + * The base implementation of `_.sampleSize` without param guards. + * + * @private + * @param {Array|Object} collection The collection to sample. + * @param {number} n The number of elements to sample. + * @returns {Array} Returns the random elements. + */ +function baseSampleSize(collection, n) { + return shuffleSelf(values(collection), n); +} + +export default baseSampleSize; diff --git a/_baseShuffle.js b/_baseShuffle.js new file mode 100644 index 000000000..f5617bbda --- /dev/null +++ b/_baseShuffle.js @@ -0,0 +1,15 @@ +import shuffleSelf from './_shuffleSelf.js'; +import values from './values.js'; + +/** + * The base implementation of `_.shuffle`. + * + * @private + * @param {Array|Object} collection The collection to shuffle. + * @returns {Array} Returns the new shuffled array. + */ +function baseShuffle(collection) { + return shuffleSelf(values(collection)); +} + +export default baseShuffle; diff --git a/_cloneBuffer.js b/_cloneBuffer.js index c1139dd8a..21b192e9f 100644 --- a/_cloneBuffer.js +++ b/_cloneBuffer.js @@ -1,3 +1,18 @@ +import root from './_root.js'; + +/** Detect free variable `exports`. */ +var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; + +/** Detect free variable `module`. */ +var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; + +/** Detect the popular CommonJS extension `module.exports`. */ +var moduleExports = freeModule && freeModule.exports === freeExports; + +/** Built-in value references. */ +var Buffer = moduleExports ? root.Buffer : undefined, + allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined; + /** * Creates a clone of `buffer`. * @@ -10,7 +25,9 @@ function cloneBuffer(buffer, isDeep) { if (isDeep) { return buffer.slice(); } - var result = new buffer.constructor(buffer.length); + var length = buffer.length, + result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length); + buffer.copy(result); return result; } diff --git a/_createFlow.js b/_createFlow.js index 443c53adb..6a31788b0 100644 --- a/_createFlow.js +++ b/_createFlow.js @@ -8,7 +8,7 @@ import isLaziable from './_isLaziable.js'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /** Used to compose bitmasks for function metadata. */ diff --git a/_createWrap.js b/_createWrap.js index 997b825db..4727ae6c8 100644 --- a/_createWrap.js +++ b/_createWrap.js @@ -9,7 +9,7 @@ import setData from './_setData.js'; import setWrapToString from './_setWrapToString.js'; import toInteger from './toInteger.js'; -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /** Used to compose bitmasks for function metadata. */ diff --git a/_shuffleSelf.js b/_shuffleSelf.js index 7eadd0e82..178c8b977 100644 --- a/_shuffleSelf.js +++ b/_shuffleSelf.js @@ -1,24 +1,28 @@ +import baseClamp from './_baseClamp.js'; import baseRandom from './_baseRandom.js'; /** - * A specialized version of `arrayShuffle` which mutates `array`. + * A specialized version of `_.shuffle` which mutates and sets the size of `array`. * * @private * @param {Array} array The array to shuffle. + * @param {number} [size=array.length] The size of `array`. * @returns {Array} Returns `array`. */ -function shuffleSelf(array) { +function shuffleSelf(array, size) { var index = -1, length = array.length, lastIndex = length - 1; - while (++index < length) { + size = size === undefined ? length : baseClamp(size, 0, length); + while (++index < size) { var rand = baseRandom(index, lastIndex), value = array[rand]; array[rand] = array[index]; array[index] = value; } + array.length = size; return array; } diff --git a/after.js b/after.js index 79a050dc1..f05a32d33 100644 --- a/after.js +++ b/after.js @@ -1,6 +1,6 @@ import toInteger from './toInteger.js'; -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /** diff --git a/before.js b/before.js index b854ca762..15a670b1f 100644 --- a/before.js +++ b/before.js @@ -1,6 +1,6 @@ import toInteger from './toInteger.js'; -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /** diff --git a/cond.js b/cond.js index ae53c78ca..9c0183131 100644 --- a/cond.js +++ b/cond.js @@ -3,7 +3,7 @@ import arrayMap from './_arrayMap.js'; import baseIteratee from './_baseIteratee.js'; import baseRest from './_baseRest.js'; -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /** diff --git a/debounce.js b/debounce.js index d2cfcc71e..645754d54 100644 --- a/debounce.js +++ b/debounce.js @@ -2,7 +2,7 @@ import isObject from './isObject.js'; import now from './now.js'; import toNumber from './toNumber.js'; -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /* Built-in method references for those with the same name as other `lodash` methods. */ diff --git a/isNative.js b/isNative.js index 13f93542e..37160daaa 100644 --- a/isNative.js +++ b/isNative.js @@ -1,6 +1,9 @@ import baseIsNative from './_baseIsNative.js'; import isMaskable from './_isMaskable.js'; +/** Error message constants. */ +var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://github.com/es-shims.'; + /** * Checks if `value` is a pristine native function. * @@ -29,7 +32,7 @@ import isMaskable from './_isMaskable.js'; */ function isNative(value) { if (isMaskable(value)) { - throw new Error('This method is not supported with core-js. Try https://github.com/es-shims.'); + throw new Error(CORE_ERROR_TEXT); } return baseIsNative(value); } diff --git a/lodash.default.js b/lodash.default.js index 084201547..2fa696005 100644 --- a/lodash.default.js +++ b/lodash.default.js @@ -45,7 +45,7 @@ import toInteger from './toInteger.js'; import lodash from './wrapperLodash.js'; /** Used as the semantic version number. */ -var VERSION = '4.16.1'; +var VERSION = '4.16.2'; /** Used to compose bitmasks for function metadata. */ var BIND_KEY_FLAG = 2; diff --git a/memoize.js b/memoize.js index 271ecd06f..8889a56bc 100644 --- a/memoize.js +++ b/memoize.js @@ -1,6 +1,6 @@ import MapCache from './_MapCache.js'; -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /** diff --git a/negate.js b/negate.js index 4353137bc..9c23aa8ae 100644 --- a/negate.js +++ b/negate.js @@ -1,4 +1,4 @@ -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /** diff --git a/package.json b/package.json index e400de8af..878790cde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-es", - "version": "4.16.1", + "version": "4.16.2", "description": "Lodash exported as ES modules.", "keywords": "es6, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds", diff --git a/parseInt.js b/parseInt.js index a5a2dc886..3400b6b9e 100644 --- a/parseInt.js +++ b/parseInt.js @@ -1,6 +1,9 @@ import root from './_root.js'; import toString from './toString.js'; +/** Used to match leading and trailing whitespace. */ +var reTrimStart = /^\s+/; + /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeParseInt = root.parseInt; @@ -34,7 +37,7 @@ function parseInt(string, radix, guard) { } else if (radix) { radix = +radix; } - return nativeParseInt(toString(string), radix || 0); + return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0); } export default parseInt; diff --git a/rest.js b/rest.js index 75cb08ba4..c46042548 100644 --- a/rest.js +++ b/rest.js @@ -1,7 +1,7 @@ import baseRest from './_baseRest.js'; import toInteger from './toInteger.js'; -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /** diff --git a/sample.js b/sample.js index 4a5e5ffe5..bebe5699e 100644 --- a/sample.js +++ b/sample.js @@ -1,6 +1,6 @@ import arraySample from './_arraySample.js'; -import isArrayLike from './isArrayLike.js'; -import values from './values.js'; +import baseSample from './_baseSample.js'; +import isArray from './isArray.js'; /** * Gets a random element from `collection`. @@ -17,7 +17,8 @@ import values from './values.js'; * // => 2 */ function sample(collection) { - return arraySample(isArrayLike(collection) ? collection : values(collection)); + var func = isArray(collection) ? arraySample : baseSample; + return func(collection); } export default sample; diff --git a/sampleSize.js b/sampleSize.js index 7be10055b..152bedb89 100644 --- a/sampleSize.js +++ b/sampleSize.js @@ -1,8 +1,8 @@ import arraySampleSize from './_arraySampleSize.js'; -import isArrayLike from './isArrayLike.js'; +import baseSampleSize from './_baseSampleSize.js'; +import isArray from './isArray.js'; import isIterateeCall from './_isIterateeCall.js'; import toInteger from './toInteger.js'; -import values from './values.js'; /** * Gets `n` random elements at unique keys from `collection` up to the @@ -30,7 +30,8 @@ function sampleSize(collection, n, guard) { } else { n = toInteger(n); } - return arraySampleSize(isArrayLike(collection) ? collection : values(collection), n); + var func = isArray(collection) ? arraySampleSize : baseSampleSize; + return func(collection, n); } export default sampleSize; diff --git a/shuffle.js b/shuffle.js index 8698ed1db..690769999 100644 --- a/shuffle.js +++ b/shuffle.js @@ -1,7 +1,6 @@ -import copyArray from './_copyArray.js'; -import isArrayLike from './isArrayLike.js'; -import shuffleSelf from './_shuffleSelf.js'; -import values from './values.js'; +import arrayShuffle from './_arrayShuffle.js'; +import baseShuffle from './_baseShuffle.js'; +import isArray from './isArray.js'; /** * Creates an array of shuffled values, using a version of the @@ -19,10 +18,8 @@ import values from './values.js'; * // => [4, 1, 3, 2] */ function shuffle(collection) { - return shuffleSelf(isArrayLike(collection) - ? copyArray(collection) - : values(collection) - ); + var func = isArray(collection) ? arrayShuffle : baseShuffle; + return func(collection); } export default shuffle; diff --git a/spread.js b/spread.js index 28d90eb4d..cf221cfc9 100644 --- a/spread.js +++ b/spread.js @@ -4,7 +4,7 @@ import baseRest from './_baseRest.js'; import castSlice from './_castSlice.js'; import toInteger from './toInteger.js'; -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /* Built-in method references for those with the same name as other `lodash` methods. */ diff --git a/throttle.js b/throttle.js index b6264e02a..f3cf43f19 100644 --- a/throttle.js +++ b/throttle.js @@ -1,7 +1,7 @@ import debounce from './debounce.js'; import isObject from './isObject.js'; -/** Used as the `TypeError` message for "Functions" methods. */ +/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /**