-
Notifications
You must be signed in to change notification settings - Fork 0
/
helperFunctions.ts
57 lines (48 loc) · 1.28 KB
/
helperFunctions.ts
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
51
52
53
54
55
56
57
import { CONFIG } from "./config";
import { ObjectT } from "./types";
export function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export const stringifyIfNotString = (data: any) => {
if (typeof data === "string") {
data = data.replace(/'/g, `"`).replace(/\s/g, "");
return data;
}
return JSON.stringify(data);
}
const memo = {
warn: {
data: "",
identicalInARow: 0
}
}
export const codebudConsoleWarn = (...data: any[]) => {
const dataStr = JSON.stringify(data);
if (dataStr === memo.warn.data) {
if (memo.warn.identicalInARow++ < CONFIG.MAX_IDENTICAL_CONSOLE_WARNINGS_IN_A_ROW)
console.warn(`${CONFIG.PRODUCT_NAME}:`, ...data);
} else {
memo.warn.data = dataStr;
memo.warn.identicalInARow = 1;
console.warn(`${CONFIG.PRODUCT_NAME}:`, ...data);
}
}
export const codebudConsoleLog = (...data: any[]) => {
console.log(`${CONFIG.PRODUCT_NAME}:`, ...data);
}
// @ts-ignore
export const emptyMiddleware = () => next => action => {
return next(action);
}
export const jsonStringifyKeepMethods = (data: ObjectT<any>) => {
return JSON.stringify(
data,
function(key, value) {
if (typeof value === 'function') {
return "Function (...)";
} else {
return value;
}
}
);
}