mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-01 21:13:11 +00:00
feat: add autoConfig/ better types for wrapperData
This commit is contained in:
16
lib/util/deepMerge.ts
Normal file
16
lib/util/deepMerge.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { object } from "ts-matches";
|
||||
|
||||
export function deepMerge(...args: unknown[]): unknown {
|
||||
const lastItem = (args as any)[args.length - 1];
|
||||
if (!object.test(lastItem)) return lastItem;
|
||||
const objects = args.filter(object.test).filter((x) => !Array.isArray(x));
|
||||
if (objects.length === 0) return lastItem as any;
|
||||
const allKeys = new Set(objects.flatMap((x) => Object.keys(x)));
|
||||
for (const key of allKeys) {
|
||||
const filteredValues = objects.flatMap((x) =>
|
||||
key in x ? [(x as any)[key]] : [],
|
||||
);
|
||||
(objects as any)[0][key] = deepMerge(...filteredValues);
|
||||
}
|
||||
return objects[0] as any;
|
||||
}
|
||||
Reference in New Issue
Block a user