UNPKG

mobx-react-form

Version:
3 lines (2 loc) 1.08 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).MobxReactFormValidatorJOI=e()}(this,function(){"use strict";class t{promises;config;state;extend;validator;schema;constructor({config:t,state:e=null,promises:a=[]}){this.state=e,this.promises=a,this.config=t,this.extend=t?.extend,this.validator=t.package,this.schema=t.schema,this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(t){const e=this.state.form.flatMapValues,{error:a}=this.schema.validate(e,{abortEarly:!1});if(!a)return;const i=(t.path??"").split("."),s=a.details.filter(t=>{const e=t.path.join("."),a=i.join(".");return e===a||e.startsWith(`${a}.`)}).map(t=>{const e=t.context?.label||t.path.join(".");return t.message.replace(`${t.path.join(".")}`,e)});s.length&&(t.validationErrorStack=s)}}return e=>({class:t,config:e})}); //# sourceMappingURL=MobxReactFormValidatorJOI.umd.min.js.map