taron133
2020-10-26 aa8d874c8a3287d41d26566ae32b6ed8d4557ff9
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
export function startsWith(value, prefix) {
  return value.lastIndexOf(prefix, 0) === 0;
};
 
export function isFunction(value) {
  if (value === undefined || value === null) {
    return false;
  }
  return typeof value === 'function';
};
 
export function log(level, args) {
  if (global.console) {
    const logger = global.console[level];
 
    if (isFunction(logger)) {
      logger.apply(global.console, args);
    }
  }
};
 
export function backoff(step, min, max) {
  const jitter = 0.5 * Math.random();
  const interval = Math.min(max, min * Math.pow(2, step + 1));
 
  return Math.floor((1 - jitter) * interval);
};
 
export function errorExists(data) {
  return 'error' in data && data.error !== null;
};
 
export function extend(a, b) {
  for (const key in b) {
    if (b.hasOwnProperty(key)) {
      a[key] = b[key];
    }
  }
  return a;
};