Compare commits

...

35 Commits

Author SHA1 Message Date
John-David Dalton
516085f332 Fix prototype pollution in _.unset and _.omit (#6063)
Prevent prototype pollution on baseUnset function by:
- Blocking "__proto__" if not an own property
- Blocking "constructor.prototype" chains (except when starting at primitive root)
- Skipping non-string keys

See: https://github.com/lodash/lodash/security/advisories/GHSA-xxjr-mmjv-4gpg
2025-12-10 07:52:48 -05:00
Benjamin Tan
c6e281b878 Bump to v4.17.21 2021-02-20 23:26:06 +08:00
Benjamin Tan
f2e7063ee4 Bump to v4.17.20. 2020-08-14 00:52:31 +08:00
John-David Dalton
f9cd8f552b Bump to v4.17.15. 2019-07-17 10:11:11 -07:00
John-David Dalton
4dd74b933e Bump to v4.17.14. 2019-07-10 06:43:54 -07:00
John-David Dalton
d73d82d963 Bump to v4.17.13. 2019-07-09 15:19:17 -07:00
John-David Dalton
793f983629 Bump to v4.17.12. 2019-07-09 14:01:55 -07:00
John-David Dalton
3e273e915d Bump to v4.17.11. 2018-09-11 22:12:11 -07:00
John-David Dalton
c4b20a6ea7 Bump to v4.17.10. 2018-04-24 11:03:11 -07:00
John-David Dalton
72ef3680a1 Bump to v4.17.9. 2018-04-24 10:41:51 -07:00
John-David Dalton
0e314104d6 Bump to v4.17.5. 2018-02-03 16:32:25 -08:00
John-David Dalton
860d1f9484 Bump to v4.17.4. 2016-12-31 13:38:56 -06:00
John-David Dalton
b93c3b1ee8 Bump to v4.17.3. 2016-12-21 15:55:54 -06:00
John-David Dalton
db9697dfef Bump to v4.17.2. 2016-11-15 22:25:47 -08:00
John-David Dalton
5585b3ae22 Bump to v4.17.1. 2016-11-14 21:01:42 -08:00
John-David Dalton
9849321273 Bump to v4.17.0. 2016-11-13 22:50:13 -08:00
John-David Dalton
39e6c50f72 Bump to v4.16.6. 2016-10-31 21:11:03 -07:00
John-David Dalton
a3710bba34 Bump to v4.16.5. 2016-10-30 20:12:25 -07:00
John-David Dalton
39e2b943dc Bump to v4.16.4. 2016-10-05 19:49:52 -07:00
John-David Dalton
eb1446def5 Bump to v4.16.3. 2016-10-02 22:00:47 -07:00
John-David Dalton
ac571efbbd Bump to v4.16.2. 2016-09-25 13:46:15 -07:00
John-David Dalton
a96a747b8c Bump to v4.16.1. 2016-09-20 09:54:46 -07:00
John-David Dalton
9e23f5441b Bump to v4.16.0. 2016-09-17 22:37:40 -07:00
John-David Dalton
a06bf83085 Bump to v4.15.0. 2016-08-11 23:33:03 -07:00
John-David Dalton
c733f930dc Bump to v4.14.2. 2016-08-07 21:38:57 -07:00
John-David Dalton
cd04b44875 Bump to v4.14.1. 2016-07-28 23:44:39 -07:00
John-David Dalton
a8d3718760 Bump to v4.14.0. 2016-07-24 09:52:33 -07:00
John-David Dalton
295d8cf415 Bump to v4.13.1. 2016-05-23 09:00:43 -07:00
John-David Dalton
0cf3476f14 Bump to v4.13.0. 2016-05-22 19:38:19 -07:00
John-David Dalton
dbe6a9008c Bump to v4.12.0. 2016-05-08 12:30:27 -07:00
John-David Dalton
ddde027fd9 Bump to v4.11.2. 2016-04-21 07:09:17 -07:00
John-David Dalton
e93cb815c3 Bump to v4.11.1. 2016-04-13 21:06:51 -07:00
John-David Dalton
63ba93dcb3 Bump to v4.11.0. 2016-04-13 10:23:46 -07:00
John-David Dalton
be0bf2681b Bump to v4.10.0. 2016-04-10 23:01:56 -07:00
John-David Dalton
7d39d58e43 Bump to v4.9.0. 2016-04-08 01:35:02 -07:00
579 changed files with 9934 additions and 6800 deletions

View File

@@ -1,4 +1,4 @@
Copyright jQuery Foundation and other contributors <https://jquery.org/> Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
Based on Underscore.js, copyright Jeremy Ashkenas, Based on Underscore.js, copyright Jeremy Ashkenas,
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/> DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>

View File

@@ -1,12 +1,12 @@
# lodash v4.8.2 # lodash v4.17.21
The [Lodash](https://lodash.com/) library exported as [Node.js](https://nodejs.org/) modules. The [Lodash](https://lodash.com/) library exported as [Node.js](https://nodejs.org/) modules.
## Installation ## Installation
Using npm: Using npm:
```bash ```shell
$ {sudo -H} npm i -g npm $ npm i -g npm
$ npm i --save lodash $ npm i --save lodash
``` ```
@@ -16,25 +16,24 @@ In Node.js:
var _ = require('lodash'); var _ = require('lodash');
// Load the core build. // Load the core build.
var _ = require('lodash/core'); var _ = require('lodash/core');
// Load the fp build for immutable auto-curried iteratee-first data-last methods. // Load the FP build for immutable auto-curried iteratee-first data-last methods.
var fp = require('lodash/fp'); var fp = require('lodash/fp');
// Load a method category. // Load method categories.
var array = require('lodash/array'); var array = require('lodash/array');
var object = require('lodash/fp/object'); var object = require('lodash/fp/object');
// Load a single method for smaller builds with browserify/rollup/webpack. // Cherry-pick methods for smaller browserify/rollup/webpack bundles.
var chunk = require('lodash/chunk'); var at = require('lodash/at');
var extend = require('lodash/fp/extend'); var curryN = require('lodash/fp/curryN');
``` ```
See the [package source](https://github.com/lodash/lodash/tree/4.8.2-npm) for more details. See the [package source](https://github.com/lodash/lodash/tree/4.17.21-npm) for more details.
**Note:**<br> **Note:**<br>
Dont assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br> Install [n_](https://www.npmjs.com/package/n_) for Lodash use in the Node.js < 6 REPL.
Install [n_](https://www.npmjs.com/package/n_) for a REPL that includes `lodash` by default.
## Support ## Support
Tested in Chrome 48-49, Firefox 44-45, IE 9-11, Edge 13, Safari 8-9, Node.js 0.10, 0.12, 4, & 5, & PhantomJS 1.9.8.<br> Tested in Chrome 74-75, Firefox 66-67, IE 11, Edge 18, Safari 11-12, & Node.js 8-12.<br>
Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available. Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available.

View File

@@ -1,18 +1,32 @@
var nativeCreate = require('./_nativeCreate'); var hashClear = require('./_hashClear'),
hashDelete = require('./_hashDelete'),
/** Used for built-in method references. */ hashGet = require('./_hashGet'),
var objectProto = Object.prototype; hashHas = require('./_hashHas'),
hashSet = require('./_hashSet');
/** /**
* Creates an hash object. * Creates a hash object.
* *
* @private * @private
* @constructor * @constructor
* @returns {Object} Returns the new hash object. * @param {Array} [entries] The key-value pairs to cache.
*/ */
function Hash() {} function Hash(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
// Avoid inheriting from `Object.prototype` when possible. this.clear();
Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto; while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
// Add methods to `Hash`.
Hash.prototype.clear = hashClear;
Hash.prototype['delete'] = hashDelete;
Hash.prototype.get = hashGet;
Hash.prototype.has = hashHas;
Hash.prototype.set = hashSet;
module.exports = Hash; module.exports = Hash;

32
_ListCache.js Normal file
View File

@@ -0,0 +1,32 @@
var listCacheClear = require('./_listCacheClear'),
listCacheDelete = require('./_listCacheDelete'),
listCacheGet = require('./_listCacheGet'),
listCacheHas = require('./_listCacheHas'),
listCacheSet = require('./_listCacheSet');
/**
* Creates an list cache object.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function ListCache(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
// Add methods to `ListCache`.
ListCache.prototype.clear = listCacheClear;
ListCache.prototype['delete'] = listCacheDelete;
ListCache.prototype.get = listCacheGet;
ListCache.prototype.has = listCacheHas;
ListCache.prototype.set = listCacheSet;
module.exports = ListCache;

View File

@@ -1,32 +1,32 @@
var mapClear = require('./_mapClear'), var mapCacheClear = require('./_mapCacheClear'),
mapDelete = require('./_mapDelete'), mapCacheDelete = require('./_mapCacheDelete'),
mapGet = require('./_mapGet'), mapCacheGet = require('./_mapCacheGet'),
mapHas = require('./_mapHas'), mapCacheHas = require('./_mapCacheHas'),
mapSet = require('./_mapSet'); mapCacheSet = require('./_mapCacheSet');
/** /**
* Creates a map cache object to store key-value pairs. * Creates a map cache object to store key-value pairs.
* *
* @private * @private
* @constructor * @constructor
* @param {Array} [values] The values to cache. * @param {Array} [entries] The key-value pairs to cache.
*/ */
function MapCache(values) { function MapCache(entries) {
var index = -1, var index = -1,
length = values ? values.length : 0; length = entries == null ? 0 : entries.length;
this.clear(); this.clear();
while (++index < length) { while (++index < length) {
var entry = values[index]; var entry = entries[index];
this.set(entry[0], entry[1]); this.set(entry[0], entry[1]);
} }
} }
// Add methods to `MapCache`. // Add methods to `MapCache`.
MapCache.prototype.clear = mapClear; MapCache.prototype.clear = mapCacheClear;
MapCache.prototype['delete'] = mapDelete; MapCache.prototype['delete'] = mapCacheDelete;
MapCache.prototype.get = mapGet; MapCache.prototype.get = mapCacheGet;
MapCache.prototype.has = mapHas; MapCache.prototype.has = mapCacheHas;
MapCache.prototype.set = mapSet; MapCache.prototype.set = mapCacheSet;
module.exports = MapCache; module.exports = MapCache;

View File

@@ -1,6 +0,0 @@
var root = require('./_root');
/** Built-in value references. */
var Reflect = root.Reflect;
module.exports = Reflect;

View File

@@ -1,9 +1,10 @@
var MapCache = require('./_MapCache'), var MapCache = require('./_MapCache'),
cachePush = require('./_cachePush'); setCacheAdd = require('./_setCacheAdd'),
setCacheHas = require('./_setCacheHas');
/** /**
* *
* Creates a set cache object to store unique values. * Creates an array cache object to store unique values.
* *
* @private * @private
* @constructor * @constructor
@@ -11,15 +12,16 @@ var MapCache = require('./_MapCache'),
*/ */
function SetCache(values) { function SetCache(values) {
var index = -1, var index = -1,
length = values ? values.length : 0; length = values == null ? 0 : values.length;
this.__data__ = new MapCache; this.__data__ = new MapCache;
while (++index < length) { while (++index < length) {
this.push(values[index]); this.add(values[index]);
} }
} }
// Add methods to `SetCache`. // Add methods to `SetCache`.
SetCache.prototype.push = cachePush; SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
SetCache.prototype.has = setCacheHas;
module.exports = SetCache; module.exports = SetCache;

View File

@@ -1,4 +1,5 @@
var stackClear = require('./_stackClear'), var ListCache = require('./_ListCache'),
stackClear = require('./_stackClear'),
stackDelete = require('./_stackDelete'), stackDelete = require('./_stackDelete'),
stackGet = require('./_stackGet'), stackGet = require('./_stackGet'),
stackHas = require('./_stackHas'), stackHas = require('./_stackHas'),
@@ -9,17 +10,11 @@ var stackClear = require('./_stackClear'),
* *
* @private * @private
* @constructor * @constructor
* @param {Array} [values] The values to cache. * @param {Array} [entries] The key-value pairs to cache.
*/ */
function Stack(values) { function Stack(entries) {
var index = -1, var data = this.__data__ = new ListCache(entries);
length = values ? values.length : 0; this.size = data.size;
this.clear();
while (++index < length) {
var entry = values[index];
this.set(entry[0], entry[1]);
}
} }
// Add methods to `Stack`. // Add methods to `Stack`.

View File

@@ -1,15 +0,0 @@
/**
* Adds the key-value `pair` to `map`.
*
* @private
* @param {Object} map The map to modify.
* @param {Array} pair The key-value pair to add.
* @returns {Object} Returns `map`.
*/
function addMapEntry(map, pair) {
// Don't return `Map#set` because it doesn't return the map instance in IE 11.
map.set(pair[0], pair[1]);
return map;
}
module.exports = addMapEntry;

View File

@@ -1,14 +0,0 @@
/**
* Adds `value` to `set`.
*
* @private
* @param {Object} set The set to modify.
* @param {*} value The value to add.
* @returns {Object} Returns `set`.
*/
function addSetEntry(set, value) {
set.add(value);
return set;
}
module.exports = addSetEntry;

View File

@@ -9,8 +9,7 @@
* @returns {*} Returns the result of `func`. * @returns {*} Returns the result of `func`.
*/ */
function apply(func, thisArg, args) { function apply(func, thisArg, args) {
var length = args.length; switch (args.length) {
switch (length) {
case 0: return func.call(thisArg); case 0: return func.call(thisArg);
case 1: return func.call(thisArg, args[0]); case 1: return func.call(thisArg, args[0]);
case 2: return func.call(thisArg, args[0], args[1]); case 2: return func.call(thisArg, args[0], args[1]);

View File

@@ -2,7 +2,7 @@
* A specialized version of `baseAggregator` for arrays. * A specialized version of `baseAggregator` for arrays.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} [array] The array to iterate over.
* @param {Function} setter The function to set `accumulator` values. * @param {Function} setter The function to set `accumulator` values.
* @param {Function} iteratee The iteratee to transform keys. * @param {Function} iteratee The iteratee to transform keys.
* @param {Object} accumulator The initial aggregated object. * @param {Object} accumulator The initial aggregated object.
@@ -10,7 +10,7 @@
*/ */
function arrayAggregator(array, setter, iteratee, accumulator) { function arrayAggregator(array, setter, iteratee, accumulator) {
var index = -1, var index = -1,
length = array.length; length = array == null ? 0 : array.length;
while (++index < length) { while (++index < length) {
var value = array[index]; var value = array[index];

View File

@@ -1,25 +0,0 @@
/**
* Creates a new array concatenating `array` with `other`.
*
* @private
* @param {Array} array The first array to concatenate.
* @param {Array} other The second array to concatenate.
* @returns {Array} Returns the new concatenated array.
*/
function arrayConcat(array, other) {
var index = -1,
length = array.length,
othIndex = -1,
othLength = other.length,
result = Array(length + othLength);
while (++index < length) {
result[index] = array[index];
}
while (++othIndex < othLength) {
result[index++] = other[othIndex];
}
return result;
}
module.exports = arrayConcat;

View File

@@ -3,13 +3,13 @@
* iteratee shorthands. * iteratee shorthands.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns `array`. * @returns {Array} Returns `array`.
*/ */
function arrayEach(array, iteratee) { function arrayEach(array, iteratee) {
var index = -1, var index = -1,
length = array.length; length = array == null ? 0 : array.length;
while (++index < length) { while (++index < length) {
if (iteratee(array[index], index, array) === false) { if (iteratee(array[index], index, array) === false) {

View File

@@ -3,12 +3,12 @@
* iteratee shorthands. * iteratee shorthands.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns `array`. * @returns {Array} Returns `array`.
*/ */
function arrayEachRight(array, iteratee) { function arrayEachRight(array, iteratee) {
var length = array.length; var length = array == null ? 0 : array.length;
while (length--) { while (length--) {
if (iteratee(array[length], length, array) === false) { if (iteratee(array[length], length, array) === false) {

View File

@@ -3,14 +3,14 @@
* iteratee shorthands. * iteratee shorthands.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} [array] The array to iterate over.
* @param {Function} predicate The function invoked per iteration. * @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if all elements pass the predicate check, * @returns {boolean} Returns `true` if all elements pass the predicate check,
* else `false`. * else `false`.
*/ */
function arrayEvery(array, predicate) { function arrayEvery(array, predicate) {
var index = -1, var index = -1,
length = array.length; length = array == null ? 0 : array.length;
while (++index < length) { while (++index < length) {
if (!predicate(array[index], index, array)) { if (!predicate(array[index], index, array)) {

View File

@@ -3,13 +3,13 @@
* iteratee shorthands. * iteratee shorthands.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} [array] The array to iterate over.
* @param {Function} predicate The function invoked per iteration. * @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array. * @returns {Array} Returns the new filtered array.
*/ */
function arrayFilter(array, predicate) { function arrayFilter(array, predicate) {
var index = -1, var index = -1,
length = array.length, length = array == null ? 0 : array.length,
resIndex = 0, resIndex = 0,
result = []; result = [];

View File

@@ -5,12 +5,13 @@ var baseIndexOf = require('./_baseIndexOf');
* specifying an index to search from. * specifying an index to search from.
* *
* @private * @private
* @param {Array} array The array to search. * @param {Array} [array] The array to inspect.
* @param {*} target The value to search for. * @param {*} target The value to search for.
* @returns {boolean} Returns `true` if `target` is found, else `false`. * @returns {boolean} Returns `true` if `target` is found, else `false`.
*/ */
function arrayIncludes(array, value) { function arrayIncludes(array, value) {
return !!array.length && baseIndexOf(array, value, 0) > -1; var length = array == null ? 0 : array.length;
return !!length && baseIndexOf(array, value, 0) > -1;
} }
module.exports = arrayIncludes; module.exports = arrayIncludes;

View File

@@ -2,14 +2,14 @@
* This function is like `arrayIncludes` except that it accepts a comparator. * This function is like `arrayIncludes` except that it accepts a comparator.
* *
* @private * @private
* @param {Array} array The array to search. * @param {Array} [array] The array to inspect.
* @param {*} target The value to search for. * @param {*} target The value to search for.
* @param {Function} comparator The comparator invoked per element. * @param {Function} comparator The comparator invoked per element.
* @returns {boolean} Returns `true` if `target` is found, else `false`. * @returns {boolean} Returns `true` if `target` is found, else `false`.
*/ */
function arrayIncludesWith(array, value, comparator) { function arrayIncludesWith(array, value, comparator) {
var index = -1, var index = -1,
length = array.length; length = array == null ? 0 : array.length;
while (++index < length) { while (++index < length) {
if (comparator(value, array[index])) { if (comparator(value, array[index])) {

49
_arrayLikeKeys.js Normal file
View File

@@ -0,0 +1,49 @@
var baseTimes = require('./_baseTimes'),
isArguments = require('./isArguments'),
isArray = require('./isArray'),
isBuffer = require('./isBuffer'),
isIndex = require('./_isIndex'),
isTypedArray = require('./isTypedArray');
/** Used for built-in method references. */
var objectProto = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* Creates an array of the enumerable property names of the array-like `value`.
*
* @private
* @param {*} value The value to query.
* @param {boolean} inherited Specify returning inherited property names.
* @returns {Array} Returns the array of property names.
*/
function arrayLikeKeys(value, inherited) {
var isArr = isArray(value),
isArg = !isArr && isArguments(value),
isBuff = !isArr && !isArg && isBuffer(value),
isType = !isArr && !isArg && !isBuff && isTypedArray(value),
skipIndexes = isArr || isArg || isBuff || isType,
result = skipIndexes ? baseTimes(value.length, String) : [],
length = result.length;
for (var key in value) {
if ((inherited || hasOwnProperty.call(value, key)) &&
!(skipIndexes && (
// Safari 9 has enumerable `arguments.length` in strict mode.
key == 'length' ||
// Node.js 0.10 has enumerable non-index properties on buffers.
(isBuff && (key == 'offset' || key == 'parent')) ||
// PhantomJS 2 has enumerable non-index properties on typed arrays.
(isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
// Skip index properties.
isIndex(key, length)
))) {
result.push(key);
}
}
return result;
}
module.exports = arrayLikeKeys;

View File

@@ -3,13 +3,13 @@
* shorthands. * shorthands.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array. * @returns {Array} Returns the new mapped array.
*/ */
function arrayMap(array, iteratee) { function arrayMap(array, iteratee) {
var index = -1, var index = -1,
length = array.length, length = array == null ? 0 : array.length,
result = Array(length); result = Array(length);
while (++index < length) { while (++index < length) {

View File

@@ -3,7 +3,7 @@
* iteratee shorthands. * iteratee shorthands.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value. * @param {*} [accumulator] The initial value.
* @param {boolean} [initAccum] Specify using the first element of `array` as * @param {boolean} [initAccum] Specify using the first element of `array` as
@@ -12,7 +12,7 @@
*/ */
function arrayReduce(array, iteratee, accumulator, initAccum) { function arrayReduce(array, iteratee, accumulator, initAccum) {
var index = -1, var index = -1,
length = array.length; length = array == null ? 0 : array.length;
if (initAccum && length) { if (initAccum && length) {
accumulator = array[++index]; accumulator = array[++index];

View File

@@ -3,7 +3,7 @@
* iteratee shorthands. * iteratee shorthands.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value. * @param {*} [accumulator] The initial value.
* @param {boolean} [initAccum] Specify using the last element of `array` as * @param {boolean} [initAccum] Specify using the last element of `array` as
@@ -11,7 +11,7 @@
* @returns {*} Returns the accumulated value. * @returns {*} Returns the accumulated value.
*/ */
function arrayReduceRight(array, iteratee, accumulator, initAccum) { function arrayReduceRight(array, iteratee, accumulator, initAccum) {
var length = array.length; var length = array == null ? 0 : array.length;
if (initAccum && length) { if (initAccum && length) {
accumulator = array[--length]; accumulator = array[--length];
} }

15
_arraySample.js Normal file
View File

@@ -0,0 +1,15 @@
var baseRandom = require('./_baseRandom');
/**
* A specialized version of `_.sample` for arrays.
*
* @private
* @param {Array} array The array to sample.
* @returns {*} Returns the random element.
*/
function arraySample(array) {
var length = array.length;
return length ? array[baseRandom(0, length - 1)] : undefined;
}
module.exports = arraySample;

17
_arraySampleSize.js Normal file
View File

@@ -0,0 +1,17 @@
var baseClamp = require('./_baseClamp'),
copyArray = require('./_copyArray'),
shuffleSelf = require('./_shuffleSelf');
/**
* A specialized version of `_.sampleSize` for arrays.
*
* @private
* @param {Array} array The array to sample.
* @param {number} n The number of elements to sample.
* @returns {Array} Returns the random elements.
*/
function arraySampleSize(array, n) {
return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
}
module.exports = arraySampleSize;

15
_arrayShuffle.js Normal file
View File

@@ -0,0 +1,15 @@
var copyArray = require('./_copyArray'),
shuffleSelf = require('./_shuffleSelf');
/**
* A specialized version of `_.shuffle` for arrays.
*
* @private
* @param {Array} array The array to shuffle.
* @returns {Array} Returns the new shuffled array.
*/
function arrayShuffle(array) {
return shuffleSelf(copyArray(array));
}
module.exports = arrayShuffle;

View File

@@ -3,14 +3,14 @@
* shorthands. * shorthands.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} [array] The array to iterate over.
* @param {Function} predicate The function invoked per iteration. * @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if any element passes the predicate check, * @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`. * else `false`.
*/ */
function arraySome(array, predicate) { function arraySome(array, predicate) {
var index = -1, var index = -1,
length = array.length; length = array == null ? 0 : array.length;
while (++index < length) { while (++index < length) {
if (predicate(array[index], index, array)) { if (predicate(array[index], index, array)) {

12
_asciiSize.js Normal file
View File

@@ -0,0 +1,12 @@
var baseProperty = require('./_baseProperty');
/**
* Gets the size of an ASCII `string`.
*
* @private
* @param {string} string The string inspect.
* @returns {number} Returns the string size.
*/
var asciiSize = baseProperty('length');
module.exports = asciiSize;

12
_asciiToArray.js Normal file
View File

@@ -0,0 +1,12 @@
/**
* Converts an ASCII `string` to an array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the converted array.
*/
function asciiToArray(string) {
return string.split('');
}
module.exports = asciiToArray;

15
_asciiWords.js Normal file
View File

@@ -0,0 +1,15 @@
/** Used to match words composed of alphanumeric characters. */
var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
/**
* Splits an ASCII `string` into an array of its words.
*
* @private
* @param {string} The string to inspect.
* @returns {Array} Returns the words of `string`.
*/
function asciiWords(string) {
return string.match(reAsciiWord) || [];
}
module.exports = asciiWords;

View File

@@ -1,4 +1,5 @@
var eq = require('./eq'); var baseAssignValue = require('./_baseAssignValue'),
eq = require('./eq');
/** /**
* This function is like `assignValue` except that it doesn't assign * This function is like `assignValue` except that it doesn't assign
@@ -11,8 +12,8 @@ var eq = require('./eq');
*/ */
function assignMergeValue(object, key, value) { function assignMergeValue(object, key, value) {
if ((value !== undefined && !eq(object[key], value)) || if ((value !== undefined && !eq(object[key], value)) ||
(typeof key == 'number' && value === undefined && !(key in object))) { (value === undefined && !(key in object))) {
object[key] = value; baseAssignValue(object, key, value);
} }
} }

View File

@@ -1,4 +1,5 @@
var eq = require('./eq'); var baseAssignValue = require('./_baseAssignValue'),
eq = require('./eq');
/** Used for built-in method references. */ /** Used for built-in method references. */
var objectProto = Object.prototype; var objectProto = Object.prototype;
@@ -8,7 +9,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
/** /**
* Assigns `value` to `key` of `object` if the existing value is not equivalent * Assigns `value` to `key` of `object` if the existing value is not equivalent
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* for equality comparisons. * for equality comparisons.
* *
* @private * @private
@@ -20,7 +21,7 @@ function assignValue(object, key, value) {
var objValue = object[key]; var objValue = object[key];
if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
(value === undefined && !(key in object))) { (value === undefined && !(key in object))) {
object[key] = value; baseAssignValue(object, key, value);
} }
} }

View File

@@ -1,16 +0,0 @@
var assocIndexOf = require('./_assocIndexOf');
/**
* Gets the associative array value for `key`.
*
* @private
* @param {Array} array The array to query.
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function assocGet(array, key) {
var index = assocIndexOf(array, key);
return index < 0 ? undefined : array[index][1];
}
module.exports = assocGet;

View File

@@ -4,7 +4,7 @@ var eq = require('./eq');
* Gets the index at which the `key` is found in `array` of key-value pairs. * Gets the index at which the `key` is found in `array` of key-value pairs.
* *
* @private * @private
* @param {Array} array The array to search. * @param {Array} array The array to inspect.
* @param {*} key The key to search for. * @param {*} key The key to search for.
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
*/ */

View File

@@ -1,20 +0,0 @@
var assocIndexOf = require('./_assocIndexOf');
/**
* Sets the associative array `key` to `value`.
*
* @private
* @param {Array} array The array to modify.
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
*/
function assocSet(array, key, value) {
var index = assocIndexOf(array, key);
if (index < 0) {
array.push([key, value]);
} else {
array[index][1] = value;
}
}
module.exports = assocSet;

17
_baseAssignIn.js Normal file
View File

@@ -0,0 +1,17 @@
var copyObject = require('./_copyObject'),
keysIn = require('./keysIn');
/**
* The base implementation of `_.assignIn` without support for multiple sources
* or `customizer` functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @returns {Object} Returns `object`.
*/
function baseAssignIn(object, source) {
return object && copyObject(source, keysIn(source), object);
}
module.exports = baseAssignIn;

25
_baseAssignValue.js Normal file
View File

@@ -0,0 +1,25 @@
var defineProperty = require('./_defineProperty');
/**
* The base implementation of `assignValue` and `assignMergeValue` without
* value checks.
*
* @private
* @param {Object} object The object to modify.
* @param {string} key The key of the property to assign.
* @param {*} value The value to assign.
*/
function baseAssignValue(object, key, value) {
if (key == '__proto__' && defineProperty) {
defineProperty(object, key, {
'configurable': true,
'enumerable': true,
'value': value,
'writable': true
});
} else {
object[key] = value;
}
}
module.exports = baseAssignValue;

View File

@@ -5,17 +5,17 @@ var get = require('./get');
* *
* @private * @private
* @param {Object} object The object to iterate over. * @param {Object} object The object to iterate over.
* @param {string[]} paths The property paths of elements to pick. * @param {string[]} paths The property paths to pick.
* @returns {Array} Returns the new array of picked elements. * @returns {Array} Returns the picked elements.
*/ */
function baseAt(object, paths) { function baseAt(object, paths) {
var index = -1, var index = -1,
isNil = object == null,
length = paths.length, length = paths.length,
result = Array(length); result = Array(length),
skip = object == null;
while (++index < length) { while (++index < length) {
result[index] = isNil ? undefined : get(object, paths[index]); result[index] = skip ? undefined : get(object, paths[index]);
} }
return result; return result;
} }

View File

@@ -1,14 +0,0 @@
var isSymbol = require('./isSymbol');
/**
* Casts `value` to a string if it's not a string or symbol.
*
* @private
* @param {*} value The value to inspect.
* @returns {string|symbol} Returns the cast key.
*/
function baseCastKey(key) {
return (typeof key == 'string' || isSymbol(key)) ? key : (key + '');
}
module.exports = baseCastKey;

View File

@@ -1,15 +0,0 @@
var isArray = require('./isArray'),
stringToPath = require('./_stringToPath');
/**
* Casts `value` to a path array if it's not one.
*
* @private
* @param {*} value The value to inspect.
* @returns {Array} Returns the cast property path array.
*/
function baseCastPath(value) {
return isArray(value) ? value : stringToPath(value);
}
module.exports = baseCastPath;

View File

@@ -1,5 +1,5 @@
/** /**
* The base implementation of `_.clamp` which doesn't coerce arguments to numbers. * The base implementation of `_.clamp` which doesn't coerce arguments.
* *
* @private * @private
* @param {number} number The number to clamp. * @param {number} number The number to clamp.

View File

@@ -2,19 +2,29 @@ var Stack = require('./_Stack'),
arrayEach = require('./_arrayEach'), arrayEach = require('./_arrayEach'),
assignValue = require('./_assignValue'), assignValue = require('./_assignValue'),
baseAssign = require('./_baseAssign'), baseAssign = require('./_baseAssign'),
baseAssignIn = require('./_baseAssignIn'),
cloneBuffer = require('./_cloneBuffer'), cloneBuffer = require('./_cloneBuffer'),
copyArray = require('./_copyArray'), copyArray = require('./_copyArray'),
copySymbols = require('./_copySymbols'), copySymbols = require('./_copySymbols'),
copySymbolsIn = require('./_copySymbolsIn'),
getAllKeys = require('./_getAllKeys'), getAllKeys = require('./_getAllKeys'),
getAllKeysIn = require('./_getAllKeysIn'),
getTag = require('./_getTag'), getTag = require('./_getTag'),
initCloneArray = require('./_initCloneArray'), initCloneArray = require('./_initCloneArray'),
initCloneByTag = require('./_initCloneByTag'), initCloneByTag = require('./_initCloneByTag'),
initCloneObject = require('./_initCloneObject'), initCloneObject = require('./_initCloneObject'),
isArray = require('./isArray'), isArray = require('./isArray'),
isBuffer = require('./isBuffer'), isBuffer = require('./isBuffer'),
isHostObject = require('./_isHostObject'), isMap = require('./isMap'),
isObject = require('./isObject'), isObject = require('./isObject'),
keys = require('./keys'); isSet = require('./isSet'),
keys = require('./keys'),
keysIn = require('./keysIn');
/** Used to compose bitmasks for cloning. */
var CLONE_DEEP_FLAG = 1,
CLONE_FLAT_FLAG = 2,
CLONE_SYMBOLS_FLAG = 4;
/** `Object#toString` result references. */ /** `Object#toString` result references. */
var argsTag = '[object Arguments]', var argsTag = '[object Arguments]',
@@ -67,16 +77,22 @@ cloneableTags[weakMapTag] = false;
* *
* @private * @private
* @param {*} value The value to clone. * @param {*} value The value to clone.
* @param {boolean} [isDeep] Specify a deep clone. * @param {boolean} bitmask The bitmask flags.
* @param {boolean} [isFull] Specify a clone including symbols. * 1 - Deep clone
* 2 - Flatten inherited properties
* 4 - Clone symbols
* @param {Function} [customizer] The function to customize cloning. * @param {Function} [customizer] The function to customize cloning.
* @param {string} [key] The key of `value`. * @param {string} [key] The key of `value`.
* @param {Object} [object] The parent object of `value`. * @param {Object} [object] The parent object of `value`.
* @param {Object} [stack] Tracks traversed objects and their clone counterparts. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
* @returns {*} Returns the cloned value. * @returns {*} Returns the cloned value.
*/ */
function baseClone(value, isDeep, isFull, customizer, key, object, stack) { function baseClone(value, bitmask, customizer, key, object, stack) {
var result; var result,
isDeep = bitmask & CLONE_DEEP_FLAG,
isFlat = bitmask & CLONE_FLAT_FLAG,
isFull = bitmask & CLONE_SYMBOLS_FLAG;
if (customizer) { if (customizer) {
result = object ? customizer(value, key, object, stack) : customizer(value); result = object ? customizer(value, key, object, stack) : customizer(value);
} }
@@ -100,18 +116,17 @@ function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
return cloneBuffer(value, isDeep); return cloneBuffer(value, isDeep);
} }
if (tag == objectTag || tag == argsTag || (isFunc && !object)) { if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
if (isHostObject(value)) { result = (isFlat || isFunc) ? {} : initCloneObject(value);
return object ? value : {};
}
result = initCloneObject(isFunc ? {} : value);
if (!isDeep) { if (!isDeep) {
return copySymbols(value, baseAssign(result, value)); return isFlat
? copySymbolsIn(value, baseAssignIn(result, value))
: copySymbols(value, baseAssign(result, value));
} }
} else { } else {
if (!cloneableTags[tag]) { if (!cloneableTags[tag]) {
return object ? value : {}; return object ? value : {};
} }
result = initCloneByTag(value, tag, baseClone, isDeep); result = initCloneByTag(value, tag, isDeep);
} }
} }
// Check for circular references and return its corresponding clone. // Check for circular references and return its corresponding clone.
@@ -122,16 +137,28 @@ function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
} }
stack.set(value, result); stack.set(value, result);
if (!isArr) { if (isSet(value)) {
var props = isFull ? getAllKeys(value) : keys(value); value.forEach(function(subValue) {
result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
});
} else if (isMap(value)) {
value.forEach(function(subValue, key) {
result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
});
} }
// Recursively populate clone (susceptible to call stack limits).
var keysFunc = isFull
? (isFlat ? getAllKeysIn : getAllKeys)
: (isFlat ? keysIn : keys);
var props = isArr ? undefined : keysFunc(value);
arrayEach(props || value, function(subValue, key) { arrayEach(props || value, function(subValue, key) {
if (props) { if (props) {
key = subValue; key = subValue;
subValue = value[key]; subValue = value[key];
} }
assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack)); // Recursively populate clone (susceptible to call stack limits).
assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
}); });
return result; return result;
} }

View File

@@ -1,32 +1,17 @@
var keys = require('./keys'); var baseConformsTo = require('./_baseConformsTo'),
keys = require('./keys');
/** /**
* The base implementation of `_.conforms` which doesn't clone `source`. * The base implementation of `_.conforms` which doesn't clone `source`.
* *
* @private * @private
* @param {Object} source The object of property predicates to conform to. * @param {Object} source The object of property predicates to conform to.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new spec function.
*/ */
function baseConforms(source) { function baseConforms(source) {
var props = keys(source), var props = keys(source);
length = props.length;
return function(object) { return function(object) {
if (object == null) { return baseConformsTo(object, source, props);
return !length;
}
var index = length;
while (index--) {
var key = props[index],
predicate = source[key],
value = object[key];
if ((value === undefined &&
!(key in Object(object))) || !predicate(value)) {
return false;
}
}
return true;
}; };
} }

27
_baseConformsTo.js Normal file
View File

@@ -0,0 +1,27 @@
/**
* The base implementation of `_.conformsTo` which accepts `props` to check.
*
* @private
* @param {Object} object The object to inspect.
* @param {Object} source The object of property predicates to conform to.
* @returns {boolean} Returns `true` if `object` conforms, else `false`.
*/
function baseConformsTo(object, source, props) {
var length = props.length;
if (object == null) {
return !length;
}
object = Object(object);
while (length--) {
var key = props[length],
predicate = source[key],
value = object[key];
if ((value === undefined && !(key in object)) || !predicate(value)) {
return false;
}
}
return true;
}
module.exports = baseConformsTo;

View File

@@ -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 = proto;
var result = new object;
object.prototype = undefined;
return result;
};
}());
module.exports = baseCreate; module.exports = baseCreate;

View File

@@ -1,15 +1,15 @@
/** 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';
/** /**
* The base implementation of `_.delay` and `_.defer` which accepts an array * The base implementation of `_.delay` and `_.defer` which accepts `args`
* of `func` arguments. * to provide to `func`.
* *
* @private * @private
* @param {Function} func The function to delay. * @param {Function} func The function to delay.
* @param {number} wait The number of milliseconds to delay invocation. * @param {number} wait The number of milliseconds to delay invocation.
* @param {Object} args The arguments to provide to `func`. * @param {Array} args The arguments to provide to `func`.
* @returns {number} Returns the timer id. * @returns {number|Object} Returns the timer id or timeout object.
*/ */
function baseDelay(func, wait, args) { function baseDelay(func, wait, args) {
if (typeof func != 'function') { if (typeof func != 'function') {

View File

@@ -45,8 +45,9 @@ function baseDifference(array, values, iteratee, comparator) {
outer: outer:
while (++index < length) { while (++index < length) {
var value = array[index], var value = array[index],
computed = iteratee ? iteratee(value) : value; computed = iteratee == null ? value : iteratee(value);
value = (comparator || value !== 0) ? value : 0;
if (isCommon && computed === computed) { if (isCommon && computed === computed) {
var valuesIndex = valuesLength; var valuesIndex = valuesLength;
while (valuesIndex--) { while (valuesIndex--) {

View File

@@ -1,3 +1,5 @@
var isSymbol = require('./isSymbol');
/** /**
* The base implementation of methods like `_.max` and `_.min` which accepts a * The base implementation of methods like `_.max` and `_.min` which accepts a
* `comparator` to determine the extremum value. * `comparator` to determine the extremum value.
@@ -17,7 +19,7 @@ function baseExtremum(array, iteratee, comparator) {
current = iteratee(value); current = iteratee(value);
if (current != null && (computed === undefined if (current != null && (computed === undefined
? current === current ? (current === current && !isSymbol(current))
: comparator(current, computed) : comparator(current, computed)
)) { )) {
var computed = current, var computed = current,

View File

@@ -1,25 +0,0 @@
/**
* The base implementation of methods like `_.find` and `_.findKey`, without
* support for iteratee shorthands, which iterates over `collection` using
* `eachFunc`.
*
* @private
* @param {Array|Object} collection The collection to search.
* @param {Function} predicate The function invoked per iteration.
* @param {Function} eachFunc The function to iterate over `collection`.
* @param {boolean} [retKey] Specify returning the key of the found element
* instead of the element itself.
* @returns {*} Returns the found element or its key, else `undefined`.
*/
function baseFind(collection, predicate, eachFunc, retKey) {
var result;
eachFunc(collection, function(value, key, collection) {
if (predicate(value, key, collection)) {
result = retKey ? key : value;
return false;
}
});
return result;
}
module.exports = baseFind;

View File

@@ -3,14 +3,15 @@
* support for iteratee shorthands. * support for iteratee shorthands.
* *
* @private * @private
* @param {Array} array The array to search. * @param {Array} array The array to inspect.
* @param {Function} predicate The function invoked per iteration. * @param {Function} predicate The function invoked per iteration.
* @param {number} fromIndex The index to search from.
* @param {boolean} [fromRight] Specify iterating from right to left. * @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
*/ */
function baseFindIndex(array, predicate, fromRight) { function baseFindIndex(array, predicate, fromIndex, fromRight) {
var length = array.length, var length = array.length,
index = fromRight ? length : -1; index = fromIndex + (fromRight ? 1 : -1);
while ((fromRight ? index-- : ++index < length)) { while ((fromRight ? index-- : ++index < length)) {
if (predicate(array[index], index, array)) { if (predicate(array[index], index, array)) {

23
_baseFindKey.js Normal file
View File

@@ -0,0 +1,23 @@
/**
* The base implementation of methods like `_.findKey` and `_.findLastKey`,
* without support for iteratee shorthands, which iterates over `collection`
* using `eachFunc`.
*
* @private
* @param {Array|Object} collection The collection to inspect.
* @param {Function} predicate The function invoked per iteration.
* @param {Function} eachFunc The function to iterate over `collection`.
* @returns {*} Returns the found element or its key, else `undefined`.
*/
function baseFindKey(collection, predicate, eachFunc) {
var result;
eachFunc(collection, function(value, key, collection) {
if (predicate(value, key, collection)) {
result = key;
return false;
}
});
return result;
}
module.exports = baseFindKey;

View File

@@ -1,7 +1,5 @@
var arrayPush = require('./_arrayPush'), var arrayPush = require('./_arrayPush'),
isArguments = require('./isArguments'), isFlattenable = require('./_isFlattenable');
isArray = require('./isArray'),
isArrayLikeObject = require('./isArrayLikeObject');
/** /**
* The base implementation of `_.flatten` with support for restricting flattening. * The base implementation of `_.flatten` with support for restricting flattening.
@@ -9,23 +7,24 @@ var arrayPush = require('./_arrayPush'),
* @private * @private
* @param {Array} array The array to flatten. * @param {Array} array The array to flatten.
* @param {number} depth The maximum recursion depth. * @param {number} depth The maximum recursion depth.
* @param {boolean} [isStrict] Restrict flattening to arrays-like objects. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
* @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
* @param {Array} [result=[]] The initial result value. * @param {Array} [result=[]] The initial result value.
* @returns {Array} Returns the new flattened array. * @returns {Array} Returns the new flattened array.
*/ */
function baseFlatten(array, depth, isStrict, result) { function baseFlatten(array, depth, predicate, isStrict, result) {
result || (result = []);
var index = -1, var index = -1,
length = array.length; length = array.length;
predicate || (predicate = isFlattenable);
result || (result = []);
while (++index < length) { while (++index < length) {
var value = array[index]; var value = array[index];
if (depth > 0 && isArrayLikeObject(value) && if (depth > 0 && predicate(value)) {
(isStrict || isArray(value) || isArguments(value))) {
if (depth > 1) { if (depth > 1) {
// Recursively flatten arrays (susceptible to call stack limits). // Recursively flatten arrays (susceptible to call stack limits).
baseFlatten(value, depth - 1, isStrict, result); baseFlatten(value, depth - 1, predicate, isStrict, result);
} else { } else {
arrayPush(result, value); arrayPush(result, value);
} }

View File

@@ -2,7 +2,7 @@ var createBaseFor = require('./_createBaseFor');
/** /**
* The base implementation of `baseForOwn` which iterates over `object` * The base implementation of `baseForOwn` which iterates over `object`
* properties returned by `keysFunc` invoking `iteratee` for each property. * properties returned by `keysFunc` and invokes `iteratee` for each property.
* Iteratee functions may exit iteration early by explicitly returning `false`. * Iteratee functions may exit iteration early by explicitly returning `false`.
* *
* @private * @private

View File

@@ -8,7 +8,7 @@ var arrayFilter = require('./_arrayFilter'),
* @private * @private
* @param {Object} object The object to inspect. * @param {Object} object The object to inspect.
* @param {Array} props The property names to filter. * @param {Array} props The property names to filter.
* @returns {Array} Returns the new array of filtered property names. * @returns {Array} Returns the function names.
*/ */
function baseFunctions(object, props) { function baseFunctions(object, props) {
return arrayFilter(props, function(key) { return arrayFilter(props, function(key) {

View File

@@ -1,5 +1,5 @@
var baseCastPath = require('./_baseCastPath'), var castPath = require('./_castPath'),
isKey = require('./_isKey'); toKey = require('./_toKey');
/** /**
* The base implementation of `_.get` without support for default values. * The base implementation of `_.get` without support for default values.
@@ -10,13 +10,13 @@ var baseCastPath = require('./_baseCastPath'),
* @returns {*} Returns the resolved value. * @returns {*} Returns the resolved value.
*/ */
function baseGet(object, path) { function baseGet(object, path) {
path = isKey(path, object) ? [path] : baseCastPath(path); path = castPath(path, object);
var index = 0, var index = 0,
length = path.length; length = path.length;
while (object != null && index < length) { while (object != null && index < length) {
object = object[path[index++]]; object = object[toKey(path[index++])];
} }
return (index && index == length) ? object : undefined; return (index && index == length) ? object : undefined;
} }

View File

@@ -14,9 +14,7 @@ var arrayPush = require('./_arrayPush'),
*/ */
function baseGetAllKeys(object, keysFunc, symbolsFunc) { function baseGetAllKeys(object, keysFunc, symbolsFunc) {
var result = keysFunc(object); var result = keysFunc(object);
return isArray(object) return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
? result
: arrayPush(result, symbolsFunc(object));
} }
module.exports = baseGetAllKeys; module.exports = baseGetAllKeys;

28
_baseGetTag.js Normal file
View File

@@ -0,0 +1,28 @@
var Symbol = require('./_Symbol'),
getRawTag = require('./_getRawTag'),
objectToString = require('./_objectToString');
/** `Object#toString` result references. */
var nullTag = '[object Null]',
undefinedTag = '[object Undefined]';
/** Built-in value references. */
var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
/**
* The base implementation of `getTag` without fallbacks for buggy environments.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
function baseGetTag(value) {
if (value == null) {
return value === undefined ? undefinedTag : nullTag;
}
return (symToStringTag && symToStringTag in Object(value))
? getRawTag(value)
: objectToString(value);
}
module.exports = baseGetTag;

14
_baseGt.js Normal file
View File

@@ -0,0 +1,14 @@
/**
* The base implementation of `_.gt` which doesn't coerce arguments.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is greater than `other`,
* else `false`.
*/
function baseGt(value, other) {
return value > other;
}
module.exports = baseGt;

View File

@@ -1,5 +1,3 @@
var getPrototype = require('./_getPrototype');
/** Used for built-in method references. */ /** Used for built-in method references. */
var objectProto = Object.prototype; var objectProto = Object.prototype;
@@ -10,16 +8,12 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* The base implementation of `_.has` without support for deep paths. * The base implementation of `_.has` without support for deep paths.
* *
* @private * @private
* @param {Object} object The object to query. * @param {Object} [object] The object to query.
* @param {Array|string} key The key to check. * @param {Array|string} key The key to check.
* @returns {boolean} Returns `true` if `key` exists, else `false`. * @returns {boolean} Returns `true` if `key` exists, else `false`.
*/ */
function baseHas(object, key) { function baseHas(object, key) {
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`, return object != null && hasOwnProperty.call(object, key);
// that are composed entirely of index properties, return `false` for
// `hasOwnProperty` checks of them.
return hasOwnProperty.call(object, key) ||
(typeof object == 'object' && key in object && getPrototype(object) === null);
} }
module.exports = baseHas; module.exports = baseHas;

View File

@@ -2,12 +2,12 @@
* The base implementation of `_.hasIn` without support for deep paths. * The base implementation of `_.hasIn` without support for deep paths.
* *
* @private * @private
* @param {Object} object The object to query. * @param {Object} [object] The object to query.
* @param {Array|string} key The key to check. * @param {Array|string} key The key to check.
* @returns {boolean} Returns `true` if `key` exists, else `false`. * @returns {boolean} Returns `true` if `key` exists, else `false`.
*/ */
function baseHasIn(object, key) { function baseHasIn(object, key) {
return key in Object(object); return object != null && key in Object(object);
} }
module.exports = baseHasIn; module.exports = baseHasIn;

View File

@@ -3,7 +3,7 @@ var nativeMax = Math.max,
nativeMin = Math.min; nativeMin = Math.min;
/** /**
* The base implementation of `_.inRange` which doesn't coerce arguments to numbers. * The base implementation of `_.inRange` which doesn't coerce arguments.
* *
* @private * @private
* @param {number} number The number to check. * @param {number} number The number to check.

View File

@@ -1,27 +1,20 @@
var indexOfNaN = require('./_indexOfNaN'); var baseFindIndex = require('./_baseFindIndex'),
baseIsNaN = require('./_baseIsNaN'),
strictIndexOf = require('./_strictIndexOf');
/** /**
* The base implementation of `_.indexOf` without `fromIndex` bounds checks. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
* *
* @private * @private
* @param {Array} array The array to search. * @param {Array} array The array to inspect.
* @param {*} value The value to search for. * @param {*} value The value to search for.
* @param {number} fromIndex The index to search from. * @param {number} fromIndex The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
*/ */
function baseIndexOf(array, value, fromIndex) { function baseIndexOf(array, value, fromIndex) {
if (value !== value) { return value === value
return indexOfNaN(array, fromIndex); ? strictIndexOf(array, value, fromIndex)
} : baseFindIndex(array, baseIsNaN, fromIndex);
var index = fromIndex - 1,
length = array.length;
while (++index < length) {
if (array[index] === value) {
return index;
}
}
return -1;
} }
module.exports = baseIndexOf; module.exports = baseIndexOf;

View File

@@ -2,7 +2,7 @@
* This function is like `baseIndexOf` except that it accepts a comparator. * This function is like `baseIndexOf` except that it accepts a comparator.
* *
* @private * @private
* @param {Array} array The array to search. * @param {Array} array The array to inspect.
* @param {*} value The value to search for. * @param {*} value The value to search for.
* @param {number} fromIndex The index to search from. * @param {number} fromIndex The index to search from.
* @param {Function} comparator The comparator invoked per element. * @param {Function} comparator The comparator invoked per element.

View File

@@ -47,6 +47,7 @@ function baseIntersection(arrays, iteratee, comparator) {
var value = array[index], var value = array[index],
computed = iteratee ? iteratee(value) : value; computed = iteratee ? iteratee(value) : value;
value = (comparator || value !== 0) ? value : 0;
if (!(seen if (!(seen
? cacheHas(seen, computed) ? cacheHas(seen, computed)
: includes(result, computed, comparator) : includes(result, computed, comparator)

View File

@@ -1,8 +1,8 @@
var apply = require('./_apply'), var apply = require('./_apply'),
baseCastPath = require('./_baseCastPath'), castPath = require('./_castPath'),
isKey = require('./_isKey'),
last = require('./last'), last = require('./last'),
parent = require('./_parent'); parent = require('./_parent'),
toKey = require('./_toKey');
/** /**
* The base implementation of `_.invoke` without support for individual * The base implementation of `_.invoke` without support for individual
@@ -15,12 +15,9 @@ var apply = require('./_apply'),
* @returns {*} Returns the result of the invoked method. * @returns {*} Returns the result of the invoked method.
*/ */
function baseInvoke(object, path, args) { function baseInvoke(object, path, args) {
if (!isKey(path, object)) { path = castPath(path, object);
path = baseCastPath(path); object = parent(object, path);
object = parent(object, path); var func = object == null ? object : object[toKey(last(path))];
path = last(path);
}
var func = object == null ? object : object[path];
return func == null ? undefined : apply(func, object, args); return func == null ? undefined : apply(func, object, args);
} }

18
_baseIsArguments.js Normal file
View File

@@ -0,0 +1,18 @@
var baseGetTag = require('./_baseGetTag'),
isObjectLike = require('./isObjectLike');
/** `Object#toString` result references. */
var argsTag = '[object Arguments]';
/**
* The base implementation of `_.isArguments`.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
*/
function baseIsArguments(value) {
return isObjectLike(value) && baseGetTag(value) == argsTag;
}
module.exports = baseIsArguments;

17
_baseIsArrayBuffer.js Normal file
View File

@@ -0,0 +1,17 @@
var baseGetTag = require('./_baseGetTag'),
isObjectLike = require('./isObjectLike');
var arrayBufferTag = '[object ArrayBuffer]';
/**
* The base implementation of `_.isArrayBuffer` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
*/
function baseIsArrayBuffer(value) {
return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
}
module.exports = baseIsArrayBuffer;

18
_baseIsDate.js Normal file
View File

@@ -0,0 +1,18 @@
var baseGetTag = require('./_baseGetTag'),
isObjectLike = require('./isObjectLike');
/** `Object#toString` result references. */
var dateTag = '[object Date]';
/**
* The base implementation of `_.isDate` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a date object, else `false`.
*/
function baseIsDate(value) {
return isObjectLike(value) && baseGetTag(value) == dateTag;
}
module.exports = baseIsDate;

View File

@@ -1,5 +1,4 @@
var baseIsEqualDeep = require('./_baseIsEqualDeep'), var baseIsEqualDeep = require('./_baseIsEqualDeep'),
isObject = require('./isObject'),
isObjectLike = require('./isObjectLike'); isObjectLike = require('./isObjectLike');
/** /**
@@ -9,22 +8,21 @@ var baseIsEqualDeep = require('./_baseIsEqualDeep'),
* @private * @private
* @param {*} value The value to compare. * @param {*} value The value to compare.
* @param {*} other The other value to compare. * @param {*} other The other value to compare.
* @param {boolean} bitmask The bitmask flags.
* 1 - Unordered comparison
* 2 - Partial comparison
* @param {Function} [customizer] The function to customize comparisons. * @param {Function} [customizer] The function to customize comparisons.
* @param {boolean} [bitmask] The bitmask of comparison flags.
* The bitmask may be composed of the following flags:
* 1 - Unordered comparison
* 2 - Partial comparison
* @param {Object} [stack] Tracks traversed `value` and `other` objects. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/ */
function baseIsEqual(value, other, customizer, bitmask, stack) { function baseIsEqual(value, other, bitmask, customizer, stack) {
if (value === other) { if (value === other) {
return true; return true;
} }
if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) { if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
return value !== value && other !== other; return value !== value && other !== other;
} }
return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack); return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
} }
module.exports = baseIsEqual; module.exports = baseIsEqual;

View File

@@ -4,11 +4,11 @@ var Stack = require('./_Stack'),
equalObjects = require('./_equalObjects'), equalObjects = require('./_equalObjects'),
getTag = require('./_getTag'), getTag = require('./_getTag'),
isArray = require('./isArray'), isArray = require('./isArray'),
isHostObject = require('./_isHostObject'), isBuffer = require('./isBuffer'),
isTypedArray = require('./isTypedArray'); isTypedArray = require('./isTypedArray');
/** Used to compose bitmasks for comparison styles. */ /** Used to compose bitmasks for value comparisons. */
var PARTIAL_COMPARE_FLAG = 2; var COMPARE_PARTIAL_FLAG = 1;
/** `Object#toString` result references. */ /** `Object#toString` result references. */
var argsTag = '[object Arguments]', var argsTag = '[object Arguments]',
@@ -29,38 +29,39 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @private * @private
* @param {Object} object The object to compare. * @param {Object} object The object to compare.
* @param {Object} other The other object to compare. * @param {Object} other The other object to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values. * @param {Function} equalFunc The function to determine equivalents of values.
* @param {Function} [customizer] The function to customize comparisons.
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
* for more details.
* @param {Object} [stack] Tracks traversed `object` and `other` objects. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/ */
function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) { function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
var objIsArr = isArray(object), var objIsArr = isArray(object),
othIsArr = isArray(other), othIsArr = isArray(other),
objTag = arrayTag, objTag = objIsArr ? arrayTag : getTag(object),
othTag = arrayTag; othTag = othIsArr ? arrayTag : getTag(other);
if (!objIsArr) { objTag = objTag == argsTag ? objectTag : objTag;
objTag = getTag(object); othTag = othTag == argsTag ? objectTag : othTag;
objTag = objTag == argsTag ? objectTag : objTag;
} var objIsObj = objTag == objectTag,
if (!othIsArr) { othIsObj = othTag == objectTag,
othTag = getTag(other);
othTag = othTag == argsTag ? objectTag : othTag;
}
var objIsObj = objTag == objectTag && !isHostObject(object),
othIsObj = othTag == objectTag && !isHostObject(other),
isSameTag = objTag == othTag; isSameTag = objTag == othTag;
if (isSameTag && isBuffer(object)) {
if (!isBuffer(other)) {
return false;
}
objIsArr = true;
objIsObj = false;
}
if (isSameTag && !objIsObj) { if (isSameTag && !objIsObj) {
stack || (stack = new Stack); stack || (stack = new Stack);
return (objIsArr || isTypedArray(object)) return (objIsArr || isTypedArray(object))
? equalArrays(object, other, equalFunc, customizer, bitmask, stack) ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
: equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack); : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
} }
if (!(bitmask & PARTIAL_COMPARE_FLAG)) { if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
@@ -69,14 +70,14 @@ function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
othUnwrapped = othIsWrapped ? other.value() : other; othUnwrapped = othIsWrapped ? other.value() : other;
stack || (stack = new Stack); stack || (stack = new Stack);
return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack); return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
} }
} }
if (!isSameTag) { if (!isSameTag) {
return false; return false;
} }
stack || (stack = new Stack); stack || (stack = new Stack);
return equalObjects(object, other, equalFunc, customizer, bitmask, stack); return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
} }
module.exports = baseIsEqualDeep; module.exports = baseIsEqualDeep;

18
_baseIsMap.js Normal file
View File

@@ -0,0 +1,18 @@
var getTag = require('./_getTag'),
isObjectLike = require('./isObjectLike');
/** `Object#toString` result references. */
var mapTag = '[object Map]';
/**
* The base implementation of `_.isMap` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a map, else `false`.
*/
function baseIsMap(value) {
return isObjectLike(value) && getTag(value) == mapTag;
}
module.exports = baseIsMap;

View File

@@ -1,9 +1,9 @@
var Stack = require('./_Stack'), var Stack = require('./_Stack'),
baseIsEqual = require('./_baseIsEqual'); baseIsEqual = require('./_baseIsEqual');
/** Used to compose bitmasks for comparison styles. */ /** Used to compose bitmasks for value comparisons. */
var UNORDERED_COMPARE_FLAG = 1, var COMPARE_PARTIAL_FLAG = 1,
PARTIAL_COMPARE_FLAG = 2; COMPARE_UNORDERED_FLAG = 2;
/** /**
* The base implementation of `_.isMatch` without support for iteratee shorthands. * The base implementation of `_.isMatch` without support for iteratee shorthands.
@@ -49,7 +49,7 @@ function baseIsMatch(object, source, matchData, customizer) {
var result = customizer(objValue, srcValue, key, object, source, stack); var result = customizer(objValue, srcValue, key, object, source, stack);
} }
if (!(result === undefined if (!(result === undefined
? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
: result : result
)) { )) {
return false; return false;

12
_baseIsNaN.js Normal file
View File

@@ -0,0 +1,12 @@
/**
* The base implementation of `_.isNaN` without support for number objects.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
*/
function baseIsNaN(value) {
return value !== value;
}
module.exports = baseIsNaN;

47
_baseIsNative.js Normal file
View File

@@ -0,0 +1,47 @@
var isFunction = require('./isFunction'),
isMasked = require('./_isMasked'),
isObject = require('./isObject'),
toSource = require('./_toSource');
/**
* Used to match `RegExp`
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
*/
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
/** Used to detect host constructors (Safari). */
var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used for built-in method references. */
var funcProto = Function.prototype,
objectProto = Object.prototype;
/** Used to resolve the decompiled source of functions. */
var funcToString = funcProto.toString;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** Used to detect if a method is native. */
var reIsNative = RegExp('^' +
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
);
/**
* The base implementation of `_.isNative` without bad shim checks.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a native function,
* else `false`.
*/
function baseIsNative(value) {
if (!isObject(value) || isMasked(value)) {
return false;
}
var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
return pattern.test(toSource(value));
}
module.exports = baseIsNative;

18
_baseIsRegExp.js Normal file
View File

@@ -0,0 +1,18 @@
var baseGetTag = require('./_baseGetTag'),
isObjectLike = require('./isObjectLike');
/** `Object#toString` result references. */
var regexpTag = '[object RegExp]';
/**
* The base implementation of `_.isRegExp` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
*/
function baseIsRegExp(value) {
return isObjectLike(value) && baseGetTag(value) == regexpTag;
}
module.exports = baseIsRegExp;

18
_baseIsSet.js Normal file
View File

@@ -0,0 +1,18 @@
var getTag = require('./_getTag'),
isObjectLike = require('./isObjectLike');
/** `Object#toString` result references. */
var setTag = '[object Set]';
/**
* The base implementation of `_.isSet` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a set, else `false`.
*/
function baseIsSet(value) {
return isObjectLike(value) && getTag(value) == setTag;
}
module.exports = baseIsSet;

60
_baseIsTypedArray.js Normal file
View File

@@ -0,0 +1,60 @@
var baseGetTag = require('./_baseGetTag'),
isLength = require('./isLength'),
isObjectLike = require('./isObjectLike');
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
arrayTag = '[object Array]',
boolTag = '[object Boolean]',
dateTag = '[object Date]',
errorTag = '[object Error]',
funcTag = '[object Function]',
mapTag = '[object Map]',
numberTag = '[object Number]',
objectTag = '[object Object]',
regexpTag = '[object RegExp]',
setTag = '[object Set]',
stringTag = '[object String]',
weakMapTag = '[object WeakMap]';
var arrayBufferTag = '[object ArrayBuffer]',
dataViewTag = '[object DataView]',
float32Tag = '[object Float32Array]',
float64Tag = '[object Float64Array]',
int8Tag = '[object Int8Array]',
int16Tag = '[object Int16Array]',
int32Tag = '[object Int32Array]',
uint8Tag = '[object Uint8Array]',
uint8ClampedTag = '[object Uint8ClampedArray]',
uint16Tag = '[object Uint16Array]',
uint32Tag = '[object Uint32Array]';
/** Used to identify `toStringTag` values of typed arrays. */
var typedArrayTags = {};
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
typedArrayTags[uint32Tag] = true;
typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
typedArrayTags[errorTag] = typedArrayTags[funcTag] =
typedArrayTags[mapTag] = typedArrayTags[numberTag] =
typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
typedArrayTags[setTag] = typedArrayTags[stringTag] =
typedArrayTags[weakMapTag] = false;
/**
* The base implementation of `_.isTypedArray` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
*/
function baseIsTypedArray(value) {
return isObjectLike(value) &&
isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
}
module.exports = baseIsTypedArray;

View File

@@ -1,16 +1,30 @@
/* Built-in method references for those with the same name as other `lodash` methods. */ var isPrototype = require('./_isPrototype'),
var nativeKeys = Object.keys; nativeKeys = require('./_nativeKeys');
/** Used for built-in method references. */
var objectProto = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** /**
* The base implementation of `_.keys` which doesn't skip the constructor * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
* property of prototypes or treat sparse arrays as dense.
* *
* @private * @private
* @param {Object} object The object to query. * @param {Object} object The object to query.
* @returns {Array} Returns the array of property names. * @returns {Array} Returns the array of property names.
*/ */
function baseKeys(object) { function baseKeys(object) {
return nativeKeys(Object(object)); if (!isPrototype(object)) {
return nativeKeys(object);
}
var result = [];
for (var key in Object(object)) {
if (hasOwnProperty.call(object, key) && key != 'constructor') {
result.push(key);
}
}
return result;
} }
module.exports = baseKeys; module.exports = baseKeys;

View File

@@ -1,36 +1,33 @@
var Reflect = require('./_Reflect'), var isObject = require('./isObject'),
iteratorToArray = require('./_iteratorToArray'); isPrototype = require('./_isPrototype'),
nativeKeysIn = require('./_nativeKeysIn');
/** Used for built-in method references. */ /** Used for built-in method references. */
var objectProto = Object.prototype; var objectProto = Object.prototype;
/** Built-in value references. */ /** Used to check objects for own properties. */
var enumerate = Reflect ? Reflect.enumerate : undefined, var hasOwnProperty = objectProto.hasOwnProperty;
propertyIsEnumerable = objectProto.propertyIsEnumerable;
/** /**
* The base implementation of `_.keysIn` which doesn't skip the constructor * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
* property of prototypes or treat sparse arrays as dense.
* *
* @private * @private
* @param {Object} object The object to query. * @param {Object} object The object to query.
* @returns {Array} Returns the array of property names. * @returns {Array} Returns the array of property names.
*/ */
function baseKeysIn(object) { function baseKeysIn(object) {
object = object == null ? object : Object(object); if (!isObject(object)) {
return nativeKeysIn(object);
}
var isProto = isPrototype(object),
result = [];
var result = [];
for (var key in object) { for (var key in object) {
result.push(key); if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
result.push(key);
}
} }
return result; return result;
} }
// Fallback for IE < 9 with es6-shim.
if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
baseKeysIn = function(object) {
return iteratorToArray(enumerate(object));
};
}
module.exports = baseKeysIn; module.exports = baseKeysIn;

14
_baseLt.js Normal file
View File

@@ -0,0 +1,14 @@
/**
* The base implementation of `_.lt` which doesn't coerce arguments.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is less than `other`,
* else `false`.
*/
function baseLt(value, other) {
return value < other;
}
module.exports = baseLt;

View File

@@ -7,7 +7,7 @@ var baseIsMatch = require('./_baseIsMatch'),
* *
* @private * @private
* @param {Object} source The object of property values to match. * @param {Object} source The object of property values to match.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new spec function.
*/ */
function baseMatches(source) { function baseMatches(source) {
var matchData = getMatchData(source); var matchData = getMatchData(source);

View File

@@ -3,11 +3,12 @@ var baseIsEqual = require('./_baseIsEqual'),
hasIn = require('./hasIn'), hasIn = require('./hasIn'),
isKey = require('./_isKey'), isKey = require('./_isKey'),
isStrictComparable = require('./_isStrictComparable'), isStrictComparable = require('./_isStrictComparable'),
matchesStrictComparable = require('./_matchesStrictComparable'); matchesStrictComparable = require('./_matchesStrictComparable'),
toKey = require('./_toKey');
/** Used to compose bitmasks for comparison styles. */ /** Used to compose bitmasks for value comparisons. */
var UNORDERED_COMPARE_FLAG = 1, var COMPARE_PARTIAL_FLAG = 1,
PARTIAL_COMPARE_FLAG = 2; COMPARE_UNORDERED_FLAG = 2;
/** /**
* The base implementation of `_.matchesProperty` which doesn't clone `srcValue`. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
@@ -15,17 +16,17 @@ var UNORDERED_COMPARE_FLAG = 1,
* @private * @private
* @param {string} path The path of the property to get. * @param {string} path The path of the property to get.
* @param {*} srcValue The value to match. * @param {*} srcValue The value to match.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new spec function.
*/ */
function baseMatchesProperty(path, srcValue) { function baseMatchesProperty(path, srcValue) {
if (isKey(path) && isStrictComparable(srcValue)) { if (isKey(path) && isStrictComparable(srcValue)) {
return matchesStrictComparable(path, srcValue); return matchesStrictComparable(toKey(path), srcValue);
} }
return function(object) { return function(object) {
var objValue = get(object, path); var objValue = get(object, path);
return (objValue === undefined && objValue === srcValue) return (objValue === undefined && objValue === srcValue)
? hasIn(object, path) ? hasIn(object, path)
: baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG); : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
}; };
} }

View File

@@ -13,7 +13,7 @@ var NAN = 0 / 0;
* @returns {number} Returns the mean. * @returns {number} Returns the mean.
*/ */
function baseMean(array, iteratee) { function baseMean(array, iteratee) {
var length = array ? array.length : 0; var length = array == null ? 0 : array.length;
return length ? (baseSum(array, iteratee) / length) : NAN; return length ? (baseSum(array, iteratee) / length) : NAN;
} }

View File

@@ -1,11 +1,10 @@
var Stack = require('./_Stack'), var Stack = require('./_Stack'),
arrayEach = require('./_arrayEach'),
assignMergeValue = require('./_assignMergeValue'), assignMergeValue = require('./_assignMergeValue'),
baseFor = require('./_baseFor'),
baseMergeDeep = require('./_baseMergeDeep'), baseMergeDeep = require('./_baseMergeDeep'),
isArray = require('./isArray'),
isObject = require('./isObject'), isObject = require('./isObject'),
isTypedArray = require('./isTypedArray'), keysIn = require('./keysIn'),
keysIn = require('./keysIn'); safeGet = require('./_safeGet');
/** /**
* The base implementation of `_.merge` without support for multiple sources. * The base implementation of `_.merge` without support for multiple sources.
@@ -22,21 +21,14 @@ function baseMerge(object, source, srcIndex, customizer, stack) {
if (object === source) { if (object === source) {
return; return;
} }
if (!(isArray(source) || isTypedArray(source))) { baseFor(source, function(srcValue, key) {
var props = keysIn(source); stack || (stack = new Stack);
}
arrayEach(props || source, function(srcValue, key) {
if (props) {
key = srcValue;
srcValue = source[key];
}
if (isObject(srcValue)) { if (isObject(srcValue)) {
stack || (stack = new Stack);
baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack); baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
} }
else { else {
var newValue = customizer var newValue = customizer
? customizer(object[key], srcValue, (key + ''), object, source, stack) ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
: undefined; : undefined;
if (newValue === undefined) { if (newValue === undefined) {
@@ -44,7 +36,7 @@ function baseMerge(object, source, srcIndex, customizer, stack) {
} }
assignMergeValue(object, key, newValue); assignMergeValue(object, key, newValue);
} }
}); }, keysIn);
} }
module.exports = baseMerge; module.exports = baseMerge;

View File

@@ -1,13 +1,17 @@
var assignMergeValue = require('./_assignMergeValue'), var assignMergeValue = require('./_assignMergeValue'),
baseClone = require('./_baseClone'), cloneBuffer = require('./_cloneBuffer'),
cloneTypedArray = require('./_cloneTypedArray'),
copyArray = require('./_copyArray'), copyArray = require('./_copyArray'),
initCloneObject = require('./_initCloneObject'),
isArguments = require('./isArguments'), isArguments = require('./isArguments'),
isArray = require('./isArray'), isArray = require('./isArray'),
isArrayLikeObject = require('./isArrayLikeObject'), isArrayLikeObject = require('./isArrayLikeObject'),
isBuffer = require('./isBuffer'),
isFunction = require('./isFunction'), isFunction = require('./isFunction'),
isObject = require('./isObject'), isObject = require('./isObject'),
isPlainObject = require('./isPlainObject'), isPlainObject = require('./isPlainObject'),
isTypedArray = require('./isTypedArray'), isTypedArray = require('./isTypedArray'),
safeGet = require('./_safeGet'),
toPlainObject = require('./toPlainObject'); toPlainObject = require('./toPlainObject');
/** /**
@@ -26,8 +30,8 @@ var assignMergeValue = require('./_assignMergeValue'),
* counterparts. * counterparts.
*/ */
function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
var objValue = object[key], var objValue = safeGet(object, key),
srcValue = source[key], srcValue = safeGet(source, key),
stacked = stack.get(srcValue); stacked = stack.get(srcValue);
if (stacked) { if (stacked) {
@@ -41,42 +45,49 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, sta
var isCommon = newValue === undefined; var isCommon = newValue === undefined;
if (isCommon) { if (isCommon) {
var isArr = isArray(srcValue),
isBuff = !isArr && isBuffer(srcValue),
isTyped = !isArr && !isBuff && isTypedArray(srcValue);
newValue = srcValue; newValue = srcValue;
if (isArray(srcValue) || isTypedArray(srcValue)) { if (isArr || isBuff || isTyped) {
if (isArray(objValue)) { if (isArray(objValue)) {
newValue = objValue; newValue = objValue;
} }
else if (isArrayLikeObject(objValue)) { else if (isArrayLikeObject(objValue)) {
newValue = copyArray(objValue); newValue = copyArray(objValue);
} }
else { else if (isBuff) {
isCommon = false; isCommon = false;
newValue = baseClone(srcValue, true); newValue = cloneBuffer(srcValue, true);
}
else if (isTyped) {
isCommon = false;
newValue = cloneTypedArray(srcValue, true);
}
else {
newValue = [];
} }
} }
else if (isPlainObject(srcValue) || isArguments(srcValue)) { else if (isPlainObject(srcValue) || isArguments(srcValue)) {
newValue = objValue;
if (isArguments(objValue)) { if (isArguments(objValue)) {
newValue = toPlainObject(objValue); newValue = toPlainObject(objValue);
} }
else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { else if (!isObject(objValue) || isFunction(objValue)) {
isCommon = false; newValue = initCloneObject(srcValue);
newValue = baseClone(srcValue, true);
}
else {
newValue = objValue;
} }
} }
else { else {
isCommon = false; isCommon = false;
} }
} }
stack.set(srcValue, newValue);
if (isCommon) { if (isCommon) {
// Recursively merge objects and arrays (susceptible to call stack limits). // Recursively merge objects and arrays (susceptible to call stack limits).
stack.set(srcValue, newValue);
mergeFunc(newValue, srcValue, srcIndex, customizer, stack); mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
stack['delete'](srcValue);
} }
stack['delete'](srcValue);
assignMergeValue(object, key, newValue); assignMergeValue(object, key, newValue);
} }

20
_baseNth.js Normal file
View File

@@ -0,0 +1,20 @@
var isIndex = require('./_isIndex');
/**
* The base implementation of `_.nth` which doesn't coerce arguments.
*
* @private
* @param {Array} array The array to query.
* @param {number} n The index of the element to return.
* @returns {*} Returns the nth element of `array`.
*/
function baseNth(array, n) {
var length = array.length;
if (!length) {
return;
}
n += n < 0 ? length : 0;
return isIndex(n, length) ? array[n] : undefined;
}
module.exports = baseNth;

View File

@@ -1,9 +1,12 @@
var arrayMap = require('./_arrayMap'), var arrayMap = require('./_arrayMap'),
baseGet = require('./_baseGet'),
baseIteratee = require('./_baseIteratee'), baseIteratee = require('./_baseIteratee'),
baseMap = require('./_baseMap'), baseMap = require('./_baseMap'),
baseSortBy = require('./_baseSortBy'), baseSortBy = require('./_baseSortBy'),
baseUnary = require('./_baseUnary'),
compareMultiple = require('./_compareMultiple'), compareMultiple = require('./_compareMultiple'),
identity = require('./identity'); identity = require('./identity'),
isArray = require('./isArray');
/** /**
* The base implementation of `_.orderBy` without param guards. * The base implementation of `_.orderBy` without param guards.
@@ -15,8 +18,21 @@ var arrayMap = require('./_arrayMap'),
* @returns {Array} Returns the new sorted array. * @returns {Array} Returns the new sorted array.
*/ */
function baseOrderBy(collection, iteratees, orders) { function baseOrderBy(collection, iteratees, orders) {
if (iteratees.length) {
iteratees = arrayMap(iteratees, function(iteratee) {
if (isArray(iteratee)) {
return function(value) {
return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
}
}
return iteratee;
});
} else {
iteratees = [identity];
}
var index = -1; var index = -1;
iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseIteratee); iteratees = arrayMap(iteratees, baseUnary(baseIteratee));
var result = baseMap(collection, function(value, key, collection) { var result = baseMap(collection, function(value, key, collection) {
var criteria = arrayMap(iteratees, function(iteratee) { var criteria = arrayMap(iteratees, function(iteratee) {

View File

@@ -1,4 +1,5 @@
var arrayReduce = require('./_arrayReduce'); var basePickBy = require('./_basePickBy'),
hasIn = require('./hasIn');
/** /**
* The base implementation of `_.pick` without support for individual * The base implementation of `_.pick` without support for individual
@@ -6,17 +7,13 @@ var arrayReduce = require('./_arrayReduce');
* *
* @private * @private
* @param {Object} object The source object. * @param {Object} object The source object.
* @param {string[]} props The property identifiers to pick. * @param {string[]} paths The property paths to pick.
* @returns {Object} Returns the new object. * @returns {Object} Returns the new object.
*/ */
function basePick(object, props) { function basePick(object, paths) {
object = Object(object); return basePickBy(object, paths, function(value, path) {
return arrayReduce(props, function(result, key) { return hasIn(object, path);
if (key in object) { });
result[key] = object[key];
}
return result;
}, {});
} }
module.exports = basePick; module.exports = basePick;

View File

@@ -1,25 +1,27 @@
var getAllKeysIn = require('./_getAllKeysIn'); var baseGet = require('./_baseGet'),
baseSet = require('./_baseSet'),
castPath = require('./_castPath');
/** /**
* The base implementation of `_.pickBy` without support for iteratee shorthands. * The base implementation of `_.pickBy` without support for iteratee shorthands.
* *
* @private * @private
* @param {Object} object The source object. * @param {Object} object The source object.
* @param {string[]} paths The property paths to pick.
* @param {Function} predicate The function invoked per property. * @param {Function} predicate The function invoked per property.
* @returns {Object} Returns the new object. * @returns {Object} Returns the new object.
*/ */
function basePickBy(object, predicate) { function basePickBy(object, paths, predicate) {
var index = -1, var index = -1,
props = getAllKeysIn(object), length = paths.length,
length = props.length,
result = {}; result = {};
while (++index < length) { while (++index < length) {
var key = props[index], var path = paths[index],
value = object[key]; value = baseGet(object, path);
if (predicate(value, key)) { if (predicate(value, path)) {
result[key] = value; baseSet(result, castPath(path, object), value);
} }
} }
return result; return result;

View File

@@ -3,7 +3,7 @@
* *
* @private * @private
* @param {string} key The key of the property to get. * @param {string} key The key of the property to get.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new accessor function.
*/ */
function baseProperty(key) { function baseProperty(key) {
return function(object) { return function(object) {

View File

@@ -5,7 +5,7 @@ var baseGet = require('./_baseGet');
* *
* @private * @private
* @param {Array|string} path The path of the property to get. * @param {Array|string} path The path of the property to get.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new accessor function.
*/ */
function basePropertyDeep(path) { function basePropertyDeep(path) {
return function(object) { return function(object) {

14
_basePropertyOf.js Normal file
View File

@@ -0,0 +1,14 @@
/**
* The base implementation of `_.propertyOf` without support for deep paths.
*
* @private
* @param {Object} object The object to query.
* @returns {Function} Returns the new accessor function.
*/
function basePropertyOf(object) {
return function(key) {
return object == null ? undefined : object[key];
};
}
module.exports = basePropertyOf;

View File

@@ -1,7 +1,8 @@
var arrayMap = require('./_arrayMap'), var arrayMap = require('./_arrayMap'),
baseIndexOf = require('./_baseIndexOf'), baseIndexOf = require('./_baseIndexOf'),
baseIndexOfWith = require('./_baseIndexOfWith'), baseIndexOfWith = require('./_baseIndexOfWith'),
baseUnary = require('./_baseUnary'); baseUnary = require('./_baseUnary'),
copyArray = require('./_copyArray');
/** Used for built-in method references. */ /** Used for built-in method references. */
var arrayProto = Array.prototype; var arrayProto = Array.prototype;
@@ -26,6 +27,9 @@ function basePullAll(array, values, iteratee, comparator) {
length = values.length, length = values.length,
seen = array; seen = array;
if (array === values) {
values = copyArray(values);
}
if (iteratee) { if (iteratee) {
seen = arrayMap(array, baseUnary(iteratee)); seen = arrayMap(array, baseUnary(iteratee));
} }

View File

@@ -1,8 +1,5 @@
var baseCastPath = require('./_baseCastPath'), var baseUnset = require('./_baseUnset'),
isIndex = require('./_isIndex'), isIndex = require('./_isIndex');
isKey = require('./_isKey'),
last = require('./last'),
parent = require('./_parent');
/** Used for built-in method references. */ /** Used for built-in method references. */
var arrayProto = Array.prototype; var arrayProto = Array.prototype;
@@ -25,21 +22,12 @@ function basePullAt(array, indexes) {
while (length--) { while (length--) {
var index = indexes[length]; var index = indexes[length];
if (lastIndex == length || index != previous) { if (length == lastIndex || index !== previous) {
var previous = index; var previous = index;
if (isIndex(index)) { if (isIndex(index)) {
splice.call(array, index, 1); splice.call(array, index, 1);
} } else {
else if (!isKey(index, array)) { baseUnset(array, index);
var path = baseCastPath(index),
object = parent(array, path);
if (object != null) {
delete object[last(path)];
}
}
else {
delete array[index];
} }
} }
} }

View File

@@ -4,14 +4,14 @@ var nativeCeil = Math.ceil,
/** /**
* The base implementation of `_.range` and `_.rangeRight` which doesn't * The base implementation of `_.range` and `_.rangeRight` which doesn't
* coerce arguments to numbers. * coerce arguments.
* *
* @private * @private
* @param {number} start The start of the range. * @param {number} start The start of the range.
* @param {number} end The end of the range. * @param {number} end The end of the range.
* @param {number} step The value to increment or decrement by. * @param {number} step The value to increment or decrement by.
* @param {boolean} [fromRight] Specify iterating from right to left. * @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Array} Returns the new array of numbers. * @returns {Array} Returns the range of numbers.
*/ */
function baseRange(start, end, step, fromRight) { function baseRange(start, end, step, fromRight) {
var index = -1, var index = -1,

17
_baseRest.js Normal file
View File

@@ -0,0 +1,17 @@
var identity = require('./identity'),
overRest = require('./_overRest'),
setToString = require('./_setToString');
/**
* The base implementation of `_.rest` which doesn't validate or coerce arguments.
*
* @private
* @param {Function} func The function to apply a rest parameter to.
* @param {number} [start=func.length-1] The start position of the rest parameter.
* @returns {Function} Returns the new function.
*/
function baseRest(func, start) {
return setToString(overRest(func, start, identity), func + '');
}
module.exports = baseRest;

15
_baseSample.js Normal file
View File

@@ -0,0 +1,15 @@
var arraySample = require('./_arraySample'),
values = require('./values');
/**
* 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));
}
module.exports = baseSample;

18
_baseSampleSize.js Normal file
View File

@@ -0,0 +1,18 @@
var baseClamp = require('./_baseClamp'),
shuffleSelf = require('./_shuffleSelf'),
values = require('./values');
/**
* 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) {
var array = values(collection);
return shuffleSelf(array, baseClamp(n, 0, array.length));
}
module.exports = baseSampleSize;

View File

@@ -1,21 +1,24 @@
var assignValue = require('./_assignValue'), var assignValue = require('./_assignValue'),
baseCastPath = require('./_baseCastPath'), castPath = require('./_castPath'),
isIndex = require('./_isIndex'), isIndex = require('./_isIndex'),
isKey = require('./_isKey'), isObject = require('./isObject'),
isObject = require('./isObject'); toKey = require('./_toKey');
/** /**
* The base implementation of `_.set`. * The base implementation of `_.set`.
* *
* @private * @private
* @param {Object} object The object to query. * @param {Object} object The object to modify.
* @param {Array|string} path The path of the property to set. * @param {Array|string} path The path of the property to set.
* @param {*} value The value to set. * @param {*} value The value to set.
* @param {Function} [customizer] The function to customize path creation. * @param {Function} [customizer] The function to customize path creation.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
*/ */
function baseSet(object, path, value, customizer) { function baseSet(object, path, value, customizer) {
path = isKey(path, object) ? [path] : baseCastPath(path); if (!isObject(object)) {
return object;
}
path = castPath(path, object);
var index = -1, var index = -1,
length = path.length, length = path.length,
@@ -23,20 +26,23 @@ function baseSet(object, path, value, customizer) {
nested = object; nested = object;
while (nested != null && ++index < length) { while (nested != null && ++index < length) {
var key = path[index]; var key = toKey(path[index]),
if (isObject(nested)) { newValue = value;
var newValue = value;
if (index != lastIndex) { if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
var objValue = nested[key]; return object;
newValue = customizer ? customizer(objValue, key, nested) : undefined;
if (newValue === undefined) {
newValue = objValue == null
? (isIndex(path[index + 1]) ? [] : {})
: objValue;
}
}
assignValue(nested, key, newValue);
} }
if (index != lastIndex) {
var objValue = nested[key];
newValue = customizer ? customizer(objValue, key, nested) : undefined;
if (newValue === undefined) {
newValue = isObject(objValue)
? objValue
: (isIndex(path[index + 1]) ? [] : {});
}
}
assignValue(nested, key, newValue);
nested = nested[key]; nested = nested[key];
} }
return object; return object;

View File

@@ -2,7 +2,7 @@ var identity = require('./identity'),
metaMap = require('./_metaMap'); metaMap = require('./_metaMap');
/** /**
* The base implementation of `setData` without support for hot loop detection. * The base implementation of `setData` without support for hot loop shorting.
* *
* @private * @private
* @param {Function} func The function to associate metadata with. * @param {Function} func The function to associate metadata with.

Some files were not shown because too many files have changed in this diff Show More