isInclusive.js 652 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var isDefiningProjection = require('./isDefiningProjection');
  3. /*!
  4. * ignore
  5. */
  6. module.exports = function isInclusive(projection) {
  7. if (projection == null) {
  8. return false;
  9. }
  10. var props = Object.keys(projection);
  11. var numProps = props.length;
  12. if (numProps === 0) {
  13. return false;
  14. }
  15. for (var i = 0; i < numProps; ++i) {
  16. var prop = props[i];
  17. // If field is truthy (1, true, etc.) and not an object, then this
  18. // projection must be inclusive. If object, assume its $meta, $slice, etc.
  19. if (isDefiningProjection(projection[prop]) && !!projection[prop]) {
  20. return true;
  21. }
  22. }
  23. return false;
  24. };