Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createDeepSingleMapper(field, emit) {
var parsedField = parseField(field);
return function (doc) {
var value = doc;
for (var i = 0, len = parsedField.length; i < len; i++) {
var key = parsedField[i];
value = value[key];
if (typeof value === 'undefined') {
return; // do nothing
}
}
emit(value);
};
}
return function (doc) {
var toEmit = [];
for (var i = 0, iLen = fields.length; i < iLen; i++) {
var parsedField = parseField(fields[i]);
var value = doc;
for (var j = 0, jLen = parsedField.length; j < jLen; j++) {
var key = parsedField[j];
value = value[key];
if (typeof value === 'undefined') {
return; // don't emit
}
}
toEmit.push(value);
}
emit(toEmit);
};
}
function pick(obj, arr) {
var res = {};
for (var i = 0, len = arr.length; i < len; i++) {
var parsedField = parseField(arr[i]);
var value = getFieldFromDoc(obj, parsedField);
if (typeof value !== 'undefined') {
setFieldInDoc(res, parsedField, value);
}
}
return res;
}