Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

379 B
Raw Blame
import type { CoercibleDate } from './date.types';

export function coerceDate(date: CoercibleDate): Date {
  if (date instanceof Date) {
    return date;
  }

  if (typeof date === 'string' || typeof date === 'number') {
    return new Date(date);
  }

  throw new Error(
    `Invalid date: expected Date, string, or number, but received value of type "${typeof date}"`,
  );
}