UNPKG

@hookform/resolvers

Version:

React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox, arktype, Typanion, Effect-TS and VineJS

3 lines (2 loc) 1.35 kB
import{toNestErrors as e,validateFieldsNatively as s}from"@hookform/resolvers";import{getDotPath as t}from"@standard-schema/utils";function o(){return o=Object.assign?Object.assign.bind():function(e){for(var s=1;s<arguments.length;s++){var t=arguments[s];for(var o in t)({}).hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},o.apply(null,arguments)}const n=Symbol("Schema root");function r(e,s){s&&(e.message=e.message?`${e.message}\n${s}`:s)}function a(a,i,c={}){return async(i,l,u)=>{let f=a["~standard"].validate(i);if(f instanceof Promise&&(f=await f),f.issues){const s=function(e,s){const a=new Map;for(let i=0;i<e.length;i++){const c=e[i],l=t(c)||n,u=a.get(l);if(u?l===n&&r(u,c.message):a.set(l,{message:c.message,type:""}),s){const e=a.get(l),s=e.types||{};e.types=o({},s,{[Object.keys(s).length]:c.message})}}const i={};for(const[e,s]of a)e!==n&&(i[e]=s);const c=a.get(n);return c&&(i.root?(r(i.root,c.message),function(e,s){if(!s)return;const t=e.types||{};for(const e of Object.values(s))t[Object.keys(t).length]=e;e.types=t}(i.root,c.types)):i.root=c),i}(f.issues,!u.shouldUseNativeValidation&&"all"===u.criteriaMode);return{values:{},errors:e(s,u)}}return u.shouldUseNativeValidation&&s({},u),{values:c.raw?Object.assign({},i):f.value,errors:{}}}}export{a as standardSchemaResolver}; //# sourceMappingURL=standard-schema.modern.mjs.map