Simplify _.isEmpty.

This commit is contained in:
John-David Dalton
2016-08-08 15:44:07 -07:00
parent f676a8c9c1
commit 6d930d6920

View File

@@ -2208,7 +2208,7 @@
* @returns {Array} Returns the array of property names. * @returns {Array} Returns the array of property names.
*/ */
function arrayLikeKeys(value, inherited) { function arrayLikeKeys(value, inherited) {
var result = (isArray(value) || isString(value) || isArguments(value)) var result = isArray(value)
? baseTimes(value.length, String) ? baseTimes(value.length, String)
: []; : [];
@@ -5748,7 +5748,7 @@
} }
var length = object ? object.length : 0; var length = object ? object.length : 0;
return !!length && isLength(length) && isIndex(key, length) && return !!length && isLength(length) && isIndex(key, length) &&
(isArray(object) || isString(object) || isArguments(object)); (isArray(object) || isArguments(object));
} }
/** /**
@@ -9401,8 +9401,7 @@
return 0; return 0;
} }
if (isArrayLike(collection)) { if (isArrayLike(collection)) {
var result = collection.length; return isString(collection) ? stringSize(collection) : collection.length;
return (result && isString(collection)) ? stringSize(collection) : result;
} }
if (isObjectLike(collection)) { if (isObjectLike(collection)) {
var tag = getTag(collection); var tag = getTag(collection);
@@ -11040,24 +11039,23 @@
*/ */
function isEmpty(value) { function isEmpty(value) {
if (isArrayLike(value) && if (isArrayLike(value) &&
(isArray(value) || isString(value) || isFunction(value.splice) || (isArray(value) || typeof value == 'string' ||
isArguments(value) || isBuffer(value))) { typeof value.splice == 'function' || isBuffer(value) || isArguments(value))) {
return !value.length; return !value.length;
} }
if (isObjectLike(value)) { var tag = getTag(value);
var tag = getTag(value); if (tag == mapTag || tag == setTag) {
if (tag == mapTag || tag == setTag) { return !value.size;
return !value.size; }
} if (nonEnumShadows || isPrototype(value)) {
return !nativeKeys(value).length;
} }
var isProto = isPrototype(value);
for (var key in value) { for (var key in value) {
if (hasOwnProperty.call(value, key) && if (hasOwnProperty.call(value, key)) {
!(isProto && key == 'constructor')) {
return false; return false;
} }
} }
return !(nonEnumShadows && nativeKeys(value).length); return true;
} }
/** /**