fix: make v2 with modules run (#6636)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user