valgen 5.6.0 → 5.7.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/core/index.js +7 -20
- package/cjs/factories.js +2 -15
- package/cjs/index.js +4 -29
- package/cjs/rules/format-rules/is-alpha.js +2 -24
- package/cjs/rules/format-rules/is-ascii.js +2 -24
- package/cjs/rules/format-rules/is-base64.js +2 -24
- package/cjs/rules/format-rules/is-btc-address.js +2 -24
- package/cjs/rules/format-rules/is-credit-card.js +2 -24
- package/cjs/rules/format-rules/is-decimal.js +2 -24
- package/cjs/rules/format-rules/is-ean.js +2 -24
- package/cjs/rules/format-rules/is-email.js +2 -24
- package/cjs/rules/format-rules/is-eth-address.js +2 -24
- package/cjs/rules/format-rules/is-fqdn.js +2 -24
- package/cjs/rules/format-rules/is-hash.js +2 -24
- package/cjs/rules/format-rules/is-hex-color.js +2 -24
- package/cjs/rules/format-rules/is-hex.js +2 -24
- package/cjs/rules/format-rules/is-iban.js +2 -24
- package/cjs/rules/format-rules/is-ip.js +2 -24
- package/cjs/rules/format-rules/is-issn.js +2 -24
- package/cjs/rules/format-rules/is-jwt.js +2 -24
- package/cjs/rules/format-rules/is-lowercase.js +2 -24
- package/cjs/rules/format-rules/is-mac-address.js +2 -24
- package/cjs/rules/format-rules/is-mobile-phone.js +2 -24
- package/cjs/rules/format-rules/is-object-id.js +2 -4
- package/cjs/rules/format-rules/is-passport-number.js +2 -24
- package/cjs/rules/format-rules/is-port.js +2 -24
- package/cjs/rules/format-rules/is-url.js +2 -24
- package/cjs/rules/format-rules/is-uuid.js +2 -24
- package/cjs/rules/format-rules/is-vat-number.js +2 -24
- package/cjs/rules/index.js +51 -64
- package/esm/constants.js +5 -2
- package/esm/core/constants.js +5 -2
- package/esm/core/context.js +9 -5
- package/esm/core/index.js +9 -6
- package/esm/core/types.js +2 -1
- package/esm/core/utilities.js +10 -6
- package/esm/core/validation-error.js +5 -1
- package/esm/core/validator.js +18 -14
- package/esm/factories.js +4 -1
- package/esm/helpers/object.utils.js +6 -2
- package/esm/helpers/omit-undefined.js +4 -1
- package/esm/helpers/string.utils.js +4 -1
- package/esm/index.js +67 -4
- package/esm/rules/format-rules/is-alpha.js +11 -6
- package/esm/rules/format-rules/is-ascii.js +8 -4
- package/esm/rules/format-rules/is-base64.js +8 -4
- package/esm/rules/format-rules/is-btc-address.js +8 -4
- package/esm/rules/format-rules/is-credit-card.js +8 -4
- package/esm/rules/format-rules/is-decimal.js +8 -4
- package/esm/rules/format-rules/is-ean.js +8 -4
- package/esm/rules/format-rules/is-email.js +8 -4
- package/esm/rules/format-rules/is-eth-address.js +8 -4
- package/esm/rules/format-rules/is-fqdn.js +8 -4
- package/esm/rules/format-rules/is-hash.js +8 -4
- package/esm/rules/format-rules/is-hex-color.js +8 -4
- package/esm/rules/format-rules/is-hex.js +8 -4
- package/esm/rules/format-rules/is-iban.js +11 -6
- package/esm/rules/format-rules/is-ip.js +11 -6
- package/esm/rules/format-rules/is-issn.js +8 -4
- package/esm/rules/format-rules/is-jwt.js +8 -4
- package/esm/rules/format-rules/is-lowercase.js +11 -6
- package/esm/rules/format-rules/is-mac-address.js +8 -4
- package/esm/rules/format-rules/is-mobile-phone.js +8 -4
- package/esm/rules/format-rules/is-object-id.js +9 -5
- package/esm/rules/format-rules/is-passport-number.js +8 -4
- package/esm/rules/format-rules/is-port.js +8 -4
- package/esm/rules/format-rules/is-url.js +8 -4
- package/esm/rules/format-rules/is-uuid.js +8 -4
- package/esm/rules/format-rules/is-vat-number.js +8 -4
- package/esm/rules/format-rules/matches.js +6 -3
- package/esm/rules/index.js +53 -50
- package/esm/rules/logical-rules/is-defined.js +6 -3
- package/esm/rules/logical-rules/is-empty.js +9 -5
- package/esm/rules/logical-rules/range.js +29 -19
- package/esm/rules/type-rules/is-any.js +6 -2
- package/esm/rules/type-rules/is-array.js +6 -3
- package/esm/rules/type-rules/is-bigint.js +6 -3
- package/esm/rules/type-rules/is-boolean.js +6 -3
- package/esm/rules/type-rules/is-date.js +14 -10
- package/esm/rules/type-rules/is-enum.js +6 -3
- package/esm/rules/type-rules/is-integer.js +6 -3
- package/esm/rules/type-rules/is-null.js +15 -9
- package/esm/rules/type-rules/is-number.js +6 -3
- package/esm/rules/type-rules/is-object.js +14 -11
- package/esm/rules/type-rules/is-record.js +6 -3
- package/esm/rules/type-rules/is-string.js +22 -13
- package/esm/rules/type-rules/is-tuple.js +6 -3
- package/esm/rules/type-rules/is-undefined.js +6 -3
- package/esm/rules/utility-rules/exists.js +6 -3
- package/esm/rules/utility-rules/get-length.js +6 -3
- package/esm/rules/utility-rules/optional.js +6 -3
- package/esm/rules/utility-rules/pipe.js +9 -5
- package/esm/rules/utility-rules/required.js +6 -3
- package/esm/rules/utility-rules/union.js +6 -3
- package/package.json +16 -16
- package/cjs/package.json +0 -3
- /package/{typings → types}/constants.d.ts +0 -0
- /package/{typings → types}/core/constants.d.ts +0 -0
- /package/{typings → types}/core/context.d.ts +0 -0
- /package/{typings → types}/core/index.d.ts +0 -0
- /package/{typings → types}/core/types.d.ts +0 -0
- /package/{typings → types}/core/utilities.d.ts +0 -0
- /package/{typings → types}/core/validation-error.d.ts +0 -0
- /package/{typings → types}/core/validator.d.ts +0 -0
- /package/{typings → types}/factories.d.ts +0 -0
- /package/{typings → types}/helpers/object.utils.d.ts +0 -0
- /package/{typings → types}/helpers/omit-undefined.d.ts +0 -0
- /package/{typings → types}/helpers/string.utils.d.ts +0 -0
- /package/{typings → types}/index.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-alpha.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-ascii.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-base64.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-btc-address.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-credit-card.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-decimal.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-ean.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-email.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-eth-address.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-fqdn.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-hash.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-hex-color.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-hex.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-iban.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-ip.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-issn.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-jwt.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-lowercase.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-mac-address.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-mobile-phone.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-object-id.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-passport-number.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-port.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-url.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-uuid.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/is-vat-number.d.ts +0 -0
- /package/{typings → types}/rules/format-rules/matches.d.ts +0 -0
- /package/{typings → types}/rules/index.d.ts +0 -0
- /package/{typings → types}/rules/logical-rules/is-defined.d.ts +0 -0
- /package/{typings → types}/rules/logical-rules/is-empty.d.ts +0 -0
- /package/{typings → types}/rules/logical-rules/range.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-any.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-array.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-bigint.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-boolean.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-date.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-enum.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-integer.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-null.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-number.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-object.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-record.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-string.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-tuple.d.ts +0 -0
- /package/{typings → types}/rules/type-rules/is-undefined.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/exists.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/get-length.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/optional.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/pipe.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/required.d.ts +0 -0
- /package/{typings → types}/rules/utility-rules/union.d.ts +0 -0
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNull = isNull;
|
|
4
|
+
exports.isNotNull = isNotNull;
|
|
5
|
+
exports.isNullish = isNullish;
|
|
6
|
+
exports.isNotNullish = isNotNullish;
|
|
7
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
8
|
/**
|
|
3
9
|
* Validates if value is "null".
|
|
4
10
|
* @validator isNull
|
|
5
11
|
*/
|
|
6
|
-
|
|
7
|
-
return validator('isNull', (input, context, _this) => {
|
|
12
|
+
function isNull(options) {
|
|
13
|
+
return (0, index_js_1.validator)('isNull', (input, context, _this) => {
|
|
8
14
|
if (input === null)
|
|
9
15
|
return input;
|
|
10
16
|
context.fail(_this, `{{label}} is not null`, input);
|
|
@@ -14,8 +20,8 @@ export function isNull(options) {
|
|
|
14
20
|
* Validates if value is not "null".
|
|
15
21
|
* @validator isNotNull
|
|
16
22
|
*/
|
|
17
|
-
|
|
18
|
-
return validator('isNotNull', (input, context, _this) => {
|
|
23
|
+
function isNotNull(options) {
|
|
24
|
+
return (0, index_js_1.validator)('isNotNull', (input, context, _this) => {
|
|
19
25
|
if (input !== null)
|
|
20
26
|
return input;
|
|
21
27
|
context.fail(_this, `{{label}} is null`, input);
|
|
@@ -25,8 +31,8 @@ export function isNotNull(options) {
|
|
|
25
31
|
* Validates if value is "null" or "undefined".
|
|
26
32
|
* @validator isNullish
|
|
27
33
|
*/
|
|
28
|
-
|
|
29
|
-
return validator('isNullish', (input, context, _this) => {
|
|
34
|
+
function isNullish(options) {
|
|
35
|
+
return (0, index_js_1.validator)('isNullish', (input, context, _this) => {
|
|
30
36
|
if (input == null)
|
|
31
37
|
return input;
|
|
32
38
|
context.fail(_this, `{{label}} is not nullish`, input);
|
|
@@ -36,8 +42,8 @@ export function isNullish(options) {
|
|
|
36
42
|
* Validates if value is not "null" nor "undefined".
|
|
37
43
|
* @validator isNotNullish
|
|
38
44
|
*/
|
|
39
|
-
|
|
40
|
-
return validator('isNotNullish', (input, context, _this) => {
|
|
45
|
+
function isNotNullish(options) {
|
|
46
|
+
return (0, index_js_1.validator)('isNotNullish', (input, context, _this) => {
|
|
41
47
|
if (input != null)
|
|
42
48
|
return input;
|
|
43
49
|
if (input === null)
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNumber = isNumber;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Validates if value is "number".
|
|
4
7
|
* Converts input value to number if coerce option is set to 'true'.
|
|
5
8
|
* @validator isNumber
|
|
6
9
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isNumber', (input, context, _this) => {
|
|
10
|
+
function isNumber(options) {
|
|
11
|
+
return (0, index_js_1.validator)('isNumber', (input, context, _this) => {
|
|
9
12
|
const coerce = options?.coerce || context.coerce;
|
|
10
13
|
let output = input;
|
|
11
14
|
if (output != null && typeof output !== 'number' && coerce) {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isObject = isObject;
|
|
4
|
+
const constants_js_1 = require("../../constants.js");
|
|
5
|
+
const index_js_1 = require("../../core/index.js");
|
|
3
6
|
/**
|
|
4
7
|
* Validates object according to schema
|
|
5
8
|
* Converts properties according to schema rules if coerce option is set to 'true'.
|
|
6
9
|
* @validator isObject
|
|
7
10
|
*/
|
|
8
|
-
|
|
11
|
+
function isObject(schema, options) {
|
|
9
12
|
const ctor = options?.ctor;
|
|
10
13
|
const ctorName = options?.name || ctor?.name;
|
|
11
14
|
const additionalFields = options?.additionalFields ?? !schema;
|
|
@@ -19,13 +22,13 @@ export function isObject(schema, options) {
|
|
|
19
22
|
const n = schema[k];
|
|
20
23
|
const key = caseInSensitive ? k.toLowerCase() : k;
|
|
21
24
|
if (Array.isArray(n)) {
|
|
22
|
-
if (!isValidator(n[0])) {
|
|
25
|
+
if (!(0, index_js_1.isValidator)(n[0])) {
|
|
23
26
|
throw new TypeError(`Invalid tuple definition in validation schema (${k})`);
|
|
24
27
|
}
|
|
25
28
|
propertyRules[key] = n[0];
|
|
26
29
|
propertyOptions[key] = { as: k, ...n[1] };
|
|
27
30
|
}
|
|
28
|
-
else if (isValidator(n)) {
|
|
31
|
+
else if ((0, index_js_1.isValidator)(n)) {
|
|
29
32
|
propertyRules[key] = n;
|
|
30
33
|
propertyOptions[key] = { as: k };
|
|
31
34
|
}
|
|
@@ -33,10 +36,10 @@ export function isObject(schema, options) {
|
|
|
33
36
|
throw new TypeError(`Invalid definition in validation schema (${k})`);
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
|
-
const _rule = validator('isObject', (input, context, _this) => {
|
|
39
|
+
const _rule = (0, index_js_1.validator)('isObject', (input, context, _this) => {
|
|
37
40
|
let output = input;
|
|
38
|
-
if (ctor && ctor[preValidation]) {
|
|
39
|
-
output = ctor[preValidation](output, context, _this);
|
|
41
|
+
if (ctor && ctor[constants_js_1.preValidation]) {
|
|
42
|
+
output = ctor[constants_js_1.preValidation](output, context, _this);
|
|
40
43
|
}
|
|
41
44
|
const coerce = options?.coerce || context.coerce;
|
|
42
45
|
if (typeof output === 'string' && coerce)
|
|
@@ -73,7 +76,7 @@ export function isObject(schema, options) {
|
|
|
73
76
|
v = output[inputKey];
|
|
74
77
|
_propRule =
|
|
75
78
|
propertyRules[schemaKey] ||
|
|
76
|
-
(isValidator(additionalFields) ? additionalFields : undefined);
|
|
79
|
+
((0, index_js_1.isValidator)(additionalFields) ? additionalFields : undefined);
|
|
77
80
|
if (_propRule) {
|
|
78
81
|
if (processedSchemaKeys[schemaKey])
|
|
79
82
|
continue;
|
|
@@ -101,8 +104,8 @@ export function isObject(schema, options) {
|
|
|
101
104
|
}
|
|
102
105
|
if (context.errors.length)
|
|
103
106
|
return undefined;
|
|
104
|
-
if (ctor && ctor[postValidation]) {
|
|
105
|
-
ctor[postValidation](out, context, _this);
|
|
107
|
+
if (ctor && ctor[constants_js_1.postValidation]) {
|
|
108
|
+
ctor[constants_js_1.postValidation](out, context, _this);
|
|
106
109
|
return out;
|
|
107
110
|
}
|
|
108
111
|
return out;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRecord = isRecord;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Validates record object according to given "key" and "value" rules
|
|
4
7
|
* Converts properties according to rules if coerce option is set to 'true'.
|
|
5
8
|
* @validator isRecord
|
|
6
9
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isRecord', (input, context, _this) => {
|
|
10
|
+
function isRecord(keyRule, valueRule, options) {
|
|
11
|
+
return (0, index_js_1.validator)('isRecord', (input, context, _this) => {
|
|
9
12
|
if (!(input && typeof input === 'object')) {
|
|
10
13
|
context.fail(_this, `{{label}} must be an object`, input);
|
|
11
14
|
return;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trimStart = exports.trimEnd = void 0;
|
|
4
|
+
exports.isString = isString;
|
|
5
|
+
exports.stringReplace = stringReplace;
|
|
6
|
+
exports.stringSplit = stringSplit;
|
|
7
|
+
exports.trim = trim;
|
|
8
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
9
|
/**
|
|
3
10
|
* Validates if value is "string".
|
|
4
11
|
* Converts input value to string if coerce option is set to 'true'.
|
|
5
12
|
* @validator isString
|
|
6
13
|
*/
|
|
7
|
-
|
|
8
|
-
return validator('isString', (input, context, _this) => {
|
|
14
|
+
function isString(options) {
|
|
15
|
+
return (0, index_js_1.validator)('isString', (input, context, _this) => {
|
|
9
16
|
const coerce = options?.coerce || context.coerce;
|
|
10
17
|
let output = input;
|
|
11
18
|
if (output != null && typeof output !== 'string' && coerce) {
|
|
@@ -23,15 +30,15 @@ export function isString(options) {
|
|
|
23
30
|
context.fail(_this, `"{{value}}" is not a string`, input);
|
|
24
31
|
}, options);
|
|
25
32
|
}
|
|
26
|
-
|
|
27
|
-
return validator('stringReplace', (input) => {
|
|
33
|
+
function stringReplace(searchValue, replacer) {
|
|
34
|
+
return (0, index_js_1.validator)('stringReplace', (input) => {
|
|
28
35
|
if (input == null)
|
|
29
36
|
return input;
|
|
30
37
|
return String(input).replace(searchValue, replacer);
|
|
31
38
|
});
|
|
32
39
|
}
|
|
33
|
-
|
|
34
|
-
return validator('stringSplit', (input) => {
|
|
40
|
+
function stringSplit(splitter, limit) {
|
|
41
|
+
return (0, index_js_1.validator)('stringSplit', (input) => {
|
|
35
42
|
if (input == null)
|
|
36
43
|
return input;
|
|
37
44
|
return String(input).split(splitter, limit);
|
|
@@ -41,8 +48,8 @@ export function stringSplit(splitter, limit) {
|
|
|
41
48
|
* Removes whitespace from both ends of a string
|
|
42
49
|
* @validator trim
|
|
43
50
|
*/
|
|
44
|
-
|
|
45
|
-
return validator('trim', (input) => {
|
|
51
|
+
function trim() {
|
|
52
|
+
return (0, index_js_1.validator)('trim', (input) => {
|
|
46
53
|
if (input == null)
|
|
47
54
|
return input;
|
|
48
55
|
return String(input).trim();
|
|
@@ -53,8 +60,9 @@ export function trim() {
|
|
|
53
60
|
* Removes whitespace from the end of a string
|
|
54
61
|
* @validator trimEnd
|
|
55
62
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
const trimEnd = () => trimEndRule;
|
|
64
|
+
exports.trimEnd = trimEnd;
|
|
65
|
+
const trimEndRule = (0, index_js_1.validator)('trimEnd', (input) => {
|
|
58
66
|
if (input == null)
|
|
59
67
|
return input;
|
|
60
68
|
return String(input).trimEnd();
|
|
@@ -64,8 +72,9 @@ const trimEndRule = validator('trimEnd', (input) => {
|
|
|
64
72
|
* Removes whitespace from the beginning of a string
|
|
65
73
|
* @validator trimStart
|
|
66
74
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
const trimStart = () => trimStartRule;
|
|
76
|
+
exports.trimStart = trimStart;
|
|
77
|
+
const trimStartRule = (0, index_js_1.validator)('trimStart', (input) => {
|
|
69
78
|
if (input == null)
|
|
70
79
|
return input;
|
|
71
80
|
return String(input).trimStart();
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTuple = isTuple;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
5
|
+
function isTuple(items, options) {
|
|
6
|
+
return (0, index_js_1.validator)('isTuple', (input, context, _this) => {
|
|
4
7
|
const coerce = options?.coerce || context.coerce;
|
|
5
8
|
let output = input;
|
|
6
9
|
if (output != null && coerce && !Array.isArray(output))
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUndefined = isUndefined;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Validates if value is "undefined"
|
|
4
7
|
* @validator isUndefined
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
return validator('isUndefined', (input, context, _this) => {
|
|
9
|
+
function isUndefined(options) {
|
|
10
|
+
return (0, index_js_1.validator)('isUndefined', (input, context, _this) => {
|
|
8
11
|
if (options?.coerce || context.coerce)
|
|
9
12
|
return undefined;
|
|
10
13
|
if (input === undefined)
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exists = exists;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Validates if property exists
|
|
4
7
|
* @validator exists
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
return validator('exists', (input, context, _this) => {
|
|
9
|
+
function exists(options) {
|
|
10
|
+
return (0, index_js_1.validator)('exists', (input, context, _this) => {
|
|
8
11
|
if (input !== undefined ||
|
|
9
12
|
(context.scope &&
|
|
10
13
|
Object.getOwnPropertyDescriptor(context.scope, input))) {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLength = getLength;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Returns length of an Array, String, ArrayBuffer, Buffer or any object with the "length" property.
|
|
4
7
|
* @validator getLength
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
return validator('getLength', (input, context, _this) => {
|
|
9
|
+
function getLength() {
|
|
10
|
+
return (0, index_js_1.validator)('getLength', (input, context, _this) => {
|
|
8
11
|
if (typeof input === 'string')
|
|
9
12
|
return input.length;
|
|
10
13
|
if (Array.isArray(input))
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.optional = optional;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Makes sub-rule optional
|
|
4
7
|
* @validator optional
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
return validator('optional', (input, context) => {
|
|
9
|
+
function optional(nested, options) {
|
|
10
|
+
return (0, index_js_1.validator)('optional', (input, context) => {
|
|
8
11
|
if (input == null)
|
|
9
12
|
return input;
|
|
10
13
|
return nested(input, context);
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pipe = pipe;
|
|
4
|
+
exports.allOf = allOf;
|
|
5
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
6
|
/**
|
|
3
7
|
*
|
|
4
8
|
* @validator pipe
|
|
5
9
|
*/
|
|
6
|
-
|
|
10
|
+
function pipe(rules, options) {
|
|
7
11
|
const l = rules.length;
|
|
8
12
|
const returnIndex = options?.returnIndex;
|
|
9
|
-
return validator('pipe', (input, context) => {
|
|
13
|
+
return (0, index_js_1.validator)('pipe', (input, context) => {
|
|
10
14
|
let i;
|
|
11
15
|
let c;
|
|
12
16
|
let v = input;
|
|
@@ -26,8 +30,8 @@ export function pipe(rules, options) {
|
|
|
26
30
|
* Test given value against to all codecs and returns original input
|
|
27
31
|
* @validator allOf
|
|
28
32
|
*/
|
|
29
|
-
|
|
30
|
-
return validator('allOf', (input, context) => {
|
|
33
|
+
function allOf(rules) {
|
|
34
|
+
return (0, index_js_1.validator)('allOf', (input, context) => {
|
|
31
35
|
let i;
|
|
32
36
|
let c;
|
|
33
37
|
const l = rules.length;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.required = required;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* Makes sub-rule required
|
|
4
7
|
* @validator required
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
return validator('required', (input, context, _this) => {
|
|
9
|
+
function required(nested, options) {
|
|
10
|
+
return (0, index_js_1.validator)('required', (input, context, _this) => {
|
|
8
11
|
if (input == null) {
|
|
9
12
|
context.fail(_this, `{{label}} is required`, input);
|
|
10
13
|
return;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.union = union;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
2
5
|
/**
|
|
3
6
|
*
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
function union(codecs) {
|
|
6
9
|
const l = codecs.length;
|
|
7
|
-
return validator('union', (input, context, _this) => {
|
|
10
|
+
return (0, index_js_1.validator)('union', (input, context, _this) => {
|
|
8
11
|
let i;
|
|
9
12
|
let c;
|
|
10
13
|
let v;
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
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.7.0",
|
|
5
5
|
"author": "Panates",
|
|
6
|
-
"contributors": [
|
|
7
|
-
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
8
|
-
],
|
|
9
6
|
"license": "MIT",
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "https://github.com/panates/valgen.git"
|
|
13
|
-
},
|
|
14
7
|
"dependencies": {
|
|
15
8
|
"@types/validator": "^13.12.0",
|
|
16
9
|
"date-fns": "^3.6.0",
|
|
17
|
-
"ts-gems": "^3.
|
|
10
|
+
"ts-gems": "^3.5.0",
|
|
18
11
|
"validator": "^13.12.0"
|
|
19
12
|
},
|
|
20
|
-
"
|
|
21
|
-
"
|
|
13
|
+
"main": "./cjs/index.js",
|
|
14
|
+
"module": "./esm/index.js",
|
|
15
|
+
"types": "./types/index.d.ts",
|
|
22
16
|
"exports": {
|
|
23
17
|
".": {
|
|
24
18
|
"require": "./cjs/index.js",
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
"import": "./esm/index.js",
|
|
20
|
+
"types": "./types/index.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"contributors": [
|
|
24
|
+
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
25
|
+
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/panates/valgen.git"
|
|
29
29
|
},
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">= 16.0"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"files": [
|
|
34
34
|
"cjs/",
|
|
35
35
|
"esm/",
|
|
36
|
-
"
|
|
36
|
+
"types/",
|
|
37
37
|
"LICENSE",
|
|
38
38
|
"README.md",
|
|
39
39
|
"CHANGELOG.md"
|
package/cjs/package.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|