mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
40 lines
921 B
JavaScript
40 lines
921 B
JavaScript
var isFunction = require('./isFunction'),
|
|
isObjectLike = require('./isObjectLike'),
|
|
keys = require('./keys'),
|
|
size = require('./size');
|
|
|
|
/**
|
|
* Checks if `value` is empty. A value is considered empty unless it's 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) {
|
|
return (!isObjectLike(value) || isFunction(value.splice))
|
|
? !size(value)
|
|
: !keys(value).length;
|
|
}
|
|
|
|
module.exports = isEmpty;
|