mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Bump to v4.7.0.
This commit is contained in:
38
isEmpty.js
38
isEmpty.js
@@ -1,8 +1,16 @@
|
||||
import getTag from './_getTag';
|
||||
import isArguments from './isArguments';
|
||||
import isArray from './isArray';
|
||||
import isArrayLike from './isArrayLike';
|
||||
import isBuffer from './isBuffer';
|
||||
import isFunction from './isFunction';
|
||||
import isObjectLike from './isObjectLike';
|
||||
import isString from './isString';
|
||||
import keys from './keys';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var mapTag = '[object Map]',
|
||||
setTag = '[object Set]';
|
||||
|
||||
/** Used for built-in method references. */
|
||||
var objectProto = Object.prototype;
|
||||
@@ -10,13 +18,25 @@ var objectProto = Object.prototype;
|
||||
/** Used to check objects for own properties. */
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/** Built-in value references. */
|
||||
var propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
||||
|
||||
/** Detect if properties shadowing those on `Object.prototype` are non-enumerable. */
|
||||
var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf');
|
||||
|
||||
/**
|
||||
* Checks if `value` is an empty collection or object. A value is considered
|
||||
* empty if it's an `arguments` object, array, string, or jQuery-like collection
|
||||
* with a length of `0` or has no own enumerable properties.
|
||||
* Checks if `value` is an empty object, collection, map, or set.
|
||||
*
|
||||
* Objects are considered empty if they have no own enumerable string keyed
|
||||
* properties.
|
||||
*
|
||||
* Array-like values such as `arguments` objects, arrays, buffers, strings, or
|
||||
* jQuery-like collections are considered empty if they have a `length` of `0`.
|
||||
* Similarly, maps and sets are considered empty if they have a `size` of `0`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 0.1.0
|
||||
* @category Lang
|
||||
* @param {*} value The value to check.
|
||||
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
||||
@@ -39,16 +59,22 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
*/
|
||||
function isEmpty(value) {
|
||||
if (isArrayLike(value) &&
|
||||
(isArray(value) || isString(value) ||
|
||||
isFunction(value.splice) || isArguments(value))) {
|
||||
(isArray(value) || isString(value) || isFunction(value.splice) ||
|
||||
isArguments(value) || isBuffer(value))) {
|
||||
return !value.length;
|
||||
}
|
||||
if (isObjectLike(value)) {
|
||||
var tag = getTag(value);
|
||||
if (tag == mapTag || tag == setTag) {
|
||||
return !value.size;
|
||||
}
|
||||
}
|
||||
for (var key in value) {
|
||||
if (hasOwnProperty.call(value, key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return !(nonEnumShadows && keys(value).length);
|
||||
}
|
||||
|
||||
export default isEmpty;
|
||||
|
||||
Reference in New Issue
Block a user