MCPcopy
hub / github.com/Automattic/mongoose / _populateObj

Function _populateObj

lib/utils.js:634–669  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

632};
633
634function _populateObj(obj) {
635 if (Array.isArray(obj.populate)) {
636 const ret = [];
637 obj.populate.forEach(function(obj) {
638 if (oneSpaceRE.test(obj.path)) {
639 const copy = Object.assign({}, obj);
640 const paths = copy.path.split(manySpaceRE);
641 paths.forEach(function(p) {
642 copy.path = p;
643 ret.push(exports.populate(copy)[0]);
644 });
645 } else {
646 ret.push(exports.populate(obj)[0]);
647 }
648 });
649 obj.populate = exports.populate(ret);
650 } else if (obj.populate != null && typeof obj.populate === 'object') {
651 obj.populate = exports.populate(obj.populate);
652 }
653
654 const ret = [];
655 const paths = oneSpaceRE.test(obj.path)
656 ? obj.path.split(manySpaceRE)
657 : Array.isArray(obj.path)
658 ? obj.path
659 : [obj.path];
660 if (obj.options != null) {
661 obj.options = clone(obj.options);
662 }
663
664 for (const path of paths) {
665 ret.push(new PopulateOptions(Object.assign({}, obj, { path: path })));
666 }
667
668 return ret;
669}
670
671/**
672 * Return the value of `obj` at the given `path`.

Callers 1

utils.jsFile · 0.85

Calls 3

testMethod · 0.80
populateMethod · 0.80
cloneFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…