ivl 0.4.1 → 0.4.4

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.
@@ -1 +1 @@
1
- var S=(n)=>typeof n==="string"||n!==null&&typeof n==="object"&&("length"in n)&&typeof n.length==="number",u=(n)=>(e)=>typeof e===n,c=(n)=>(e)=>typeof e==="string"&&n.test(e),C=(n=1/0)=>(e)=>typeof e==="number"&&e<=n,a=(n=-1/0)=>(e)=>typeof e==="number"&&e>=n,R=(n=1/0)=>(e)=>S(e)&&e.length<=n,_=(n=0)=>(e)=>S(e)&&e.length>=n,p=(n=1/0,e=0)=>(t)=>typeof t==="string"&&t.length>=e&&t.length<=n,l=(n=1/0,e=-1/0)=>(t)=>typeof t==="number"&&t>=e&&t<=n,m=(n=[])=>async(e,...t)=>(await Promise.all(n.map((r)=>r(e,...t)))).some((r)=>r),y=(n=[])=>(e,...t)=>n.map((r)=>r(e,...t)).some((r)=>r);var i=(n)=>typeof n==="function"&&n.constructor.name==="AsyncFunction";var N=(n)=>Object.entries(n).reduce((e,[t,r])=>{if(i(r))return{...e,[t]:async(o,...s)=>typeof o>"u"?!0:r(o,...s)};return{...e,[t]:(o,...s)=>typeof o>"u"?!0:r(o,...s)}},{}),O=(n,e)=>Object.entries(e).reduce((t,[r,o])=>{if(i(o))return{...t,[r]:async(s,...E)=>o(n(s),...E)};return{...t,[r]:(s,...E)=>o(n(s),...E)}},{});export{m as acceptAnyAsync,y as acceptAnySync,N as allowUndefined,u as isType,c as matchesRegex,C as max,R as maxLength,a as min,_ as minLength,l as numberBetween,O as preprocess,p as stringBetween};
1
+ var E=(n)=>typeof n==="string"||n!==null&&typeof n==="object"&&("length"in n)&&typeof n.length==="number",a=(n)=>(e)=>typeof e===n,i=(n)=>(e)=>typeof e==="string"&&n.test(e),S=(n=1/0)=>(e)=>typeof e==="number"&&e<=n,l=(n=-1/0)=>(e)=>typeof e==="number"&&e>=n,C=(n=1/0)=>(e)=>E(e)&&e.length<=n,R=(n=0)=>(e)=>E(e)&&e.length>=n,f=(n=1/0,e=0)=>(t)=>typeof t==="string"&&t.length>=e&&t.length<=n,y=(n=1/0,e=-1/0)=>(t)=>typeof t==="number"&&t>=e&&t<=n,w=(n)=>(e)=>e===n||Number.isNaN(n)&&Number.isNaN(e),p=(n=[])=>{let e=new Set(n);return(t)=>e.has(t)},k=()=>(n)=>Number.isInteger(n),_=()=>(n)=>Array.isArray(n),N=(n)=>(e)=>e instanceof n,O=(n)=>(e,...t)=>{try{return!n(e,...t)}catch{return!0}},m=(n)=>async(e,...t)=>{try{return!await n(e,...t)}catch{return!0}},A=(n)=>(e,...t)=>{if(!Array.isArray(e))return!1;for(let o=0;o<e.length;o++)if(!n(e[o],...t))return!1;return!0},U=(n)=>async(e,...t)=>{if(!Array.isArray(e))return!1;for(let o=0;o<e.length;o++)if(!await n(e[o],...t))return!1;return!0},L=(n=[])=>async(e,...t)=>(await Promise.all(n.map((o)=>o(e,...t)))).some((o)=>o),g=(n=[])=>(e,...t)=>n.map((o)=>o(e,...t)).some((o)=>o);var c=(n)=>typeof n==="function"&&n.constructor.name==="AsyncFunction";var u=(n,e)=>Object.fromEntries(Object.entries(n).map(([t,o])=>[t,c(o)?async(s,...r)=>e(o,s,r):(s,...r)=>e(o,s,r)])),d=(n)=>u(n,(e,t,o)=>typeof t>"u"?!0:e(t,...o)),b=(n)=>u(n,(e,t,o)=>t===null?!0:e(t,...o)),H=(n,e)=>u(e,(t,o,s)=>t(n(o),...s));export{L as acceptAnyAsync,g as acceptAnySync,b as allowNull,d as allowUndefined,w as equals,U as everyElementAsync,A as everyElementSync,_ as isArray,N as isInstanceOf,k as isInteger,p as isOneOf,a as isType,i as matchesRegex,S as max,C as maxLength,l as min,R as minLength,m as notAsync,O as notSync,y as numberBetween,H as preprocess,f as stringBetween};
@@ -1,4 +1,4 @@
1
- import type { RULE, RULE_SYNC } from '../types';
1
+ import type { RULE, RULE_ASYNC, RULE_SYNC } from '../types';
2
2
  export type TYPEOF_RESULT = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
3
3
  export declare const isType: (type: TYPEOF_RESULT) => RULE_SYNC;
4
4
  export declare const matchesRegex: (regex: RegExp) => RULE_SYNC;
@@ -8,7 +8,32 @@ export declare const maxLength: (max_length?: number) => RULE_SYNC;
8
8
  export declare const minLength: (min_length?: number) => RULE_SYNC;
9
9
  export declare const stringBetween: (max?: number, min?: number) => RULE_SYNC;
10
10
  export declare const numberBetween: (max?: number, min?: number) => RULE_SYNC;
11
+ /** Equality using SameValueZero semantics (`===`, except `NaN` equals `NaN`) - the same comparison `isOneOf` uses. */
12
+ export declare const equals: (expected: unknown) => RULE_SYNC;
13
+ /** Membership in `allowed_values`, using SameValueZero semantics - the same comparison `equals` uses. */
14
+ export declare const isOneOf: (allowed_values?: unknown[]) => RULE_SYNC;
15
+ export declare const isInteger: () => RULE_SYNC;
16
+ export declare const isArray: () => RULE_SYNC;
17
+ export declare const isInstanceOf: (constructor: abstract new (...args: never[]) => unknown) => RULE_SYNC;
18
+ /** Inverts the given rule; a throwing rule counts as failed, so its negation passes. The rule must be synchronous. */
19
+ export declare const notSync: <V = unknown, O extends unknown[] = unknown[]>(rule: RULE_SYNC<V, O>) => RULE_SYNC<V, O>;
20
+ /**
21
+ * Inverts the given rule; a throwing/rejecting rule counts as failed, so its negation passes.
22
+ * Always async - a single async rule switches the whole rule set onto the async execution
23
+ * path, so prefer `notSync` unless the wrapped rule is genuinely async.
24
+ */
25
+ export declare const notAsync: <V = unknown, O extends unknown[] = unknown[]>(rule: RULE<V, O>) => RULE_ASYNC<V, O>;
26
+ /** Passes if the value is an array and every element (holes included) passes the given rule. Stops at the first failure. The rule must be synchronous. */
27
+ export declare const everyElementSync: <E = unknown, O extends unknown[] = unknown[]>(rule: RULE_SYNC<E, O>) => RULE_SYNC<unknown, O>;
28
+ /**
29
+ * Passes if the value is an array and every element (holes included) passes the given rule.
30
+ * Elements are checked sequentially, stopping at the first failure, so an early invalid
31
+ * element in an attacker-sized array doesn't fan out rule calls for the rest of it.
32
+ * Always async - a single async rule switches the whole rule set onto the async execution
33
+ * path, so prefer `everyElementSync` unless the element rule is genuinely async.
34
+ */
35
+ export declare const everyElementAsync: <E = unknown, O extends unknown[] = unknown[]>(rule: RULE<E, O>) => RULE_ASYNC<unknown, O>;
11
36
  /** Passes if *any* of the given rules passes. Always async. */
12
- export declare const acceptAnyAsync: <V = unknown, O extends unknown[] = unknown[]>(rules?: RULE<V, O>[]) => RULE<V, O>;
37
+ export declare const acceptAnyAsync: <V = unknown, O extends unknown[] = unknown[]>(rules?: RULE<V, O>[]) => RULE_ASYNC<V, O>;
13
38
  /** Passes if *any* of the given rules passes. All rules must be synchronous. */
14
39
  export declare const acceptAnySync: <V = unknown, O extends unknown[] = unknown[]>(rules?: RULE_SYNC<V, O>[]) => RULE_SYNC<V, O>;
@@ -13,6 +13,12 @@ type REWRAPPED<R extends RULES<never>, V> = {
13
13
  * still pick the correct execution path.
14
14
  */
15
15
  export declare const allowUndefined: <R extends RULES>(rules: R) => R;
16
+ /**
17
+ * Wraps every rule so that a `null` value always passes.
18
+ * Sync rules stay sync and async rules stay async, so `getValueErrors`/`getSchemaErrors`
19
+ * still pick the correct execution path.
20
+ */
21
+ export declare const allowNull: <R extends RULES>(rules: R) => R;
16
22
  /**
17
23
  * Wraps every rule so that the value is passed through `fn` before being validated.
18
24
  * The rules may be typed against the *output* of `fn`; the returned rules accept `unknown`.
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- var A={strict:!1};var u=(n)=>typeof n==="function"&&n.constructor.name==="AsyncFunction",N=(n)=>{if(Array.isArray(n))return n.some((s)=>Object.values(s).some(u));return Object.values(n).some(u)},a=async(n,s,...S)=>{let r={};return Object.entries(s).forEach(([t,E])=>{r[t]=Promise.resolve(!1).then(()=>E(n,...S)).then((e)=>r[t]=e).catch(()=>r[t]=!1)}),await Promise.allSettled(Object.values(r)),Object.entries(r).reduce((t,[E,e])=>e?t:[...t,E],[])},O=async(n,s,S=A,...r)=>{let t={},E=[];if(Object.entries(s).forEach(([e,C])=>{let i;if(Array.isArray(C))i=Promise.allSettled(C.map((o)=>a(n[e],o,...r))).then((o)=>{let l=o.map((c)=>{if(c.status==="fulfilled")return c.value;return["Unknown error occurred"]});if(l.some((c)=>!c.length))t[e]=[];else t[e]=l}).catch((o)=>{if(o instanceof Error)t[e]=[o.message];else t[e]=["Unknown error occurred"]});else i=a(n[e],C,...r).then((o)=>{t[e]=o}).catch((o)=>{t[e]=[o instanceof Error?o.message:"Unknown error occurred"]});E.push(i)}),S.strict){let e=Object.keys(n),C=new Set(Object.keys(s));e.filter((o)=>!C.has(o)).forEach((o)=>{t[o]=["Key not allowed"]})}return await Promise.allSettled(E),t},_=(n,s,...S)=>Object.entries(s).reduce((r,[t,E])=>{try{return E(n,...S)?r:[...r,t]}catch(e){return[...r,t]}},[]),H=(n,s,S=A,...r)=>{let t=Object.entries(s).reduce((E,[e,C])=>{if(Array.isArray(C)){let i=C.map((o)=>_(n[e],o,...r));if(i.some((o)=>!o.length))return{...E,[e]:[]};return{...E,[e]:i}}return{...E,[e]:_(n[e],C,...r)}},{});if(S.strict){let E=Object.keys(n),e=new Set(Object.keys(s));E.filter((i)=>!e.has(i)).forEach((i)=>{t[i]=["Key not allowed"]})}return t},M=(n,s,...S)=>N(s)?a(n,s,...S):_(n,s,...S),m=(n)=>Object.values(n).some(N),R=(n,s,S=A,...r)=>m(s)?O(n,s,S,...r):H(n,s,S,...r);export{R as getSchemaErrors,O as getSchemaErrorsAsync,H as getSchemaErrorsSync,M as getValueErrors,a as getValueErrorsAsync,_ as getValueErrorsSync,N as hasAsyncFunction,u as isAsyncFunction};
1
+ var f={strict:!1};var C=(e)=>typeof e==="function"&&e.constructor.name==="AsyncFunction",A=(e)=>{if(Array.isArray(e))return e.some((r)=>Object.values(r).some(C));return Object.values(e).some(C)},l=async(e,r,...E)=>{let t={},s=[];for(let[n,S]of Object.entries(r)){if(t[n]=!1,C(S)){s.push(S(e,...E).then((o)=>{t[n]=Boolean(o)}).catch(()=>{t[n]=!1}));continue}try{let o=S(e,...E);if(o!==null&&(typeof o==="object"||typeof o==="function")&&typeof o.then==="function")s.push(Promise.resolve(o).then((i)=>{t[n]=Boolean(i)}).catch(()=>{t[n]=!1}));else t[n]=Boolean(o)}catch{t[n]=!1}}if(s.length)await Promise.allSettled(s);let c=[];for(let[n,S]of Object.entries(t))if(!S)c.push(n);return c},y=async(e,r,E=f,...t)=>{let s={},c=[];if(Object.entries(r).forEach(([n,S])=>{let o;if(Array.isArray(S))o=Promise.allSettled(S.map((i)=>l(e[n],i,...t))).then((i)=>{let _=i.map((a)=>{if(a.status==="fulfilled")return a.value;return["Unknown error occurred"]});if(_.some((a)=>!a.length))s[n]=[];else s[n]=_}).catch((i)=>{if(i instanceof Error)s[n]=[i.message];else s[n]=["Unknown error occurred"]});else o=l(e[n],S,...t).then((i)=>{s[n]=i}).catch((i)=>{s[n]=[i instanceof Error?i.message:"Unknown error occurred"]});c.push(o)}),E.strict){let n=Object.keys(e),S=new Set(Object.keys(r));n.filter((i)=>!S.has(i)).forEach((i)=>{s[i]=["Key not allowed"]})}return await Promise.allSettled(c),s},u=(e,r,...E)=>{let t=[];for(let[s,c]of Object.entries(r))try{let n=c(e,...E);if(n!==null&&(typeof n==="object"||typeof n==="function")&&typeof n.then==="function")t.push(s);else if(!n)t.push(s)}catch(n){t.push(s)}return t},N=(e,r,E=f,...t)=>{let s={};for(let[c,n]of Object.entries(r))if(Array.isArray(n)){let S=n.map((o)=>u(e[c],o,...t));s[c]=S.some((o)=>!o.length)?[]:S}else s[c]=u(e[c],n,...t);if(E.strict){let c=Object.keys(e),n=new Set(Object.keys(r));c.filter((o)=>!n.has(o)).forEach((o)=>{s[o]=["Key not allowed"]})}return s},O=(e,r,...E)=>A(r)?l(e,r,...E):u(e,r,...E),H=(e)=>Object.values(e).some(A),m=(e,r,E=f,...t)=>H(r)?y(e,r,E,...t):N(e,r,E,...t);export{m as getSchemaErrors,y as getSchemaErrorsAsync,N as getSchemaErrorsSync,O as getValueErrors,l as getValueErrorsAsync,u as getValueErrorsSync,A as hasAsyncFunction,C as isAsyncFunction};
@@ -1 +1 @@
1
- var T=/^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{1,}$/,A=/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,_=/^(https?:\/\/)?([^\s$.?#].[^\s]*)\.[a-z]{2,}(\/[^ \t\r\n\v\f]*)?$/i,E=/^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:[+-][0-2]\d:[0-5]\d|Z)?)$/,t=/^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d(?::[0-5]\d(?:\.\d+)?)?)$/,d=/^(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(Z|[+-](?:2[0-3]|[01][0-9]):([0-5][0-9]))?$/,o=/[a-z]/,R=/[A-Z]/,N=/\d/,C=/[^\w\s]/;export{N as CONTAINS_DIGIT_CHARACTER_PATTERN,o as CONTAINS_LOWERCASE_CHARACTER_PATTERN,C as CONTAINS_SYMBOL_CHARACTER_PATTERN,R as CONTAINS_UPPERCASE_CHARACTER_PATTERN,T as EMAIL_PATTERN,t as ISO_8601_DATETIME_PATTERN,E as ISO_8601_DATETIME_PATTERN_STRICT,d as ISO_8601_TIME_PATTERN,A as MYSQL_TIMESTAMP_PATTERN,_ as URL_PATTERN};
1
+ var E=/^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{1,}$/,t=/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,_=/^(https?:\/\/)?([^\s$.?#].[^\s]*)\.[a-z]{2,}(\/[^ \t\r\n\v\f]*)?$/i,o=/^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:[+-][0-2]\d:[0-5]\d|Z)?)$/,R=/^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d(?::[0-5]\d(?:\.\d+)?)?)$/,a=/^(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(Z|[+-](?:2[0-3]|[01][0-9]):([0-5][0-9]))?$/,d=/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/,T=(A)=>`[0-9a-f]{8}-[0-9a-f]{4}-${A}[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`;var f=new RegExp(`^(?:${T("[1-8]")}|0{8}-0{4}-0{4}-0{4}-0{12}|f{8}-f{4}-f{4}-f{4}-f{12})$`,"i"),e=new RegExp(`^${T("4")}$`,"i"),n=new RegExp("^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$"),p=new RegExp("^(?:"+["(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}","(?:[0-9a-f]{1,4}:){1,7}:","(?:[0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}","(?:[0-9a-f]{1,4}:){1,5}(?::[0-9a-f]{1,4}){1,2}","(?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,3}","(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,4}","(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,5}","[0-9a-f]{1,4}:(?::[0-9a-f]{1,4}){1,6}",":(?:(?::[0-9a-f]{1,4}){1,7}|:)","::(?:ffff(?::0{1,4})?:)?(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)","(?:[0-9a-f]{1,4}:){1,4}:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)"].join("|")+")$","i"),P=/^[0-9a-f]{2}([:-])(?:[0-9a-f]{2}\1){4}[0-9a-f]{2}$/i,s=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,x=/^[a-z0-9]+(-[a-z0-9]+)*$/,N=/^\+[1-9]\d{1,14}$/,r=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,c=/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/,I=/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/,S=/[a-z]/,C=/[A-Z]/,z=/\d/,O=/[^\w\s]/;export{c as BASE64_PATTERN,z as CONTAINS_DIGIT_CHARACTER_PATTERN,S as CONTAINS_LOWERCASE_CHARACTER_PATTERN,O as CONTAINS_SYMBOL_CHARACTER_PATTERN,C as CONTAINS_UPPERCASE_CHARACTER_PATTERN,N as E164_PHONE_PATTERN,E as EMAIL_PATTERN,s as HEX_COLOR_PATTERN,n as IPV4_PATTERN,p as IPV6_PATTERN,R as ISO_8601_DATETIME_PATTERN,o as ISO_8601_DATETIME_PATTERN_STRICT,d as ISO_8601_DATE_PATTERN,a as ISO_8601_TIME_PATTERN,I as JWT_PATTERN,P as MAC_ADDRESS_PATTERN,t as MYSQL_TIMESTAMP_PATTERN,r as SEMVER_PATTERN,x as SLUG_PATTERN,_ as URL_PATTERN,f as UUID_PATTERN,e as UUID_V4_PATTERN};
@@ -4,6 +4,18 @@ export declare const URL_PATTERN: RegExp;
4
4
  export declare const ISO_8601_DATETIME_PATTERN_STRICT: RegExp;
5
5
  export declare const ISO_8601_DATETIME_PATTERN: RegExp;
6
6
  export declare const ISO_8601_TIME_PATTERN: RegExp;
7
+ export declare const ISO_8601_DATE_PATTERN: RegExp;
8
+ export declare const UUID_PATTERN: RegExp;
9
+ export declare const UUID_V4_PATTERN: RegExp;
10
+ export declare const IPV4_PATTERN: RegExp;
11
+ export declare const IPV6_PATTERN: RegExp;
12
+ export declare const MAC_ADDRESS_PATTERN: RegExp;
13
+ export declare const HEX_COLOR_PATTERN: RegExp;
14
+ export declare const SLUG_PATTERN: RegExp;
15
+ export declare const E164_PHONE_PATTERN: RegExp;
16
+ export declare const SEMVER_PATTERN: RegExp;
17
+ export declare const BASE64_PATTERN: RegExp;
18
+ export declare const JWT_PATTERN: RegExp;
7
19
  export declare const CONTAINS_LOWERCASE_CHARACTER_PATTERN: RegExp;
8
20
  export declare const CONTAINS_UPPERCASE_CHARACTER_PATTERN: RegExp;
9
21
  export declare const CONTAINS_DIGIT_CHARACTER_PATTERN: RegExp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ivl",
3
- "version": "0.4.1",
3
+ "version": "0.4.4",
4
4
  "author": {
5
5
  "name": "Oskar Voorel",
6
6
  "email": "oskar@voorel.com"
@@ -9,6 +9,7 @@
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/Oskar-V/ivl.git"
11
11
  },
12
+ "type": "module",
12
13
  "main": "lib/index.js",
13
14
  "devDependencies": {
14
15
  "@types/bun": "^1.4.0",