-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (47 loc) · 1.37 KB
/
index.js
File metadata and controls
50 lines (47 loc) · 1.37 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
utils = {
/**
* Used to create a copy of any existing JSON object
* @param {ref} object any type of object
*/
cloneObject(object) {
let clone = {};
for (let property in object) {
if (Array.isArray(object[property])) {
clone[property] = utils.cloneArray(object[property]);
} else if (object[property] !== null && typeof(object[property]) === 'object') {
clone[property] = utils.cloneObject(object[property])
} else {
clone[property] = object[property];
}
}
return clone;
},
/**
* Used to create a copy of any existing JSON array
* @param {ref} array any type of array
*/
cloneArray(array) {
let clone = [];
if (array.length === 0) {
return clone;
}
for (let i = 0; i < array.length; i++) {
if (Array.isArray(array[i])) {
clone[i] = utils.cloneArray(array[i]);
} else {
if (array[i] !== null && typeof(array[i]) === 'object') {
clone[i] = utils.cloneObject(array[i]);
} else {
clone[i] = array[i];
}
}
}
return clone;
}
};
lib = {
clone: obj => {
return utils.cloneObject(obj);
}
};
module.exports = lib;