UNPKG

adverich-kun-ui

Version:

Una librería de componentes Vue.js con Tailwind CSS

32 lines (31 loc) 921 B
import { ref as f, watch as d } from "vue"; function g(e, o) { const i = f(!0), u = f([]); function c(t) { const a = e.rules || [], n = []; for (const s of a) if (typeof s == "function") { const l = s(t); typeof l == "string" ? n.push(l) : l === !1 && n.push("Campo inválido"); } else typeof s == "string" ? n.push(s) : s === !1 && n.push("Campo inválido"); return n; } const r = () => { const t = e.validationValue !== void 0 ? e.validationValue : o.value, a = c(t); return u.value = a.slice(0, Number(e.maxErrors ?? 1)), i.value = a.length === 0, i.value; }, v = () => { u.value = [], i.value = !0; }; return d(o, () => { var t; (e.validateOn === "input" || (t = e.validateOn) != null && t.includes("input")) && r(); }), { errorMessages: u, isValid: i, validate: r, resetValidation: v }; } export { g as useValidation };