All files / src/utils helpers.ts

71.42% Statements 25/35
82.35% Branches 14/17
64.28% Functions 9/14
82.14% Lines 23/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  7x 9x 9x 9x   18x 9x     7x 7x 7x 7x 7x   9x 9x       28x 28x         4x 4x   8x 8x  
export default async function wait(time: number) {
  await new Promise((r) => setTimeout(r, time));
}
 
export function addTime(value: number, unit: TimeUnit, start?: Date) {
  let addedValue = value;
 
  switch (unit) {
    case 's':
      addedValue *= 1000;
      break;
    case 'm':
      addedValue *= 60 * 1000;
      break;
    case 'h':
      addedValue *= 60 * 60 * 1000;
      break;
    case 'd':
      addedValue *= 24 * 60 * 60 * 1000;
      break;
  }
  const initValue = start ? start.getTime() : Date.now();
  return new Date(initValue + addedValue);
}

export function kebabCase(value: string) {
  return value.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
}
 
export function camelCase(value: string) {
  return value.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
}