@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) • 3.15 kB
JavaScript
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@hookform/resolvers"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form"],e):e((r||self).hookformResolversZod={},r.hookformResolvers,r.ReactHookForm)}(this,function(r,e,o){function n(){return n=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var n in o)({}).hasOwnProperty.call(o,n)&&(r[n]=o[n])}return r},n.apply(null,arguments)}function t(r,e){try{var o=r()}catch(r){return e(r)}return o&&o.then?o.then(void 0,e):o}function s(r,e){for(var n={};r.length;){var t=r[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("unionErrors"in t){var u,l,c=t.unionErrors.reduce(function(r,e){return e.errors.length<r.errors.length?e:r}).errors[0];n[a]={message:null!=(u=null==c?void 0:c.message)?u:i,type:null!=(l=null==c?void 0:c.code)?l:s}}else n[a]={message:i,type:s};if("unionErrors"in t&&t.unionErrors.forEach(function(e){return e.errors.forEach(function(e){return r.push(e)})}),e){var f=n[a].types,d=f&&f[t.code];n[a]=o.appendErrors(a,e,n,s,d?[].concat(d,t.message):t.message)}r.shift()}return n}function i(r,e){for(var t={},s=function(){var s=r[0],i=s.code,a=s.message,u=s.path.join(".");if(!t[u])if("invalid_union"===s.code&&s.errors.length>0){var l,c,f=s.errors.reduce(function(r,e){return e.length<r.length?e:r})[0];t[u]={message:null!=(l=null==f?void 0:f.message)?l:a,type:null!=(c=null==f?void 0:f.code)?c:i}}else t[u]={message:a,type:i};if("invalid_union"===s.code&&s.errors.forEach(function(e){return e.forEach(function(e){return r.push(n({},e,{path:[].concat(s.path,e.path)}))})}),e){var d=t[u].types,h=d&&d[s.code];t[u]=o.appendErrors(u,e,t,i,h?[].concat(h,s.message):s.message)}r.shift()};r.length;)s();return t}r.zodResolver=function(r,o,n){if(void 0===n&&(n={}),function(r){return"_zod"in r&&"object"==typeof r._zod}(r))return function(s,a,u){try{return Promise.resolve(t(function(){function t(r){return u.shouldUseNativeValidation&&e.validateFieldsNatively({},u),{errors:{},values:n.raw?Object.assign({},s):r}}var i=r;return"sync"===n.mode?t(i.parse(s,o)):Promise.resolve(i.parseAsync(s,o)).then(t)},function(r){if(function(r){var e;return!(null==r||null==(e=r._zod)||null==(e=e.traits)||!e.has("$ZodError"))}(r))return{values:{},errors:e.toNestErrors(i(r.issues,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw r}))}catch(r){return Promise.reject(r)}};if(function(r){return"_def"in r&&"object"==typeof r._def}(r))return function(i,a,u){try{return Promise.resolve(t(function(){return Promise.resolve(r["sync"===n.mode?"parse":"parseAsync"](i,o)).then(function(r){return u.shouldUseNativeValidation&&e.validateFieldsNatively({},u),{errors:{},values:n.raw?Object.assign({},i):r}})},function(r){if(function(r){return Array.isArray(null==r?void 0:r.issues)}(r))return{values:{},errors:e.toNestErrors(s(r.errors,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw r}))}catch(r){return Promise.reject(r)}};throw new Error("Invalid input: not a Zod schema")}});
//# sourceMappingURL=zod.umd.js.map