feat: add autoConfig/ better types for wrapperData

This commit is contained in:
BluJ
2023-04-19 17:23:16 -06:00
parent 7c4f94ba8f
commit e279711f8e
39 changed files with 431 additions and 291 deletions

16
lib/util/deepMerge.ts Normal file
View 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;
}