UNPKG

bbo

Version:

bbo is a utility library of zero dependencies for javascript.

30 lines (26 loc) 746 B
import isObject from './is_object.js'; import './get_tag.js'; import './is_array.js'; import './is_string.js'; import './is_map.js'; import './is_set.js'; import isEmpty from './is_empty.js'; import properObject from './proper_object.js'; var addedDiff = (lhs, rhs) => { if (lhs === rhs || !isObject(lhs) || !isObject(rhs)) return {}; var l = properObject(lhs); var r = properObject(rhs); return Object.keys(r).reduce((acc, key) => { if (l.hasOwnProperty(key)) { var difference = addedDiff(l[key], r[key]); if (isObject(difference) && isEmpty(difference)) return acc; return { ...acc, [key]: difference }; } return { ...acc, [key]: r[key] }; }, {}); }; export default addedDiff;