UNPKG

956 BJavaScriptView Raw
1import isNil from './is-nil';
2import isArrayLike from './is-array-like';
3import getType from './get-type';
4import isPrototype from './is-prototype';
5var hasOwnProperty = Object.prototype.hasOwnProperty;
6function isEmpty(value) {
7 /**
8 * isEmpty(null) => true
9 * isEmpty() => true
10 * isEmpty(true) => true
11 * isEmpty(1) => true
12 * isEmpty([1, 2, 3]) => false
13 * isEmpty('abc') => false
14 * isEmpty({ a: 1 }) => false
15 */
16 if (isNil(value)) {
17 return true;
18 }
19 if (isArrayLike(value)) {
20 return !value.length;
21 }
22 var type = getType(value);
23 if (type === 'Map' || type === 'Set') {
24 return !value.size;
25 }
26 if (isPrototype(value)) {
27 return !Object.keys(value).length;
28 }
29 for (var key in value) {
30 if (hasOwnProperty.call(value, key)) {
31 return false;
32 }
33 }
34 return true;
35}
36export default isEmpty;
37//# sourceMappingURL=is-empty.js.map
\No newline at end of file