UNPKG

@transkripid/flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS - Transkrip.id fork

1 lines 1.85 kB
{"version":3,"file":"merge-deep.mjs","sources":["../../src/helpers/merge-deep.ts"],"sourcesContent":["import { cloneDeep } from './clone-deep';\nimport { isObject } from './is-object';\n\n/**\n * Merge and deep copy the values of all of the enumerable own properties of target object from source object to a new object\n * @param target The target object to get properties from.\n * @param source The source object from which to copy properties.\n * @return A new merged and deep copied object.\n */\nexport function mergeDeep<T extends object, S extends object>(target: T, source: S): T & S {\n if (isObject(source) && Object.keys(source).length === 0) {\n return cloneDeep({ ...target, ...source });\n }\n\n const output = { ...target, ...source };\n\n if (isObject(source) && isObject(target)) {\n for (const key in source) {\n if (isObject(source[key]) && key in target && isObject(target[key])) {\n (output as Record<string, unknown>)[key] = mergeDeep(target[key] as object, source[key] as object);\n } else {\n (output as Record<string, unknown>)[key] = isObject(source[key]) ? cloneDeep(source[key]) : source[key];\n }\n }\n }\n\n return output;\n}\n"],"names":["mergeDeep","target","source","isObject","Object","keys","length","cloneDeep","output","key"],"mappings":";;AASgBA,SAAAA,EAA8CC,GAAWC,GAAkB;AACrFC,MAAAA,EAASD,CAAM,KAAKE,OAAOC,KAAKH,CAAM,EAAEI,WAAW;AACrD,WAAOC,EAAU;AAAA,MAAE,GAAGN;AAAAA,MAAQ,GAAGC;AAAAA,IAAAA,CAAQ;AAG3C,QAAMM,IAAS;AAAA,IAAE,GAAGP;AAAAA,IAAQ,GAAGC;AAAAA,EAAAA;AAE/B,MAAIC,EAASD,CAAM,KAAKC,EAASF,CAAM;AACrC,eAAWQ,KAAOP;AACZC,MAAAA,EAASD,EAAOO,CAAG,CAAC,KAAKA,KAAOR,KAAUE,EAASF,EAAOQ,CAAG,CAAC,IAC/DD,EAAmCC,CAAG,IAAIT,EAAUC,EAAOQ,CAAG,GAAaP,EAAOO,CAAG,CAAY,IAEjGD,EAAmCC,CAAG,IAAIN,EAASD,EAAOO,CAAG,CAAC,IAAIF,EAAUL,EAAOO,CAAG,CAAC,IAAIP,EAAOO,CAAG;AAKrGD,SAAAA;AACT;"}