MCPcopy Create free account
hub / github.com/Automattic/mongoose / scopePaths

Function scopePaths

lib/schema/documentarray.js:350–379  ·  view source on GitHub ↗
(array, fields, init)

Source from the content-addressed store, hash-verified

348 */
349
350function scopePaths(array, fields, init) {
351 if (!(init && fields)) {
352 return undefined;
353 }
354
355 var path = array.path + '.';
356 var keys = Object.keys(fields);
357 var i = keys.length;
358 var selected = {};
359 var hasKeys;
360 var key;
361 var sub;
362
363 while (i--) {
364 key = keys[i];
365 if (key.indexOf(path) === 0) {
366 sub = key.substring(path.length);
367 if (sub === '$') {
368 continue;
369 }
370 if (sub.indexOf('$.') === 0) {
371 sub = sub.substr(2);
372 }
373 hasKeys || (hasKeys = true);
374 selected[sub] = fields[key];
375 }
376 }
377
378 return hasKeys && selected || undefined;
379}
380
381/*!
382 * Module exports.

Callers 1

documentarray.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected