Files
medusa-store/packages/admin/admin-shared/src/utils/deep-merge.ts
Leonardo Benini 226984cf0f feat(admin-*,dashboard): add dashboard i18n extensions (#13763)
* virtual i18n module

* changeset

* fallback ns

fallback to the default "translation" ns if the key isnt found. Allows to use a single "useTranslation("customNs")" hook for both custom and medusa-provided keys

* simplify merges

* optional for backward compat

* fix HMR

* fix generated deepMerge

* test
2025-10-23 15:16:43 -04:00

27 lines
649 B
TypeScript

import { isObject } from "./is-object"
export function deepMerge(target: any, source: any) {
const recursive = (a:any, b:any) => {
if (!isObject(a)) {
return b
}
if (!isObject(b)) {
return a
}
Object.keys(b).forEach((key) => {
if (isObject((b as any)[key])) {
(a as any)[key] ??= {};
(a as any)[key] = deepMerge((a as any)[key], (b as any)[key])
} else {
(a as any)[key] = (b as any)[key]
}
})
return a
}
const copy = { ...target }
return recursive(copy, source)
}