superjson-temporal
Version:
SuperJSON serializers/deserializers for Temporal types.
44 lines • 1.97 kB
JavaScript
import { Temporal } from "temporal-polyfill";
export const registerSuperJSONTemporal = (superjson) => {
superjson.registerCustom({
isApplicable: (v) => v instanceof Temporal.ZonedDateTime,
serialize: (v) => v.toJSON(),
deserialize: (raw) => Temporal.ZonedDateTime.from(raw),
}, "Temporal.ZonedDateTime");
superjson.registerCustom({
isApplicable: (v) => v instanceof Temporal.PlainTime,
serialize: (v) => v.toJSON(),
deserialize: (raw) => Temporal.PlainTime.from(raw),
}, "Temporal.PlainTime");
superjson.registerCustom({
isApplicable: (v) => v instanceof Temporal.PlainMonthDay,
serialize: (v) => v.toJSON(),
deserialize: (raw) => Temporal.PlainMonthDay.from(raw),
}, "Temporal.PlainMonthDay");
superjson.registerCustom({
isApplicable: (v) => v instanceof Temporal.PlainYearMonth,
serialize: (v) => v.toJSON(),
deserialize: (raw) => Temporal.PlainYearMonth.from(raw),
}, "Temporal.PlainYearMonth");
superjson.registerCustom({
isApplicable: (v) => v instanceof Temporal.PlainDate,
serialize: (v) => v.toJSON(),
deserialize: (raw) => Temporal.PlainDate.from(raw),
}, "Temporal.PlainDate");
superjson.registerCustom({
isApplicable: (v) => v instanceof Temporal.PlainDateTime,
serialize: (v) => v.toJSON(),
deserialize: (raw) => Temporal.PlainDateTime.from(raw),
}, "Temporal.PlainDateTime");
superjson.registerCustom({
isApplicable: (v) => v instanceof Temporal.Duration,
serialize: (v) => v.toJSON(),
deserialize: (raw) => Temporal.Duration.from(raw),
}, "Temporal.Duration");
superjson.registerCustom({
isApplicable: (v) => v instanceof Temporal.Instant,
serialize: (v) => v.toJSON(),
deserialize: (raw) => Temporal.Instant.from(raw),
}, "Temporal.Instant");
};
//# sourceMappingURL=registerSuperJSONTemporal.js.map