Skip to content

Open-source status page, incident response and uptime monitoring

624 B
Raw Blame
import { z } from "@hono/zod-openapi";
import { ZodError } from "zod";

export const isoDate = z.preprocess((val) => {
  try {
    if (val) {
      return new Date(String(val)).toISOString();
    }
    return new Date().toISOString();
  } catch (_e) {
    throw new ZodError([
      {
        code: "invalid_type",
        message: "Invalid date",
        expected: "string",
        path: [],
      },
    ]);
  }
}, z.string());

export function isNumberArray<T>(
  monitors: number[] | T[],
): monitors is number[] {
  return (
    Array.isArray(monitors) &&
    monitors.every((item) => typeof item === "number")
  );
}