forked from Nanciee/cypress-autorecord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
41 lines (37 loc) · 1 KB
/
util.js
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
const sizeInMbytes = (obj) => {
let bytes = 0;
const sizeOf = (obj) => {
if (obj !== null && obj !== undefined) {
switch (typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
bytes += obj.length * 2;
break;
case 'boolean':
bytes += 4;
break;
case 'object':
var objClass = Object.prototype.toString.call(obj).slice(8, -1);
if (objClass === 'Object' || objClass === 'Array') {
for (var key in obj) {
if (!obj.hasOwnProperty(key)) continue;
sizeOf(obj[key]);
}
} else bytes += obj.toString().length * 2;
break;
}
}
return bytes;
};
return sizeOf(obj) / 1024;
};
const guidGenerator = () => {
const S4 = () => (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
return (S4() + S4() + S4() + S4() + S4() + S4() + S4() + S4());
};
module.exports = {
sizeInMbytes,
guidGenerator,
};