mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-24 17:49:18 +02:00
some progress
This commit is contained in:
parent
aea93a5527
commit
e3c15bd288
1388 changed files with 306946 additions and 68323 deletions
40
node_modules/mongoose/lib/helpers/projection/hasIncludedChildren.js
generated
vendored
Normal file
40
node_modules/mongoose/lib/helpers/projection/hasIncludedChildren.js
generated
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* Creates an object that precomputes whether a given path has child fields in
|
||||
* the projection.
|
||||
*
|
||||
* #### Example:
|
||||
*
|
||||
* const res = hasIncludedChildren({ 'a.b.c': 0 });
|
||||
* res.a; // 1
|
||||
* res['a.b']; // 1
|
||||
* res['a.b.c']; // 1
|
||||
* res['a.c']; // undefined
|
||||
*
|
||||
* @param {Object} fields
|
||||
* @api private
|
||||
*/
|
||||
|
||||
module.exports = function hasIncludedChildren(fields) {
|
||||
const hasIncludedChildren = {};
|
||||
const keys = Object.keys(fields);
|
||||
|
||||
for (const key of keys) {
|
||||
if (key.indexOf('.') === -1) {
|
||||
hasIncludedChildren[key] = 1;
|
||||
continue;
|
||||
}
|
||||
const parts = key.split('.');
|
||||
let c = parts[0];
|
||||
|
||||
for (let i = 0; i < parts.length; ++i) {
|
||||
hasIncludedChildren[c] = 1;
|
||||
if (i + 1 < parts.length) {
|
||||
c = c + '.' + parts[i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hasIncludedChildren;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue