aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/utilities/language-untilities.ts
blob: 944346655667bc4a052069c16d8e635a940dcef6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export function nullIfUndefined<T>(value: T | undefined): T | null {
  return value === undefined ? null : value;
}

export function throwIfNullOrUndefined<T>(value: T | null | undefined,
  message: string | (() => string) = 'Value mustn\'t be null or undefined'): T | never {
  if (value === null || value === undefined) {
    throw new Error(typeof message === 'string' ? message : message());
  } else {
    return value;
  }
}

export function repeat(time: number, action: (index?: number) => void) {
  for (let i = 0; i < time; i++) {
    action(i);
  }
}