isEmpty.js 669 B

1234567891011121314151617181920
  1. var _getLength = require('./_getLength.js');
  2. var isArray = require('./isArray.js');
  3. var isString = require('./isString.js');
  4. var isArguments = require('./isArguments.js');
  5. var keys = require('./keys.js');
  6. // Is a given array, string, or object empty?
  7. // An "empty" object has no enumerable own-properties.
  8. 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. }
  18. module.exports = isEmpty;