| 1234567891011121314151617181920212223242526272829303132333435363738 |
- var isNil = require('./type/is-nil');
- var isArrayLike = require('./type/is-array-like');
- var getType = require('./type/get-type');
- var isPrototype = require('./type/is-prototype');
- var hasOwnProperty = Object.prototype.hasOwnProperty;
- function isEmpty(value) {
- /**
- * isEmpty(null) => true
- * isEmpty() => true
- * isEmpty(true) => true
- * isEmpty(1) => true
- * isEmpty([1, 2, 3]) => false
- * isEmpty('abc') => false
- * isEmpty({ a: 1 }) => false
- */
- if (isNil(value)) {
- return true;
- }
- if (isArrayLike(value)) {
- return !value.length;
- }
- var type = getType(value);
- if (type === 'Map' || type === 'Set') {
- return !value.size;
- }
- if (isPrototype(value)) {
- return !Object.keys(value).length;
- }
- for (var key in value) {
- if (hasOwnProperty.call(value, key)) {
- return false;
- }
- }
- return true;
- }
- module.exports = isEmpty;
|