export function validateString(value: any) {
  if (!(typeof value === 'string')) {
    throw new Error("Not a string: " + JSON.stringify(value));
  }
  return value;
}

export function validateBoolean(value: any) {
  if (!(typeof value === 'boolean')) {
    throw new Error("Not a boolean: " + JSON.stringify(value));
  }
  return value;
}

export function validateDate(value: any): Date {
  const date = new Date(Date.parse(validateString(value)));
  if (!date) {
    throw new Error("Not a date: " + JSON.stringify(value));
  }
  return date;
}

export function orNull<T, R>(t: T | null | undefined, map: (t: T) => R): R | null {
  if (t === null || t === undefined) {
    return null;
  }
  return map(t);
}
