@anglefeint/astro-theme 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ export type DeepPartial<T> = {
2
+ [K in keyof T]?: T[K] extends Array<infer U>
3
+ ? Array<DeepPartial<U>>
4
+ : T[K] extends object
5
+ ? DeepPartial<T[K]>
6
+ : T[K];
7
+ };
8
+
9
+ export function isPlainObject(value: unknown): value is Record<string, unknown> {
10
+ return Object.prototype.toString.call(value) === '[object Object]';
11
+ }
12
+
13
+ export function deepMerge<T>(base: T, override: DeepPartial<T>): T {
14
+ if (!isPlainObject(base) || !isPlainObject(override)) return (override as T) ?? base;
15
+
16
+ const result: Record<string, unknown> = { ...(base as Record<string, unknown>) };
17
+ for (const [key, value] of Object.entries(override)) {
18
+ if (value === undefined) continue;
19
+ const existing = result[key];
20
+ if (Array.isArray(value)) {
21
+ result[key] = value;
22
+ continue;
23
+ }
24
+ if (isPlainObject(existing) && isPlainObject(value)) {
25
+ result[key] = deepMerge(existing, value);
26
+ continue;
27
+ }
28
+ result[key] = value;
29
+ }
30
+ return result as T;
31
+ }