UNPKG

@react-form-builder/core

Version:

React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required

22 lines (21 loc) 1.04 kB
import { ruleBuilder as a } from "../utils/ruleBuilder.js"; import { zodErrorParams as l, errorForUndefined as w } from "./consts.js"; import * as r from "zod/mini"; import { toRuleValidator as i } from "./zodRuleBuilders.js"; const m = (t) => { const e = w(t); if (e) return e; const { code: o, origin: u, maximum: c, minimum: s } = t; if ((o === "too_small" || o === "too_big") && u === "date") { const f = o === "too_small" ? s : c, n = new Date(f).toString(); return o === "too_small" ? `Too small: expected date to be >=${n}` : `Too big: expected date to be <=${n}`; } }, d = r.date({ error: m }), g = { required: a().withValidatorFactory(() => i(d, r.refine((t) => t))), min: a().withParameter("value", "date", !0).withValidatorFactory(({ value: t, message: e }) => i(d, r.gte(new Date(t), l(e, m)))), max: a().withParameter("value", "date", !0).withValidatorFactory(({ value: t, message: e }) => i(d, r.lte(new Date(t), l(e, m)))) }; export { g as ZodDateRules }; //# sourceMappingURL=ZodDateRules.js.map