ivl 0.3.1 → 0.3.2
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/lib/helpers/index.d.ts +2 -2
- package/lib/helpers/index.js +1 -1
- package/lib/index.d.ts +10 -3
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/helpers/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const stringBetween: (max?: number, min?: number) => RULE_SYNC;
|
|
|
15
15
|
export declare const numberBetween: (max?: number, min?: number) => RULE_SYNC;
|
|
16
16
|
export declare const acceptAnyAsync: (rules?: RULE[]) => RULE;
|
|
17
17
|
export declare const acceptAnySync: (rules?: RULE_SYNC[]) => RULE_SYNC;
|
|
18
|
-
export declare const allowUndefined: (rules: RULES) =>
|
|
19
|
-
export declare const preprocess: (fn: Function, rules: RULES) =>
|
|
18
|
+
export declare const allowUndefined: (rules: RULES) => RULES;
|
|
19
|
+
export declare const preprocess: (fn: Function, rules: RULES) => RULES;
|
|
20
20
|
|
|
21
21
|
export {};
|
package/lib/helpers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var U=(n)=>typeof n==="string"||n!==null&&typeof n==="object"&&("length"in n)&&typeof n.length==="number",Y=(n)=>(f)=>typeof f===n,N=(n)=>(f)=>typeof f==="string"&&n.test(f),g=(n=1/0)=>(f)=>typeof f==="number"&&f<=n,I=(n=-1/0)=>(f)=>typeof f==="number"&&f>=n,q=(n=1/0)=>(f)=>U(f)&&f.length<=n,z=(n=0)=>(f)=>U(f)&&f.length>=n,B=(n=1/0,f=0)=>(w)=>typeof w==="string"&&w.length>=f&&w.length<=n,G=(n=1/0,f=-1/0)=>(w)=>typeof w==="number"&&w>=f&&w<=n,Q=(n=[])=>async(f,...w)=>(await Promise.all(n.map((R)=>R(f,...w)))).some((R)=>R),W=(n=[])=>(f,...w)=>n.map((R)=>R(f,...w)).some((R)=>R);var p=(n)=>typeof n==="function"&&n.constructor.name==="AsyncFunction";var J=(n)=>Object.entries(n).reduce((f,[w,R])=>{if(p(R))return{...f,[w]:async(L,...x)=>typeof L==="undefined"?!0:R(L,...x)};return{...f,[w]:(L,...x)=>typeof L==="undefined"?!0:R(L,...x)}},{}),K=(n,f)=>Object.entries(f).reduce((w,[R,L])=>({...w,[R]:(x,...t)=>L(n(x),...t)}),{});export{B as stringBetween,K as preprocess,G as numberBetween,z as minLength,I as min,q as maxLength,g as max,N as matchesRegex,Y as isType,J as allowUndefined,W as acceptAnySync,Q as acceptAnyAsync};
|
package/lib/index.d.ts
CHANGED
|
@@ -27,13 +27,20 @@ export type CHECKED_SCHEMA_SYNC<T extends keyof CHECKABLE_OBJECT> = {
|
|
|
27
27
|
[K in T]: string[] | string[][];
|
|
28
28
|
};
|
|
29
29
|
export type CHECKED_SCHEMA<T extends keyof CHECKABLE_OBJECT> = Promise<CHECKED_SCHEMA_SYNC<T>>;
|
|
30
|
+
/**
|
|
31
|
+
* Detect if a function is async or not
|
|
32
|
+
*
|
|
33
|
+
* @param {Function} fn a rules object
|
|
34
|
+
* @returns {boolean} true if any of the rules is an async function otherwise false
|
|
35
|
+
*/
|
|
36
|
+
export declare const isAsyncFunction: (fn: Function) => boolean;
|
|
30
37
|
/**
|
|
31
38
|
* Detect if a RULES object has any async rules in it
|
|
32
39
|
*
|
|
33
|
-
* @param {
|
|
40
|
+
* @param {RULES|RULES[]} rules a rules object
|
|
34
41
|
* @returns {boolean} true if any of the rules is an async function otherwise false
|
|
35
42
|
*/
|
|
36
|
-
export declare const hasAsyncFunction: (rules:
|
|
43
|
+
export declare const hasAsyncFunction: (rules: RULES | RULES[]) => boolean;
|
|
37
44
|
/**
|
|
38
45
|
* Check the input against all provided validation rules asynchronously
|
|
39
46
|
*
|
|
@@ -54,7 +61,7 @@ export declare const getValueErrorsAsync: (value: unknown, rules: RULES, ...over
|
|
|
54
61
|
*/
|
|
55
62
|
export declare const getSchemaErrorsAsync: <T extends keyof CHECKABLE_OBJECT>(object_to_check: Pick<CHECKABLE_OBJECT, T>, schema: {
|
|
56
63
|
[K in T]: RULES | RULES[];
|
|
57
|
-
}, options?: SCHEMA_OPTIONS, ...overload: unknown[]) =>
|
|
64
|
+
}, options?: SCHEMA_OPTIONS, ...overload: unknown[]) => CHECKED_SCHEMA<T>;
|
|
58
65
|
/**
|
|
59
66
|
*
|
|
60
67
|
* @param {unknown} value the value to check
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var K={strict:!1},
|
|
1
|
+
var K={strict:!1},I=(x)=>typeof x==="function"&&x.constructor.name==="AsyncFunction",L=(x)=>{if(Array.isArray(x))return x.some((G)=>Object.values(G).some(I));return Object.values(x).some(I)},Y=async(x,G,...X)=>{let Q={};return Object.entries(G).forEach(([z,W])=>{Q[z]=Promise.resolve(!1).then(()=>W(x,...X)).then((q)=>Q[z]=q).catch(()=>{return Q[z]=!1})}),await Promise.allSettled(Object.values(Q)),Object.entries(Q).reduce((z,[W,q])=>q?z:[...z,W],[])},w=async(x,G,X=K,...Q)=>{let z={},W=[];if(Object.entries(G).forEach(([q,$])=>{let Z;if(Array.isArray($))Z=Promise.allSettled($.map((R)=>Y(x[q],R,...Q))).then((R)=>{let U=R.map((J)=>{if(J.status==="fulfilled")return J.value;return["Unknown error occurred"]},[]);if(U.some((J)=>!J.length))z[q]=[];else z[q]=U}).catch((R)=>{if(R instanceof Error)z[q]=[R.message];else z[q]=["Unknown error occurred"]});else Z=Y(x[q],$,...Q).then((R)=>{z[q]=R}).catch((R)=>{z[q]=R});W.push(Z)}),X.strict){let q=Object.keys(x),$=new Set(Object.keys(G));q.filter((R)=>!$.has(R)).forEach((R)=>{z[R]=["Key not allowed"]})}return await Promise.allSettled(W),z},B=(x,G,...X)=>Object.entries(G).reduce((Q,[z,W])=>{try{return W(x,...X)?Q:[...Q,z]}catch(q){return[...Q,z]}},[]),D=(x,G,X=K,...Q)=>{let z=Object.entries(G).reduce((W,[q,$])=>{if(Array.isArray($)){let Z=$.map((R)=>B(x[q],R,...Q));if(Z.some((R)=>!R.length))return{...W,[q]:[]};return{...W,[q]:Z}}return{...W,[q]:B(x[q],$,...Q)}},{});if(X.strict){let W=Object.keys(x),q=new Set(Object.keys(G));W.filter((Z)=>!q.has(Z)).forEach((Z)=>{z[Z]=["Key not allowed"]})}return z},P=(x,G,...X)=>{if(L(G))return Y(x,G,...X);return B(x,G,...X)},N=(x)=>Object.values(x).some(L),V=(x,G,X=K,...Q)=>{if(N(G))return w(x,G,X,...Q);return D(x,G,X,...Q)};export{I as isAsyncFunction,L as hasAsyncFunction,B as getValueErrorsSync,Y as getValueErrorsAsync,P as getValueErrors,D as getSchemaErrorsSync,w as getSchemaErrorsAsync,V as getSchemaErrors};
|