-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
44 lines (39 loc) · 993 Bytes
/
utils.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
42
43
44
"use strict";
function exampleFunction(input) {
console.log("Some line of code");
if (true === false) {
return;
}
return input
.replace(new RegExp("", "g"), "")
.replace(new RegExp("", "g"), "");
}
function removeInstrumentation(input) {
return input
.replace(/\s*\$_\$wf\(\d+\);/gm, "")
.replace(/\$_\$w\(\d+, \d+\), /gm, "")
.replace(/\s+\$_\$w\(\d+, \d+\);/gm, ";")
.replace(/\$_\$tracer\.log\((.*), '', \d+, \d+\)/gm, "console.log($1)");
}
function waitForEmptyQueue() {
let promise = Promise.resolve();
let count = 5;
while (count--) {
promise = promise.then(() => Promise.resolve());
}
return promise;
}
function silenceErrorsFromThen(promise) {
const then = promise.then;
promise.then = function() {
const newPromise = then.apply(this, arguments);
newPromise.catch(() => {});
return newPromise;
};
}
module.exports = {
exampleFunction,
removeInstrumentation,
waitForEmptyQueue,
silenceErrorsFromThen
};