mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Bump to v4.7.0.
This commit is contained in:
36
isEmpty.js
36
isEmpty.js
@@ -1,4 +1,8 @@
|
||||
define(['./isArguments', './isArray', './isArrayLike', './isFunction', './isString'], function(isArguments, isArray, isArrayLike, isFunction, isString) {
|
||||
define(['./_getTag', './isArguments', './isArray', './isArrayLike', './isBuffer', './isFunction', './isObjectLike', './isString', './keys'], function(getTag, isArguments, isArray, isArrayLike, isBuffer, isFunction, isObjectLike, isString, keys) {
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var mapTag = '[object Map]',
|
||||
setTag = '[object Set]';
|
||||
|
||||
/** Used for built-in method references. */
|
||||
var objectProto = Object.prototype;
|
||||
@@ -6,13 +10,25 @@ define(['./isArguments', './isArray', './isArrayLike', './isFunction', './isStri
|
||||
/** 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`.
|
||||
@@ -35,16 +51,22 @@ define(['./isArguments', './isArray', './isArrayLike', './isFunction', './isStri
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
return isEmpty;
|
||||
|
||||
Reference in New Issue
Block a user