isEmpty.js 639 B

123456789101112131415161718
  1. import getLength from './_getLength.js';
  2. import isArray from './isArray.js';
  3. import isString from './isString.js';
  4. import isArguments from './isArguments.js';
  5. import keys from './keys.js';
  6. // Is a given array, string, or object empty?
  7. // An "empty" object has no enumerable own-properties.
  8. export default function isEmpty(obj) {
  9. if (obj == null) return true;
  10. // Skip the more expensive `toString`-based type checks if `obj` has no
  11. // `.length`.
  12. var length = getLength(obj);
  13. if (typeof length == 'number' && (
  14. isArray(obj) || isString(obj) || isArguments(obj)
  15. )) return length === 0;
  16. return getLength(keys(obj)) === 0;
  17. }