UNPKG

@prismicio/types-internal

Version:
18 lines (16 loc) 403 B
import { chain } from "fp-ts/Either" import { pipe } from "fp-ts/function" import * as t from "io-ts" export default new t.Type<Date, number, unknown>( "dateFromTsMs", (u): u is Date => u instanceof Date, (u, c) => pipe( t.number.validate(u, c), chain((s) => { const d = new Date(s) return isNaN(d.getTime()) ? t.failure(u, c) : t.success(d) }), ), (date) => date.getTime(), )