is-empty.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var is_nil_1 = require("./is-nil");
  4. var is_array_like_1 = require("./is-array-like");
  5. var get_type_1 = require("./get-type");
  6. var is_prototype_1 = require("./is-prototype");
  7. var hasOwnProperty = Object.prototype.hasOwnProperty;
  8. function isEmpty(value) {
  9. /**
  10. * isEmpty(null) => true
  11. * isEmpty() => true
  12. * isEmpty(true) => true
  13. * isEmpty(1) => true
  14. * isEmpty([1, 2, 3]) => false
  15. * isEmpty('abc') => false
  16. * isEmpty({ a: 1 }) => false
  17. */
  18. if (is_nil_1.default(value)) {
  19. return true;
  20. }
  21. if (is_array_like_1.default(value)) {
  22. return !value.length;
  23. }
  24. var type = get_type_1.default(value);
  25. if (type === 'Map' || type === 'Set') {
  26. return !value.size;
  27. }
  28. if (is_prototype_1.default(value)) {
  29. return !Object.keys(value).length;
  30. }
  31. for (var key in value) {
  32. if (hasOwnProperty.call(value, key)) {
  33. return false;
  34. }
  35. }
  36. return true;
  37. }
  38. exports.default = isEmpty;
  39. //# sourceMappingURL=is-empty.js.map