bbo
Version:
bbo is a utility library of zero dependencies for javascript.
37 lines (31 loc) • 932 B
JavaScript
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 isDate from './is_date.js';
import isEmpty from './is_empty.js';
import properObject from './proper_object.js';
var updatedDiff = (lhs, rhs) => {
if (lhs === rhs) return {};
if (!isObject(lhs) || !isObject(rhs)) return rhs;
var l = properObject(lhs);
var r = properObject(rhs);
if (isDate(l) || isDate(r)) {
// eslint-disable-next-line eqeqeq
if (l.valueOf() == r.valueOf()) return {};
return r;
}
return Object.keys(r).reduce((acc, key) => {
if (l.hasOwnProperty(key)) {
var difference = updatedDiff(l[key], r[key]);
if (isObject(difference) && isEmpty(difference) && !isDate(difference)) return acc;
return { ...acc,
[key]: difference
};
}
return acc;
}, {});
};
export default updatedDiff;