mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Bump to v3.0.0.
This commit is contained in:
48
lang/isEmpty.js
Normal file
48
lang/isEmpty.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import isArguments from './isArguments';
|
||||
import isArray from './isArray';
|
||||
import isFunction from './isFunction';
|
||||
import isLength from '../internal/isLength';
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
import isString from './isString';
|
||||
import keys from '../object/keys';
|
||||
|
||||
/**
|
||||
* Checks if a value is empty. A value is considered empty unless it is an
|
||||
* `arguments` object, array, string, or jQuery-like collection with a length
|
||||
* greater than `0` or an object with own enumerable properties.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Lang
|
||||
* @param {Array|Object|string} value The value to inspect.
|
||||
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.isEmpty(null);
|
||||
* // => true
|
||||
*
|
||||
* _.isEmpty(true);
|
||||
* // => true
|
||||
*
|
||||
* _.isEmpty(1);
|
||||
* // => true
|
||||
*
|
||||
* _.isEmpty([1, 2, 3]);
|
||||
* // => false
|
||||
*
|
||||
* _.isEmpty({ 'a': 1 });
|
||||
* // => false
|
||||
*/
|
||||
function isEmpty(value) {
|
||||
if (value == null) {
|
||||
return true;
|
||||
}
|
||||
var length = value.length;
|
||||
if (isLength(length) && (isArray(value) || isString(value) || isArguments(value) ||
|
||||
(isObjectLike(value) && isFunction(value.splice)))) {
|
||||
return !length;
|
||||
}
|
||||
return !keys(value).length;
|
||||
}
|
||||
|
||||
export default isEmpty;
|
||||
Reference in New Issue
Block a user