mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-01 11:56:48 +01:00
Add object deep merge utility function
This commit is contained in:
parent
91d54026a0
commit
a5dc2184f5
22
src/util.js
22
src/util.js
@ -196,6 +196,27 @@ async function readAllChunks(readableStream) {
|
||||
});
|
||||
}
|
||||
|
||||
function isObject(item) {
|
||||
return (item && typeof item === 'object' && !Array.isArray(item));
|
||||
}
|
||||
|
||||
function deepMerge(target, source) {
|
||||
let output = Object.assign({}, target);
|
||||
if (isObject(target) && isObject(source)) {
|
||||
Object.keys(source).forEach(key => {
|
||||
if (isObject(source[key])) {
|
||||
if (!(key in target))
|
||||
Object.assign(output, { [key]: source[key] });
|
||||
else
|
||||
output[key] = deepMerge(target[key], source[key]);
|
||||
} else {
|
||||
Object.assign(output, { [key]: source[key] });
|
||||
}
|
||||
});
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getConfig,
|
||||
getConfigValue,
|
||||
@ -205,4 +226,5 @@ module.exports = {
|
||||
getImageBuffers,
|
||||
readAllChunks,
|
||||
delay,
|
||||
deepMerge,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user