is-empty.js 956 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import isNil from './is-nil';
  2. import isArrayLike from './is-array-like';
  3. import getType from './get-type';
  4. import isPrototype from './is-prototype';
  5. var hasOwnProperty = Object.prototype.hasOwnProperty;
  6. function 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. }
  36. export default isEmpty;
  37. //# sourceMappingURL=is-empty.js.map