Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getIn(schema, path, value, context) {
let parent, lastPart, lastPartDebug;
// if only one "value" arg then use it for both
context = context || value;
if (!path)
return {
parent,
parentPath: path,
schema,
};
forEach(path, (_part, isBracket, isArray) => {
let part = isBracket ? trim(_part) : _part;
if (isArray || has(schema, '_subType')) {
// we skipped an array: foo[].bar
let idx = isArray ? parseInt(part, 10) : 0;
schema = schema.resolve({ context, parent, value })._subType;
if (value) {
if (isArray && idx >= value.length) {
throw new Error(
`Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. ` +
`because there is no value at that index. `,
);
}
function getIn(schema, path, value, context) {
let parent, lastPart, lastPartDebug;
context = context || value;
if (!path)
return {
parent,
parentPath: path,
schema
};
forEach(path, (_part, isBracket, isArray) => {
let part = isBracket ? trim(_part) : _part;
if (isArray || has(schema, "_subType")) {
let index = isArray ? parseInt(part, 10) : 0;
schema = schema.resolve({ context, parent, value })._subType;
if (value) {
value = value[index];
}
}
if (!isArray) {
schema = schema.resolve({ context, parent, value });
schema = schema.fields[part];
parent = value;
value = value && value[part];
lastPart = part;