mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab95e7dde7 |
@@ -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.
|
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 ./
|
$ 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.
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import baseRandom from './_baseRandom.js';
|
import baseRandom from './_baseRandom.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialized version of `_.sample` for arrays without support for iteratee
|
* A specialized version of `_.sample` for arrays.
|
||||||
* shorthands.
|
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Array} array The array to sample.
|
* @param {Array} array The array to sample.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import arrayShuffle from './_arrayShuffle.js';
|
import copyArray from './_copyArray.js';
|
||||||
import baseClamp from './_baseClamp.js';
|
import shuffleSelf from './_shuffleSelf.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialized version of `_.sampleSize` for arrays.
|
* A specialized version of `_.sampleSize` for arrays.
|
||||||
@@ -10,9 +10,7 @@ import baseClamp from './_baseClamp.js';
|
|||||||
* @returns {Array} Returns the random elements.
|
* @returns {Array} Returns the random elements.
|
||||||
*/
|
*/
|
||||||
function arraySampleSize(array, n) {
|
function arraySampleSize(array, n) {
|
||||||
var result = arrayShuffle(array);
|
return shuffleSelf(copyArray(array), n);
|
||||||
result.length = baseClamp(n, 0, result.length);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default arraySampleSize;
|
export default arraySampleSize;
|
||||||
|
|||||||
@@ -8,11 +8,23 @@ var objectCreate = Object.create;
|
|||||||
* properties to the created object.
|
* properties to the created object.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} prototype The object to inherit from.
|
* @param {Object} proto The object to inherit from.
|
||||||
* @returns {Object} Returns the new object.
|
* @returns {Object} Returns the new object.
|
||||||
*/
|
*/
|
||||||
function baseCreate(proto) {
|
var baseCreate = (function() {
|
||||||
return isObject(proto) ? objectCreate(proto) : {};
|
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;
|
export default baseCreate;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
15
_baseSample.js
Normal file
15
_baseSample.js
Normal file
@@ -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;
|
||||||
16
_baseSampleSize.js
Normal file
16
_baseSampleSize.js
Normal file
@@ -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;
|
||||||
15
_baseShuffle.js
Normal file
15
_baseShuffle.js
Normal file
@@ -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;
|
||||||
@@ -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`.
|
* Creates a clone of `buffer`.
|
||||||
*
|
*
|
||||||
@@ -10,7 +25,9 @@ function cloneBuffer(buffer, isDeep) {
|
|||||||
if (isDeep) {
|
if (isDeep) {
|
||||||
return buffer.slice();
|
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);
|
buffer.copy(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import isLaziable from './_isLaziable.js';
|
|||||||
/** Used as the size to enable large array optimizations. */
|
/** Used as the size to enable large array optimizations. */
|
||||||
var LARGE_ARRAY_SIZE = 200;
|
var LARGE_ARRAY_SIZE = 200;
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/** Used to compose bitmasks for function metadata. */
|
/** Used to compose bitmasks for function metadata. */
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import setData from './_setData.js';
|
|||||||
import setWrapToString from './_setWrapToString.js';
|
import setWrapToString from './_setWrapToString.js';
|
||||||
import toInteger from './toInteger.js';
|
import toInteger from './toInteger.js';
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/** Used to compose bitmasks for function metadata. */
|
/** Used to compose bitmasks for function metadata. */
|
||||||
|
|||||||
@@ -1,24 +1,28 @@
|
|||||||
|
import baseClamp from './_baseClamp.js';
|
||||||
import baseRandom from './_baseRandom.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
|
* @private
|
||||||
* @param {Array} array The array to shuffle.
|
* @param {Array} array The array to shuffle.
|
||||||
|
* @param {number} [size=array.length] The size of `array`.
|
||||||
* @returns {Array} Returns `array`.
|
* @returns {Array} Returns `array`.
|
||||||
*/
|
*/
|
||||||
function shuffleSelf(array) {
|
function shuffleSelf(array, size) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = array.length,
|
length = array.length,
|
||||||
lastIndex = length - 1;
|
lastIndex = length - 1;
|
||||||
|
|
||||||
while (++index < length) {
|
size = size === undefined ? length : baseClamp(size, 0, length);
|
||||||
|
while (++index < size) {
|
||||||
var rand = baseRandom(index, lastIndex),
|
var rand = baseRandom(index, lastIndex),
|
||||||
value = array[rand];
|
value = array[rand];
|
||||||
|
|
||||||
array[rand] = array[index];
|
array[rand] = array[index];
|
||||||
array[index] = value;
|
array[index] = value;
|
||||||
}
|
}
|
||||||
|
array.length = size;
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
after.js
2
after.js
@@ -1,6 +1,6 @@
|
|||||||
import toInteger from './toInteger.js';
|
import toInteger from './toInteger.js';
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import toInteger from './toInteger.js';
|
import toInteger from './toInteger.js';
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
2
cond.js
2
cond.js
@@ -3,7 +3,7 @@ import arrayMap from './_arrayMap.js';
|
|||||||
import baseIteratee from './_baseIteratee.js';
|
import baseIteratee from './_baseIteratee.js';
|
||||||
import baseRest from './_baseRest.js';
|
import baseRest from './_baseRest.js';
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import isObject from './isObject.js';
|
|||||||
import now from './now.js';
|
import now from './now.js';
|
||||||
import toNumber from './toNumber.js';
|
import toNumber from './toNumber.js';
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/* Built-in method references for those with the same name as other `lodash` methods. */
|
/* Built-in method references for those with the same name as other `lodash` methods. */
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import baseIsNative from './_baseIsNative.js';
|
import baseIsNative from './_baseIsNative.js';
|
||||||
import isMaskable from './_isMaskable.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.
|
* Checks if `value` is a pristine native function.
|
||||||
*
|
*
|
||||||
@@ -29,7 +32,7 @@ import isMaskable from './_isMaskable.js';
|
|||||||
*/
|
*/
|
||||||
function isNative(value) {
|
function isNative(value) {
|
||||||
if (isMaskable(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);
|
return baseIsNative(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import toInteger from './toInteger.js';
|
|||||||
import lodash from './wrapperLodash.js';
|
import lodash from './wrapperLodash.js';
|
||||||
|
|
||||||
/** Used as the semantic version number. */
|
/** Used as the semantic version number. */
|
||||||
var VERSION = '4.16.1';
|
var VERSION = '4.16.2';
|
||||||
|
|
||||||
/** Used to compose bitmasks for function metadata. */
|
/** Used to compose bitmasks for function metadata. */
|
||||||
var BIND_KEY_FLAG = 2;
|
var BIND_KEY_FLAG = 2;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import MapCache from './_MapCache.js';
|
import MapCache from './_MapCache.js';
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lodash-es",
|
"name": "lodash-es",
|
||||||
"version": "4.16.1",
|
"version": "4.16.2",
|
||||||
"description": "Lodash exported as ES modules.",
|
"description": "Lodash exported as ES modules.",
|
||||||
"keywords": "es6, modules, stdlib, util",
|
"keywords": "es6, modules, stdlib, util",
|
||||||
"homepage": "https://lodash.com/custom-builds",
|
"homepage": "https://lodash.com/custom-builds",
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import root from './_root.js';
|
import root from './_root.js';
|
||||||
import toString from './toString.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. */
|
/* Built-in method references for those with the same name as other `lodash` methods. */
|
||||||
var nativeParseInt = root.parseInt;
|
var nativeParseInt = root.parseInt;
|
||||||
|
|
||||||
@@ -34,7 +37,7 @@ function parseInt(string, radix, guard) {
|
|||||||
} else if (radix) {
|
} else if (radix) {
|
||||||
radix = +radix;
|
radix = +radix;
|
||||||
}
|
}
|
||||||
return nativeParseInt(toString(string), radix || 0);
|
return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default parseInt;
|
export default parseInt;
|
||||||
|
|||||||
2
rest.js
2
rest.js
@@ -1,7 +1,7 @@
|
|||||||
import baseRest from './_baseRest.js';
|
import baseRest from './_baseRest.js';
|
||||||
import toInteger from './toInteger.js';
|
import toInteger from './toInteger.js';
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import arraySample from './_arraySample.js';
|
import arraySample from './_arraySample.js';
|
||||||
import isArrayLike from './isArrayLike.js';
|
import baseSample from './_baseSample.js';
|
||||||
import values from './values.js';
|
import isArray from './isArray.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a random element from `collection`.
|
* Gets a random element from `collection`.
|
||||||
@@ -17,7 +17,8 @@ import values from './values.js';
|
|||||||
* // => 2
|
* // => 2
|
||||||
*/
|
*/
|
||||||
function sample(collection) {
|
function sample(collection) {
|
||||||
return arraySample(isArrayLike(collection) ? collection : values(collection));
|
var func = isArray(collection) ? arraySample : baseSample;
|
||||||
|
return func(collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default sample;
|
export default sample;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import arraySampleSize from './_arraySampleSize.js';
|
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 isIterateeCall from './_isIterateeCall.js';
|
||||||
import toInteger from './toInteger.js';
|
import toInteger from './toInteger.js';
|
||||||
import values from './values.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets `n` random elements at unique keys from `collection` up to the
|
* Gets `n` random elements at unique keys from `collection` up to the
|
||||||
@@ -30,7 +30,8 @@ function sampleSize(collection, n, guard) {
|
|||||||
} else {
|
} else {
|
||||||
n = toInteger(n);
|
n = toInteger(n);
|
||||||
}
|
}
|
||||||
return arraySampleSize(isArrayLike(collection) ? collection : values(collection), n);
|
var func = isArray(collection) ? arraySampleSize : baseSampleSize;
|
||||||
|
return func(collection, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default sampleSize;
|
export default sampleSize;
|
||||||
|
|||||||
13
shuffle.js
13
shuffle.js
@@ -1,7 +1,6 @@
|
|||||||
import copyArray from './_copyArray.js';
|
import arrayShuffle from './_arrayShuffle.js';
|
||||||
import isArrayLike from './isArrayLike.js';
|
import baseShuffle from './_baseShuffle.js';
|
||||||
import shuffleSelf from './_shuffleSelf.js';
|
import isArray from './isArray.js';
|
||||||
import values from './values.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of shuffled values, using a version of the
|
* Creates an array of shuffled values, using a version of the
|
||||||
@@ -19,10 +18,8 @@ import values from './values.js';
|
|||||||
* // => [4, 1, 3, 2]
|
* // => [4, 1, 3, 2]
|
||||||
*/
|
*/
|
||||||
function shuffle(collection) {
|
function shuffle(collection) {
|
||||||
return shuffleSelf(isArrayLike(collection)
|
var func = isArray(collection) ? arrayShuffle : baseShuffle;
|
||||||
? copyArray(collection)
|
return func(collection);
|
||||||
: values(collection)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default shuffle;
|
export default shuffle;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import baseRest from './_baseRest.js';
|
|||||||
import castSlice from './_castSlice.js';
|
import castSlice from './_castSlice.js';
|
||||||
import toInteger from './toInteger.js';
|
import toInteger from './toInteger.js';
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/* Built-in method references for those with the same name as other `lodash` methods. */
|
/* Built-in method references for those with the same name as other `lodash` methods. */
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import debounce from './debounce.js';
|
import debounce from './debounce.js';
|
||||||
import isObject from './isObject.js';
|
import isObject from './isObject.js';
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user