MCPcopy Create free account
hub / github.com/mswjs/interceptors / cloneObject

Function cloneObject

src/utils/cloneObject.ts:17–36  ·  view source on GitHub ↗
(
  obj: ObjectType
)

Source from the content-addressed store, hash-verified

15}
16
17export function cloneObject<ObjectType extends Record<string, any>>(
18 obj: ObjectType
19): ObjectType {
20 logger.info('cloning object:', obj)
21
22 const enumerableProperties = Object.entries(obj).reduce<Record<string, any>>(
23 (acc, [key, value]) => {
24 logger.info('analyzing key-value pair:', key, value)
25
26 // Recursively clone only plain objects, omitting class instances.
27 acc[key] = isPlainObject(value) ? cloneObject(value) : value
28 return acc
29 },
30 {}
31 )
32
33 return isPlainObject(obj)
34 ? enumerableProperties
35 : Object.assign(Object.getPrototypeOf(obj), enumerableProperties)
36}

Callers 2

resolveRequestOptionsFunction · 0.90

Calls 1

isPlainObjectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…