File size: 552 Bytes
7aec436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const deepClone = (obj) => {
  if (obj instanceof Blob) {
    return obj;
  }
  if (Array.isArray(obj)) {
    const result = [];
    for (const value of obj) {
      result.push(deepClone(value));
    }
    return result;
  }
  if (obj && typeof obj === 'object') {
    // TODO: there's probably some prototype pollution in here
    const result = {};
    for (const key of Object.keys(obj)) {
      result[key] = deepClone(obj[key]);
    }
    return result;
  }
  // Primitive type
  return obj;
};

export default deepClone;