lookupLocalFields.js 529 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. module.exports = function lookupLocalFields(cur, path, val) {
  3. if (cur == null) {
  4. return cur;
  5. }
  6. if (cur._doc != null) {
  7. cur = cur._doc;
  8. }
  9. if (arguments.length >= 3) {
  10. if (typeof cur !== 'object') {
  11. return void 0;
  12. }
  13. cur[path] = val;
  14. return val;
  15. }
  16. // Support populating paths under maps using `map.$*.subpath`
  17. if (path === '$*') {
  18. return cur instanceof Map ?
  19. Array.from(cur.values()) :
  20. Object.keys(cur).map(key => cur[key]);
  21. }
  22. return cur[path];
  23. };