Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function walk(doc, tokens) {
const length = tokens.length;
let i = 0;
let target = doc;
let token;
while (i < length - 1) {
token = tokens[i++];
if (Array.isArray(target)) validArrayToken(token, target.length);
else if (typeof target !== OBJECT || target === null)
throw new Error("Cannot be walked");
target = target[token];
}
token = tokens[i];
if (Array.isArray(target)) validArrayToken(token, target.length);
else if (typeof target !== OBJECT || target === null)
throw new Error("Invalid target");
return [token, target];
};