valgen 5.15.3 → 5.17.0
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/CHANGELOG.md +23 -1
- package/cjs/index.js +68 -64
- package/cjs/rules/type-rules/is-array.js +1 -1
- package/cjs/rules/type-rules/is-bigint.js +1 -1
- package/cjs/rules/type-rules/is-boolean.js +1 -1
- package/cjs/rules/type-rules/is-date.js +148 -65
- package/cjs/rules/type-rules/is-integer.js +1 -1
- package/cjs/rules/type-rules/is-number.js +1 -1
- package/cjs/rules/type-rules/is-object.js +1 -1
- package/cjs/rules/type-rules/is-string.js +1 -1
- package/cjs/rules/type-rules/is-tuple.js +1 -1
- package/cjs/rules/type-rules/is-undefined.js +1 -1
- package/esm/index.js +34 -32
- package/esm/rules/type-rules/is-array.js +1 -1
- package/esm/rules/type-rules/is-bigint.js +1 -1
- package/esm/rules/type-rules/is-boolean.js +1 -1
- package/esm/rules/type-rules/is-date.js +147 -65
- package/esm/rules/type-rules/is-integer.js +1 -1
- package/esm/rules/type-rules/is-number.js +1 -1
- package/esm/rules/type-rules/is-object.js +1 -1
- package/esm/rules/type-rules/is-string.js +1 -1
- package/esm/rules/type-rules/is-tuple.js +1 -1
- package/esm/rules/type-rules/is-undefined.js +1 -1
- package/package.json +2 -1
- package/types/index.d.cts +34 -32
- package/types/index.d.ts +34 -32
- package/types/rules/type-rules/is-date.d.ts +12 -11
|
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
|
|
|
6
6
|
*/
|
|
7
7
|
export function isBigint(options) {
|
|
8
8
|
return validator('isBigint', (input, context, _this) => {
|
|
9
|
-
const coerce = options?.coerce
|
|
9
|
+
const coerce = options?.coerce ?? context.coerce;
|
|
10
10
|
if (typeof input === 'bigint')
|
|
11
11
|
return input;
|
|
12
12
|
if ((typeof input === 'number' && !isNaN(input)) ||
|
|
@@ -8,7 +8,7 @@ const FALSE_PATTERN = /^false|f|0|no|n$/i;
|
|
|
8
8
|
*/
|
|
9
9
|
export function isBoolean(options) {
|
|
10
10
|
return validator('isBoolean', (input, context, _this) => {
|
|
11
|
-
const coerce = options?.coerce
|
|
11
|
+
const coerce = options?.coerce ?? context.coerce;
|
|
12
12
|
let output = input;
|
|
13
13
|
if (output != null && typeof output !== 'boolean' && coerce) {
|
|
14
14
|
if (typeof input === 'string') {
|
|
@@ -1,94 +1,176 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as datefns from 'date-fns';
|
|
2
2
|
import { validator, } from '../../core/index.js';
|
|
3
|
-
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
4
|
-
const DATE_PATTERN = /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[T ](([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?(?:\.(\d{0,3}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
|
|
5
3
|
/**
|
|
6
|
-
* Validates if value is
|
|
7
|
-
*
|
|
4
|
+
* Validates if value is a "Date" instance or ISO 8601 formatted date string.
|
|
5
|
+
* if a `coerce` option is `true`, converts input value to Date instance
|
|
8
6
|
* @validator isDate
|
|
9
7
|
*/
|
|
10
8
|
export function isDate(options) {
|
|
11
|
-
const
|
|
9
|
+
const trim = options?.trim;
|
|
12
10
|
return validator('isDate', (input, context, _this) => {
|
|
13
|
-
const coerce = options?.coerce
|
|
11
|
+
const coerce = options?.coerce ?? context.coerce;
|
|
14
12
|
let d;
|
|
15
13
|
if (input instanceof Date)
|
|
16
14
|
d = input;
|
|
17
|
-
else if (
|
|
18
|
-
if (typeof input === '
|
|
19
|
-
d = parseISO(input);
|
|
20
|
-
}
|
|
21
|
-
else if (typeof input === 'number')
|
|
15
|
+
else if (coerce) {
|
|
16
|
+
if (typeof input === 'number')
|
|
22
17
|
d = new Date(input);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
if (precision === 'month') {
|
|
30
|
-
d.setHours(0, 0, 0, 0);
|
|
31
|
-
d.setDate(1);
|
|
18
|
+
else if (typeof input === 'string') {
|
|
19
|
+
const parsed = coerceDateString(input);
|
|
20
|
+
if (parsed) {
|
|
21
|
+
d = new Date(parsed.value);
|
|
22
|
+
}
|
|
32
23
|
}
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
}
|
|
25
|
+
if (datefns.isValid(d)) {
|
|
26
|
+
setPrecision(d, trim);
|
|
35
27
|
return d;
|
|
36
28
|
}
|
|
37
|
-
context.fail(_this, `Value
|
|
29
|
+
context.fail(_this, `Value is not valid date`, input, {
|
|
38
30
|
...options,
|
|
39
31
|
});
|
|
40
32
|
}, options);
|
|
41
33
|
}
|
|
42
34
|
/**
|
|
43
35
|
* Validates if value is DFS (date formatted string).
|
|
44
|
-
* Converts input value to DFS if coerce option is set to 'true'.
|
|
36
|
+
* Converts input value to DFS if the "coerce" option is set to 'true'.
|
|
45
37
|
* @validator isDateString
|
|
46
38
|
*/
|
|
47
39
|
export function isDateString(options) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
40
|
+
const precisionMin = options?.precisionMin || 'minutes';
|
|
41
|
+
const precisionMax = options?.precisionMax || 'tz';
|
|
42
|
+
const precisionMaxIdx = PRECISION_INDEX[precisionMax] || 9;
|
|
43
|
+
const precisionMinIdx = Math.min(precisionMaxIdx, PRECISION_INDEX[precisionMin] || 6);
|
|
50
44
|
return validator('isDateString', (input, context, _this) => {
|
|
51
|
-
const coerce = options?.coerce
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!precision ||
|
|
58
|
-
precision === 'year' ||
|
|
59
|
-
(precision === 'month' && m[2]) ||
|
|
60
|
-
(precision === 'date' && m[2] && m[3]) ||
|
|
61
|
-
(precision === 'time' && m[2] && m[3] && m[4])) {
|
|
62
|
-
if (!coerce)
|
|
63
|
-
return input;
|
|
64
|
-
let s = m[1];
|
|
65
|
-
if (m[2])
|
|
66
|
-
s += '-' + m[2];
|
|
67
|
-
else
|
|
68
|
-
return s;
|
|
69
|
-
if (m[3])
|
|
70
|
-
s += '-' + m[3];
|
|
71
|
-
else
|
|
72
|
-
return s;
|
|
73
|
-
if (trim === 'date' || !m[4])
|
|
74
|
-
return s;
|
|
75
|
-
s += 'T' + m[4].substring(0, 8);
|
|
76
|
-
if (trim === 'time')
|
|
77
|
-
return s;
|
|
78
|
-
if (m[9])
|
|
79
|
-
s += m[9];
|
|
80
|
-
return s;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
45
|
+
const coerce = options?.coerce ?? context.coerce;
|
|
46
|
+
const parsed = coerceDateString(input, options?.trim);
|
|
47
|
+
if (parsed) {
|
|
48
|
+
if (parsed.precision >= precisionMinIdx &&
|
|
49
|
+
parsed.precision <= precisionMaxIdx) {
|
|
50
|
+
return coerce ? parsed.value : input;
|
|
83
51
|
}
|
|
84
52
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
?
|
|
88
|
-
:
|
|
89
|
-
}
|
|
90
|
-
context.fail(_this, `Value must be a valid date string`, input, {
|
|
53
|
+
context.fail(_this, `Value is not valid date string` +
|
|
54
|
+
(options?.precisionMin || options?.precisionMax
|
|
55
|
+
? ` with required precision`
|
|
56
|
+
: ''), input, {
|
|
91
57
|
...options,
|
|
92
58
|
});
|
|
93
59
|
}, options);
|
|
94
60
|
}
|
|
61
|
+
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
62
|
+
const DATE_PATTERN = /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[T ](?:([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?(?:\.(\d{0,3}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
|
|
63
|
+
function coerceDateString(input, precision) {
|
|
64
|
+
let dateParts;
|
|
65
|
+
let outPrecision = 0;
|
|
66
|
+
if (input instanceof Date || typeof input === 'number') {
|
|
67
|
+
const d = typeof input === 'number' ? new Date(input) : input;
|
|
68
|
+
dateParts = [
|
|
69
|
+
padString(d.getFullYear(), 4),
|
|
70
|
+
padString(d.getMonth() + 1, 2),
|
|
71
|
+
padString(d.getDate(), 2),
|
|
72
|
+
padString(d.getHours(), 2),
|
|
73
|
+
padString(d.getMinutes(), 2),
|
|
74
|
+
padString(d.getSeconds(), 2),
|
|
75
|
+
String(d.getMilliseconds()),
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
else if (typeof input === 'string') {
|
|
79
|
+
const d = datefns.parseISO(input);
|
|
80
|
+
const m = DATE_PATTERN.exec(input);
|
|
81
|
+
if (m && datefns.isValid(d)) {
|
|
82
|
+
m.shift();
|
|
83
|
+
dateParts = m;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!dateParts)
|
|
87
|
+
return;
|
|
88
|
+
outPrecision = dateParts.findIndex(v => !v);
|
|
89
|
+
if (outPrecision === -1)
|
|
90
|
+
outPrecision = dateParts.length + 1;
|
|
91
|
+
const precisionIndex = (precision ? PRECISION_INDEX[precision] : 9) || 9;
|
|
92
|
+
let value = dateParts[0] || '0000';
|
|
93
|
+
if (precisionIndex > 1)
|
|
94
|
+
value += '-' + (dateParts[1] || '01');
|
|
95
|
+
if (precisionIndex > 2)
|
|
96
|
+
value += '-' + (dateParts[2] || '01');
|
|
97
|
+
if (precisionIndex > 3)
|
|
98
|
+
value += 'T' + (dateParts[3] || '00');
|
|
99
|
+
if (precisionIndex > 4)
|
|
100
|
+
value += ':' + (dateParts[4] || '00');
|
|
101
|
+
if (precisionIndex > 5)
|
|
102
|
+
value += ':' + (dateParts[5] || '00');
|
|
103
|
+
if (precisionIndex > 6)
|
|
104
|
+
value += dateParts[6] ? '.' + dateParts[6] : '';
|
|
105
|
+
if (precisionIndex > 7)
|
|
106
|
+
value += dateParts[7] || '';
|
|
107
|
+
return {
|
|
108
|
+
value,
|
|
109
|
+
precision: outPrecision || 8,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const PRECISION_INDEX = {
|
|
113
|
+
year: 1,
|
|
114
|
+
yr: 1,
|
|
115
|
+
month: 2,
|
|
116
|
+
mo: 2,
|
|
117
|
+
day: 3,
|
|
118
|
+
d: 4,
|
|
119
|
+
hours: 4,
|
|
120
|
+
hr: 4,
|
|
121
|
+
minutes: 5,
|
|
122
|
+
min: 5,
|
|
123
|
+
seconds: 6,
|
|
124
|
+
sec: 6,
|
|
125
|
+
milliseconds: 7,
|
|
126
|
+
ms: 7,
|
|
127
|
+
tz: 8,
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Pads a string to the specified length
|
|
131
|
+
* @param value - The string to pad
|
|
132
|
+
* @param len - The desired total length of the resulting string
|
|
133
|
+
* @param padChar - The character to pad with (defaults to '0')
|
|
134
|
+
* @returns The padded string
|
|
135
|
+
*/
|
|
136
|
+
function padString(value, len, padChar = '0') {
|
|
137
|
+
// Convert value to string if it's a number
|
|
138
|
+
const str = String(value);
|
|
139
|
+
// Return original string if it's already longer or equal to target length
|
|
140
|
+
if (str.length >= len) {
|
|
141
|
+
return str;
|
|
142
|
+
}
|
|
143
|
+
// Create padding and concatenate with original string
|
|
144
|
+
const padding = padChar.repeat(len - str.length);
|
|
145
|
+
return padding + str;
|
|
146
|
+
}
|
|
147
|
+
function setPrecision(d, precision) {
|
|
148
|
+
switch (precision) {
|
|
149
|
+
case 'year': {
|
|
150
|
+
d.setMonth(0, 1);
|
|
151
|
+
d.setHours(0, 0, 0, 0);
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case 'month': {
|
|
155
|
+
d.setDate(1);
|
|
156
|
+
d.setHours(0, 0, 0, 0);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case 'day': {
|
|
160
|
+
d.setHours(0, 0, 0, 0);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case 'hours': {
|
|
164
|
+
d.setMinutes(0, 0, 0);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case 'minutes': {
|
|
168
|
+
d.setSeconds(0, 0);
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case 'seconds': {
|
|
172
|
+
d.setMilliseconds(0);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
|
|
|
6
6
|
*/
|
|
7
7
|
export function isInteger(options) {
|
|
8
8
|
return validator('isInteger', (input, context, _this) => {
|
|
9
|
-
const coerce = options?.coerce
|
|
9
|
+
const coerce = options?.coerce ?? context.coerce;
|
|
10
10
|
let output = input;
|
|
11
11
|
if (output != null && typeof output !== 'number' && coerce) {
|
|
12
12
|
if (typeof input === 'string')
|
|
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
|
|
|
6
6
|
*/
|
|
7
7
|
export function isNumber(options) {
|
|
8
8
|
return validator('isNumber', (input, context, _this) => {
|
|
9
|
-
const coerce = options?.coerce
|
|
9
|
+
const coerce = options?.coerce ?? context.coerce;
|
|
10
10
|
let output = input;
|
|
11
11
|
if (output != null && typeof output !== 'number' && coerce) {
|
|
12
12
|
if (typeof input === 'string')
|
|
@@ -38,7 +38,7 @@ export function isObject(schema, options) {
|
|
|
38
38
|
if (ctor && ctor[preValidation]) {
|
|
39
39
|
output = ctor[preValidation](output, context, _this);
|
|
40
40
|
}
|
|
41
|
-
const coerce = options?.coerce
|
|
41
|
+
const coerce = options?.coerce ?? context.coerce;
|
|
42
42
|
if (typeof output === 'string' && coerce)
|
|
43
43
|
output = JSON.parse(output);
|
|
44
44
|
if (!(output && typeof output === 'object')) {
|
|
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
|
|
|
6
6
|
*/
|
|
7
7
|
export function isString(options) {
|
|
8
8
|
return validator('isString', (input, context, _this) => {
|
|
9
|
-
const coerce = options?.coerce
|
|
9
|
+
const coerce = options?.coerce ?? context.coerce;
|
|
10
10
|
let output = input;
|
|
11
11
|
if (output != null && typeof output !== 'string' && coerce) {
|
|
12
12
|
if (typeof output === 'object') {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validator, } from '../../core/index.js';
|
|
2
2
|
export function isTuple(items, options) {
|
|
3
3
|
return validator('isTuple', (input, context, _this) => {
|
|
4
|
-
const coerce = options?.coerce
|
|
4
|
+
const coerce = options?.coerce ?? context.coerce;
|
|
5
5
|
let output = input;
|
|
6
6
|
if (output != null && coerce && !Array.isArray(output))
|
|
7
7
|
output = [output];
|
|
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
|
|
|
5
5
|
*/
|
|
6
6
|
export function isUndefined(options) {
|
|
7
7
|
return validator('isUndefined', (input, context, _this) => {
|
|
8
|
-
if (options?.coerce
|
|
8
|
+
if (options?.coerce ?? context.coerce)
|
|
9
9
|
return undefined;
|
|
10
10
|
if (input === undefined)
|
|
11
11
|
return;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valgen",
|
|
3
3
|
"description": "Fast runtime type validator, converter and io (encoding/decoding) library",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.17.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@browsery/validator": "^13.12.0-r3",
|
|
9
|
+
"@js-temporal/polyfill": "^0.5.1",
|
|
9
10
|
"date-fns": "^4.1.0",
|
|
10
11
|
"reflect-metadata": "^0.2.2",
|
|
11
12
|
"ts-gems": "^3.11.3",
|
package/types/index.d.cts
CHANGED
|
@@ -2,62 +2,64 @@ import * as vg from './rules/index.js';
|
|
|
2
2
|
export * from './constants.js';
|
|
3
3
|
export * from './core/index.js';
|
|
4
4
|
export type { IsObject } from './rules/type-rules/is-object.js';
|
|
5
|
+
declare const isAlpha: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
6
|
+
declare const isAlphanumeric: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
5
7
|
declare const isAny: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
6
8
|
declare const isArray: import("./core/validator.js").Validator<unknown[], unknown, import("./core/types.js").ExecutionOptions>;
|
|
9
|
+
declare const isAscii: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
10
|
+
declare const isBase64: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
7
11
|
declare const isBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
|
|
8
12
|
declare const isBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
|
|
13
|
+
declare const isBtcAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
14
|
+
declare const isCreditCard: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
9
15
|
declare const isDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
10
16
|
declare const isDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
17
|
+
declare const isDecimal: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
18
|
+
declare const isDefined: import("./core/validator.js").Validator<any, unknown, import("./core/types.js").ExecutionOptions>;
|
|
19
|
+
declare const isEAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
20
|
+
declare const isEmail: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
11
21
|
declare const isEmpty: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
12
|
-
declare const
|
|
22
|
+
declare const isETHAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
23
|
+
declare const isFQDN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
24
|
+
declare const isHex: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
25
|
+
declare const isHexColor: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
26
|
+
declare const isIBAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
13
27
|
declare const isInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
14
|
-
declare const
|
|
28
|
+
declare const isIP: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
29
|
+
declare const isIPRange: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
30
|
+
declare const isISSN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
31
|
+
declare const isJWT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
32
|
+
declare const isLowercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
33
|
+
declare const isMACAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
34
|
+
declare const isMobilePhone: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
35
|
+
declare const isNotEmpty: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
15
36
|
declare const isNotNull: import("./core/validator.js").Validator<unknown, unknown, import("./core/types.js").ExecutionOptions>;
|
|
16
|
-
declare const isNullish: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
|
|
17
37
|
declare const isNotNullish: import("./core/validator.js").Validator<unknown, unknown, import("./core/types.js").ExecutionOptions>;
|
|
18
|
-
declare const
|
|
19
|
-
declare const
|
|
38
|
+
declare const isNull: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
|
|
39
|
+
declare const isNullish: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
|
|
20
40
|
declare const isNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
21
41
|
declare const isObject: vg.IsObject.Validator<object, string | object>;
|
|
22
42
|
declare const isObjectId: import("./core/validator.js").Validator<string | vg.ObjectIdLike | Uint8Array<ArrayBufferLike>, unknown, import("./core/types.js").ExecutionOptions>;
|
|
43
|
+
declare const isPort: import("./core/validator.js").Validator<number, string | number, import("./core/types.js").ExecutionOptions>;
|
|
23
44
|
declare const isString: import("./core/validator.js").Validator<string, unknown, import("./core/types.js").ExecutionOptions>;
|
|
45
|
+
declare const isSWIFT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
46
|
+
declare const isTime: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
47
|
+
declare const isUndefined: import("./core/validator.js").Validator<any, unknown, import("./core/types.js").ExecutionOptions>;
|
|
48
|
+
declare const isUppercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
49
|
+
declare const isURL: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
24
50
|
declare const isUUID: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
25
51
|
declare const isUUID1: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
26
52
|
declare const isUUID2: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
27
53
|
declare const isUUID3: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
28
54
|
declare const isUUID4: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
29
55
|
declare const isUUID5: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
30
|
-
declare const isEmail: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
31
|
-
declare const isMobilePhone: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
32
|
-
declare const isIP: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
33
|
-
declare const isIPRange: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
34
|
-
declare const isMACAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
35
|
-
declare const isPort: import("./core/validator.js").Validator<number, string | number, import("./core/types.js").ExecutionOptions>;
|
|
36
|
-
declare const isURL: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
37
|
-
declare const isBase64: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
38
|
-
declare const isSWIFT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
39
|
-
declare const isCreditCard: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
40
|
-
declare const isIBAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
41
|
-
declare const isEAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
42
|
-
declare const isFQDN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
43
|
-
declare const isISSN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
44
|
-
declare const isBtcAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
45
|
-
declare const isETHAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
46
|
-
declare const isHexColor: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
47
|
-
declare const isJWT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
48
|
-
declare const isLowercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
49
|
-
declare const isUppercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
50
|
-
declare const isAlpha: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
51
|
-
declare const isAlphanumeric: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
52
|
-
declare const isAscii: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
53
|
-
declare const isDecimal: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
54
|
-
declare const isHex: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
55
56
|
declare const toArray: import("./core/validator.js").Validator<any[], any, import("./core/types.js").ExecutionOptions>;
|
|
57
|
+
declare const toBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
|
|
56
58
|
declare const toBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
|
|
57
59
|
declare const toDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
58
|
-
declare const toBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
|
|
59
60
|
declare const toDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
60
61
|
declare const toInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
61
62
|
declare const toNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
62
63
|
declare const toString: import("./core/validator.js").Validator<string, unknown, import("./core/types.js").ExecutionOptions>;
|
|
63
|
-
|
|
64
|
+
declare const toTime: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
65
|
+
export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
|
package/types/index.d.ts
CHANGED
|
@@ -2,62 +2,64 @@ import * as vg from './rules/index.js';
|
|
|
2
2
|
export * from './constants.js';
|
|
3
3
|
export * from './core/index.js';
|
|
4
4
|
export type { IsObject } from './rules/type-rules/is-object.js';
|
|
5
|
+
declare const isAlpha: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
6
|
+
declare const isAlphanumeric: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
5
7
|
declare const isAny: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
6
8
|
declare const isArray: import("./core/validator.js").Validator<unknown[], unknown, import("./core/types.js").ExecutionOptions>;
|
|
9
|
+
declare const isAscii: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
10
|
+
declare const isBase64: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
7
11
|
declare const isBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
|
|
8
12
|
declare const isBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
|
|
13
|
+
declare const isBtcAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
14
|
+
declare const isCreditCard: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
9
15
|
declare const isDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
10
16
|
declare const isDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
17
|
+
declare const isDecimal: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
18
|
+
declare const isDefined: import("./core/validator.js").Validator<any, unknown, import("./core/types.js").ExecutionOptions>;
|
|
19
|
+
declare const isEAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
20
|
+
declare const isEmail: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
11
21
|
declare const isEmpty: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
12
|
-
declare const
|
|
22
|
+
declare const isETHAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
23
|
+
declare const isFQDN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
24
|
+
declare const isHex: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
25
|
+
declare const isHexColor: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
26
|
+
declare const isIBAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
13
27
|
declare const isInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
14
|
-
declare const
|
|
28
|
+
declare const isIP: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
29
|
+
declare const isIPRange: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
30
|
+
declare const isISSN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
31
|
+
declare const isJWT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
32
|
+
declare const isLowercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
33
|
+
declare const isMACAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
34
|
+
declare const isMobilePhone: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
35
|
+
declare const isNotEmpty: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
15
36
|
declare const isNotNull: import("./core/validator.js").Validator<unknown, unknown, import("./core/types.js").ExecutionOptions>;
|
|
16
|
-
declare const isNullish: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
|
|
17
37
|
declare const isNotNullish: import("./core/validator.js").Validator<unknown, unknown, import("./core/types.js").ExecutionOptions>;
|
|
18
|
-
declare const
|
|
19
|
-
declare const
|
|
38
|
+
declare const isNull: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
|
|
39
|
+
declare const isNullish: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
|
|
20
40
|
declare const isNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
21
41
|
declare const isObject: vg.IsObject.Validator<object, string | object>;
|
|
22
42
|
declare const isObjectId: import("./core/validator.js").Validator<string | vg.ObjectIdLike | Uint8Array<ArrayBufferLike>, unknown, import("./core/types.js").ExecutionOptions>;
|
|
43
|
+
declare const isPort: import("./core/validator.js").Validator<number, string | number, import("./core/types.js").ExecutionOptions>;
|
|
23
44
|
declare const isString: import("./core/validator.js").Validator<string, unknown, import("./core/types.js").ExecutionOptions>;
|
|
45
|
+
declare const isSWIFT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
46
|
+
declare const isTime: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
47
|
+
declare const isUndefined: import("./core/validator.js").Validator<any, unknown, import("./core/types.js").ExecutionOptions>;
|
|
48
|
+
declare const isUppercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
49
|
+
declare const isURL: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
24
50
|
declare const isUUID: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
25
51
|
declare const isUUID1: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
26
52
|
declare const isUUID2: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
27
53
|
declare const isUUID3: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
28
54
|
declare const isUUID4: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
29
55
|
declare const isUUID5: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
30
|
-
declare const isEmail: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
31
|
-
declare const isMobilePhone: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
32
|
-
declare const isIP: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
33
|
-
declare const isIPRange: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
34
|
-
declare const isMACAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
35
|
-
declare const isPort: import("./core/validator.js").Validator<number, string | number, import("./core/types.js").ExecutionOptions>;
|
|
36
|
-
declare const isURL: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
37
|
-
declare const isBase64: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
38
|
-
declare const isSWIFT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
39
|
-
declare const isCreditCard: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
40
|
-
declare const isIBAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
41
|
-
declare const isEAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
42
|
-
declare const isFQDN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
43
|
-
declare const isISSN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
44
|
-
declare const isBtcAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
45
|
-
declare const isETHAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
46
|
-
declare const isHexColor: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
47
|
-
declare const isJWT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
48
|
-
declare const isLowercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
49
|
-
declare const isUppercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
50
|
-
declare const isAlpha: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
51
|
-
declare const isAlphanumeric: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
52
|
-
declare const isAscii: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
53
|
-
declare const isDecimal: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
54
|
-
declare const isHex: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
55
56
|
declare const toArray: import("./core/validator.js").Validator<any[], any, import("./core/types.js").ExecutionOptions>;
|
|
57
|
+
declare const toBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
|
|
56
58
|
declare const toBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
|
|
57
59
|
declare const toDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
58
|
-
declare const toBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
|
|
59
60
|
declare const toDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
60
61
|
declare const toInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
61
62
|
declare const toNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
62
63
|
declare const toString: import("./core/validator.js").Validator<string, unknown, import("./core/types.js").ExecutionOptions>;
|
|
63
|
-
|
|
64
|
+
declare const toTime: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
65
|
+
export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
2
|
+
type Precision = 'year' | 'yr' | 'month' | 'mo' | 'day' | 'd' | 'hours' | 'hr' | 'minutes' | 'min' | 'seconds' | 'sec' | 'milliseconds' | 'ms' | 'tz';
|
|
3
|
+
export interface IsDateOptions extends ValidationOptions {
|
|
4
|
+
trim?: Precision;
|
|
5
|
+
}
|
|
2
6
|
/**
|
|
3
|
-
* Validates if value is
|
|
4
|
-
*
|
|
7
|
+
* Validates if value is a "Date" instance or ISO 8601 formatted date string.
|
|
8
|
+
* if a `coerce` option is `true`, converts input value to Date instance
|
|
5
9
|
* @validator isDate
|
|
6
10
|
*/
|
|
7
|
-
export declare function isDate(options?:
|
|
11
|
+
export declare function isDate(options?: IsDateOptions): import("../../core/validator.js").Validator<Date, string | number | Date, import("../../core/types.js").ExecutionOptions>;
|
|
8
12
|
export interface IsDateStringOptions extends ValidationOptions {
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
precisionMin?: Precision;
|
|
14
|
+
precisionMax?: Precision;
|
|
15
|
+
trim?: Precision;
|
|
11
16
|
}
|
|
12
17
|
/**
|
|
13
18
|
* Validates if value is DFS (date formatted string).
|
|
14
|
-
* Converts input value to DFS if coerce option is set to 'true'.
|
|
19
|
+
* Converts input value to DFS if the "coerce" option is set to 'true'.
|
|
15
20
|
* @validator isDateString
|
|
16
21
|
*/
|
|
17
22
|
export declare function isDateString(options?: IsDateStringOptions): import("../../core/validator.js").Validator<string, string | number | Date, import("../../core/types.js").ExecutionOptions>;
|
|
18
|
-
export
|
|
19
|
-
interface Options extends ValidationOptions {
|
|
20
|
-
precision?: 'year' | 'month' | 'date' | 'time';
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
+
export {};
|