Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (Array.isArray(afterValue) && Array.isArray(beforeValue)) {
const arrayBefore = beforeValue as any[]
const arrayAfter = afterValue as any[]
diff.added = arrayAfter.filter(o => !includes(arrayBefore, o))
diff.removed = arrayBefore.filter(o => !includes(arrayAfter, o))
// Do the same, but for keys inside an object if they both are objects.
} else if (isobject(afterValue) && isobject(beforeValue)) {
const beforeKeys = keys(beforeValue) as string[]
const afterKeys = keys(afterValue) as string[]
diff.added = afterKeys.filter(o => !includes(beforeKeys, o))
diff.removed = beforeKeys.filter(o => !includes(afterKeys, o))
}
jsonpointer.set(accumulator, backAStepPath, diff)
return accumulator
}, Object.create(null))
}
// If they both are arrays, add some extra metadata about what was
// added or removed. This makes it really easy to act on specific
// changes to JSON DSLs
if (Array.isArray(afterValue) && Array.isArray(beforeValue)) {
const arrayBefore = beforeValue
const arrayAfter = afterValue
diff.added = arrayAfter.filter(o => !includes(arrayBefore, o))
diff.removed = arrayBefore.filter(o => !includes(arrayAfter, o))
// Do the same, but for keys inside an object if they both are objects.
} else if (isobject(afterValue) && isobject(beforeValue)) {
const beforeKeys = keys(beforeValue)
const afterKeys = keys(afterValue)
diff.added = afterKeys.filter(o => !includes(beforeKeys, o))
diff.removed = beforeKeys.filter(o => !includes(afterKeys, o))
}
jsonpointer.set(accumulator, backAStepPath, diff)
return accumulator
}, Object.create(null))
}
update(rel, obj, data) {
return jsonPointer.set(obj, rel, data)
}