vuelidify 2.2.2 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -317,26 +317,26 @@ declare function minLength<T extends string | number | undefined | null>(min: nu
|
|
|
317
317
|
*/
|
|
318
318
|
declare function maxLength<T extends string | number | undefined | null>(max: number, message?: string): SyncValidator<T>;
|
|
319
319
|
/**
|
|
320
|
-
* Validates a
|
|
320
|
+
* Validates a value is a number and is at least some value.
|
|
321
321
|
* @param min the minimum number the value can be.
|
|
322
322
|
* @param message sets the error message returned.
|
|
323
323
|
*/
|
|
324
324
|
declare function minNumber<T extends number | undefined | null>(min: number, message?: string): SyncValidator<T>;
|
|
325
325
|
/**
|
|
326
|
-
* Validates a
|
|
327
|
-
* @param min the
|
|
326
|
+
* Validates a value is a number and is greater than some value.
|
|
327
|
+
* @param min the number the value must be greater than.
|
|
328
328
|
* @param message sets the error message returned.
|
|
329
329
|
*/
|
|
330
330
|
declare function exclusiveMinNumber<T extends number | undefined | null>(min: number, message?: string): SyncValidator<T>;
|
|
331
331
|
/**
|
|
332
|
-
* Validates a
|
|
332
|
+
* Validates a value is a number and is at most some value.
|
|
333
333
|
* @param max the maximum number the value can be.
|
|
334
334
|
* @param message sets the error message returned.
|
|
335
335
|
*/
|
|
336
336
|
declare function maxNumber<T extends number | undefined | null>(max: number, message?: string): SyncValidator<T>;
|
|
337
337
|
/**
|
|
338
|
-
* Validates a
|
|
339
|
-
* @param max the
|
|
338
|
+
* Validates a value is a number and is less than some value.
|
|
339
|
+
* @param max the number the value must be less than.
|
|
340
340
|
* @param message sets the error message returned.
|
|
341
341
|
*/
|
|
342
342
|
declare function exclusiveMaxNumber<T extends number | undefined | null>(max: number, message?: string): SyncValidator<T>;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ref as
|
|
1
|
+
import{ref as D}from"vue";var w=Symbol("Throttled function call was ignored");function Q(e){let a=0,t;return(...n)=>{let r=++a;return(t??Promise.resolve()).then(()=>r!==a?w:e(...n)).finally(()=>{r===a&&(t=void 0)})}}function X(e,a){let t=0,n=0;return async(...r)=>{let s=++t,f=Date.now()-n;return f<a&&(await new Promise(u=>setTimeout(u,a-f)),s!==t)?w:(n=Date.now(),await e(...r))}}function Y(e,a){let t=0;return(...n)=>new Promise(r=>{let s=++t;setTimeout(async()=>{s==t?r(await e(...n)):r(w)},a)})}function W(e,a){let t=D(!1);return{isThrottled:t,throttledFunc:(...r)=>t.value?w:(t.value=!0,setTimeout(()=>t.value=!1,a),e(...r))}}function F(e,a=t=>t){return e.reduce((t,n)=>{let r=a(n);return r!=null&&t.push(r),t},[])}function te(e){return a=>({isValid:a.value!=null,message:e??"This field is required"})}function ie(e){return a=>({isValid:a.value!=null&&a.value!==""&&String(a.value).trim().length>0,message:e??"Must not be empty"})}function ne(e,a){return t=>{let n=String(t.value??"");return{isValid:n.length>=e,message:a??`Too short (${n.length} / ${e})`}}}function re(e,a){return t=>{let n=String(t.value??"");return{isValid:n.length<=e,message:a??`Too long (${n.length} / ${e})`}}}function oe(e,a){return t=>({isValid:typeof t.value=="number"&&Number.isFinite(t.value)&&t.value>=e,message:a??`The minimum value is ${e}`})}function se(e,a){return t=>({isValid:typeof t.value=="number"&&Number.isFinite(t.value)&&t.value>e,message:a??`Must be greater than ${e}`})}function le(e,a){return t=>({isValid:typeof t.value=="number"&&Number.isFinite(t.value)&&t.value<=e,message:a??`The maximum value is ${e}`})}function de(e,a){return t=>({isValid:typeof t.value=="number"&&Number.isFinite(t.value)&&t.value<e,message:a??`Must be less than ${e}`})}function ue(e,a){return t=>({isValid:e(t),message:a})}function ce(e,a){return async t=>{if(await e(t))return a}}function fe(e){return a=>({isValid:a.value?RegExp(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/).test(a.value):!1,message:e??"Invalid email format"})}import{computed as A,reactive as q,ref as E,shallowRef as K,watch as J}from"vue";import{computed as B,toValue as S}from"vue";import{computed as g,reactive as O,ref as T,toValue as k}from"vue";function L(){return`${Date.now()}-${Math.floor(Math.random()*1e3)}`}function z(e,a){return C(e,a)}function x(e,a,t){let n=[],r=()=>`${a?"reactive":"lazy"}-${L()}`;t!=null&&(r=s=>`${t}-${s}`);for(let[s,d]of e.entries())n.push({validatorId:r(s),validator:d,optimized:!1,isReactive:a,previouslyReturnedValidators:!1,previouslySpawnedValidators:{},spawnedValidators:{}});return n}function M(e,a,t=[]){let n=O({$state:{isValid:g(()=>{let l=u.isLazyValid.value??!1,b=u.isReactiveValid.value??!1;return l&&b}),isValidating:g(()=>u.isValidatingReactive.value||u.isValidatingLazy.value),isErrored:g(()=>n.$state?.resultsArray.some(l=>l.isValid===!1)??!1),errorMessages:g(()=>F(n.$state?.resultsArray??[],l=>l.isValid?void 0:l.message)),results:g(()=>u.namedValidationResults.value),resultsArray:g(()=>u.validationResults.value)},$arrayState:g(()=>{if(Array.isArray(e.value)===!1||u.elementValidation===void 0)return[];let l=e.value,b=u.elementValidation,m=u.arrayConfigMap,i=[],V={},o,p=[];for(let c=0;c<l.length;c++){let v=l[c]!==void 0&&typeof l[c]=="object";if(v?(l[c].$ffId===void 0&&Object.defineProperty(l[c],"$ffId",{value:`${u.id}-${u.elementId++}`,writable:!1,configurable:!1,enumerable:!1}),o=l[c].$ffId):l[c]!==void 0&&(o=c),p.push(o),m[o]){i.push(m[o].validationState),V[o]=m[o];continue}let y=g(()=>l[c]),R=[...u.arrayAncestors];v&&R.push({ancestor:y,array:l,index:c});let P=C(y,b,R);m[o]={validationConfigs:P.validationConfigs,validationState:P.state},i.push(m[o].validationState),V[o]=m[o]}return u.arrayConfigMap=V,i})}),r=!0,s=!0,d=[],f=[];a.$reactive&&a.$reactive.length>0&&(s=!1,d=x(a.$reactive,!0)),a.$lazy&&a.$lazy?.length>0&&(r=!1,f=x(a.$lazy,!1));let u={id:L(),reactiveIterationId:0,lazyIterationId:0,isReactiveValid:T(s),isValidatingReactive:T(!1),reactiveProcessedValidators:d,isLazyValid:T(r),isValidatingLazy:T(!1),lazyProcessedValidators:f,target:e,validation:a,validationState:n,validationResults:T([]),namedValidationResults:T({}),arrayConfigMap:{},elementId:0,elementValidation:a.$each,arrayAncestors:O(t)};return u}function C(e,a,t=[]){let n=[],r={};if(N(a)){let d=g(()=>k(e)),f=M(d,a,t);n.push(f),r=f.validationState}a!=null&&s(e,a,r);function s(d,f,u){if(I(f)!==!1)for(let l in f){if(l==="$reactive"||l==="$lazy"||l==="$each")continue;let b=g(()=>{let i=k(d);return I(i)?i[l]:(console.error(`Vuelidify Error: validation could not be setup correctly on ${i} because ${d} is not enumerable.`),null)}),m=f[l];if(N(m)){let i=M(b,m,t);n.push(i),u[l]=i.validationState}if(I(m)){let i=u[l]??{};u[l]=i,s(b,m,i)}}}return{validationConfigs:n,state:r}}function N(e){return Array.isArray(e?.$reactive)||Array.isArray(e?.$lazy)||e?.$each!==void 0}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}async function j(e,a,t,n,r,s){let d=!0,f=(i,V,o)=>{if(n!==S(r))return;o.isValid===!1&&(d=!1),o.id=V.validatorId;let p=i.validationResults.value.find(c=>c.id===o.id);p!==void 0?(Object.assign(p,o),o.name!==void 0&&i.namedValidationResults.value[o.name]!==void 0&&Object.assign(i.namedValidationResults.value[o.name],o)):(i.validationResults.value.push(o),o.name!==void 0&&(i.namedValidationResults.value[o.name]=o))},u=[];for(let i of s){let V=(i.activeValidation??Promise.resolve()).then(async()=>n!==S(r)?[]:await b(i,!0));i.activeValidation=V,u.push(V)}return await Promise.all(u),d;function l(i,V){let o=[];for(let p of i)o.push(b(p,!1,V));return o}async function b(i,V,o=i){let p=[],c=i.previouslyReturnedValidators;c&&(i.previouslySpawnedValidators=i.spawnedValidators,i.spawnedValidators={}),i.previouslyReturnedValidators=!1;let v={value:e.target.value,model:a,args:t,arrayAncestors:e.arrayAncestors},y=i.validator(v);if(y instanceof Promise){let R=await y;if(Array.isArray(R)){let P=m(i,R,o),$=await Promise.all(P);p.push(...$.flat()),c&&G(e,i)}else c&&G(e,i),R!=null&&(p.push(R),f(e,i,R))}else if(Array.isArray(y)){let R=m(i,y,o),P=await Promise.all(R);p.push(...P.flat()),c&&G(e,i)}else if(c&&G(e,i),y!=null){if(V&&i.optimized===!1){let R=i.validator,P=B(()=>{let $={value:e.target.value,model:a,args:t,arrayAncestors:e.arrayAncestors};return R($)});i.optimized=!0,i.validator=()=>P.value}p.push(y),f(e,i,y)}return p}function m(i,V,o){let p=x(V,i.isReactive,i.validatorId),c=l(p,o),v=o.spawnedValidators;for(let y of p)v[y.validatorId]!=null&&console.error(`Unable to keep track of nested validators. Validator ID: ${y.validatorId} was not unique.`),v[y.validatorId]=y;return i.spawnedValidators=v,i.previouslyReturnedValidators=!0,c}}function G(e,a){for(let t in a.previouslySpawnedValidators){if(a.spawnedValidators[t]!=null)continue;let n=e.validationResults.value.findIndex(r=>r.id===t);n!==-1&&e.validationResults.value.splice(n,1)}}async function _(e,a,t,n,r){e.isValidatingReactive.value=!0;let s=await j(e,a,t,n,r,e.reactiveProcessedValidators);return n===S(r)&&(e.isReactiveValid.value=s,e.isValidatingReactive.value=!1),e.isReactiveValid.value??!1}async function U(e,a,t,n,r){e.isValidatingLazy.value=!0;let s=await j(e,a,t,n,r,e.lazyProcessedValidators);return n===S(r)&&(e.isLazyValid.value=s,e.isValidatingLazy.value=!1),e.isLazyValid.value??!1}function h(e,a,t,n,r){let s=[];for(let d of e)if(n&&d.reactiveProcessedValidators.length>0&&s.push(_(d,a.value,t,++d.reactiveIterationId,()=>d.reactiveIterationId)),r&&d.lazyProcessedValidators.length>0&&s.push(U(d,a.value,t,++d.lazyIterationId,()=>d.lazyIterationId)),Array.isArray(d.validationState.$arrayState)){let f=[];for(let u in d.arrayConfigMap)f.push(...d.arrayConfigMap[u].validationConfigs);s.push(h(f,a,t,n,r))}return Promise.all(s).then(d=>d.every(f=>f===!0))}function Z(e){e.delayReactiveValidation??=!0;let{model:a,validation:t,delayReactiveValidation:n,args:r}=e,s=E(!1),d=A(()=>V.value.some(v=>v.isValidatingLazy.value||v.isValidatingReactive.value)),f=A(()=>V.value.some(v=>v.validationResults.value.some(y=>y.isValid===!1))),u=A(()=>V.value.every(y=>y.isReactiveValid.value&&y.isLazyValid.value)),l=E(JSON.stringify(e.model.value)),b=A(()=>l.value!==JSON.stringify(e.model.value)),m=z(a,t),i=K(m.state),V=K(m.validationConfigs);J(e.model,()=>{n?s.value===!0&&h(V.value,a,r,!0,!1):h(V.value,a,r,!0,!1)},{deep:!0});async function o(){let v=await h(V.value,a,r,!0,!0);return s.value=!0,v}function p(v){l.value=JSON.stringify(v)}function c(){s.value=!1,m=z(a,t),V.value=m.validationConfigs,i.value=m.state}return q({hasValidated:s,validate:o,isValidating:d,state:A(()=>i.value),isValid:u,isErrored:f,setReference:p,isDirty:b,reset:c})}export{w as V$_IGNORE,Q as bufferAsync,de as exclusiveMaxNumber,se as exclusiveMinNumber,fe as isEmailSync,re as maxLength,le as maxNumber,ne as minLength,oe as minNumber,ue as must,ie as notEmpty,F as reduceUndefined,te as required,W as throttleAsync,X as throttleBufferAsync,Y as trailingDebounceAsync,Z as useValidation,ce as validateIf};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vuelidify",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"author": "Daniel Walbolt",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"issues": "https://github.com/Daniel-Walbolt/vuelidify/issues",
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
28
|
-
"url": "https://github.com/Daniel-Walbolt/vuelidify"
|
|
28
|
+
"url": "git+https://github.com/Daniel-Walbolt/vuelidify.git"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"vue": "^3.0.0"
|