Spaces:
Sleeping
Sleeping
File size: 787 Bytes
7aec436 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
const type = (obj) => {
if (obj === null) return 'null';
if (Array.isArray(obj)) return 'array';
if (typeof Blob !== 'undefined' && obj instanceof Blob) return 'blob';
return typeof obj;
};
const merge = (into, from) => {
const typeInto = type(into);
const typeFrom = type(from);
if (from === null && typeInto === 'blob') {
return into;
}
if (typeInto !== typeFrom || typeInto === 'undefined') {
return from;
}
if (typeInto === 'object') {
for (const key of Object.keys(from)) {
into[key] = merge(into[key], from[key]);
}
for (const key of Object.keys(into)) {
if (!Object.prototype.hasOwnProperty.call(from, key)) {
delete into[key];
}
}
}
return into;
};
export default merge;
|