isEmpty.js 626 B

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