valgen 4.3.2 → 5.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/CHANGELOG.md +7 -0
- package/cjs/constants.js +5 -0
- package/cjs/core/index.js +1 -0
- package/cjs/{rules → core}/utilities.js +1 -1
- package/cjs/factories.js +17 -0
- package/cjs/index.js +112 -1
- package/cjs/rules/index.js +1 -2
- package/cjs/rules/is-object.js +11 -12
- package/cjs/rules/{is-matches.js → is-regexp.js} +3 -3
- package/cjs/rules/string-formats.js +62 -1
- package/esm/constants.js +2 -0
- package/esm/core/index.js +1 -0
- package/esm/{rules → core}/utilities.js +1 -1
- package/esm/factories.js +1 -0
- package/esm/index.js +51 -1
- package/esm/rules/index.js +1 -2
- package/esm/rules/is-object.js +11 -12
- package/esm/rules/{is-matches.js → is-regexp.js} +1 -1
- package/esm/rules/string-formats.js +56 -0
- package/package.json +2 -2
- package/typings/constants.d.ts +2 -0
- package/typings/core/index.d.ts +1 -0
- package/typings/{rules → core}/utilities.d.ts +2 -2
- package/typings/factories.d.ts +1 -0
- package/typings/index.d.ts +52 -1
- package/typings/rules/index.d.ts +1 -2
- package/typings/rules/is-date.d.ts +6 -4
- package/typings/rules/is-object.d.ts +18 -20
- package/typings/rules/is-regexp.d.ts +9 -0
- package/typings/rules/string-formats.d.ts +26 -0
- package/typings/rules/is-matches.d.ts +0 -9
package/CHANGELOG.md
CHANGED
package/cjs/constants.js
ADDED
package/cjs/core/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.iif = exports.forwardRef = void 0;
|
|
4
|
-
const index_js_1 = require("
|
|
4
|
+
const index_js_1 = require("./index.js");
|
|
5
5
|
/**
|
|
6
6
|
* Forwards codec process to a sub codec. Useful for circular checks
|
|
7
7
|
* @validator forwardRef
|
package/cjs/factories.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./rules/index.js"), exports);
|
package/cjs/index.js
CHANGED
|
@@ -10,9 +10,120 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
13
25
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
27
|
};
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.isHexadecimal = exports.isDecimal = exports.isAscii = exports.isAlphanumeric = exports.isAlpha = exports.isUppercase = exports.isLowercase = exports.isJWT = exports.isHexColor = exports.isETHAddress = exports.isBtcAddress = exports.isISSN = exports.isFQDN = exports.isEAN = exports.isIBAN = exports.isCreditCard = exports.isBIC = exports.isBase64 = exports.isURL = exports.isPort = exports.isMACAddress = exports.isIPRange = exports.isIP = exports.isMobilePhone = exports.isEmail = exports.isUUID5 = exports.isUUID4 = exports.isUUID3 = exports.isUUID2 = exports.isUUID1 = exports.isUUID = exports.isString = exports.isObjectId = exports.isObject = exports.isNumber = exports.isUndefined = exports.isDefined = exports.isNullish = exports.isNull = exports.isInteger = exports.isNotEmpty = exports.isEmpty = exports.isDateString = exports.isDate = exports.isBoolean = exports.isBigint = exports.isArray = exports.isAny = exports.vg = void 0;
|
|
30
|
+
const vg = __importStar(require("./rules/index.js"));
|
|
31
|
+
exports.vg = vg;
|
|
32
|
+
__exportStar(require("./constants.js"), exports);
|
|
17
33
|
__exportStar(require("./core/index.js"), exports);
|
|
18
|
-
|
|
34
|
+
const isAny = vg.isAny();
|
|
35
|
+
exports.isAny = isAny;
|
|
36
|
+
const isArray = vg.isArray();
|
|
37
|
+
exports.isArray = isArray;
|
|
38
|
+
const isBigint = vg.isBigint();
|
|
39
|
+
exports.isBigint = isBigint;
|
|
40
|
+
const isBoolean = vg.isBoolean();
|
|
41
|
+
exports.isBoolean = isBoolean;
|
|
42
|
+
const isDate = vg.isDate();
|
|
43
|
+
exports.isDate = isDate;
|
|
44
|
+
const isDateString = vg.isDateString();
|
|
45
|
+
exports.isDateString = isDateString;
|
|
46
|
+
const isEmpty = vg.isEmpty();
|
|
47
|
+
exports.isEmpty = isEmpty;
|
|
48
|
+
const isNotEmpty = vg.isNotEmpty();
|
|
49
|
+
exports.isNotEmpty = isNotEmpty;
|
|
50
|
+
const isInteger = vg.isInteger();
|
|
51
|
+
exports.isInteger = isInteger;
|
|
52
|
+
const isNull = vg.isNull();
|
|
53
|
+
exports.isNull = isNull;
|
|
54
|
+
const isNullish = vg.isNullish();
|
|
55
|
+
exports.isNullish = isNullish;
|
|
56
|
+
const isDefined = vg.isDefined();
|
|
57
|
+
exports.isDefined = isDefined;
|
|
58
|
+
const isUndefined = vg.isUndefined();
|
|
59
|
+
exports.isUndefined = isUndefined;
|
|
60
|
+
const isNumber = vg.isNumber();
|
|
61
|
+
exports.isNumber = isNumber;
|
|
62
|
+
const isObject = vg.isObject();
|
|
63
|
+
exports.isObject = isObject;
|
|
64
|
+
const isObjectId = vg.isObjectId();
|
|
65
|
+
exports.isObjectId = isObjectId;
|
|
66
|
+
const isString = vg.isString();
|
|
67
|
+
exports.isString = isString;
|
|
68
|
+
const isUUID = vg.isUUID();
|
|
69
|
+
exports.isUUID = isUUID;
|
|
70
|
+
const isUUID1 = vg.isUUID(1);
|
|
71
|
+
exports.isUUID1 = isUUID1;
|
|
72
|
+
const isUUID2 = vg.isUUID(2);
|
|
73
|
+
exports.isUUID2 = isUUID2;
|
|
74
|
+
const isUUID3 = vg.isUUID(3);
|
|
75
|
+
exports.isUUID3 = isUUID3;
|
|
76
|
+
const isUUID4 = vg.isUUID(4);
|
|
77
|
+
exports.isUUID4 = isUUID4;
|
|
78
|
+
const isUUID5 = vg.isUUID(5);
|
|
79
|
+
exports.isUUID5 = isUUID5;
|
|
80
|
+
const isEmail = vg.isEmail();
|
|
81
|
+
exports.isEmail = isEmail;
|
|
82
|
+
const isMobilePhone = vg.isMobilePhone();
|
|
83
|
+
exports.isMobilePhone = isMobilePhone;
|
|
84
|
+
const isIP = vg.isIP();
|
|
85
|
+
exports.isIP = isIP;
|
|
86
|
+
const isIPRange = vg.isIPRange();
|
|
87
|
+
exports.isIPRange = isIPRange;
|
|
88
|
+
const isMACAddress = vg.isMACAddress();
|
|
89
|
+
exports.isMACAddress = isMACAddress;
|
|
90
|
+
const isPort = vg.isPort();
|
|
91
|
+
exports.isPort = isPort;
|
|
92
|
+
const isURL = vg.isURL();
|
|
93
|
+
exports.isURL = isURL;
|
|
94
|
+
const isBase64 = vg.isBase64();
|
|
95
|
+
exports.isBase64 = isBase64;
|
|
96
|
+
const isBIC = vg.isBIC();
|
|
97
|
+
exports.isBIC = isBIC;
|
|
98
|
+
const isCreditCard = vg.isCreditCard();
|
|
99
|
+
exports.isCreditCard = isCreditCard;
|
|
100
|
+
const isIBAN = vg.isIBAN();
|
|
101
|
+
exports.isIBAN = isIBAN;
|
|
102
|
+
const isEAN = vg.isEAN();
|
|
103
|
+
exports.isEAN = isEAN;
|
|
104
|
+
const isFQDN = vg.isFQDN();
|
|
105
|
+
exports.isFQDN = isFQDN;
|
|
106
|
+
const isISSN = vg.isISSN();
|
|
107
|
+
exports.isISSN = isISSN;
|
|
108
|
+
const isBtcAddress = vg.isBtcAddress();
|
|
109
|
+
exports.isBtcAddress = isBtcAddress;
|
|
110
|
+
const isETHAddress = vg.isETHAddress();
|
|
111
|
+
exports.isETHAddress = isETHAddress;
|
|
112
|
+
const isHexColor = vg.isHexColor();
|
|
113
|
+
exports.isHexColor = isHexColor;
|
|
114
|
+
const isJWT = vg.isJWT();
|
|
115
|
+
exports.isJWT = isJWT;
|
|
116
|
+
const isLowercase = vg.isLowercase();
|
|
117
|
+
exports.isLowercase = isLowercase;
|
|
118
|
+
const isUppercase = vg.isUppercase();
|
|
119
|
+
exports.isUppercase = isUppercase;
|
|
120
|
+
const isAlpha = vg.isAlpha();
|
|
121
|
+
exports.isAlpha = isAlpha;
|
|
122
|
+
const isAlphanumeric = vg.isAlphanumeric();
|
|
123
|
+
exports.isAlphanumeric = isAlphanumeric;
|
|
124
|
+
const isAscii = vg.isAscii();
|
|
125
|
+
exports.isAscii = isAscii;
|
|
126
|
+
const isDecimal = vg.isDecimal();
|
|
127
|
+
exports.isDecimal = isDecimal;
|
|
128
|
+
const isHexadecimal = vg.isHexadecimal();
|
|
129
|
+
exports.isHexadecimal = isHexadecimal;
|
package/cjs/rules/index.js
CHANGED
|
@@ -23,7 +23,7 @@ __exportStar(require("./is-empty.js"), exports);
|
|
|
23
23
|
__exportStar(require("./is-enum.js"), exports);
|
|
24
24
|
__exportStar(require("./is-integer.js"), exports);
|
|
25
25
|
__exportStar(require("./is-null.js"), exports);
|
|
26
|
-
__exportStar(require("./is-
|
|
26
|
+
__exportStar(require("./is-regexp.js"), exports);
|
|
27
27
|
__exportStar(require("./is-number.js"), exports);
|
|
28
28
|
__exportStar(require("./is-object.js"), exports);
|
|
29
29
|
__exportStar(require("./is-object-id.js"), exports);
|
|
@@ -36,4 +36,3 @@ __exportStar(require("./pipe.js"), exports);
|
|
|
36
36
|
__exportStar(require("./range.js"), exports);
|
|
37
37
|
__exportStar(require("./string-formats.js"), exports);
|
|
38
38
|
__exportStar(require("./union.js"), exports);
|
|
39
|
-
__exportStar(require("./utilities.js"), exports);
|
package/cjs/rules/is-object.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isObject = void 0;
|
|
4
|
+
const constants_js_1 = require("../constants.js");
|
|
4
5
|
const index_js_1 = require("../core/index.js");
|
|
5
6
|
/**
|
|
6
7
|
* Validates object according to schema
|
|
@@ -10,12 +11,14 @@ const index_js_1 = require("../core/index.js");
|
|
|
10
11
|
function isObject(schema, options) {
|
|
11
12
|
const ctor = options?.ctor;
|
|
12
13
|
const ctorName = options?.name || ctor?.name;
|
|
13
|
-
const additionalFields = options?.additionalFields ??
|
|
14
|
+
const additionalFields = options?.additionalFields ?? !schema;
|
|
14
15
|
const caseInSensitive = !!options?.caseInSensitive;
|
|
15
16
|
const detectCircular = !!options?.detectCircular;
|
|
16
17
|
const propertyRules = {};
|
|
17
18
|
const propertyOptions = {};
|
|
18
|
-
|
|
19
|
+
schema = schema || {};
|
|
20
|
+
const schemaKeys = Object.keys(schema);
|
|
21
|
+
for (const k of schemaKeys) {
|
|
19
22
|
const n = schema[k];
|
|
20
23
|
const key = caseInSensitive ? k.toLowerCase() : k;
|
|
21
24
|
if (Array.isArray(n)) {
|
|
@@ -30,17 +33,17 @@ function isObject(schema, options) {
|
|
|
30
33
|
}
|
|
31
34
|
else
|
|
32
35
|
throw new TypeError(`Invalid definition in validation schema (${k})`);
|
|
33
|
-
}
|
|
36
|
+
}
|
|
34
37
|
const _rule = (0, index_js_1.validator)('isObject', function (input, context, _this) {
|
|
35
|
-
if (ctor && ctor[
|
|
36
|
-
input = ctor[
|
|
38
|
+
if (ctor && ctor[constants_js_1.preValidation])
|
|
39
|
+
input = ctor[constants_js_1.preValidation](input, context, _this);
|
|
37
40
|
if (typeof input === 'string' && context.coerce)
|
|
38
41
|
input = JSON.parse(input);
|
|
39
42
|
if (!(input && typeof input === 'object')) {
|
|
40
43
|
context.fail(_this, `{{label}} must be an object`, input);
|
|
41
44
|
return;
|
|
42
45
|
}
|
|
43
|
-
const keys = [...Object.keys(input), ...
|
|
46
|
+
const keys = [...Object.keys(input), ...schemaKeys];
|
|
44
47
|
const l = keys.length;
|
|
45
48
|
let i = 0;
|
|
46
49
|
let inputKey;
|
|
@@ -91,8 +94,8 @@ function isObject(schema, options) {
|
|
|
91
94
|
}
|
|
92
95
|
if (context.errors.length)
|
|
93
96
|
return undefined;
|
|
94
|
-
if (ctor && ctor[
|
|
95
|
-
ctor[
|
|
97
|
+
if (ctor && ctor[constants_js_1.postValidation]) {
|
|
98
|
+
ctor[constants_js_1.postValidation](out, context, _this);
|
|
96
99
|
return out;
|
|
97
100
|
}
|
|
98
101
|
return out;
|
|
@@ -101,7 +104,3 @@ function isObject(schema, options) {
|
|
|
101
104
|
return _rule;
|
|
102
105
|
}
|
|
103
106
|
exports.isObject = isObject;
|
|
104
|
-
(function (isObject) {
|
|
105
|
-
isObject.postValidation = Symbol('postValidation');
|
|
106
|
-
isObject.preValidation = Symbol('preValidation');
|
|
107
|
-
})(isObject || (exports.isObject = isObject = {}));
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isRegExp = void 0;
|
|
4
4
|
const index_js_1 = require("../core/index.js");
|
|
5
5
|
/**
|
|
6
6
|
* Coerces given value to "UUID" format or returns undefined if nullish
|
|
7
7
|
* @validator uuid
|
|
8
8
|
*/
|
|
9
|
-
function
|
|
9
|
+
function isRegExp(format, options) {
|
|
10
10
|
const regExp = format instanceof RegExp ? format : new RegExp(format);
|
|
11
11
|
const formatName = options?.formatName;
|
|
12
12
|
return (0, index_js_1.validator)('matches', function (input, context, _this) {
|
|
@@ -17,4 +17,4 @@ function isMatches(format, options) {
|
|
|
17
17
|
context.fail(_this, `{{label}} does not match ${formatName || 'requested'} format`, input, { format, formatName });
|
|
18
18
|
}, options);
|
|
19
19
|
}
|
|
20
|
-
exports.
|
|
20
|
+
exports.isRegExp = isRegExp;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isUppercase = exports.isLowercase = exports.isJWT = exports.isHexColor = exports.isHash = exports.isETHAddress = exports.isBtcAddress = exports.isVAT = exports.isISSN = exports.isFQDN = exports.isEAN = exports.isPassportNumber = exports.isIBAN = exports.isCreditCard = exports.isBIC = exports.isBase64 = exports.isURL = exports.isPort = exports.isMACAddress = exports.isIPRange = exports.isIP = exports.isMobilePhone = exports.isEmail = exports.isUUID = void 0;
|
|
6
|
+
exports.isHexadecimal = exports.isDecimal = exports.isAscii = exports.isAlphanumeric = exports.isAlpha = exports.isUppercase = exports.isLowercase = exports.isJWT = exports.isHexColor = exports.isHash = exports.isETHAddress = exports.isBtcAddress = exports.isVAT = exports.isISSN = exports.isFQDN = exports.isEAN = exports.isPassportNumber = exports.isIBAN = exports.isCreditCard = exports.isBIC = exports.isBase64 = exports.isURL = exports.isPort = exports.isMACAddress = exports.isIPRange = exports.isIP = exports.isMobilePhone = exports.isEmail = exports.isUUID = void 0;
|
|
7
7
|
const validator_1 = __importDefault(require("validator"));
|
|
8
8
|
const index_js_1 = require("../core/index.js");
|
|
9
9
|
/**
|
|
@@ -294,3 +294,64 @@ function isUppercase(options) {
|
|
|
294
294
|
}, options);
|
|
295
295
|
}
|
|
296
296
|
exports.isUppercase = isUppercase;
|
|
297
|
+
/**
|
|
298
|
+
* Check if the string contains only letters (a-zA-Z).
|
|
299
|
+
* @validator isAlpha
|
|
300
|
+
*/
|
|
301
|
+
function isAlpha(options) {
|
|
302
|
+
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
303
|
+
if (typeof input === 'string' && validator_1.default.isAlpha(input))
|
|
304
|
+
return input;
|
|
305
|
+
context.fail(_this, `{{label}} is not an alpha string`, input);
|
|
306
|
+
}, options);
|
|
307
|
+
}
|
|
308
|
+
exports.isAlpha = isAlpha;
|
|
309
|
+
/**
|
|
310
|
+
* Check if the string contains only letters and numbers.
|
|
311
|
+
* @validator isAlphanumeric
|
|
312
|
+
*/
|
|
313
|
+
function isAlphanumeric(options) {
|
|
314
|
+
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
315
|
+
if (typeof input === 'string' && validator_1.default.isAlphanumeric(input))
|
|
316
|
+
return input;
|
|
317
|
+
context.fail(_this, `{{label}} is not an alphanumeric string`, input);
|
|
318
|
+
}, options);
|
|
319
|
+
}
|
|
320
|
+
exports.isAlphanumeric = isAlphanumeric;
|
|
321
|
+
/**
|
|
322
|
+
* Check if the string contains ASCII chars only.
|
|
323
|
+
* @validator isAscii
|
|
324
|
+
*/
|
|
325
|
+
function isAscii(options) {
|
|
326
|
+
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
327
|
+
if (typeof input === 'string' && validator_1.default.isAscii(input))
|
|
328
|
+
return input;
|
|
329
|
+
context.fail(_this, `{{label}} is not an ascii string`, input);
|
|
330
|
+
}, options);
|
|
331
|
+
}
|
|
332
|
+
exports.isAscii = isAscii;
|
|
333
|
+
/**
|
|
334
|
+
* Check if the string represents a decimal number,
|
|
335
|
+
* such as `0.1`, `.3`, `1.1`, `1.00003`, `4.0` etc.
|
|
336
|
+
* @validator isDecimal
|
|
337
|
+
*/
|
|
338
|
+
function isDecimal(options) {
|
|
339
|
+
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
340
|
+
if (typeof input === 'string' && validator_1.default.isDecimal(input))
|
|
341
|
+
return input;
|
|
342
|
+
context.fail(_this, `{{label}} is not an decimal number string`, input);
|
|
343
|
+
}, options);
|
|
344
|
+
}
|
|
345
|
+
exports.isDecimal = isDecimal;
|
|
346
|
+
/**
|
|
347
|
+
* Check if the string is a hexadecimal number.
|
|
348
|
+
* @validator isHexadecimal
|
|
349
|
+
*/
|
|
350
|
+
function isHexadecimal(options) {
|
|
351
|
+
return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
|
|
352
|
+
if (typeof input === 'string' && validator_1.default.isHexadecimal(input))
|
|
353
|
+
return input;
|
|
354
|
+
context.fail(_this, `{{label}} is not an hexadecimal string`, input);
|
|
355
|
+
}, options);
|
|
356
|
+
}
|
|
357
|
+
exports.isHexadecimal = isHexadecimal;
|
package/esm/constants.js
ADDED
package/esm/core/index.js
CHANGED
package/esm/factories.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rules/index.js';
|
package/esm/index.js
CHANGED
|
@@ -1,2 +1,52 @@
|
|
|
1
|
+
import * as vg from './rules/index.js';
|
|
2
|
+
export * from './constants.js';
|
|
1
3
|
export * from './core/index.js';
|
|
2
|
-
|
|
4
|
+
const isAny = vg.isAny();
|
|
5
|
+
const isArray = vg.isArray();
|
|
6
|
+
const isBigint = vg.isBigint();
|
|
7
|
+
const isBoolean = vg.isBoolean();
|
|
8
|
+
const isDate = vg.isDate();
|
|
9
|
+
const isDateString = vg.isDateString();
|
|
10
|
+
const isEmpty = vg.isEmpty();
|
|
11
|
+
const isNotEmpty = vg.isNotEmpty();
|
|
12
|
+
const isInteger = vg.isInteger();
|
|
13
|
+
const isNull = vg.isNull();
|
|
14
|
+
const isNullish = vg.isNullish();
|
|
15
|
+
const isDefined = vg.isDefined();
|
|
16
|
+
const isUndefined = vg.isUndefined();
|
|
17
|
+
const isNumber = vg.isNumber();
|
|
18
|
+
const isObject = vg.isObject();
|
|
19
|
+
const isObjectId = vg.isObjectId();
|
|
20
|
+
const isString = vg.isString();
|
|
21
|
+
const isUUID = vg.isUUID();
|
|
22
|
+
const isUUID1 = vg.isUUID(1);
|
|
23
|
+
const isUUID2 = vg.isUUID(2);
|
|
24
|
+
const isUUID3 = vg.isUUID(3);
|
|
25
|
+
const isUUID4 = vg.isUUID(4);
|
|
26
|
+
const isUUID5 = vg.isUUID(5);
|
|
27
|
+
const isEmail = vg.isEmail();
|
|
28
|
+
const isMobilePhone = vg.isMobilePhone();
|
|
29
|
+
const isIP = vg.isIP();
|
|
30
|
+
const isIPRange = vg.isIPRange();
|
|
31
|
+
const isMACAddress = vg.isMACAddress();
|
|
32
|
+
const isPort = vg.isPort();
|
|
33
|
+
const isURL = vg.isURL();
|
|
34
|
+
const isBase64 = vg.isBase64();
|
|
35
|
+
const isBIC = vg.isBIC();
|
|
36
|
+
const isCreditCard = vg.isCreditCard();
|
|
37
|
+
const isIBAN = vg.isIBAN();
|
|
38
|
+
const isEAN = vg.isEAN();
|
|
39
|
+
const isFQDN = vg.isFQDN();
|
|
40
|
+
const isISSN = vg.isISSN();
|
|
41
|
+
const isBtcAddress = vg.isBtcAddress();
|
|
42
|
+
const isETHAddress = vg.isETHAddress();
|
|
43
|
+
const isHexColor = vg.isHexColor();
|
|
44
|
+
const isJWT = vg.isJWT();
|
|
45
|
+
const isLowercase = vg.isLowercase();
|
|
46
|
+
const isUppercase = vg.isUppercase();
|
|
47
|
+
const isAlpha = vg.isAlpha();
|
|
48
|
+
const isAlphanumeric = vg.isAlphanumeric();
|
|
49
|
+
const isAscii = vg.isAscii();
|
|
50
|
+
const isDecimal = vg.isDecimal();
|
|
51
|
+
const isHexadecimal = vg.isHexadecimal();
|
|
52
|
+
export { vg, isAny, isArray, isBigint, isBoolean, isDate, isDateString, isEmpty, isNotEmpty, isInteger, isNull, isNullish, isDefined, isUndefined, isNumber, isObject, isObjectId, isString, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isEmail, isMobilePhone, isIP, isIPRange, isMACAddress, isPort, isURL, isBase64, isBIC, isCreditCard, isIBAN, isEAN, isFQDN, isISSN, isBtcAddress, isETHAddress, isHexColor, isJWT, isLowercase, isUppercase, isAlpha, isAlphanumeric, isAscii, isDecimal, isHexadecimal };
|
package/esm/rules/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export * from './is-empty.js';
|
|
|
7
7
|
export * from './is-enum.js';
|
|
8
8
|
export * from './is-integer.js';
|
|
9
9
|
export * from './is-null.js';
|
|
10
|
-
export * from './is-
|
|
10
|
+
export * from './is-regexp.js';
|
|
11
11
|
export * from './is-number.js';
|
|
12
12
|
export * from './is-object.js';
|
|
13
13
|
export * from './is-object-id.js';
|
|
@@ -20,4 +20,3 @@ export * from './pipe.js';
|
|
|
20
20
|
export * from './range.js';
|
|
21
21
|
export * from './string-formats.js';
|
|
22
22
|
export * from './union.js';
|
|
23
|
-
export * from './utilities.js';
|
package/esm/rules/is-object.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { postValidation, preValidation } from '../constants.js';
|
|
1
2
|
import { isValidator, validator } from '../core/index.js';
|
|
2
3
|
/**
|
|
3
4
|
* Validates object according to schema
|
|
@@ -7,12 +8,14 @@ import { isValidator, validator } from '../core/index.js';
|
|
|
7
8
|
export function isObject(schema, options) {
|
|
8
9
|
const ctor = options?.ctor;
|
|
9
10
|
const ctorName = options?.name || ctor?.name;
|
|
10
|
-
const additionalFields = options?.additionalFields ??
|
|
11
|
+
const additionalFields = options?.additionalFields ?? !schema;
|
|
11
12
|
const caseInSensitive = !!options?.caseInSensitive;
|
|
12
13
|
const detectCircular = !!options?.detectCircular;
|
|
13
14
|
const propertyRules = {};
|
|
14
15
|
const propertyOptions = {};
|
|
15
|
-
|
|
16
|
+
schema = schema || {};
|
|
17
|
+
const schemaKeys = Object.keys(schema);
|
|
18
|
+
for (const k of schemaKeys) {
|
|
16
19
|
const n = schema[k];
|
|
17
20
|
const key = caseInSensitive ? k.toLowerCase() : k;
|
|
18
21
|
if (Array.isArray(n)) {
|
|
@@ -27,17 +30,17 @@ export function isObject(schema, options) {
|
|
|
27
30
|
}
|
|
28
31
|
else
|
|
29
32
|
throw new TypeError(`Invalid definition in validation schema (${k})`);
|
|
30
|
-
}
|
|
33
|
+
}
|
|
31
34
|
const _rule = validator('isObject', function (input, context, _this) {
|
|
32
|
-
if (ctor && ctor[
|
|
33
|
-
input = ctor[
|
|
35
|
+
if (ctor && ctor[preValidation])
|
|
36
|
+
input = ctor[preValidation](input, context, _this);
|
|
34
37
|
if (typeof input === 'string' && context.coerce)
|
|
35
38
|
input = JSON.parse(input);
|
|
36
39
|
if (!(input && typeof input === 'object')) {
|
|
37
40
|
context.fail(_this, `{{label}} must be an object`, input);
|
|
38
41
|
return;
|
|
39
42
|
}
|
|
40
|
-
const keys = [...Object.keys(input), ...
|
|
43
|
+
const keys = [...Object.keys(input), ...schemaKeys];
|
|
41
44
|
const l = keys.length;
|
|
42
45
|
let i = 0;
|
|
43
46
|
let inputKey;
|
|
@@ -88,8 +91,8 @@ export function isObject(schema, options) {
|
|
|
88
91
|
}
|
|
89
92
|
if (context.errors.length)
|
|
90
93
|
return undefined;
|
|
91
|
-
if (ctor && ctor[
|
|
92
|
-
ctor[
|
|
94
|
+
if (ctor && ctor[postValidation]) {
|
|
95
|
+
ctor[postValidation](out, context, _this);
|
|
93
96
|
return out;
|
|
94
97
|
}
|
|
95
98
|
return out;
|
|
@@ -97,7 +100,3 @@ export function isObject(schema, options) {
|
|
|
97
100
|
_rule.schema = schema;
|
|
98
101
|
return _rule;
|
|
99
102
|
}
|
|
100
|
-
(function (isObject) {
|
|
101
|
-
isObject.postValidation = Symbol('postValidation');
|
|
102
|
-
isObject.preValidation = Symbol('preValidation');
|
|
103
|
-
})(isObject || (isObject = {}));
|
|
@@ -3,7 +3,7 @@ import { validator } from '../core/index.js';
|
|
|
3
3
|
* Coerces given value to "UUID" format or returns undefined if nullish
|
|
4
4
|
* @validator uuid
|
|
5
5
|
*/
|
|
6
|
-
export function
|
|
6
|
+
export function isRegExp(format, options) {
|
|
7
7
|
const regExp = format instanceof RegExp ? format : new RegExp(format);
|
|
8
8
|
const formatName = options?.formatName;
|
|
9
9
|
return validator('matches', function (input, context, _this) {
|
|
@@ -264,3 +264,59 @@ export function isUppercase(options) {
|
|
|
264
264
|
context.fail(_this, `{{label}} is not an uppercase string`, input);
|
|
265
265
|
}, options);
|
|
266
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Check if the string contains only letters (a-zA-Z).
|
|
269
|
+
* @validator isAlpha
|
|
270
|
+
*/
|
|
271
|
+
export function isAlpha(options) {
|
|
272
|
+
return validator('isLowercase', function (input, context, _this) {
|
|
273
|
+
if (typeof input === 'string' && validatorJS.isAlpha(input))
|
|
274
|
+
return input;
|
|
275
|
+
context.fail(_this, `{{label}} is not an alpha string`, input);
|
|
276
|
+
}, options);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Check if the string contains only letters and numbers.
|
|
280
|
+
* @validator isAlphanumeric
|
|
281
|
+
*/
|
|
282
|
+
export function isAlphanumeric(options) {
|
|
283
|
+
return validator('isLowercase', function (input, context, _this) {
|
|
284
|
+
if (typeof input === 'string' && validatorJS.isAlphanumeric(input))
|
|
285
|
+
return input;
|
|
286
|
+
context.fail(_this, `{{label}} is not an alphanumeric string`, input);
|
|
287
|
+
}, options);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Check if the string contains ASCII chars only.
|
|
291
|
+
* @validator isAscii
|
|
292
|
+
*/
|
|
293
|
+
export function isAscii(options) {
|
|
294
|
+
return validator('isLowercase', function (input, context, _this) {
|
|
295
|
+
if (typeof input === 'string' && validatorJS.isAscii(input))
|
|
296
|
+
return input;
|
|
297
|
+
context.fail(_this, `{{label}} is not an ascii string`, input);
|
|
298
|
+
}, options);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Check if the string represents a decimal number,
|
|
302
|
+
* such as `0.1`, `.3`, `1.1`, `1.00003`, `4.0` etc.
|
|
303
|
+
* @validator isDecimal
|
|
304
|
+
*/
|
|
305
|
+
export function isDecimal(options) {
|
|
306
|
+
return validator('isLowercase', function (input, context, _this) {
|
|
307
|
+
if (typeof input === 'string' && validatorJS.isDecimal(input))
|
|
308
|
+
return input;
|
|
309
|
+
context.fail(_this, `{{label}} is not an decimal number string`, input);
|
|
310
|
+
}, options);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Check if the string is a hexadecimal number.
|
|
314
|
+
* @validator isHexadecimal
|
|
315
|
+
*/
|
|
316
|
+
export function isHexadecimal(options) {
|
|
317
|
+
return validator('isLowercase', function (input, context, _this) {
|
|
318
|
+
if (typeof input === 'string' && validatorJS.isHexadecimal(input))
|
|
319
|
+
return input;
|
|
320
|
+
context.fail(_this, `{{label}} is not an hexadecimal string`, input);
|
|
321
|
+
}, options);
|
|
322
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valgen",
|
|
3
3
|
"description": "Fast runtime type validator, converter and io (encoding/decoding) library",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@types/validator": "^13.11.7",
|
|
16
16
|
"dayjs": "^2.0.0-alpha.4",
|
|
17
|
-
"ts-gems": "^
|
|
17
|
+
"ts-gems": "^3.1.0",
|
|
18
18
|
"validator": "^13.11.0"
|
|
19
19
|
},
|
|
20
20
|
"type": "module",
|
package/typings/core/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Context, Validator } from '
|
|
1
|
+
import { Context, Validator } from './index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Forwards codec process to a sub codec. Useful for circular checks
|
|
4
4
|
* @validator forwardRef
|
|
5
5
|
*/
|
|
6
|
-
export declare function forwardRef<T, I>(fn: (context: Context) => Validator<T, I>): Validator<T, I, import("
|
|
6
|
+
export declare function forwardRef<T, I>(fn: (context: Context) => Validator<T, I>): Validator<T, I, import("./types.js").ExecutionOptions>;
|
|
7
7
|
/**
|
|
8
8
|
* if "check" codec passes returns "then", "else" otherwise
|
|
9
9
|
* @validator iif
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rules/index.js';
|
package/typings/index.d.ts
CHANGED
|
@@ -1,2 +1,53 @@
|
|
|
1
|
+
import * as vg from './rules/index.js';
|
|
2
|
+
export * from './constants.js';
|
|
1
3
|
export * from './core/index.js';
|
|
2
|
-
export
|
|
4
|
+
export { IsObject } from './rules/is-object.js';
|
|
5
|
+
declare const isAny: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
|
|
6
|
+
declare const isArray: import("./core/validator.js").Validator<unknown[], unknown, import("./core/types.js").ExecutionOptions>;
|
|
7
|
+
declare const isBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
|
|
8
|
+
declare const isBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
|
|
9
|
+
declare const isDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
10
|
+
declare const isDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
|
|
11
|
+
declare const isEmpty: import("./core/validator.js").Validator<string | object | any[] | Set<any> | Map<any, any>, string | object | any[] | Set<any> | Map<any, any>, import("./core/types.js").ExecutionOptions>;
|
|
12
|
+
declare const isNotEmpty: import("./core/validator.js").Validator<string | object | any[] | Set<any> | Map<any, any>, string | object | any[] | Set<any> | Map<any, any>, import("./core/types.js").ExecutionOptions>;
|
|
13
|
+
declare const isInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
14
|
+
declare const isNull: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
|
|
15
|
+
declare const isNullish: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
|
|
16
|
+
declare const isDefined: import("./core/validator.js").Validator<any, unknown, import("./core/types.js").ExecutionOptions>;
|
|
17
|
+
declare const isUndefined: import("./core/validator.js").Validator<any, unknown, import("./core/types.js").ExecutionOptions>;
|
|
18
|
+
declare const isNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
|
|
19
|
+
declare const isObject: vg.IsObject.Validator<object, string | object>;
|
|
20
|
+
declare const isObjectId: import("./core/validator.js").Validator<string | vg.ObjectIdLike | Uint8Array, unknown, import("./core/types.js").ExecutionOptions>;
|
|
21
|
+
declare const isString: import("./core/validator.js").Validator<string, unknown, import("./core/types.js").ExecutionOptions>;
|
|
22
|
+
declare const isUUID: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
23
|
+
declare const isUUID1: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
24
|
+
declare const isUUID2: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
25
|
+
declare const isUUID3: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
26
|
+
declare const isUUID4: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
27
|
+
declare const isUUID5: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
28
|
+
declare const isEmail: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
29
|
+
declare const isMobilePhone: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
30
|
+
declare const isIP: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
31
|
+
declare const isIPRange: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
32
|
+
declare const isMACAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
33
|
+
declare const isPort: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
34
|
+
declare const isURL: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
35
|
+
declare const isBase64: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
36
|
+
declare const isBIC: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
37
|
+
declare const isCreditCard: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
38
|
+
declare const isIBAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
39
|
+
declare const isEAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
40
|
+
declare const isFQDN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
41
|
+
declare const isISSN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
42
|
+
declare const isBtcAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
43
|
+
declare const isETHAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
44
|
+
declare const isHexColor: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
45
|
+
declare const isJWT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
46
|
+
declare const isLowercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
47
|
+
declare const isUppercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
48
|
+
declare const isAlpha: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
49
|
+
declare const isAlphanumeric: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
50
|
+
declare const isAscii: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
51
|
+
declare const isDecimal: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
52
|
+
declare const isHexadecimal: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
|
|
53
|
+
export { vg, isAny, isArray, isBigint, isBoolean, isDate, isDateString, isEmpty, isNotEmpty, isInteger, isNull, isNullish, isDefined, isUndefined, isNumber, isObject, isObjectId, isString, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isEmail, isMobilePhone, isIP, isIPRange, isMACAddress, isPort, isURL, isBase64, isBIC, isCreditCard, isIBAN, isEAN, isFQDN, isISSN, isBtcAddress, isETHAddress, isHexColor, isJWT, isLowercase, isUppercase, isAlpha, isAlphanumeric, isAscii, isDecimal, isHexadecimal };
|
package/typings/rules/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from './is-empty.js';
|
|
|
7
7
|
export * from './is-enum.js';
|
|
8
8
|
export * from './is-integer.js';
|
|
9
9
|
export * from './is-null.js';
|
|
10
|
-
export * from './is-
|
|
10
|
+
export * from './is-regexp.js';
|
|
11
11
|
export * from './is-number.js';
|
|
12
12
|
export * from './is-object.js';
|
|
13
13
|
export * from './is-object-id.js';
|
|
@@ -20,4 +20,3 @@ export * from './pipe.js';
|
|
|
20
20
|
export * from './range.js';
|
|
21
21
|
export * from './string-formats.js';
|
|
22
22
|
export * from './union.js';
|
|
23
|
-
export * from './utilities.js';
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { ValidationOptions } from '../core/index.js';
|
|
2
|
-
export interface IsDateOptions extends ValidationOptions {
|
|
3
|
-
precision?: 'year' | 'month' | 'date' | 'time';
|
|
4
|
-
}
|
|
5
2
|
/**
|
|
6
3
|
* Validates if value is instance of "Date".
|
|
7
4
|
* Converts input value to Date if coerce option is set to 'true'.
|
|
8
5
|
* @validator isDate
|
|
9
6
|
*/
|
|
10
|
-
export declare function isDate(options?:
|
|
7
|
+
export declare function isDate(options?: isDate.Options): import("../core/validator.js").Validator<Date, string | number | Date, import("../core/types.js").ExecutionOptions>;
|
|
11
8
|
export interface IsDateStringOptions extends ValidationOptions {
|
|
12
9
|
precision?: 'year' | 'month' | 'date' | 'time';
|
|
13
10
|
trim?: 'date' | 'time';
|
|
@@ -18,3 +15,8 @@ export interface IsDateStringOptions extends ValidationOptions {
|
|
|
18
15
|
* @validator isDateString
|
|
19
16
|
*/
|
|
20
17
|
export declare function isDateString(options?: IsDateStringOptions): import("../core/validator.js").Validator<string, string | number | Date, import("../core/types.js").ExecutionOptions>;
|
|
18
|
+
export declare namespace isDate {
|
|
19
|
+
interface Options extends ValidationOptions {
|
|
20
|
+
precision?: 'year' | 'month' | 'date' | 'time';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import { Type, ValidationOptions, Validator } from '../core/index.js';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { Type, ValidationOptions, Validator as Validator_ } from '../core/index.js';
|
|
2
|
+
export declare namespace IsObject {
|
|
3
|
+
interface Validator<T extends object = object, I = object> extends Validator_<T, I> {
|
|
4
|
+
schema: Schema;
|
|
5
|
+
}
|
|
6
|
+
type PropertyOptions = {
|
|
7
|
+
label?: string;
|
|
8
|
+
as?: string;
|
|
9
|
+
};
|
|
10
|
+
type Schema = Record<string | number, Validator_ | [Validator_, PropertyOptions]>;
|
|
11
|
+
interface Options<T> extends ValidationOptions {
|
|
12
|
+
name?: string;
|
|
13
|
+
ctor?: Type<T>;
|
|
14
|
+
additionalFields?: boolean | Validator_ | 'error';
|
|
15
|
+
caseInSensitive?: boolean;
|
|
16
|
+
detectCircular?: boolean;
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Validates object according to schema
|
|
19
21
|
* Converts properties according to schema rules if coerce option is set to 'true'.
|
|
20
22
|
* @validator isObject
|
|
21
23
|
*/
|
|
22
|
-
export declare function isObject<T extends object = object, I = object | string>(schema
|
|
23
|
-
export declare namespace isObject {
|
|
24
|
-
const postValidation: unique symbol;
|
|
25
|
-
const preValidation: unique symbol;
|
|
26
|
-
}
|
|
24
|
+
export declare function isObject<T extends object = object, I = object | string>(schema?: IsObject.Schema, options?: IsObject.Options<T>): IsObject.Validator<T, I>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidationOptions } from '../core/index.js';
|
|
2
|
+
export interface IsRegExpOptions extends ValidationOptions {
|
|
3
|
+
formatName?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Coerces given value to "UUID" format or returns undefined if nullish
|
|
7
|
+
* @validator uuid
|
|
8
|
+
*/
|
|
9
|
+
export declare function isRegExp(format: string | RegExp, options?: IsRegExpOptions): import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
|
|
@@ -138,3 +138,29 @@ export declare function isLowercase(options?: ValidationOptions): import("../cor
|
|
|
138
138
|
* @validator isUppercase
|
|
139
139
|
*/
|
|
140
140
|
export declare function isUppercase(options?: ValidationOptions): import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
|
|
141
|
+
/**
|
|
142
|
+
* Check if the string contains only letters (a-zA-Z).
|
|
143
|
+
* @validator isAlpha
|
|
144
|
+
*/
|
|
145
|
+
export declare function isAlpha(options?: ValidationOptions): import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
|
|
146
|
+
/**
|
|
147
|
+
* Check if the string contains only letters and numbers.
|
|
148
|
+
* @validator isAlphanumeric
|
|
149
|
+
*/
|
|
150
|
+
export declare function isAlphanumeric(options?: ValidationOptions): import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
|
|
151
|
+
/**
|
|
152
|
+
* Check if the string contains ASCII chars only.
|
|
153
|
+
* @validator isAscii
|
|
154
|
+
*/
|
|
155
|
+
export declare function isAscii(options?: ValidationOptions): import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
|
|
156
|
+
/**
|
|
157
|
+
* Check if the string represents a decimal number,
|
|
158
|
+
* such as `0.1`, `.3`, `1.1`, `1.00003`, `4.0` etc.
|
|
159
|
+
* @validator isDecimal
|
|
160
|
+
*/
|
|
161
|
+
export declare function isDecimal(options?: ValidationOptions): import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
|
|
162
|
+
/**
|
|
163
|
+
* Check if the string is a hexadecimal number.
|
|
164
|
+
* @validator isHexadecimal
|
|
165
|
+
*/
|
|
166
|
+
export declare function isHexadecimal(options?: ValidationOptions): import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ValidationOptions } from '../core/index.js';
|
|
2
|
-
export interface IsMatchesOptions extends ValidationOptions {
|
|
3
|
-
formatName?: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Coerces given value to "UUID" format or returns undefined if nullish
|
|
7
|
-
* @validator uuid
|
|
8
|
-
*/
|
|
9
|
-
export declare function isMatches(format: string | RegExp, options?: IsMatchesOptions): import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
|