vue-tiny-validate
Advanced tools
Comparing version
import { UnknownObject } from './types'; | ||
export declare const setReactiveValue: (obj: any, key: string, value: any) => void; | ||
export declare const hasOwn: (obj: UnknownObject, key: string) => boolean; | ||
@@ -18,2 +19,3 @@ export declare const isObject: (obj: UnknownObject) => boolean; | ||
touchOnTest: boolean; | ||
transform: (value: any) => any; | ||
}; |
@@ -1,1 +0,1 @@ | ||
"use strict";var t=Object.defineProperty,e=Object.defineProperties,r=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,c=Object.prototype.propertyIsEnumerable,a=(e,r,o)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,n=(t,e)=>{for(var r in e||(e={}))s.call(e,r)&&a(t,r,e[r]);if(o)for(var r of o(e))c.call(e,r)&&a(t,r,e[r]);return t},i=(t,o)=>e(t,r(o)),u=require("vue");const f=(t,e)=>void 0!==t[e],l=t=>"[object Object]"===Object.prototype.toString.call(t),$=t=>u.isRef(t)?t.value:t,y=()=>{},p={$invalid:!1,$errors:[],$messages:[],$pending:!1},d=u.reactive({autoTest:!1,autoTouch:!1,lazy:!1,firstError:!1,touchOnTest:!1});module.exports=(t,e,r=d)=>{const o=u.reactive({}),s=u.reactive({}),c=u.reactive({}),a=u.computed((()=>v(c,o))),b=u.computed((()=>n(n({},d),$(r)))),v=(t,e)=>{const r=i(n({},p),{$dirty:!1,$test:y,$reset:y,$touch:y}),o=Object.keys(t),s={$test:[],$reset:[],$touch:[]},c=Object.keys(s),a=(t,e)=>{const r=[...Object.keys(p),"$dirty"];for(const o of r)Array.isArray(t[o])?t[o]=[...t[o],...e[o]]:!t[o]&&e[o]&&(t[o]=!0);for(const o of c)s[o].push(e[o])};for(const i of o)if(l(t[i])&&!f(t[i],"$invalid")){const o=v(t[i],e[i]);r[i]=n({},o),a(r,o)}else r[i]=n({},t[i]),r[i].$dirty=e[i],a(r,r[i]);for(const n of c)r[n]=()=>{s[n].forEach((t=>t()))};return r},O=(t,e,r,o,s)=>{const c=Object.keys(e);for(const a of c){if(l(e[a])&&!f(e[a],"$test")){o[a]={},r[a]=u.reactive({}),s[a]=u.reactive({});const c=[t[a],e[a],r[a],o[a],s[a]];return O(...c)}r[a]=!1,o[a]=t[a];const c={data:t,rules:e,dirt:r,rawData:o,entries:s};s[a]=i(n({},p),{$reset:()=>j(c,a),$test:()=>h(c,a),$touch:()=>g(c,a)}),Object.setPrototypeOf(s[a],{$uw:u.watch((()=>t[a]),(()=>{b.value.autoTest&&s[a].$test(),b.value.autoTouch&&s[a].$touch()}))})}},h=async(t,e)=>{const{data:r,rules:o,dirt:s,rawData:c,entries:a}=t,{lazy:u,firstError:f,touchOnTest:l}=b.value;if(s[e]=l||s[e]||r[e]!==c[e],u&&!s[e])return;let $=[],y=[],p=o[e];if(p){Array.isArray(p)||(p=[p]);for(const t of p){const{$test:o,$message:s=null,$key:c}=t;let n=o(r[e]);if(n instanceof Promise){a[e].$pending=!0;try{n=await n}catch(d){n=!1}a[e].$pending=!1}if(!n){const t="function"==typeof s?s(r[e]):s;if($=[...$,{name:c,message:t}],t&&y.push(t),f)break}}a[e]=i(n({},a[e]),{$errors:$,$messages:y,$invalid:Boolean($.length)})}},j=(t,e)=>{t.dirt[e]=!1,t.entries[e]=n(n({},t.entries[e]),p)},g=(t,e)=>{t.dirt[e]=!0},m=()=>{O($(t),$(e),o,s,c)};return m(),u.watch(t,m),u.watch(e,m),u.watch(r,m),{result:a}}; | ||
"use strict";var e=Object.defineProperty,t=Object.defineProperties,r=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,c=(t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,n=(e,t)=>{for(var r in t||(t={}))s.call(t,r)&&c(e,r,t[r]);if(o)for(var r of o(t))a.call(t,r)&&c(e,r,t[r]);return e},i=(e,o)=>t(e,r(o)),u=require("vue-demi");const f=(e,t,r)=>{u.isVue2?u.Vue2.set(e,t,r):e[t]=r},l=(e,t)=>void 0!==e[t],y=e=>"[object Object]"===Object.prototype.toString.call(e),$=e=>u.isRef(e)?e.value:e,p=()=>{},d={$invalid:!1,$errors:[],$messages:[],$pending:!1},v=u.reactive({autoTest:!1,autoTouch:!1,lazy:!1,firstError:!1,touchOnTest:!1,transform:e=>e});module.exports=(e,t,r=u.reactive({}))=>{const o=u.reactive({}),s=u.reactive({}),a=u.reactive({}),c=u.computed((()=>n(n({},v),$(r)))),b=u.computed((()=>{const s=m(a,o),{transform:n}=c.value;return n?n(s,$(e),$(t),$(r)):s})),m=(e,t)=>{const r=i(n({},d),{$dirty:!1,$test:p,$reset:p,$touch:p}),o=Object.keys(e),s={$test:[],$reset:[],$touch:[]},a=Object.keys(s),c=(e,t)=>{const r=[...Object.keys(d),"$dirty"];for(const o of r)Array.isArray(e[o])?e[o]=[...e[o],...t[o]]:!e[o]&&t[o]&&(e[o]=!0);for(const o of a)s[o].push(t[o])};for(const i of o)if(y(e[i])&&!l(e[i],"$invalid")){const o=m(e[i],t[i]);r[i]=n({},o),c(r,o)}else r[i]=n({},e[i]),r[i].$dirty=t[i],c(r,r[i]);for(const n of a)r[n]=()=>{if("$test"===n)return Promise.all(s[n].map((e=>e())));s[n].forEach((e=>e()))};return r},O=(e,t,r,o,s)=>{const a=Object.keys(t);for(const $ of a)if(!y(t[$])||l(t[$],"test")||l(t[$],"name")){f(r,$,!1),f(o,$,e()[$]);const a={data:e,rules:t,dirt:r,rawData:o,entries:s};f(s,$,i(n({},d),{$reset:()=>j(a,$),$test:async()=>await h(a,$),$touch:()=>g(a,$)})),Object.setPrototypeOf(s[$],{$uw:u.watch((()=>e()[$]),(()=>{c.value.autoTest&&s[$].$test(),c.value.autoTouch&&s[$].$touch()}))})}else{f(o,$,{}),f(r,$,u.reactive({})),f(s,$,u.reactive({}));const a=[()=>e()[$],t[$],r[$],o[$],s[$]];O(...a)}},h=async(o,s)=>{const{data:a,rules:l,dirt:y,rawData:p,entries:d}=o,{lazy:v,firstError:b,touchOnTest:m}=c.value;let O=!1;const h=u.watch((()=>d[s].$pending),(e=>{e||(O=!0,h())}));if(f(y,s,m||y[s]||a()[s]!==p[s]),v&&!y[s])return;let j=[],g=[],w=l[s];if(w){Array.isArray(w)||(w=[w]);for(const o of w){const{test:c,message:n=null,name:i}=o;let u=c(a()[s],$(e),$(t),$(r));if(u instanceof Promise){d[s].$pending=!0;try{u=await u}catch(P){u=!1}O||(d[s].$pending=!1)}if(!u){const e="function"==typeof n?n(a()[s]):n;if(j=[...j,{name:i,message:e}],e&&g.push(e),b)break}}O||f(d,s,i(n({},d[s]),{$errors:j,$messages:g,$invalid:Boolean(j.length)}))}},j=(e,t)=>{const{dirt:r,entries:o}=e;f(r,t,!1),f(o,t,n(n({},o[t]),d))},g=(e,t)=>{const{dirt:r}=e;f(r,t,!0)},w=()=>{O((()=>$(e)),$(t),o,s,a)};return w(),u.watch(t,w),u.watch(r,w),{result:b}}; |
@@ -1,2 +0,2 @@ | ||
import { UnwrapRef, Ref, ComputedRef } from 'vue'; | ||
import { UnwrapRef, Ref, ComputedRef } from 'vue-demi'; | ||
import { Data, Rules, Option, UseValidate } from './types'; | ||
@@ -3,0 +3,0 @@ declare const useValidate: (_data: UnwrapRef<Data> | Ref<Data> | ComputedRef<Data>, _rules: UnwrapRef<Rules> | Ref<Rules> | ComputedRef<Rules>, _option?: UnwrapRef<Option> | Ref<Option> | ComputedRef<Option>) => UseValidate; |
@@ -1,1 +0,1 @@ | ||
var t=Object.defineProperty,e=Object.defineProperties,r=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,a=(e,r,o)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,c=(t,e)=>{for(var r in e||(e={}))s.call(e,r)&&a(t,r,e[r]);if(o)for(var r of o(e))n.call(e,r)&&a(t,r,e[r]);return t},i=(t,o)=>e(t,r(o));import{reactive as f,isRef as u,computed as l,watch as $}from"vue";const y=(t,e)=>void 0!==t[e],p=t=>"[object Object]"===Object.prototype.toString.call(t),b=t=>u(t)?t.value:t,d=()=>{},O={$invalid:!1,$errors:[],$messages:[],$pending:!1},h=f({autoTest:!1,autoTouch:!1,lazy:!1,firstError:!1,touchOnTest:!1});export default(t,e,r=h)=>{const o=f({}),s=f({}),n=f({}),a=l((()=>j(n,o))),u=l((()=>c(c({},h),b(r)))),j=(t,e)=>{const r=i(c({},O),{$dirty:!1,$test:d,$reset:d,$touch:d}),o=Object.keys(t),s={$test:[],$reset:[],$touch:[]},n=Object.keys(s),a=(t,e)=>{const r=[...Object.keys(O),"$dirty"];for(const o of r)Array.isArray(t[o])?t[o]=[...t[o],...e[o]]:!t[o]&&e[o]&&(t[o]=!0);for(const o of n)s[o].push(e[o])};for(const i of o)if(p(t[i])&&!y(t[i],"$invalid")){const o=j(t[i],e[i]);r[i]=c({},o),a(r,o)}else r[i]=c({},t[i]),r[i].$dirty=e[i],a(r,r[i]);for(const c of n)r[c]=()=>{s[c].forEach((t=>t()))};return r},v=(t,e,r,o,s)=>{const n=Object.keys(e);for(const a of n){if(p(e[a])&&!y(e[a],"$test")){o[a]={},r[a]=f({}),s[a]=f({});const n=[t[a],e[a],r[a],o[a],s[a]];return v(...n)}r[a]=!1,o[a]=t[a];const n={data:t,rules:e,dirt:r,rawData:o,entries:s};s[a]=i(c({},O),{$reset:()=>m(n,a),$test:()=>g(n,a),$touch:()=>w(n,a)}),Object.setPrototypeOf(s[a],{$uw:$((()=>t[a]),(()=>{u.value.autoTest&&s[a].$test(),u.value.autoTouch&&s[a].$touch()}))})}},g=async(t,e)=>{const{data:r,rules:o,dirt:s,rawData:n,entries:a}=t,{lazy:f,firstError:l,touchOnTest:$}=u.value;if(s[e]=$||s[e]||r[e]!==n[e],f&&!s[e])return;let y=[],p=[],b=o[e];if(b){Array.isArray(b)||(b=[b]);for(const t of b){const{$test:o,$message:s=null,$key:n}=t;let c=o(r[e]);if(c instanceof Promise){a[e].$pending=!0;try{c=await c}catch(d){c=!1}a[e].$pending=!1}if(!c){const t="function"==typeof s?s(r[e]):s;if(y=[...y,{name:n,message:t}],t&&p.push(t),l)break}}a[e]=i(c({},a[e]),{$errors:y,$messages:p,$invalid:Boolean(y.length)})}},m=(t,e)=>{t.dirt[e]=!1,t.entries[e]=c(c({},t.entries[e]),O)},w=(t,e)=>{t.dirt[e]=!0},P=()=>{v(b(t),b(e),o,s,n)};return P(),$(t,P),$(e,P),$(r,P),{result:a}}; | ||
var t=Object.defineProperty,e=Object.defineProperties,r=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,a=(e,r,o)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,c=(t,e)=>{for(var r in e||(e={}))s.call(e,r)&&a(t,r,e[r]);if(o)for(var r of o(e))n.call(e,r)&&a(t,r,e[r]);return t},i=(t,o)=>e(t,r(o));import{reactive as f,isRef as l,isVue2 as u,Vue2 as y,computed as $,watch as p}from"vue-demi";const d=(t,e,r)=>{u?y.set(t,e,r):t[e]=r},b=(t,e)=>void 0!==t[e],O=t=>"[object Object]"===Object.prototype.toString.call(t),m=t=>l(t)?t.value:t,h=()=>{},j={$invalid:!1,$errors:[],$messages:[],$pending:!1},v=f({autoTest:!1,autoTouch:!1,lazy:!1,firstError:!1,touchOnTest:!1,transform:t=>t});export default(t,e,r=f({}))=>{const o=f({}),s=f({}),n=f({}),a=$((()=>c(c({},v),m(r)))),l=$((()=>{const s=u(n,o),{transform:c}=a.value;return c?c(s,m(t),m(e),m(r)):s})),u=(t,e)=>{const r=i(c({},j),{$dirty:!1,$test:h,$reset:h,$touch:h}),o=Object.keys(t),s={$test:[],$reset:[],$touch:[]},n=Object.keys(s),a=(t,e)=>{const r=[...Object.keys(j),"$dirty"];for(const o of r)Array.isArray(t[o])?t[o]=[...t[o],...e[o]]:!t[o]&&e[o]&&(t[o]=!0);for(const o of n)s[o].push(e[o])};for(const i of o)if(O(t[i])&&!b(t[i],"$invalid")){const o=u(t[i],e[i]);r[i]=c({},o),a(r,o)}else r[i]=c({},t[i]),r[i].$dirty=e[i],a(r,r[i]);for(const c of n)r[c]=()=>{if("$test"===c)return Promise.all(s[c].map((t=>t())));s[c].forEach((t=>t()))};return r},y=(t,e,r,o,s)=>{const n=Object.keys(e);for(const l of n)if(!O(e[l])||b(e[l],"test")||b(e[l],"name")){d(r,l,!1),d(o,l,t()[l]);const n={data:t,rules:e,dirt:r,rawData:o,entries:s};d(s,l,i(c({},j),{$reset:()=>w(n,l),$test:async()=>await g(n,l),$touch:()=>P(n,l)})),Object.setPrototypeOf(s[l],{$uw:p((()=>t()[l]),(()=>{a.value.autoTest&&s[l].$test(),a.value.autoTouch&&s[l].$touch()}))})}else{d(o,l,{}),d(r,l,f({})),d(s,l,f({}));const n=[()=>t()[l],e[l],r[l],o[l],s[l]];y(...n)}},g=async(o,s)=>{const{data:n,rules:f,dirt:l,rawData:u,entries:y}=o,{lazy:$,firstError:b,touchOnTest:O}=a.value;let h=!1;const j=p((()=>y[s].$pending),(t=>{t||(h=!0,j())}));if(d(l,s,O||l[s]||n()[s]!==u[s]),$&&!l[s])return;let v=[],g=[],w=f[s];if(w){Array.isArray(w)||(w=[w]);for(const o of w){const{test:a,message:c=null,name:i}=o;let f=a(n()[s],m(t),m(e),m(r));if(f instanceof Promise){y[s].$pending=!0;try{f=await f}catch(P){f=!1}h||(y[s].$pending=!1)}if(!f){const t="function"==typeof c?c(n()[s]):c;if(v=[...v,{name:i,message:t}],t&&g.push(t),b)break}}h||d(y,s,i(c({},y[s]),{$errors:v,$messages:g,$invalid:Boolean(v.length)}))}},w=(t,e)=>{const{dirt:r,entries:o}=t;d(r,e,!1),d(o,e,c(c({},o[e]),j))},P=(t,e)=>{const{dirt:r}=t;d(r,e,!0)},T=()=>{y((()=>m(t)),m(e),o,s,n)};return T(),p(e,T),p(r,T),{result:l}}; |
@@ -1,1 +0,1 @@ | ||
var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):(e="undefined"!=typeof globalThis?globalThis:e||self)["vue-tiny-validate"]=t(e.Vue)}(this,(function(e){"use strict";const t=(e,t)=>void 0!==e[t],r=e=>"[object Object]"===Object.prototype.toString.call(e),s=t=>e.isRef(t)?t.value:t,o=()=>{},a={$invalid:!1,$errors:[],$messages:[],$pending:!1},n=e.reactive({autoTest:!1,autoTouch:!1,lazy:!1,firstError:!1,touchOnTest:!1});return(c,i,p=n)=>{const u=e.reactive({}),_=e.reactive({}),l=e.reactive({}),f=e.computed((()=>y(l,u))),d=e.computed((()=>__spreadValues(__spreadValues({},n),s(p)))),y=(e,s)=>{const n=__spreadProps(__spreadValues({},a),{$dirty:!1,$test:o,$reset:o,$touch:o}),c=Object.keys(e),i={$test:[],$reset:[],$touch:[]},p=Object.keys(i),u=(e,t)=>{const r=[...Object.keys(a),"$dirty"];for(const s of r)Array.isArray(e[s])?e[s]=[...e[s],...t[s]]:!e[s]&&t[s]&&(e[s]=!0);for(const s of p)i[s].push(t[s])};for(const o of c)if(r(e[o])&&!t(e[o],"$invalid")){const t=y(e[o],s[o]);n[o]=__spreadValues({},t),u(n,t)}else n[o]=__spreadValues({},e[o]),n[o].$dirty=s[o],u(n,n[o]);for(const t of p)n[t]=()=>{i[t].forEach((e=>e()))};return n},$=(s,o,n,c,i)=>{const p=Object.keys(o);for(const u of p){if(r(o[u])&&!t(o[u],"$test")){c[u]={},n[u]=e.reactive({}),i[u]=e.reactive({});const t=[s[u],o[u],n[u],c[u],i[u]];return $(...t)}n[u]=!1,c[u]=s[u];const p={data:s,rules:o,dirt:n,rawData:c,entries:i};i[u]=__spreadProps(__spreadValues({},a),{$reset:()=>O(p,u),$test:()=>b(p,u),$touch:()=>P(p,u)}),Object.setPrototypeOf(i[u],{$uw:e.watch((()=>s[u]),(()=>{d.value.autoTest&&i[u].$test(),d.value.autoTouch&&i[u].$touch()}))})}},b=async(e,t)=>{const{data:r,rules:s,dirt:o,rawData:a,entries:n}=e,{lazy:c,firstError:i,touchOnTest:p}=d.value;if(o[t]=p||o[t]||r[t]!==a[t],c&&!o[t])return;let u=[],_=[],l=s[t];if(l){Array.isArray(l)||(l=[l]);for(const e of l){const{$test:s,$message:o=null,$key:a}=e;let c=s(r[t]);if(c instanceof Promise){n[t].$pending=!0;try{c=await c}catch(f){c=!1}n[t].$pending=!1}if(!c){const e="function"==typeof o?o(r[t]):o;if(u=[...u,{name:a,message:e}],e&&_.push(e),i)break}}n[t]=__spreadProps(__spreadValues({},n[t]),{$errors:u,$messages:_,$invalid:Boolean(u.length)})}},O=(e,t)=>{e.dirt[t]=!1,e.entries[t]=__spreadValues(__spreadValues({},e.entries[t]),a)},P=(e,t)=>{e.dirt[t]=!0},h=()=>{$(s(c),s(i),u,_,l)};return h(),e.watch(c,h),e.watch(i,h),e.watch(p,h),{result:f}}})); | ||
var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue-demi")):"function"==typeof define&&define.amd?define(["vue-demi"],t):(e="undefined"!=typeof globalThis?globalThis:e||self)["vue-tiny-validate"]=t(e.VueDemi)}(this,(function(e){"use strict";const t=(t,r,s)=>{e.isVue2?e.Vue2.set(t,r,s):t[r]=s},r=(e,t)=>void 0!==e[t],s=e=>"[object Object]"===Object.prototype.toString.call(e),o=t=>e.isRef(t)?t.value:t,a=()=>{},n={$invalid:!1,$errors:[],$messages:[],$pending:!1},i=e.reactive({autoTest:!1,autoTouch:!1,lazy:!1,firstError:!1,touchOnTest:!1,transform:e=>e});return(c,p,u=e.reactive({}))=>{const l=e.reactive({}),_=e.reactive({}),f=e.reactive({}),d=e.computed((()=>__spreadValues(__spreadValues({},i),o(u)))),y=e.computed((()=>{const e=m(f,l),{transform:t}=d.value;return t?t(e,o(c),o(p),o(u)):e})),m=(e,t)=>{const o=__spreadProps(__spreadValues({},n),{$dirty:!1,$test:a,$reset:a,$touch:a}),i=Object.keys(e),c={$test:[],$reset:[],$touch:[]},p=Object.keys(c),u=(e,t)=>{const r=[...Object.keys(n),"$dirty"];for(const s of r)Array.isArray(e[s])?e[s]=[...e[s],...t[s]]:!e[s]&&t[s]&&(e[s]=!0);for(const s of p)c[s].push(t[s])};for(const a of i)if(s(e[a])&&!r(e[a],"$invalid")){const r=m(e[a],t[a]);o[a]=__spreadValues({},r),u(o,r)}else o[a]=__spreadValues({},e[a]),o[a].$dirty=t[a],u(o,o[a]);for(const r of p)o[r]=()=>{if("$test"===r)return Promise.all(c[r].map((e=>e())));c[r].forEach((e=>e()))};return o},$=(o,a,i,c,p)=>{const u=Object.keys(a);for(const l of u)if(!s(a[l])||r(a[l],"test")||r(a[l],"name")){t(i,l,!1),t(c,l,o()[l]);const r={data:o,rules:a,dirt:i,rawData:c,entries:p};t(p,l,__spreadProps(__spreadValues({},n),{$reset:()=>O(r,l),$test:async()=>await b(r,l),$touch:()=>P(r,l)})),Object.setPrototypeOf(p[l],{$uw:e.watch((()=>o()[l]),(()=>{d.value.autoTest&&p[l].$test(),d.value.autoTouch&&p[l].$touch()}))})}else{t(c,l,{}),t(i,l,e.reactive({})),t(p,l,e.reactive({}));const r=[()=>o()[l],a[l],i[l],c[l],p[l]];$(...r)}},b=async(r,s)=>{const{data:a,rules:n,dirt:i,rawData:l,entries:_}=r,{lazy:f,firstError:y,touchOnTest:m}=d.value;let $=!1;const b=e.watch((()=>_[s].$pending),(e=>{e||($=!0,b())}));if(t(i,s,m||i[s]||a()[s]!==l[s]),f&&!i[s])return;let O=[],P=[],v=n[s];if(v){Array.isArray(v)||(v=[v]);for(const e of v){const{test:t,message:r=null,name:n}=e;let i=t(a()[s],o(c),o(p),o(u));if(i instanceof Promise){_[s].$pending=!0;try{i=await i}catch(h){i=!1}$||(_[s].$pending=!1)}if(!i){const e="function"==typeof r?r(a()[s]):r;if(O=[...O,{name:n,message:e}],e&&P.push(e),y)break}}$||t(_,s,__spreadProps(__spreadValues({},_[s]),{$errors:O,$messages:P,$invalid:Boolean(O.length)}))}},O=(e,r)=>{const{dirt:s,entries:o}=e;t(s,r,!1),t(o,r,__spreadValues(__spreadValues({},o[r]),n))},P=(e,r)=>{const{dirt:s}=e;t(s,r,!0)},v=()=>{$((()=>o(c)),o(p),l,_,f)};return v(),e.watch(p,v),e.watch(u,v),{result:y}}})); |
@@ -1,2 +0,2 @@ | ||
import { ComputedRef } from 'vue'; | ||
import { ComputedRef } from 'vue-demi'; | ||
export declare type UnknownObject = { | ||
@@ -14,8 +14,9 @@ [key: string]: any; | ||
touchOnTest?: boolean; | ||
transform?: ((value: any, data?: Data, rules?: Rules, option?: Option) => Result | any) | ((value: any, data?: Data, rules?: Rules, option?: Option) => Promise<Result | any>); | ||
}; | ||
export declare type Data = UnknownObject; | ||
export declare type Rule = { | ||
$test: ((value: any) => boolean) | ((value: any) => Promise<boolean>); | ||
$message?: string | ((value: any) => string); | ||
$key: string; | ||
test: ((value: any, data?: Data, rules?: Rules, option?: Option) => boolean) | ((value: any, data?: Data, rules?: Rules, option?: Option) => Promise<boolean>); | ||
message?: string | ((value: any) => string); | ||
name: string; | ||
}; | ||
@@ -41,3 +42,3 @@ export declare type Rules = { | ||
$pending: boolean; | ||
$test: () => void; | ||
$test: (() => void) | (() => Promise<void>); | ||
$reset: () => void; | ||
@@ -50,5 +51,6 @@ $touch: () => void; | ||
}; | ||
export declare type Args = [Data, Rules, Dirt, UnknownObject, Entries]; | ||
export declare type GetDataFn = () => Data; | ||
export declare type Args = [GetDataFn, Rules, Dirt, UnknownObject, Entries]; | ||
export declare type ArgsObject = { | ||
data: Data; | ||
data: GetDataFn; | ||
rules: Rules; | ||
@@ -63,3 +65,3 @@ dirt: Dirt; | ||
$messages: Array<string>; | ||
$test: () => void; | ||
$test: (() => void) | (() => Promise<void>); | ||
$reset: () => void; | ||
@@ -71,3 +73,3 @@ $touch: () => void; | ||
export declare type UseValidate = { | ||
result: ComputedRef<Result>; | ||
result: ComputedRef<Result | any>; | ||
}; |
{ | ||
"name": "vue-tiny-validate", | ||
"version": "0.2.1", | ||
"description": "Tiny (2.5KB minified) Vue Validate Composition", | ||
"main": "dist/index.cjs.js", | ||
"version": "0.2.2", | ||
"description": "Tiny Vue Validate Composition", | ||
"main": "dist/index.umd.js", | ||
"module": "dist/index.es.js", | ||
@@ -38,3 +38,3 @@ "sideEffects": false, | ||
"dev:docs": "vitepress dev docs --port 4000", | ||
"build": "yarn clean && yarn pretty && vite build --mode library && yarn type && size-limit", | ||
"build": "yarn clean && yarn pretty && vite build --mode library && yarn type", | ||
"build:docs": "yarn clean && vitepress build docs", | ||
@@ -44,5 +44,9 @@ "build:example": "yarn clean && yarn pretty && vite build --mode example", | ||
}, | ||
"dependencies": { | ||
"vue-demi": "^0.11.2" | ||
}, | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^4.11.0", | ||
"@types/jest": "^26.0.23", | ||
"@types/lodash": "^4.14.171", | ||
"@vitejs/plugin-vue": "^1.2.3", | ||
@@ -56,2 +60,3 @@ "@vue/compiler-sfc": "^3.0.5", | ||
"lint-staged": ">=10", | ||
"lodash": "^4.17.21", | ||
"np": "^7.5.0", | ||
@@ -71,4 +76,10 @@ "prettier": "^2.3.0", | ||
"peerDependencies": { | ||
"vue": "^3.0.11" | ||
"@vue/composition-api": "^1.0.0-rc.1", | ||
"vue": ">= 2.6 || >=3.0.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"@vue/composition-api": { | ||
"optional": true | ||
} | ||
}, | ||
"lint-staged": { | ||
@@ -75,0 +86,0 @@ "**/*.{ts,js,css,md,vue,html}": "prettier --write" |
## `vue-tiny-validate` | ||
Tiny (2.5KB minified) Vue Validate Composition | ||
Tiny Vue Validate Composition | ||
## Motivation | ||
During the time of refactoring our project, we were coped with so many challenges. One of them was to minimize bundle | ||
size of the external libraries. Over time, the Vue community has seen so many great validation tools, such as | ||
[Vuelidate](https://github.com/vuelidate/vuelidate) or [vee-validate](https://github.com/logaretm/vee-validate). They | ||
are all great. | ||
During the time of refactoring our project, we have coped with so many challenges, one of which was to minimize bundle | ||
size of the external libraries. We looked for a solution in the Vue community, and we have seen so many great validation | ||
tools, namely [Vuelidate](https://github.com/vuelidate/vuelidate) or | ||
[vee-validate](https://github.com/logaretm/vee-validate). They were all great, but they weren't the best fit for our | ||
problem at hand. | ||
However, most (or maybe all) of them are over **3KB** that we think it's way too much for just a validation library. | ||
We want a **minimal** but **robust** and **fully supported** one. | ||
Most, or maybe all of them, are over **10KB** minified. This was way too heavy for our goal of keeping our validation library | ||
**robust**, **fully-supported**, and most importantly, **minimal**. | ||
@@ -20,5 +21,6 @@ That's why `vue-tiny-validate` was born. | ||
- Easy. Come with familiar API and coherent documentation. | ||
- Tiny. No dependencies. Only 2.5KB minified. | ||
- Tiny. No dependencies. Only **3KB** minified. **1.3KB** gzipped. | ||
- Flexible. Full control over everything. | ||
- Fully functional. Sync validation, async validation, etc supported. | ||
- Fully functional. Sync validation, async validation, etc supported.\ | ||
- Compatible. Works with both Vue 2.6 and Vue 3. | ||
@@ -31,4 +33,4 @@ ## Usage | ||
- This library is heavily inspired from [Vuelidate](https://github.com/vuelidate/vuelidate). | ||
- Created by [Anh Le](https://github.com/culee) from [ShopBase Front Team](https://github.com/FrontLabsOfficial). | ||
- This library is heavily inspired by [Vuelidate](https://github.com/vuelidate/vuelidate). | ||
- Created by [Anh Le](https://github.com/culee). | ||
@@ -35,0 +37,0 @@ ## LICENSE |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22396
9.22%131
5.65%38
5.56%0
-100%3
200%24
9.09%+ Added
+ Added
+ Added
+ Added