fix: make v2 with modules run (#6636)

This commit is contained in:
Sebastian Rindom
2024-03-09 15:09:06 +00:00
committed by GitHub
parent c2d56ca12b
commit a838ebae1b
10 changed files with 43 additions and 39 deletions
-5
View File
@@ -3,17 +3,12 @@ import { isObject } from "./is-object"
/**
* In most casees, JSON.parse(JSON.stringify(obj)) is enough to deep copy an object.
* But in some cases, it's not enough. For example, if the object contains a function or a proxy, it will be lost after JSON.parse(JSON.stringify(obj)).
* Furthermore, structuredClone is not present in all environments, such as with jest so we need to use a custom deepCopy function.
*
* @param obj
*/
export function deepCopy<T extends Record<any, any> = Record<any, any>>(
obj: T | T[]
): T | T[] {
if (typeof structuredClone != "undefined") {
return structuredClone(obj)
}
if (obj === null || typeof obj !== "object") {
return obj
}