@react-form-builder/core
Version:
React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required
32 lines (31 loc) • 2.06 kB
JavaScript
import { ruleBuilder as a } from "../utils/ruleBuilder.js";
import { zodErrorParams as o, requiredMessage as l } from "./consts.js";
import * as r from "zod/mini";
import { toRuleValidator as e, stringScheme as m, pipeStringScheme as n } from "./zodRuleBuilders.js";
const d = "Invalid ip", c = {
required: a().withValidatorFactory(() => e(m, r.minLength(1, { error: l }))),
nonEmpty: a().withValidatorFactory(() => e(m, r.minLength(1))),
length: a().withParameter("length", "number", !0).withValidatorFactory(({ length: t, message: i }) => e(m, r.length(t, o(i)))),
min: a().withParameter("limit", "number", !0).withValidatorFactory(({ limit: t, message: i }) => e(m, r.minLength(t, o(i)))),
max: a().withParameter("limit", "number", !0).withValidatorFactory(({ limit: t, message: i }) => e(m, r.maxLength(t, o(i)))),
regex: a().withParameter("regex", "string", !0).withValidatorFactory(({ message: t, regex: i }) => e(m, r.regex(new RegExp(i), o(t)))),
email: a().withValidatorFactory(({ message: t }) => e(n(r.email(o(t))))),
url: a().withValidatorFactory(({ message: t }) => e(n(r.url(o(t))))),
uuid: a().withValidatorFactory(({ message: t }) => e(n(r.uuid(o(t))))),
ip: a().withValidatorFactory(() => e(n(r.union([r.ipv4(), r.ipv6()], { error: d })))),
datetime: a().withParameter("precision", "number").withParameter("offset", "boolean").withValidatorFactory(({ message: t, offset: i, precision: h }) => e(n(r.iso.datetime({
offset: i,
precision: h,
...o(t)
})))),
includes: a().withParameter("value", "string", !0).withParameter("position", "number").withValidatorFactory(({ message: t, value: i, position: h }) => e(m, r.includes(i, {
position: h,
...o(t)
}))),
startsWith: a().withParameter("value", "string", !0).withValidatorFactory(({ message: t, value: i }) => e(m, r.startsWith(i, o(t)))),
endsWith: a().withParameter("value", "string", !0).withValidatorFactory(({ message: t, value: i }) => e(m, r.endsWith(i, o(t))))
};
export {
c as ZodStringRules
};
//# sourceMappingURL=ZodStringRules.js.map