-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(query): move selectedInclusively() into separate helper
Re: #5737
- Loading branch information
Showing
2 changed files
with
26 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
module.exports = function isInclusive(projection) { | ||
if (projection == null) { | ||
return false; | ||
} | ||
|
||
var props = Object.keys(projection); | ||
var numProps = props.length; | ||
if (numProps === 0) { | ||
return false; | ||
} | ||
|
||
for (var i = 0; i < numProps; ++i) { | ||
var prop = props[i]; | ||
// If field is truthy (1, true, etc.) and not an object, then this | ||
// projection must be inclusive. If object, assume its $meta, $slice, etc. | ||
if (typeof projection[prop] !== 'object' && !!projection[prop]) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}; |