1import { transform, isEqual, isObject } from 'lodash';
2
3/**
4 * Deep diff between two object, using lodash
5 * @param {Object} object Object compared
6 * @param {Object} base Object to compare with
7 * @return {Object} Return a new object who represent the diff
8 */
9function difference(object, base) {
10 return transform(object, (result, value, key) => {
11 if (!isEqual(value, base[key])) {
12 result[key] = isObject(value) && isObject(base[key]) ? difference(value, base[key]) : value;
13 }
14 });
15}