ivl 0.2.0 → 0.2.5
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 +1 -1
- package/lib/index.d.ts +57 -3
- package/lib/index.js +1 -1
- package/lib/patterns/index.d.ts +1 -1
- package/lib/patterns/index.js +1 -1
- package/package.json +4 -4
package/lib/helpers/index.d.ts
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
3
|
export type RULE_SYNC = (value: unknown, ...overload: unknown[]) => boolean;
|
|
4
4
|
export type RULE = (value: unknown, ...overload: unknown[]) => boolean | Promise<boolean>;
|
|
@@ -19,7 +19,6 @@ export type CHECKABLE_OBJECT = {
|
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* @arg {boolean} strict --- Don't allow object to have keys not included in the schema
|
|
22
|
-
* @arg {boolean} break_early --- Return the first error found
|
|
23
22
|
*/
|
|
24
23
|
export type SCHEMA_OPTIONS = {
|
|
25
24
|
strict?: boolean;
|
|
@@ -28,12 +27,67 @@ export type CHECKED_SCHEMA_SYNC = {
|
|
|
28
27
|
[index: string]: string[];
|
|
29
28
|
};
|
|
30
29
|
export type CHECKED_SCHEMA = Promise<CHECKED_SCHEMA_SYNC>;
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Detect if a RULES object has any async rules in it
|
|
32
|
+
*
|
|
33
|
+
* @param {Record<string, RULE>} rules a rules object
|
|
34
|
+
* @returns {boolean} true if any of the rules is an async function otherwise false
|
|
35
|
+
*/
|
|
36
|
+
export declare const hasAsyncFunction: (rules: Record<string, RULE>) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Check the input against all provided validation rules asynchronously
|
|
39
|
+
*
|
|
40
|
+
* @param {unknown} value the value to check
|
|
41
|
+
* @param {RULES} rules rules object to use for validating the provided value
|
|
42
|
+
* @param {unknown[]} overload array of extra values the validator rules might need to properly validate the value
|
|
43
|
+
* @returns {string[]} a list of rule names which failed validation
|
|
44
|
+
*/
|
|
32
45
|
export declare const getValueErrorsAsync: (value: unknown, rules: RULES, ...overload: unknown[]) => Promise<string[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Check a schema against all provided validation rules asynchronously
|
|
48
|
+
*
|
|
49
|
+
* @param {CHECKABLE_OBJECT} object object to be validated
|
|
50
|
+
* @param {SCHEMA} schema schema to validate against
|
|
51
|
+
* @param {SCHEMA_OPTIONS} options options affecting how the rules are run
|
|
52
|
+
* @param {unknown[]} overload array of extra values the validator rules might need to properly validate the value
|
|
53
|
+
* @returns {CHECKED_SCHEMA} an object containing keys and their respective lists of failed rule names
|
|
54
|
+
*/
|
|
33
55
|
export declare const getSchemaErrorsAsync: (object: CHECKABLE_OBJECT, schema: SCHEMA, options?: SCHEMA_OPTIONS, ...overload: unknown[]) => CHECKED_SCHEMA;
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @param {unknown} value the value to check
|
|
59
|
+
* @param {RULES_SYNC} rules rules object to use for validating the provided value
|
|
60
|
+
* @param {unknown[]} overload array of extra values the validator rules might need to properly validate the value
|
|
61
|
+
* @returns {string[]} a list of rule names which failed validation
|
|
62
|
+
*/
|
|
34
63
|
export declare const getValueErrorsSync: (value: unknown, rules: RULES_SYNC, ...overload: unknown[]) => string[];
|
|
64
|
+
/**
|
|
65
|
+
* Check a schema against all provided validation rules asynchronously
|
|
66
|
+
*
|
|
67
|
+
* @param {CHECKABLE_OBJECT} object object to be validated
|
|
68
|
+
* @param {SCHEMA} schema schema to validate against
|
|
69
|
+
* @param {SCHEMA_OPTIONS} options options affecting how the rules are run
|
|
70
|
+
* @param {unknown[]} overload array of extra values the validator rules might need to properly validate the value
|
|
71
|
+
* @returns {CHECKED_SCHEMA} an object containing keys and their respective lists of failed rule names
|
|
72
|
+
*/
|
|
35
73
|
export declare const getSchemaErrorsSync: (object: CHECKABLE_OBJECT, schema: SCHEMA_SYNC, options?: SCHEMA_OPTIONS, ...overload: unknown[]) => CHECKED_SCHEMA_SYNC;
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* @param {unknown} value the value to check
|
|
77
|
+
* @param {RULES|RULES_SYNC} rules rules object to use for validating the provided value
|
|
78
|
+
* @param {unknown[]} overload array of extra values the validator rules might need to properly validate the value
|
|
79
|
+
* @returns {string[]} a list of rule names which failed validation
|
|
80
|
+
*/
|
|
36
81
|
export declare const getValueErrors: (value: unknown, rules: RULES | RULES_SYNC, ...overload: unknown[]) => string[] | Promise<string[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Check a schema against all provided validation rules
|
|
84
|
+
*
|
|
85
|
+
* @param {CHECKABLE_OBJECT} object object to be validated
|
|
86
|
+
* @param {SCHEMA} schema schema to validate against
|
|
87
|
+
* @param {SCHEMA_OPTIONS} options options affecting how the rules are run
|
|
88
|
+
* @param {unknown[]} overload array of extra values the validator rules might need to properly validate the value
|
|
89
|
+
* @returns {CHECKED_SCHEMA} an object containing keys and their respective lists of failed rule names
|
|
90
|
+
*/
|
|
37
91
|
export declare const getSchemaErrors: (object: CHECKABLE_OBJECT, schema: SCHEMA_SYNC | SCHEMA, options?: SCHEMA_OPTIONS, ...overload: unknown[]) => CHECKED_SCHEMA_SYNC | CHECKED_SCHEMA;
|
|
38
92
|
|
|
39
93
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Z={strict:!1},$=(z)=>Object.values(z).some((q)=>typeof q==="function"&&q.constructor.name==="AsyncFunction"),J=async(z,q,...W)=>{const G={};return Object.entries(q).forEach(([x,Q])=>{G[x]=Promise.resolve(!1).then(()=>Q(z,...W)).then((R)=>G[x]=R).catch((R)=>{return console.warn(`Rule validation functions for "${x}" didn't exit cleanly`,R),G[x]=!1})}),await Promise.allSettled(Object.values(G)),Object.entries(G).reduce((x,[Q,R])=>R?x:[...x,Q],[])},K=async(z,q,W=Z,...G)=>{const x={};if(Object.entries(q).forEach(([Q,R])=>{x[Q]=J(z[Q],R,...G).then((X)=>{x[Q]=X}).catch((X)=>{x[Q]=X})}),W.strict){const Q=Object.keys(z),R=new Set(Object.keys(q));Q.filter((Y)=>!R.has(Y)).forEach((Y)=>{x[Y]=["Key not allowed"]})}return await Promise.allSettled(Object.values(x)),x},B=(z,q,...W)=>Object.entries(q).reduce((G,[x,Q])=>{try{return Q(z,...W)?G:[...G,x]}catch(R){return console.warn(`Rule validation function for "${x}" didn't exit cleanly`,R),[...G,x]}},[]),f=(z,q,W=Z,...G)=>{const x=Object.entries(q).reduce((Q,[R,X])=>({...Q,[R]:B(z[R],X,...G)}),{});if(W.strict){const Q=Object.keys(z),R=new Set(Object.keys(q));Q.filter((Y)=>!R.has(Y)).forEach((Y)=>{x[Y]=["Key not allowed"]})}return x},U=(z,q,...W)=>{if($(q))return J(z,q,...W);return B(z,q,...W)},I=(z,q,W=Z,...G)=>{if(Object.values(q).some($))return K(z,q,W,...G);return f(z,q,W,...G)};export{$ as hasAsyncFunction,B as getValueErrorsSync,J as getValueErrorsAsync,U as getValueErrors,f as getSchemaErrorsSync,K as getSchemaErrorsAsync,I as getSchemaErrors};
|
package/lib/patterns/index.d.ts
CHANGED
package/lib/patterns/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var x=/^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{1,}$/,c=/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,d=/^(https?:\/\/)?([^\s$.?#].[^\s]*)\.[a-z]{2,}(\/[
|
|
1
|
+
var x=/^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{1,}$/,c=/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,d=/^(https?:\/\/)?([^\s$.?#].[^\s]*)\.[a-z]{2,}(\/[^ \t\r\n\v\f]*)?$/i,f=/^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:[+-][0-2]\d:[0-5]\d|Z)?)$/,j=/^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d(?::[0-5]\d(?:\.\d+)?)?)$/,k=/^(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]))?$/,l=/^(?:(Sun|Mon|Tue|Wed|Thu|Fri|Sat),\s)?(0[1-9]|[1-2]?[0-9]|3[01])\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(19[0-9]{2}|[2-9][0-9]{3})\s(2[0-3]|[0-1][0-9]):([0-5][0-9])(?::(60|[0-5][0-9]))?\s([-\+][0-9]{2}[0-5][0-9]|(?:UT|GMT|(?:E|C|M|P)(?:ST|DT)|[A-IK-Z]))(?:\s|\((?:[^()\\]+|\\.)*?\))*$/,m=/[a-z]/,p=/[A-Z]/,q=/\d/,r=/[^\w\s]/;export{d as URL_PATTERN,l as RFC_2822_TIMESTAMP_PATTERN,c as MYSQL_TIMESTAMP_PATTERN,k as ISO_8601_TIME_PATTERN,f as ISO_8601_DATETIME_PATTERN_STRICT,j as ISO_8601_DATETIME_PATTERN,x as EMAIL_PATTERN,p as CONTAINS_UPPERCASE_CHARACTER_PATTERN,r as CONTAINS_SYMBOL_CHARACTER_PATTERN,m as CONTAINS_LOWERCASE_CHARACTER_PATTERN,q as CONTAINS_DIGIT_CHARACTER_PATTERN};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ivl",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Oskar Voorel",
|
|
6
6
|
"email": "oskar@voorel.com"
|
|
7
7
|
},
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/Oskar-V/
|
|
10
|
+
"url": "git+https://github.com/Oskar-V/ivl.git"
|
|
11
11
|
},
|
|
12
12
|
"main": "lib/index.js",
|
|
13
13
|
"devDependencies": {
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"bugs": {
|
|
36
|
-
"url": "https://github.com/Oskar-V/
|
|
36
|
+
"url": "https://github.com/Oskar-V/ivl/issues/new"
|
|
37
37
|
},
|
|
38
38
|
"description": "Lightweight input validation",
|
|
39
39
|
"files": [
|
|
40
40
|
"lib"
|
|
41
41
|
],
|
|
42
|
-
"homepage": "https://github.com/Oskar-V/
|
|
42
|
+
"homepage": "https://github.com/Oskar-V/ivl",
|
|
43
43
|
"keywords": [
|
|
44
44
|
"validation",
|
|
45
45
|
"typescript",
|