valgen 5.20.0 → 6.0.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/constants.js +1 -1
- package/index.d.ts +3 -6
- package/index.js +4 -4
- package/package.json +1 -1
- package/rules/format-rules/is-alpha.d.ts +5 -6
- package/rules/format-rules/is-alpha.js +1 -13
- package/rules/format-rules/is-alphanumeric.d.ts +10 -0
- package/rules/format-rules/is-alphanumeric.js +14 -0
- package/rules/format-rules/is-ascii.d.ts +5 -1
- package/rules/format-rules/is-base64.d.ts +5 -3
- package/rules/format-rules/is-btc-address.d.ts +5 -1
- package/rules/format-rules/is-credit-card.d.ts +5 -3
- package/rules/format-rules/is-decimal.d.ts +5 -1
- package/rules/format-rules/is-ean.d.ts +5 -1
- package/rules/format-rules/is-email.d.ts +59 -57
- package/rules/format-rules/is-eth-address.d.ts +6 -2
- package/rules/format-rules/is-eth-address.js +1 -1
- package/rules/format-rules/is-fqdn.d.ts +10 -8
- package/rules/format-rules/is-hash.d.ts +4 -2
- package/rules/format-rules/is-hex-color.d.ts +5 -1
- package/rules/format-rules/is-hex.d.ts +5 -1
- package/rules/format-rules/is-iban.d.ts +5 -6
- package/rules/format-rules/is-iban.js +0 -11
- package/rules/format-rules/is-ip.d.ts +9 -2
- package/rules/format-rules/is-issn.d.ts +11 -9
- package/rules/format-rules/is-jwt.d.ts +5 -1
- package/rules/format-rules/is-lowercase.d.ts +5 -6
- package/rules/format-rules/is-lowercase.js +0 -12
- package/rules/format-rules/is-mac-address.d.ts +18 -16
- package/rules/format-rules/is-mobile-phone.d.ts +16 -14
- package/rules/format-rules/is-object-id.d.ts +7 -5
- package/rules/format-rules/is-passport-number.d.ts +5 -1
- package/rules/format-rules/is-port.d.ts +5 -1
- package/rules/format-rules/is-swift.d.ts +10 -0
- package/rules/format-rules/is-swift.js +13 -0
- package/rules/format-rules/is-time.d.ts +5 -3
- package/rules/format-rules/is-uppercase.d.ts +10 -0
- package/rules/format-rules/is-uppercase.js +14 -0
- package/rules/format-rules/is-url.d.ts +5 -3
- package/rules/format-rules/is-uuid.d.ts +6 -2
- package/rules/format-rules/is-vat-number.d.ts +6 -2
- package/rules/format-rules/matches.d.ts +6 -4
- package/rules/index.d.ts +9 -0
- package/rules/index.js +9 -0
- package/rules/logical-rules/is-defined.d.ts +5 -1
- package/rules/logical-rules/is-empty.d.ts +12 -4
- package/rules/logical-rules/is-empty.js +2 -2
- package/rules/logical-rules/is-equal.d.ts +10 -2
- package/rules/logical-rules/is-gt.d.ts +12 -0
- package/rules/logical-rules/is-gt.js +27 -0
- package/rules/logical-rules/is-gte.d.ts +12 -0
- package/rules/logical-rules/is-gte.js +27 -0
- package/rules/logical-rules/is-lt.d.ts +12 -0
- package/rules/logical-rules/is-lt.js +27 -0
- package/rules/logical-rules/is-lte.d.ts +12 -0
- package/rules/logical-rules/is-lte.js +27 -0
- package/rules/logical-rules/length.d.ts +10 -0
- package/rules/logical-rules/length.js +29 -0
- package/rules/logical-rules/range.d.ts +6 -42
- package/rules/logical-rules/range.js +0 -134
- package/rules/type-rules/is-any.d.ts +1 -1
- package/rules/type-rules/is-any.js +1 -1
- package/rules/type-rules/is-array.d.ts +7 -3
- package/rules/type-rules/is-array.js +2 -2
- package/rules/type-rules/is-bigint.d.ts +6 -2
- package/rules/type-rules/is-bigint.js +1 -1
- package/rules/type-rules/is-boolean.d.ts +6 -2
- package/rules/type-rules/is-boolean.js +1 -1
- package/rules/type-rules/is-date.d.ts +17 -12
- package/rules/type-rules/is-date.js +1 -1
- package/rules/type-rules/is-enum.d.ts +8 -5
- package/rules/type-rules/is-enum.js +1 -1
- package/rules/type-rules/is-integer.d.ts +7 -3
- package/rules/type-rules/is-integer.js +2 -2
- package/rules/type-rules/is-null.d.ts +24 -8
- package/rules/type-rules/is-null.js +4 -4
- package/rules/type-rules/is-number.d.ts +7 -3
- package/rules/type-rules/is-number.js +2 -2
- package/rules/type-rules/is-object.d.ts +7 -7
- package/rules/type-rules/is-object.js +2 -2
- package/rules/type-rules/is-record.d.ts +7 -3
- package/rules/type-rules/is-record.js +2 -2
- package/rules/type-rules/is-string.d.ts +7 -38
- package/rules/type-rules/is-string.js +2 -49
- package/rules/type-rules/is-tuple.d.ts +13 -9
- package/rules/type-rules/is-undefined.d.ts +6 -2
- package/rules/type-rules/is-undefined.js +1 -1
- package/rules/utility-rules/all-of.d.ts +6 -2
- package/rules/utility-rules/all-of.js +3 -3
- package/rules/utility-rules/exists.d.ts +5 -1
- package/rules/utility-rules/one-of.d.ts +6 -2
- package/rules/utility-rules/one-of.js +4 -4
- package/rules/utility-rules/optional.d.ts +6 -2
- package/rules/utility-rules/optional.js +1 -1
- package/rules/utility-rules/pipe.d.ts +6 -4
- package/rules/utility-rules/string-utils.d.ts +35 -0
- package/rules/utility-rules/string-utils.js +48 -0
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { validator, } from '../../core/index.js';
|
|
2
|
-
import { allOf } from '../utility-rules/all-of.js';
|
|
3
|
-
import { getLength } from '../utility-rules/get-length.js';
|
|
4
|
-
import { pipe } from '../utility-rules/pipe.js';
|
|
5
2
|
/**
|
|
6
3
|
* Checks if value is between minValue and maxValue
|
|
7
4
|
* @validator range
|
|
@@ -32,134 +29,3 @@ export function range(minValue, maxValue, options) {
|
|
|
32
29
|
context.fail(_this, `Value must be between ${minValue} and ${maxValue}`, input);
|
|
33
30
|
}, options);
|
|
34
31
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Checks if value is grater than "minValue"
|
|
37
|
-
* @validator iGt
|
|
38
|
-
*/
|
|
39
|
-
export function isGt(minValue, options) {
|
|
40
|
-
return validator('isGt', (input, context, _this) => {
|
|
41
|
-
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
42
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
43
|
-
input > minValue) {
|
|
44
|
-
return input;
|
|
45
|
-
}
|
|
46
|
-
if (minValue instanceof Date &&
|
|
47
|
-
input instanceof Date &&
|
|
48
|
-
input > minValue) {
|
|
49
|
-
return input;
|
|
50
|
-
}
|
|
51
|
-
if (typeof minValue === 'string' &&
|
|
52
|
-
typeof input === 'string' &&
|
|
53
|
-
(input > minValue ||
|
|
54
|
-
(options?.caseInsensitive &&
|
|
55
|
-
input.toLowerCase() > minValue.toLowerCase()))) {
|
|
56
|
-
return input;
|
|
57
|
-
}
|
|
58
|
-
context.fail(_this, `Value must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
59
|
-
}, options);
|
|
60
|
-
}
|
|
61
|
-
// *************************************************************
|
|
62
|
-
/**
|
|
63
|
-
* Checks if value is grater than or equal to minValue
|
|
64
|
-
* @validator isGte
|
|
65
|
-
*/
|
|
66
|
-
export function isGte(minValue, options) {
|
|
67
|
-
return validator('isGte', (input, context, _this) => {
|
|
68
|
-
if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
|
|
69
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
70
|
-
input >= minValue) {
|
|
71
|
-
return input;
|
|
72
|
-
}
|
|
73
|
-
if (minValue instanceof Date &&
|
|
74
|
-
input instanceof Date &&
|
|
75
|
-
input >= minValue) {
|
|
76
|
-
return input;
|
|
77
|
-
}
|
|
78
|
-
if (typeof minValue === 'string' &&
|
|
79
|
-
typeof input === 'string' &&
|
|
80
|
-
(input >= minValue ||
|
|
81
|
-
(options?.caseInsensitive &&
|
|
82
|
-
input.toLowerCase() >= minValue.toLowerCase()))) {
|
|
83
|
-
return input;
|
|
84
|
-
}
|
|
85
|
-
context.fail(_this, `Value must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
|
|
86
|
-
}, options);
|
|
87
|
-
}
|
|
88
|
-
// *************************************************************
|
|
89
|
-
/**
|
|
90
|
-
* Checks if number value is lover than maxValue
|
|
91
|
-
* @validator isLt
|
|
92
|
-
*/
|
|
93
|
-
export function isLt(maxValue, options) {
|
|
94
|
-
return validator('isLt', (input, context, _this) => {
|
|
95
|
-
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
96
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
97
|
-
input < maxValue) {
|
|
98
|
-
return input;
|
|
99
|
-
}
|
|
100
|
-
if (maxValue instanceof Date &&
|
|
101
|
-
input instanceof Date &&
|
|
102
|
-
input < maxValue) {
|
|
103
|
-
return input;
|
|
104
|
-
}
|
|
105
|
-
if (typeof maxValue === 'string' &&
|
|
106
|
-
typeof input === 'string' &&
|
|
107
|
-
(input < maxValue ||
|
|
108
|
-
(options?.caseInsensitive &&
|
|
109
|
-
input.toLowerCase() < maxValue.toLowerCase()))) {
|
|
110
|
-
return input;
|
|
111
|
-
}
|
|
112
|
-
context.fail(_this, `Value must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
|
|
113
|
-
}, options);
|
|
114
|
-
}
|
|
115
|
-
// *************************************************************
|
|
116
|
-
/**
|
|
117
|
-
* Checks if value is lover than or equal to maxValue
|
|
118
|
-
* @validator isLte
|
|
119
|
-
*/
|
|
120
|
-
export function isLte(maxValue, options) {
|
|
121
|
-
return validator('isLte', (input, context, _this) => {
|
|
122
|
-
if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
|
|
123
|
-
(typeof input === 'number' || typeof input === 'bigint') &&
|
|
124
|
-
input <= maxValue) {
|
|
125
|
-
return input;
|
|
126
|
-
}
|
|
127
|
-
if (maxValue instanceof Date &&
|
|
128
|
-
input instanceof Date &&
|
|
129
|
-
input <= maxValue) {
|
|
130
|
-
return input;
|
|
131
|
-
}
|
|
132
|
-
if (typeof maxValue === 'string' &&
|
|
133
|
-
typeof input === 'string' &&
|
|
134
|
-
(input <= maxValue ||
|
|
135
|
-
(options?.caseInsensitive &&
|
|
136
|
-
input.toLowerCase() <= maxValue.toLowerCase()))) {
|
|
137
|
-
return input;
|
|
138
|
-
}
|
|
139
|
-
context.fail(_this, `Value must be lover than or equal to ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
|
|
140
|
-
}, options);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Checks the length is at least "minValue"
|
|
144
|
-
* @validator lengthMin
|
|
145
|
-
*/
|
|
146
|
-
export const lengthMin = (minValue) => allOf([
|
|
147
|
-
pipe([
|
|
148
|
-
getLength(),
|
|
149
|
-
isGte(minValue, {
|
|
150
|
-
onFail: () => `Value length must be at least ${minValue}`,
|
|
151
|
-
}),
|
|
152
|
-
]),
|
|
153
|
-
]);
|
|
154
|
-
/**
|
|
155
|
-
* Checks if the length is at most "maxValue"
|
|
156
|
-
* @validator lengthMax
|
|
157
|
-
*/
|
|
158
|
-
export const lengthMax = (maxValue) => allOf([
|
|
159
|
-
pipe([
|
|
160
|
-
getLength(),
|
|
161
|
-
isLte(maxValue, {
|
|
162
|
-
onFail: () => `The length of {{label}} must be at most ${maxValue}`,
|
|
163
|
-
}),
|
|
164
|
-
]),
|
|
165
|
-
]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Does nothing, just returns original input value.
|
|
2
|
+
* Does nothing, just returns the original input value.
|
|
3
3
|
* @validator isAny
|
|
4
4
|
*/
|
|
5
5
|
export declare const isAny: () => import("../../core/validator.js").Validator<any, any, import("../../core/types.js").ExecutionOptions>;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type ValidationOptions, type Validator } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if value is "array" and applies validation for each item.
|
|
4
|
-
* Converts input value to array if coerce option is set to 'true'.
|
|
3
|
+
* Validates if the value is "array" and applies validation for each item.
|
|
4
|
+
* Converts input value to array if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isArray
|
|
6
6
|
*/
|
|
7
|
-
export declare function isArray<T, I>(itemValidator?: Validator<T, I>, options?:
|
|
7
|
+
export declare function isArray<T, I>(itemValidator?: Validator<T, I>, options?: isArray.Options): Validator<T[], I | I[], import("../../core/types.js").ExecutionOptions>;
|
|
8
|
+
export declare namespace isArray {
|
|
9
|
+
interface Options extends ValidationOptions {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if value is "array" and applies validation for each item.
|
|
4
|
-
* Converts input value to array if coerce option is set to 'true'.
|
|
3
|
+
* Validates if the value is "array" and applies validation for each item.
|
|
4
|
+
* Converts input value to array if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isArray
|
|
6
6
|
*/
|
|
7
7
|
export function isArray(itemValidator, options) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Validates if value is "BigInt".
|
|
4
|
-
* Converts input value to number if coerce option is set to 'true'.
|
|
4
|
+
* Converts input value to number if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isNumber
|
|
6
6
|
*/
|
|
7
|
-
export declare function isBigint(options?:
|
|
7
|
+
export declare function isBigint(options?: isBigint.Options): import("../../core/validator.js").Validator<bigint, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
8
|
+
export declare namespace isBigint {
|
|
9
|
+
interface Options extends ValidationOptions {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Validates if value is "BigInt".
|
|
4
|
-
* Converts input value to number if coerce option is set to 'true'.
|
|
4
|
+
* Converts input value to number if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isNumber
|
|
6
6
|
*/
|
|
7
7
|
export function isBigint(options) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Validates if value is "boolean".
|
|
4
|
-
* Converts input value to boolean if coerce option is set to 'true'.
|
|
4
|
+
* Converts input value to boolean if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isBoolean
|
|
6
6
|
*/
|
|
7
|
-
export declare function isBoolean(options?:
|
|
7
|
+
export declare function isBoolean(options?: isBoolean.Options): import("../../core/validator.js").Validator<boolean | undefined, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
8
|
+
export declare namespace isBoolean {
|
|
9
|
+
interface Options extends ValidationOptions {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -3,7 +3,7 @@ const TRUE_PATTERN = /^true|t|1|yes|y$/i;
|
|
|
3
3
|
const FALSE_PATTERN = /^false|f|0|no|n$/i;
|
|
4
4
|
/**
|
|
5
5
|
* Validates if value is "boolean".
|
|
6
|
-
* Converts input value to boolean if coerce option is set to 'true'.
|
|
6
|
+
* Converts input value to boolean if the coerce option is set to 'true'.
|
|
7
7
|
* @validator isBoolean
|
|
8
8
|
*/
|
|
9
9
|
export function isBoolean(options) {
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
2
|
-
export type DatePrecision = 'year' | 'yr' | 'month' | 'mo' | 'day' | 'd' | 'hours' | 'hr' | 'minutes' | 'min' | 'seconds' | 'sec' | 'milliseconds' | 'ms' | 'tz';
|
|
3
|
-
export interface IsDateOptions extends ValidationOptions {
|
|
4
|
-
trim?: DatePrecision;
|
|
5
|
-
}
|
|
6
2
|
/**
|
|
7
3
|
* Validates if value is a "Date" instance or ISO 8601 formatted date string.
|
|
8
4
|
* if a `coerce` option is `true`, converts input value to Date instance
|
|
9
5
|
* @validator isDate
|
|
10
6
|
*/
|
|
11
|
-
export declare function isDate(options?:
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
export declare function isDate(options?: isDate.Options): import("../../core/validator.js").Validator<Date, string | number | Date, import("../../core/types.js").ExecutionOptions>;
|
|
8
|
+
export declare namespace isDate {
|
|
9
|
+
type Precision = 'year' | 'yr' | 'month' | 'mo' | 'day' | 'd' | 'hours' | 'hr' | 'minutes' | 'min' | 'seconds' | 'sec' | 'milliseconds' | 'ms' | 'tz';
|
|
10
|
+
interface Options extends ValidationOptions {
|
|
11
|
+
trim?: Precision;
|
|
12
|
+
}
|
|
17
13
|
}
|
|
18
14
|
/**
|
|
19
|
-
* Validates if value is DFS (date
|
|
15
|
+
* Validates if value is DFS (date-formatted string).
|
|
20
16
|
* Converts input value to DFS if the "coerce" option is set to 'true'.
|
|
21
17
|
* @validator isDateString
|
|
22
18
|
*/
|
|
23
|
-
export declare function isDateString(options?:
|
|
19
|
+
export declare function isDateString(options?: isDateString.Options): import("../../core/validator.js").Validator<string, string | number | Date, import("../../core/types.js").ExecutionOptions>;
|
|
20
|
+
export declare namespace isDateString {
|
|
21
|
+
type Precision = isDate.Precision;
|
|
22
|
+
interface Options extends ValidationOptions {
|
|
23
|
+
precisionMin?: Precision;
|
|
24
|
+
precisionMax?: Precision;
|
|
25
|
+
trim?: boolean;
|
|
26
|
+
timeZone?: boolean | number;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -32,7 +32,7 @@ export function isDate(options) {
|
|
|
32
32
|
}, options);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* Validates if value is DFS (date
|
|
35
|
+
* Validates if value is DFS (date-formatted string).
|
|
36
36
|
* Converts input value to DFS if the "coerce" option is set to 'true'.
|
|
37
37
|
* @validator isDateString
|
|
38
38
|
*/
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { type ValidationOptions, type Validator } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if given value is one of enum values.
|
|
3
|
+
* Validates if the given value is one of enum values.
|
|
4
4
|
* @validator isEnum
|
|
5
5
|
*/
|
|
6
|
-
export declare function isEnum<T1>(values: any, options?:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export declare function isEnum<T1>(values: any, options?: isEnum.Options): Validator<T1, any>;
|
|
7
|
+
export declare namespace isEnum {
|
|
8
|
+
interface Options extends ValidationOptions {
|
|
9
|
+
caseInSensitive?: boolean;
|
|
10
|
+
enumName?: string;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if value is "integer".
|
|
4
|
-
* Converts input value to integer number if coerce option is set to 'true'.
|
|
3
|
+
* Validates if the value is "integer".
|
|
4
|
+
* Converts the input value to an integer number if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isInteger
|
|
6
6
|
*/
|
|
7
|
-
export declare function isInteger(options?:
|
|
7
|
+
export declare function isInteger(options?: isInteger.Options): import("../../core/validator.js").Validator<number, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
8
|
+
export declare namespace isInteger {
|
|
9
|
+
interface Options extends ValidationOptions {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if value is "integer".
|
|
4
|
-
* Converts input value to integer number if coerce option is set to 'true'.
|
|
3
|
+
* Validates if the value is "integer".
|
|
4
|
+
* Converts the input value to an integer number if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isInteger
|
|
6
6
|
*/
|
|
7
7
|
export function isInteger(options) {
|
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if value is "null".
|
|
3
|
+
* Validates if the value is "null".
|
|
4
4
|
* @validator isNull
|
|
5
5
|
*/
|
|
6
|
-
export declare function isNull(options?:
|
|
6
|
+
export declare function isNull(options?: isNull.Options): import("../../core/validator.js").Validator<null, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
7
|
+
export declare namespace isNull {
|
|
8
|
+
interface Options extends ValidationOptions {
|
|
9
|
+
}
|
|
10
|
+
}
|
|
7
11
|
/**
|
|
8
|
-
* Validates if value is not "null".
|
|
12
|
+
* Validates if the value is not "null".
|
|
9
13
|
* @validator isNotNull
|
|
10
14
|
*/
|
|
11
|
-
export declare function isNotNull(options?:
|
|
15
|
+
export declare function isNotNull(options?: isNotNull.Options): import("../../core/validator.js").Validator<unknown, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
16
|
+
export declare namespace isNotNull {
|
|
17
|
+
interface Options extends ValidationOptions {
|
|
18
|
+
}
|
|
19
|
+
}
|
|
12
20
|
/**
|
|
13
|
-
* Validates if value is "null" or "undefined".
|
|
21
|
+
* Validates if the value is "null" or "undefined".
|
|
14
22
|
* @validator isNullish
|
|
15
23
|
*/
|
|
16
|
-
export declare function isNullish(options?:
|
|
24
|
+
export declare function isNullish(options?: isNullish.Options): import("../../core/validator.js").Validator<null, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
25
|
+
export declare namespace isNullish {
|
|
26
|
+
interface Options extends ValidationOptions {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
17
29
|
/**
|
|
18
|
-
* Validates if value is not "null" nor "undefined".
|
|
30
|
+
* Validates if the value is not "null" nor "undefined".
|
|
19
31
|
* @validator isNotNullish
|
|
20
32
|
*/
|
|
21
|
-
export declare function isNotNullish(options?:
|
|
33
|
+
export declare function isNotNullish(options?: isNotNullish.Options): import("../../core/validator.js").Validator<unknown, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
34
|
+
export declare namespace isNotNullish {
|
|
35
|
+
interface Options extends ValidationOptions {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if value is "null".
|
|
3
|
+
* Validates if the value is "null".
|
|
4
4
|
* @validator isNull
|
|
5
5
|
*/
|
|
6
6
|
export function isNull(options) {
|
|
@@ -11,7 +11,7 @@ export function isNull(options) {
|
|
|
11
11
|
}, options);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Validates if value is not "null".
|
|
14
|
+
* Validates if the value is not "null".
|
|
15
15
|
* @validator isNotNull
|
|
16
16
|
*/
|
|
17
17
|
export function isNotNull(options) {
|
|
@@ -22,7 +22,7 @@ export function isNotNull(options) {
|
|
|
22
22
|
}, options);
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* Validates if value is "null" or "undefined".
|
|
25
|
+
* Validates if the value is "null" or "undefined".
|
|
26
26
|
* @validator isNullish
|
|
27
27
|
*/
|
|
28
28
|
export function isNullish(options) {
|
|
@@ -33,7 +33,7 @@ export function isNullish(options) {
|
|
|
33
33
|
}, options);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* Validates if value is not "null" nor "undefined".
|
|
36
|
+
* Validates if the value is not "null" nor "undefined".
|
|
37
37
|
* @validator isNotNullish
|
|
38
38
|
*/
|
|
39
39
|
export function isNotNullish(options) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if value is
|
|
4
|
-
* Converts input value to number if coerce option is set to 'true'.
|
|
3
|
+
* Validates if the value is a number.
|
|
4
|
+
* Converts input value to number if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isNumber
|
|
6
6
|
*/
|
|
7
|
-
export declare function isNumber(options?:
|
|
7
|
+
export declare function isNumber(options?: isNumber.Options): import("../../core/validator.js").Validator<number, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
8
|
+
export declare namespace isNumber {
|
|
9
|
+
interface Options extends ValidationOptions {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if value is
|
|
4
|
-
* Converts input value to number if coerce option is set to 'true'.
|
|
3
|
+
* Validates if the value is a number.
|
|
4
|
+
* Converts input value to number if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isNumber
|
|
6
6
|
*/
|
|
7
7
|
export function isNumber(options) {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { type Type, type ValidationOptions, type Validator as Validator_ } from '../../core/index.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Validates the object according to schema
|
|
4
|
+
* Converts properties according to schema rules if the coerce option is set to 'true'.
|
|
5
|
+
* @validator isObject
|
|
6
|
+
*/
|
|
7
|
+
export declare function isObject<T extends object = object, I = object | string>(schema?: isObject.Schema, options?: isObject.Options<T>): isObject.Validator<T, I>;
|
|
8
|
+
export declare namespace isObject {
|
|
3
9
|
interface Validator<T extends object = object, I = object> extends Validator_<T, I> {
|
|
4
10
|
schema: Schema;
|
|
5
11
|
}
|
|
@@ -16,9 +22,3 @@ export declare namespace IsObject {
|
|
|
16
22
|
detectCircular?: boolean;
|
|
17
23
|
}
|
|
18
24
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Validates object according to schema
|
|
21
|
-
* Converts properties according to schema rules if coerce option is set to 'true'.
|
|
22
|
-
* @validator isObject
|
|
23
|
-
*/
|
|
24
|
-
export declare function isObject<T extends object = object, I = object | string>(schema?: IsObject.Schema, options?: IsObject.Options<T>): IsObject.Validator<T, I>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { postValidation, preValidation } from '../../constants.js';
|
|
2
2
|
import { isValidator, validator, } from '../../core/index.js';
|
|
3
3
|
/**
|
|
4
|
-
* Validates object according to schema
|
|
5
|
-
* Converts properties according to schema rules if coerce option is set to 'true'.
|
|
4
|
+
* Validates the object according to schema
|
|
5
|
+
* Converts properties according to schema rules if the coerce option is set to 'true'.
|
|
6
6
|
* @validator isObject
|
|
7
7
|
*/
|
|
8
8
|
export function isObject(schema, options) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type ValidationOptions, type Validator } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates record object according to given "key" and "value" rules
|
|
4
|
-
* Converts properties according to rules if coerce option is set to 'true'.
|
|
3
|
+
* Validates the record object according to given "key" and "value" rules
|
|
4
|
+
* Converts properties according to rules if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isRecord
|
|
6
6
|
*/
|
|
7
|
-
export declare function isRecord<TKeys extends string | number | symbol, TValues>(keyRule: Validator<TKeys>, valueRule: Validator<TValues>, options?:
|
|
7
|
+
export declare function isRecord<TKeys extends string | number | symbol, TValues>(keyRule: Validator<TKeys>, valueRule: Validator<TValues>, options?: isRecord.Options): Validator<Record<TKeys, TValues>, Record<TKeys, TValues>, import("../../core/types.js").ExecutionOptions>;
|
|
8
|
+
export declare namespace isRecord {
|
|
9
|
+
interface Options extends ValidationOptions {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates record object according to given "key" and "value" rules
|
|
4
|
-
* Converts properties according to rules if coerce option is set to 'true'.
|
|
3
|
+
* Validates the record object according to given "key" and "value" rules
|
|
4
|
+
* Converts properties according to rules if the coerce option is set to 'true'.
|
|
5
5
|
* @validator isRecord
|
|
6
6
|
*/
|
|
7
7
|
export function isRecord(keyRule, valueRule, options) {
|
|
@@ -1,42 +1,11 @@
|
|
|
1
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if value is
|
|
4
|
-
* Converts input value to string if
|
|
3
|
+
* Validates if the value is a string.
|
|
4
|
+
* Converts input value to string if the oerce option is set to 'true'.
|
|
5
5
|
* @validator isString
|
|
6
6
|
*/
|
|
7
|
-
export declare function isString(options?:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export declare function stringReplace(searchValue: string | RegExp, replaceValue: string): any;
|
|
13
|
-
export declare function stringReplace(searchValue: string | RegExp, replacer: (subsring: string, ...args: any[]) => string): any;
|
|
14
|
-
export declare function stringReplace(searchValue: {
|
|
15
|
-
[Symbol.replace](string: string, replaceValue: string): string;
|
|
16
|
-
}, replaceValue: string): any;
|
|
17
|
-
export declare function stringReplace(searchValue: {
|
|
18
|
-
[Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string;
|
|
19
|
-
}, replacer: (substring: string, ...args: any[]) => string): any;
|
|
20
|
-
/**
|
|
21
|
-
* Process "String.split" method
|
|
22
|
-
* @validator split
|
|
23
|
-
*/
|
|
24
|
-
export declare function stringSplit(separator: string | RegExp, limit?: number): any;
|
|
25
|
-
export declare function stringSplit(splitter: {
|
|
26
|
-
[Symbol.split](string: string, limit?: number): string[];
|
|
27
|
-
}, limit?: number): any;
|
|
28
|
-
/**
|
|
29
|
-
* Removes whitespace from both ends of a string
|
|
30
|
-
* @validator trim
|
|
31
|
-
*/
|
|
32
|
-
export declare function trim(): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
|
|
33
|
-
/**
|
|
34
|
-
* Removes whitespace from the end of a string
|
|
35
|
-
* @validator trimEnd
|
|
36
|
-
*/
|
|
37
|
-
export declare const trimEnd: () => import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
|
|
38
|
-
/**
|
|
39
|
-
* Removes whitespace from the beginning of a string
|
|
40
|
-
* @validator trimStart
|
|
41
|
-
*/
|
|
42
|
-
export declare const trimStart: () => import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
|
|
7
|
+
export declare function isString(options?: isString.Options): import("../../core/validator.js").Validator<string, unknown, import("../../core/types.js").ExecutionOptions>;
|
|
8
|
+
export declare namespace isString {
|
|
9
|
+
interface Options extends ValidationOptions {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validator, } from '../../core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Validates if value is
|
|
4
|
-
* Converts input value to string if
|
|
3
|
+
* Validates if the value is a string.
|
|
4
|
+
* Converts input value to string if the oerce option is set to 'true'.
|
|
5
5
|
* @validator isString
|
|
6
6
|
*/
|
|
7
7
|
export function isString(options) {
|
|
@@ -23,50 +23,3 @@ export function isString(options) {
|
|
|
23
23
|
context.fail(_this, `Value must be a string`, input);
|
|
24
24
|
}, options);
|
|
25
25
|
}
|
|
26
|
-
export function stringReplace(searchValue, replacer) {
|
|
27
|
-
return validator('stringReplace', (input) => {
|
|
28
|
-
if (input == null)
|
|
29
|
-
return input;
|
|
30
|
-
return String(input).replace(searchValue, replacer);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
export function stringSplit(splitter, limit) {
|
|
34
|
-
return validator('stringSplit', (input) => {
|
|
35
|
-
if (input == null)
|
|
36
|
-
return input;
|
|
37
|
-
return String(input).split(splitter, limit);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Removes whitespace from both ends of a string
|
|
42
|
-
* @validator trim
|
|
43
|
-
*/
|
|
44
|
-
export function trim() {
|
|
45
|
-
return validator('trim', (input) => {
|
|
46
|
-
if (input == null)
|
|
47
|
-
return input;
|
|
48
|
-
return String(input).trim();
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
// *************************************************************
|
|
52
|
-
/**
|
|
53
|
-
* Removes whitespace from the end of a string
|
|
54
|
-
* @validator trimEnd
|
|
55
|
-
*/
|
|
56
|
-
export const trimEnd = () => trimEndRule;
|
|
57
|
-
const trimEndRule = validator('trimEnd', (input) => {
|
|
58
|
-
if (input == null)
|
|
59
|
-
return input;
|
|
60
|
-
return String(input).trimEnd();
|
|
61
|
-
});
|
|
62
|
-
// *************************************************************
|
|
63
|
-
/**
|
|
64
|
-
* Removes whitespace from the beginning of a string
|
|
65
|
-
* @validator trimStart
|
|
66
|
-
*/
|
|
67
|
-
export const trimStart = () => trimStartRule;
|
|
68
|
-
const trimStartRule = validator('trimStart', (input) => {
|
|
69
|
-
if (input == null)
|
|
70
|
-
return input;
|
|
71
|
-
return String(input).trimStart();
|
|
72
|
-
});
|