UNPKG

731 BJavaScriptView Raw
1'use strict';
2
3const isDefiningProjection = require('./isDefiningProjection');
4
5/*!
6 * Determines if `path` is excluded by `projection`
7 *
8 * @param {Object} projection
9 * @param {string} path
10 * @return {Boolean}
11 */
12
13module.exports = function isPathExcluded(projection, path) {
14 if (path === '_id') {
15 return projection._id === 0;
16 }
17
18 const paths = Object.keys(projection);
19 let type = null;
20
21 for (const _path of paths) {
22 if (isDefiningProjection(projection[_path])) {
23 type = projection[path] === 1 ? 'inclusive' : 'exclusive';
24 break;
25 }
26 }
27
28 if (type === 'inclusive') {
29 return projection[path] !== 1;
30 }
31 if (type === 'exclusive') {
32 return projection[path] === 0;
33 }
34 return false;
35};