mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-05 06:26:08 +00:00
fix(common): Options merge side effect
This commit is contained in:
parent
d05a89b064
commit
75401227ca
@ -23,25 +23,28 @@ export const Options = <T = any>(defaults: any, ...options: any[]): T => {
|
|||||||
|
|
||||||
const source = options.shift();
|
const source = options.shift();
|
||||||
|
|
||||||
if (isObject(defaults) && isPlainObject(source)) {
|
// This prevents default options from being intercepted by `Object.assign`
|
||||||
|
const $ = { ...defaults };
|
||||||
|
|
||||||
|
if (isObject($) && isPlainObject(source)) {
|
||||||
Object.entries(source).forEach(([key, value]) => {
|
Object.entries(source).forEach(([key, value]) => {
|
||||||
if (typeof value === 'undefined') {
|
if (typeof value === 'undefined') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPlainObject(value)) {
|
if (isPlainObject(value)) {
|
||||||
if (!(key in defaults)) {
|
if (!(key in $)) {
|
||||||
Object.assign(defaults, { [key]: {} });
|
Object.assign($, { [key]: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
Options(defaults[key], value);
|
Options($[key], value);
|
||||||
} else {
|
} else {
|
||||||
Object.assign(defaults, { [key]: value });
|
Object.assign($, { [key]: value });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return Options(defaults, ...options);
|
return Options($, ...options);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Convert a camelCase object to snake_case.
|
* Convert a camelCase object to snake_case.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user