valgen 5.18.1 → 5.19.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/{types/constants.d.ts → constants.d.ts} +1 -0
- package/{esm/constants.js → constants.js} +1 -0
- package/{esm/core → core}/context.js +12 -2
- package/{esm/core → core}/validation-error.js +1 -1
- package/{esm/index.js → index.js} +1 -1
- package/package.json +9 -25
- package/{types/rules → rules}/type-rules/is-date.d.ts +1 -0
- package/{esm/rules → rules}/type-rules/is-date.js +21 -10
- package/CHANGELOG.md +0 -378
- package/cjs/constants.js +0 -7
- package/cjs/core/constants.js +0 -5
- package/cjs/core/context.js +0 -74
- package/cjs/core/index.js +0 -9
- package/cjs/core/types.js +0 -2
- package/cjs/core/utilities.js +0 -30
- package/cjs/core/validation-error.js +0 -12
- package/cjs/core/validator.js +0 -71
- package/cjs/factories.js +0 -4
- package/cjs/helpers/object.utils.js +0 -18
- package/cjs/helpers/omit-undefined.js +0 -14
- package/cjs/helpers/string.utils.js +0 -6
- package/cjs/index.js +0 -129
- package/cjs/package.json +0 -3
- package/cjs/rules/format-rules/is-alpha.js +0 -30
- package/cjs/rules/format-rules/is-ascii.js +0 -17
- package/cjs/rules/format-rules/is-base64.js +0 -18
- package/cjs/rules/format-rules/is-btc-address.js +0 -18
- package/cjs/rules/format-rules/is-credit-card.js +0 -19
- package/cjs/rules/format-rules/is-decimal.js +0 -19
- package/cjs/rules/format-rules/is-ean.js +0 -17
- package/cjs/rules/format-rules/is-email.js +0 -66
- package/cjs/rules/format-rules/is-eth-address.js +0 -18
- package/cjs/rules/format-rules/is-fqdn.js +0 -21
- package/cjs/rules/format-rules/is-hash.js +0 -18
- package/cjs/rules/format-rules/is-hex-color.js +0 -18
- package/cjs/rules/format-rules/is-hex.js +0 -18
- package/cjs/rules/format-rules/is-iban.js +0 -29
- package/cjs/rules/format-rules/is-ip.js +0 -35
- package/cjs/rules/format-rules/is-issn.js +0 -21
- package/cjs/rules/format-rules/is-jwt.js +0 -17
- package/cjs/rules/format-rules/is-lowercase.js +0 -31
- package/cjs/rules/format-rules/is-mac-address.js +0 -24
- package/cjs/rules/format-rules/is-mobile-phone.js +0 -22
- package/cjs/rules/format-rules/is-object-id.js +0 -28
- package/cjs/rules/format-rules/is-passport-number.js +0 -19
- package/cjs/rules/format-rules/is-port.js +0 -22
- package/cjs/rules/format-rules/is-time.js +0 -51
- package/cjs/rules/format-rules/is-url.js +0 -20
- package/cjs/rules/format-rules/is-uuid.js +0 -20
- package/cjs/rules/format-rules/is-vat-number.js +0 -18
- package/cjs/rules/format-rules/matches.js +0 -22
- package/cjs/rules/index.js +0 -56
- package/cjs/rules/logical-rules/is-defined.js +0 -15
- package/cjs/rules/logical-rules/is-empty.js +0 -110
- package/cjs/rules/logical-rules/is-equal.js +0 -32
- package/cjs/rules/logical-rules/range.js +0 -175
- package/cjs/rules/type-rules/is-any.js +0 -10
- package/cjs/rules/type-rules/is-array.js +0 -45
- package/cjs/rules/type-rules/is-bigint.js +0 -21
- package/cjs/rules/type-rules/is-boolean.js +0 -31
- package/cjs/rules/type-rules/is-date.js +0 -180
- package/cjs/rules/type-rules/is-enum.js +0 -31
- package/cjs/rules/type-rules/is-integer.js +0 -30
- package/cjs/rules/type-rules/is-null.js +0 -54
- package/cjs/rules/type-rules/is-number.js +0 -27
- package/cjs/rules/type-rules/is-object.js +0 -113
- package/cjs/rules/type-rules/is-record.js +0 -42
- package/cjs/rules/type-rules/is-string.js +0 -81
- package/cjs/rules/type-rules/is-tuple.js +0 -38
- package/cjs/rules/type-rules/is-undefined.js +0 -17
- package/cjs/rules/utility-rules/all-of.js +0 -20
- package/cjs/rules/utility-rules/exists.js +0 -18
- package/cjs/rules/utility-rules/get-length.js +0 -29
- package/cjs/rules/utility-rules/one-of.js +0 -59
- package/cjs/rules/utility-rules/optional.js +0 -15
- package/cjs/rules/utility-rules/pipe.js +0 -28
- package/cjs/rules/utility-rules/required.js +0 -19
- package/cjs/tsconfig-build-cjs.tsbuildinfo +0 -1
- package/esm/package.json +0 -3
- package/esm/tsconfig-build-esm.tsbuildinfo +0 -1
- package/types/index.d.cts +0 -65
- /package/{types/core → core}/constants.d.ts +0 -0
- /package/{esm/core → core}/constants.js +0 -0
- /package/{types/core → core}/context.d.ts +0 -0
- /package/{types/core → core}/index.d.ts +0 -0
- /package/{esm/core → core}/index.js +0 -0
- /package/{types/core → core}/types.d.ts +0 -0
- /package/{esm/core → core}/types.js +0 -0
- /package/{types/core → core}/utilities.d.ts +0 -0
- /package/{esm/core → core}/utilities.js +0 -0
- /package/{types/core → core}/validation-error.d.ts +0 -0
- /package/{types/core → core}/validator.d.ts +0 -0
- /package/{esm/core → core}/validator.js +0 -0
- /package/{types/factories.d.ts → factories.d.ts} +0 -0
- /package/{esm/factories.js → factories.js} +0 -0
- /package/{types/helpers → helpers}/object.utils.d.ts +0 -0
- /package/{esm/helpers → helpers}/object.utils.js +0 -0
- /package/{types/helpers → helpers}/omit-undefined.d.ts +0 -0
- /package/{esm/helpers → helpers}/omit-undefined.js +0 -0
- /package/{types/helpers → helpers}/string.utils.d.ts +0 -0
- /package/{esm/helpers → helpers}/string.utils.js +0 -0
- /package/{types/index.d.ts → index.d.ts} +0 -0
- /package/{types/rules → rules}/format-rules/is-alpha.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-alpha.js +0 -0
- /package/{types/rules → rules}/format-rules/is-ascii.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-ascii.js +0 -0
- /package/{types/rules → rules}/format-rules/is-base64.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-base64.js +0 -0
- /package/{types/rules → rules}/format-rules/is-btc-address.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-btc-address.js +0 -0
- /package/{types/rules → rules}/format-rules/is-credit-card.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-credit-card.js +0 -0
- /package/{types/rules → rules}/format-rules/is-decimal.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-decimal.js +0 -0
- /package/{types/rules → rules}/format-rules/is-ean.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-ean.js +0 -0
- /package/{types/rules → rules}/format-rules/is-email.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-email.js +0 -0
- /package/{types/rules → rules}/format-rules/is-eth-address.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-eth-address.js +0 -0
- /package/{types/rules → rules}/format-rules/is-fqdn.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-fqdn.js +0 -0
- /package/{types/rules → rules}/format-rules/is-hash.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-hash.js +0 -0
- /package/{types/rules → rules}/format-rules/is-hex-color.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-hex-color.js +0 -0
- /package/{types/rules → rules}/format-rules/is-hex.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-hex.js +0 -0
- /package/{types/rules → rules}/format-rules/is-iban.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-iban.js +0 -0
- /package/{types/rules → rules}/format-rules/is-ip.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-ip.js +0 -0
- /package/{types/rules → rules}/format-rules/is-issn.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-issn.js +0 -0
- /package/{types/rules → rules}/format-rules/is-jwt.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-jwt.js +0 -0
- /package/{types/rules → rules}/format-rules/is-lowercase.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-lowercase.js +0 -0
- /package/{types/rules → rules}/format-rules/is-mac-address.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-mac-address.js +0 -0
- /package/{types/rules → rules}/format-rules/is-mobile-phone.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-mobile-phone.js +0 -0
- /package/{types/rules → rules}/format-rules/is-object-id.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-object-id.js +0 -0
- /package/{types/rules → rules}/format-rules/is-passport-number.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-passport-number.js +0 -0
- /package/{types/rules → rules}/format-rules/is-port.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-port.js +0 -0
- /package/{types/rules → rules}/format-rules/is-time.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-time.js +0 -0
- /package/{types/rules → rules}/format-rules/is-url.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-url.js +0 -0
- /package/{types/rules → rules}/format-rules/is-uuid.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-uuid.js +0 -0
- /package/{types/rules → rules}/format-rules/is-vat-number.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/is-vat-number.js +0 -0
- /package/{types/rules → rules}/format-rules/matches.d.ts +0 -0
- /package/{esm/rules → rules}/format-rules/matches.js +0 -0
- /package/{types/rules → rules}/index.d.ts +0 -0
- /package/{esm/rules → rules}/index.js +0 -0
- /package/{types/rules → rules}/logical-rules/is-defined.d.ts +0 -0
- /package/{esm/rules → rules}/logical-rules/is-defined.js +0 -0
- /package/{types/rules → rules}/logical-rules/is-empty.d.ts +0 -0
- /package/{esm/rules → rules}/logical-rules/is-empty.js +0 -0
- /package/{types/rules → rules}/logical-rules/is-equal.d.ts +0 -0
- /package/{esm/rules → rules}/logical-rules/is-equal.js +0 -0
- /package/{types/rules → rules}/logical-rules/range.d.ts +0 -0
- /package/{esm/rules → rules}/logical-rules/range.js +0 -0
- /package/{types/rules → rules}/type-rules/is-any.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-any.js +0 -0
- /package/{types/rules → rules}/type-rules/is-array.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-array.js +0 -0
- /package/{types/rules → rules}/type-rules/is-bigint.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-bigint.js +0 -0
- /package/{types/rules → rules}/type-rules/is-boolean.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-boolean.js +0 -0
- /package/{types/rules → rules}/type-rules/is-enum.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-enum.js +0 -0
- /package/{types/rules → rules}/type-rules/is-integer.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-integer.js +0 -0
- /package/{types/rules → rules}/type-rules/is-null.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-null.js +0 -0
- /package/{types/rules → rules}/type-rules/is-number.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-number.js +0 -0
- /package/{types/rules → rules}/type-rules/is-object.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-object.js +0 -0
- /package/{types/rules → rules}/type-rules/is-record.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-record.js +0 -0
- /package/{types/rules → rules}/type-rules/is-string.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-string.js +0 -0
- /package/{types/rules → rules}/type-rules/is-tuple.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-tuple.js +0 -0
- /package/{types/rules → rules}/type-rules/is-undefined.d.ts +0 -0
- /package/{esm/rules → rules}/type-rules/is-undefined.js +0 -0
- /package/{types/rules → rules}/utility-rules/all-of.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/all-of.js +0 -0
- /package/{types/rules → rules}/utility-rules/exists.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/exists.js +0 -0
- /package/{types/rules → rules}/utility-rules/get-length.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/get-length.js +0 -0
- /package/{types/rules → rules}/utility-rules/one-of.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/one-of.js +0 -0
- /package/{types/rules → rules}/utility-rules/optional.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/optional.js +0 -0
- /package/{types/rules → rules}/utility-rules/pipe.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/pipe.js +0 -0
- /package/{types/rules → rules}/utility-rules/required.d.ts +0 -0
- /package/{esm/rules → rules}/utility-rules/required.js +0 -0
|
@@ -3,9 +3,19 @@ import { ValidationError } from './validation-error.js';
|
|
|
3
3
|
const VARIABLE_REPLACE_PATTERN = /{{([^}]*)}}/g;
|
|
4
4
|
const OPTIONAL_VAR_PATTERN = /^([^?]+)(?:\||(.*))?$/;
|
|
5
5
|
export class Context {
|
|
6
|
+
isRoot = true;
|
|
7
|
+
errors = [];
|
|
8
|
+
maxErrors;
|
|
9
|
+
onFail;
|
|
10
|
+
coerce;
|
|
11
|
+
root;
|
|
12
|
+
location;
|
|
13
|
+
scope;
|
|
14
|
+
context;
|
|
15
|
+
property;
|
|
16
|
+
index;
|
|
17
|
+
label;
|
|
6
18
|
constructor(options) {
|
|
7
|
-
this.isRoot = true;
|
|
8
|
-
this.errors = [];
|
|
9
19
|
Object.assign(this, options);
|
|
10
20
|
}
|
|
11
21
|
fail(rule, message, value, details) {
|
|
@@ -56,7 +56,7 @@ const toArray = vg.isArray(isAny, { coerce: true });
|
|
|
56
56
|
const toBigint = vg.isBigint({ coerce: true });
|
|
57
57
|
const toBoolean = vg.isBoolean({ coerce: true });
|
|
58
58
|
const toDate = vg.isDate({ coerce: true });
|
|
59
|
-
const toDateString = vg.isDateString({ coerce: true });
|
|
59
|
+
const toDateString = vg.isDateString({ coerce: true, precisionMin: 'day' });
|
|
60
60
|
const toInteger = vg.isInteger({ coerce: true });
|
|
61
61
|
const toNumber = vg.isNumber({ coerce: true });
|
|
62
62
|
const toString = vg.isString({ coerce: true });
|
package/package.json
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
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.19.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@browsery/validator": "^13.
|
|
8
|
+
"@browsery/validator": "^13.15.15",
|
|
9
9
|
"date-fns": "^4.1.0",
|
|
10
10
|
"reflect-metadata": "^0.2.2",
|
|
11
11
|
"ts-gems": "^3.11.3",
|
|
12
12
|
"tslib": "^2.8.1"
|
|
13
13
|
},
|
|
14
14
|
"type": "module",
|
|
15
|
+
"module": "./index.js",
|
|
16
|
+
"types": "./index.d.ts",
|
|
15
17
|
"exports": {
|
|
16
18
|
".": {
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"default": "./esm/index.js"
|
|
20
|
-
},
|
|
21
|
-
"require": {
|
|
22
|
-
"types": "./types/index.d.cts",
|
|
23
|
-
"default": "./cjs/index.js"
|
|
24
|
-
},
|
|
25
|
-
"default": "./esm/index.js"
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"default": "./index.js"
|
|
26
21
|
},
|
|
27
22
|
"./package.json": "./package.json"
|
|
28
23
|
},
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20.0"
|
|
26
|
+
},
|
|
32
27
|
"contributors": [
|
|
33
28
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
34
29
|
],
|
|
@@ -36,17 +31,6 @@
|
|
|
36
31
|
"type": "git",
|
|
37
32
|
"url": "https://github.com/panates/valgen.git"
|
|
38
33
|
},
|
|
39
|
-
"engines": {
|
|
40
|
-
"node": ">= 16.0"
|
|
41
|
-
},
|
|
42
|
-
"files": [
|
|
43
|
-
"cjs/",
|
|
44
|
-
"esm/",
|
|
45
|
-
"types/",
|
|
46
|
-
"LICENSE",
|
|
47
|
-
"README.md",
|
|
48
|
-
"CHANGELOG.md"
|
|
49
|
-
],
|
|
50
34
|
"keywords": [
|
|
51
35
|
"validate",
|
|
52
36
|
"validation",
|
|
@@ -37,10 +37,11 @@ export function isDate(options) {
|
|
|
37
37
|
* @validator isDateString
|
|
38
38
|
*/
|
|
39
39
|
export function isDateString(options) {
|
|
40
|
-
const
|
|
40
|
+
const trimIdx = PRECISION_INDEX[options?.trim || 'tz'] || 9;
|
|
41
|
+
const precisionMin = options?.precisionMin || options?.trim || 'minutes';
|
|
41
42
|
const precisionMax = options?.precisionMax || 'tz';
|
|
42
43
|
const precisionMaxIdx = PRECISION_INDEX[precisionMax] || 9;
|
|
43
|
-
const precisionMinIdx = Math.min(precisionMaxIdx, PRECISION_INDEX[precisionMin] || 6);
|
|
44
|
+
const precisionMinIdx = Math.min(trimIdx, precisionMaxIdx, PRECISION_INDEX[precisionMin] || 6);
|
|
44
45
|
return validator('isDateString', (input, context, _this) => {
|
|
45
46
|
const coerce = options?.coerce ?? context.coerce;
|
|
46
47
|
const parsed = coerceDateString(input, options?.trim);
|
|
@@ -62,8 +63,9 @@ export function isDateString(options) {
|
|
|
62
63
|
const DATE_PATTERN = /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[T ](?:([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?(?:\.(\d{0,6}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
|
|
63
64
|
const DATE_PATTERN2 = /^(\d{4,14})(?:\.(\d{1,6}))?(?:(?:([+-])(0[0-9]|1[0-2])(\d{2})?)|Z)?$/;
|
|
64
65
|
function coerceDateString(input, precision) {
|
|
66
|
+
const precisionIndex = (precision ? PRECISION_INDEX[precision] : 9) || 9;
|
|
65
67
|
let dateParts;
|
|
66
|
-
let
|
|
68
|
+
let detectedPrecision = 0;
|
|
67
69
|
if (input instanceof Date || typeof input === 'number') {
|
|
68
70
|
const d = typeof input === 'number' ? new Date(input) : input;
|
|
69
71
|
dateParts = [
|
|
@@ -74,8 +76,18 @@ function coerceDateString(input, precision) {
|
|
|
74
76
|
String(d.getMinutes()).padStart(2, '0'),
|
|
75
77
|
String(d.getSeconds()).padStart(2, '0'),
|
|
76
78
|
];
|
|
77
|
-
if (d.getMilliseconds() > 0)
|
|
79
|
+
if (precisionIndex >= 7 && d.getMilliseconds() > 0)
|
|
78
80
|
dateParts.push(String(d.getMilliseconds()).padStart(3, '0'));
|
|
81
|
+
if (precisionIndex >= 8) {
|
|
82
|
+
const tzOffset = d.getTimezoneOffset();
|
|
83
|
+
const tz = tzOffset > 0
|
|
84
|
+
? '-'
|
|
85
|
+
: '+' +
|
|
86
|
+
String(Math.floor(Math.abs(tzOffset) / 60)).padStart(2, '0') +
|
|
87
|
+
':' +
|
|
88
|
+
String(Math.abs(tzOffset) % 60).padStart(2, '0');
|
|
89
|
+
dateParts.push(tz);
|
|
90
|
+
}
|
|
79
91
|
}
|
|
80
92
|
else if (typeof input === 'string') {
|
|
81
93
|
const d = datefns.parseISO(input);
|
|
@@ -102,10 +114,9 @@ function coerceDateString(input, precision) {
|
|
|
102
114
|
}
|
|
103
115
|
if (!dateParts)
|
|
104
116
|
return;
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
const precisionIndex = (precision ? PRECISION_INDEX[precision] : 9) || 9;
|
|
117
|
+
detectedPrecision = dateParts.findIndex(v => !v);
|
|
118
|
+
if (detectedPrecision === -1)
|
|
119
|
+
detectedPrecision = Math.min(dateParts.length, 8);
|
|
109
120
|
let value = dateParts[0] || '0000';
|
|
110
121
|
if (precisionIndex > 1)
|
|
111
122
|
value += '-' + (dateParts[1] || '01');
|
|
@@ -117,13 +128,13 @@ function coerceDateString(input, precision) {
|
|
|
117
128
|
value += ':' + (dateParts[4] || '00');
|
|
118
129
|
if (precisionIndex > 5)
|
|
119
130
|
value += ':' + (dateParts[5] || '00');
|
|
120
|
-
if (precisionIndex >
|
|
131
|
+
if (precisionIndex > 6)
|
|
121
132
|
value += dateParts[6] ? '.' + dateParts[6] : '';
|
|
122
133
|
if (precisionIndex > 7)
|
|
123
134
|
value += dateParts[7] || '';
|
|
124
135
|
return {
|
|
125
136
|
value,
|
|
126
|
-
precision:
|
|
137
|
+
precision: detectedPrecision || 8,
|
|
127
138
|
};
|
|
128
139
|
}
|
|
129
140
|
const PRECISION_INDEX = {
|
package/CHANGELOG.md
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
## Changelog
|
|
2
|
-
|
|
3
|
-
### [v5.18.1](https://github.com/panates/valgen/compare/v5.18.0...v5.18.1) -
|
|
4
|
-
|
|
5
|
-
#### 🪲 Fixes
|
|
6
|
-
|
|
7
|
-
- fix: Increased ms precision @Eray Hanoğlu
|
|
8
|
-
|
|
9
|
-
### [v5.18.0](https://github.com/panates/valgen/compare/v5.17.3...v5.18.0) - 31 July 2025
|
|
10
|
-
|
|
11
|
-
#### 🚀 New Features
|
|
12
|
-
|
|
13
|
-
- feat: isTime accept Date instance @Eray Hanoğlu
|
|
14
|
-
|
|
15
|
-
#### 🪲 Fixes
|
|
16
|
-
|
|
17
|
-
- fix: Minor fix in isDate rule @Eray Hanoğlu
|
|
18
|
-
|
|
19
|
-
### [v5.17.3](https://github.com/panates/valgen/compare/v5.17.2...v5.17.3) - 30 July 2025
|
|
20
|
-
|
|
21
|
-
#### 🚀 New Features
|
|
22
|
-
|
|
23
|
-
- feat: isDate can parse date string without signs @Eray Hanoğlu
|
|
24
|
-
|
|
25
|
-
### [v5.17.2](https://github.com/panates/valgen/compare/v5.17.1...v5.17.2) - 29 July 2025
|
|
26
|
-
|
|
27
|
-
#### 🛠 Refactoring and Updates
|
|
28
|
-
|
|
29
|
-
- refactor: Minor date rule optimization @Eray Hanoğlu
|
|
30
|
-
|
|
31
|
-
### [v5.17.1](https://github.com/panates/valgen/compare/v5.17.0...v5.17.1) - 24 July 2025
|
|
32
|
-
|
|
33
|
-
#### 🪲 Fixes
|
|
34
|
-
|
|
35
|
-
- fix: isDate milliseconds padding @Eray Hanoğlu
|
|
36
|
-
|
|
37
|
-
### [v5.17.0](https://github.com/panates/valgen/compare/v5.16.0...v5.17.0) - 24 July 2025
|
|
38
|
-
|
|
39
|
-
#### 🪲 Fixes
|
|
40
|
-
|
|
41
|
-
- refactor: Refactored isDate and isDateString validation rules @Eray Hanoğlu
|
|
42
|
-
|
|
43
|
-
#### 🛠 Refactoring and Updates
|
|
44
|
-
|
|
45
|
-
- refactor: Refactored isDate and isDateString validation rules @Eray Hanoğlu
|
|
46
|
-
|
|
47
|
-
### [v5.16.0](https://github.com/panates/valgen/compare/v5.15.4...v5.16.0) - 16 July 2025
|
|
48
|
-
|
|
49
|
-
#### 🛠 Refactoring and Updates
|
|
50
|
-
|
|
51
|
-
- refactor: Refactored isDate and isDateString validation rules @Eray Hanoğlu
|
|
52
|
-
|
|
53
|
-
### [v5.15.4](https://github.com/panates/valgen/compare/v5.15.3...v5.15.4) - 11 July 2025
|
|
54
|
-
|
|
55
|
-
#### 🛠 Refactoring and Updates
|
|
56
|
-
|
|
57
|
-
- refactor: Exported default isTime rule @Eray Hanoğlu
|
|
58
|
-
|
|
59
|
-
### [v5.15.3](https://github.com/panates/valgen/compare/v5.15.2...v5.15.3) - 20 June 2025
|
|
60
|
-
|
|
61
|
-
#### 🚀 New Features
|
|
62
|
-
|
|
63
|
-
- feat: Adde default value option to "required" rule @Eray Hanoğlu
|
|
64
|
-
|
|
65
|
-
### [v5.15.2](https://github.com/panates/valgen/compare/v5.15.1...v5.15.2) - 27 May 2025
|
|
66
|
-
|
|
67
|
-
#### 🛠 Refactoring and Updates
|
|
68
|
-
|
|
69
|
-
- refactor: Refactored isGte, isGt, isLte, isLt typing @Eray Hanoğlu
|
|
70
|
-
|
|
71
|
-
### [v5.15.1](https://github.com/panates/valgen/compare/v5.15.0...v5.15.1) - 27 May 2025
|
|
72
|
-
|
|
73
|
-
#### 🚀 New Features
|
|
74
|
-
|
|
75
|
-
- feat: Added isTime rule @Eray Hanoğlu
|
|
76
|
-
|
|
77
|
-
#### 🪲 Fixes
|
|
78
|
-
|
|
79
|
-
- fix: Error message fix @Eray Hanoğlu
|
|
80
|
-
|
|
81
|
-
#### 🛠 Refactoring and Updates
|
|
82
|
-
|
|
83
|
-
- refactor: Removed path filter @Eray Hanoğlu
|
|
84
|
-
|
|
85
|
-
### [v5.15.0](https://github.com/panates/valgen/compare/v5.14.1...v5.15.0) - 24 April 2025
|
|
86
|
-
|
|
87
|
-
#### 🚀 New Features
|
|
88
|
-
|
|
89
|
-
- feat: Added discriminator validation to oneOf rule @Eray Hanoğlu
|
|
90
|
-
- feat: Added isEqual, isNotEqual rules @Eray Hanoğlu
|
|
91
|
-
|
|
92
|
-
#### 🛠 Refactoring and Updates
|
|
93
|
-
|
|
94
|
-
- refactor: Fixes and improvements @Eray Hanoğlu
|
|
95
|
-
- refactor: Removed union rule. Use oneOf rule instead @Eray Hanoğlu
|
|
96
|
-
|
|
97
|
-
### [v5.14.1](https://github.com/panates/valgen/compare/v5.14.0...v5.14.1) - 21 April 2025
|
|
98
|
-
|
|
99
|
-
#### 🪲 Fixes
|
|
100
|
-
|
|
101
|
-
- fix: Fixed validation issue while using silent mode @Eray Hanoğlu
|
|
102
|
-
|
|
103
|
-
#### 💬 General Changes
|
|
104
|
-
|
|
105
|
-
- dev: Moved from nyc to c8 @Eray Hanoğlu
|
|
106
|
-
- ci: Added workflows @Eray Hanoğlu
|
|
107
|
-
- dev: Fixed nycrc file @Eray Hanoğlu
|
|
108
|
-
- dev: Added publishConfig @Eray Hanoğlu
|
|
109
|
-
- dev: Fixed nycrc file @Eray Hanoğlu
|
|
110
|
-
- dev: Fixed paths @Eray Hanoğlu
|
|
111
|
-
- dev: Fixed nycrc file @Eray Hanoğlu
|
|
112
|
-
- dev: Fixed nycrc file @Eray Hanoğlu
|
|
113
|
-
- dev: Added qc script @Eray Hanoğlu
|
|
114
|
-
|
|
115
|
-
### [v5.14.0](https://github.com/panates/valgen/compare/v5.13.4...v5.14.0) - 30 March 2025
|
|
116
|
-
|
|
117
|
-
#### 🛠 Refactoring and Updates
|
|
118
|
-
|
|
119
|
-
- refactor: Moved from jest to mocha @Eray Hanoğlu
|
|
120
|
-
|
|
121
|
-
### [v5.13.4](https://github.com/panates/valgen/compare/v5.13.3...v5.13.4) - 26 March 2025
|
|
122
|
-
|
|
123
|
-
#### 🪲 Fixes
|
|
124
|
-
|
|
125
|
-
- fix: isNotEmpty do not work for number and boolean types @Eray Hanoğlu
|
|
126
|
-
|
|
127
|
-
### [v5.13.3](https://github.com/panates/valgen/compare/v5.13.2...v5.13.3) - 17 March 2025
|
|
128
|
-
|
|
129
|
-
#### 🪲 Fixes
|
|
130
|
-
|
|
131
|
-
- fix: isEmpty and isNotEmpty rules adds error issue twice @Eray Hanoğlu
|
|
132
|
-
|
|
133
|
-
### [v5.13.2](https://github.com/panates/valgen/compare/v5.13.1...v5.13.2) - 15 March 2025
|
|
134
|
-
|
|
135
|
-
#### 🪲 Fixes
|
|
136
|
-
|
|
137
|
-
- fix: Fixed ignoring pipe validators if context.errors has items. @Eray Hanoğlu
|
|
138
|
-
|
|
139
|
-
### [v5.13.1](https://github.com/panates/valgen/compare/v5.13.0...v5.13.1) - 14 March 2025
|
|
140
|
-
|
|
141
|
-
#### 🪲 Fixes
|
|
142
|
-
|
|
143
|
-
- fix: Fixed validation of Date, Buffer and ArrayBuffer objects of isEmpty and isNotEmpty rules @Eray Hanoğlu
|
|
144
|
-
- fix: Fixed validation of Date, Buffer and ArrayBuffer objects of isEmpty and isNotEmpty rules @Eray Hanoğlu
|
|
145
|
-
|
|
146
|
-
### [v5.13.0](https://github.com/panates/valgen/compare/v5.12.0...v5.13.0) - 3 February 2025
|
|
147
|
-
|
|
148
|
-
#### 🛠 Refactoring and Updates
|
|
149
|
-
|
|
150
|
-
- refactor: Updated dependencies @Eray Hanoğlu
|
|
151
|
-
- refactor: Changed error messages to "positive sentences" @Eray Hanoğlu
|
|
152
|
-
|
|
153
|
-
#### 💬 General Changes
|
|
154
|
-
|
|
155
|
-
- dev: Fixed ts config @Eray Hanoğlu
|
|
156
|
-
- dev: Added missing script @Eray Hanoğlu
|
|
157
|
-
|
|
158
|
-
### [v5.12.0](https://github.com/panates/valgen/compare/v5.11.0...v5.12.0) - 4 November 2024
|
|
159
|
-
|
|
160
|
-
#### 🛠 Refactoring and Updates
|
|
161
|
-
|
|
162
|
-
- refactor: Move from 'validator' library to "@browsery/validator" for ESM compatibility @Eray Hanoğlu
|
|
163
|
-
|
|
164
|
-
### [v5.11.0](https://github.com/panates/valgen/compare/v5.10.0...v5.11.0) - 4 November 2024
|
|
165
|
-
|
|
166
|
-
#### 💬 General Changes
|
|
167
|
-
|
|
168
|
-
- nit: Updated dependencies @Eray Hanoğlu
|
|
169
|
-
|
|
170
|
-
### [v5.10.0](https://github.com/panates/valgen/compare/v5.9.0...v5.10.0) - 14 September 2024
|
|
171
|
-
|
|
172
|
-
#### 💬 General Changes
|
|
173
|
-
|
|
174
|
-
- fixed: Circular imports @Eray Hanoğlu
|
|
175
|
-
|
|
176
|
-
### [v5.9.0](https://github.com/panates/valgen/compare/v5.8.2...v5.9.0) - 20 August 2024
|
|
177
|
-
|
|
178
|
-
#### 💬 General Changes
|
|
179
|
-
|
|
180
|
-
- Fixed compatibility for "Node16" and "NodeNext" moduleResolution options @Eray Hanoğlu
|
|
181
|
-
|
|
182
|
-
### [v5.8.2](https://github.com/panates/valgen/compare/v5.8.1...v5.8.2) - 12 August 2024
|
|
183
|
-
|
|
184
|
-
#### 💬 General Changes
|
|
185
|
-
|
|
186
|
-
- Applied publint to check package.json @Eray Hanoğlu
|
|
187
|
-
|
|
188
|
-
### [v5.8.1](https://github.com/panates/valgen/compare/v5.8.0...v5.8.1) - 12 August 2024
|
|
189
|
-
|
|
190
|
-
#### 💬 General Changes
|
|
191
|
-
|
|
192
|
-
- Applied publint to check package.json @Eray Hanoğlu
|
|
193
|
-
|
|
194
|
-
### [v5.8.0](https://github.com/panates/valgen/compare/v5.7.0...v5.8.0) - 12 August 2024
|
|
195
|
-
|
|
196
|
-
#### 💬 General Changes
|
|
197
|
-
|
|
198
|
-
- Rollback to ES2020 @Eray Hanoğlu
|
|
199
|
-
|
|
200
|
-
### [v5.7.0](https://github.com/panates/valgen/compare/v5.6.0...v5.7.0) - 9 August 2024
|
|
201
|
-
|
|
202
|
-
#### 💬 General Changes
|
|
203
|
-
|
|
204
|
-
- Made ready for Node16 moduleResolution @Eray Hanoğlu
|
|
205
|
-
|
|
206
|
-
### [v5.6.0](https://github.com/panates/valgen/compare/v5.5.0...v5.6.0) - 14 July 2024
|
|
207
|
-
|
|
208
|
-
#### 💬 General Changes
|
|
209
|
-
|
|
210
|
-
- Added isNotNull and isNotNullish rules @Eray Hanoğlu
|
|
211
|
-
- Added isNotNull and isNotNullish rules @Eray Hanoğlu
|
|
212
|
-
|
|
213
|
-
### [v5.5.0](https://github.com/panates/valgen/compare/v5.4.1...v5.5.0) - 14 July 2024
|
|
214
|
-
|
|
215
|
-
#### 💬 General Changes
|
|
216
|
-
|
|
217
|
-
- Moved eslint config to @panates/eslint-config @Eray Hanoğlu
|
|
218
|
-
- Changed error message @Eray Hanoğlu
|
|
219
|
-
- Removed coercing of isNull and isNullish rules @Eray Hanoğlu
|
|
220
|
-
- Now pipe can return original input value when returnIndex = -1 @Eray Hanoğlu
|
|
221
|
-
|
|
222
|
-
### [v5.4.1](https://github.com/panates/valgen/compare/v5.4.0...v5.4.1) - 18 May 2024
|
|
223
|
-
|
|
224
|
-
#### 💬 General Changes
|
|
225
|
-
|
|
226
|
-
- Exposed toBigint @Eray Hanoğlu
|
|
227
|
-
|
|
228
|
-
### [v5.4.0](https://github.com/panates/valgen/compare/v5.3.2...v5.4.0) - 18 May 2024
|
|
229
|
-
|
|
230
|
-
#### 💬 General Changes
|
|
231
|
-
|
|
232
|
-
- Added returnIndex to pipe() @Eray Hanoğlu
|
|
233
|
-
- Updated circleci config @Eray Hanoğlu
|
|
234
|
-
|
|
235
|
-
### [v5.3.2](https://github.com/panates/valgen/compare/v5.3.1...v5.3.2) - 18 May 2024
|
|
236
|
-
|
|
237
|
-
#### 💬 General Changes
|
|
238
|
-
|
|
239
|
-
- Updated dependencies @Eray Hanoğlu
|
|
240
|
-
- Fixed coveralls token @Eray Hanoğlu
|
|
241
|
-
|
|
242
|
-
### [v5.3.1](https://github.com/panates/valgen/compare/v5.3.0...v5.3.1) - 18 May 2024
|
|
243
|
-
|
|
244
|
-
#### 💬 General Changes
|
|
245
|
-
|
|
246
|
-
- Reorganized many rules @Eray Hanoğlu
|
|
247
|
-
- Updated code documentation @Eray Hanoğlu
|
|
248
|
-
- Fixed rule name @Eray Hanoğlu
|
|
249
|
-
|
|
250
|
-
### [v5.3.0](https://github.com/panates/valgen/compare/v5.2.2...v5.3.0) - 6 May 2024
|
|
251
|
-
|
|
252
|
-
#### 💬 General Changes
|
|
253
|
-
|
|
254
|
-
- Added validation generation option to enable coercing by default. @Eray Hanoğlu
|
|
255
|
-
|
|
256
|
-
### [v5.2.2](https://github.com/panates/valgen/compare/v5.2.1...v5.2.2) - 29 March 2024
|
|
257
|
-
|
|
258
|
-
#### 💬 General Changes
|
|
259
|
-
|
|
260
|
-
- Updated dependencies @Eray Hanoğlu
|
|
261
|
-
- Updated dependencies @Eray Hanoğlu
|
|
262
|
-
|
|
263
|
-
### [v5.2.1](https://github.com/panates/valgen/compare/v5.2.0...v5.2.1) - 27 March 2024
|
|
264
|
-
|
|
265
|
-
#### 💬 General Changes
|
|
266
|
-
|
|
267
|
-
- Updated dependencies @Eray Hanoğlu
|
|
268
|
-
|
|
269
|
-
### [v5.2.0](https://github.com/panates/valgen/compare/v5.1.0...v5.2.0) - 4 January 2024
|
|
270
|
-
|
|
271
|
-
#### 💬 General Changes
|
|
272
|
-
|
|
273
|
-
- Now validator options persist in context @Eray Hanoğlu
|
|
274
|
-
|
|
275
|
-
### [v5.1.0](https://github.com/panates/valgen/compare/v5.0.1...v5.1.0) - 23 December 2023
|
|
276
|
-
|
|
277
|
-
#### 💬 General Changes
|
|
278
|
-
|
|
279
|
-
- Moved from "dayjs" to "date-fns" @Eray Hanoğlu
|
|
280
|
-
|
|
281
|
-
### [v5.0.1](https://github.com/panates/valgen/compare/v5.0.0...v5.0.1) - 23 December 2023
|
|
282
|
-
|
|
283
|
-
#### 💬 General Changes
|
|
284
|
-
|
|
285
|
-
- Added new rules @Eray Hanoğlu
|
|
286
|
-
- Moved all validator factories into "factories" namespace, @Eray Hanoğlu
|
|
287
|
-
|
|
288
|
-
## [v5.0.0](https://github.com/panates/valgen/compare/v4.3.2...v5.0.0) - 21 December 2023
|
|
289
|
-
|
|
290
|
-
#### 💬 General Changes
|
|
291
|
-
|
|
292
|
-
- Moved all validator factories into "factories" namespace, @Eray Hanoğlu
|
|
293
|
-
|
|
294
|
-
### [v4.3.2](https://github.com/panates/valgen/compare/v4.3.1...v4.3.2) - 8 December 2023
|
|
295
|
-
|
|
296
|
-
#### 💬 General Changes
|
|
297
|
-
|
|
298
|
-
- Updated dependenices @Eray Hanoğlu
|
|
299
|
-
- Pass "_this" parameter to preValidation and postValidation methods @Eray Hanoğlu
|
|
300
|
-
|
|
301
|
-
### [v4.3.1](https://github.com/panates/valgen/compare/v4.3.0...v4.3.1) - 4 December 2023
|
|
302
|
-
|
|
303
|
-
#### 💬 General Changes
|
|
304
|
-
|
|
305
|
-
- Made preValidation and postValidation static @Eray Hanoğlu
|
|
306
|
-
|
|
307
|
-
### [v4.3.0](https://github.com/panates/valgen/compare/v4.2.5...v4.3.0) - 2 December 2023
|
|
308
|
-
|
|
309
|
-
#### 💬 General Changes
|
|
310
|
-
|
|
311
|
-
- Updated dependencies @Eray Hanoğlu
|
|
312
|
-
- Added [preValidation] and [postValidation] to isObject rule @Eray Hanoğlu
|
|
313
|
-
|
|
314
|
-
### [v4.2.5](https://github.com/panates/valgen/compare/v4.2.4...v4.2.5) - 27 November 2023
|
|
315
|
-
|
|
316
|
-
#### 💬 General Changes
|
|
317
|
-
|
|
318
|
-
- Fixed isArray error location property. @Eray Hanoğlu
|
|
319
|
-
|
|
320
|
-
### [v4.2.4](https://github.com/panates/valgen/compare/v4.2.3...v4.2.4) - 20 November 2023
|
|
321
|
-
|
|
322
|
-
#### 💬 General Changes
|
|
323
|
-
|
|
324
|
-
- Added json parsing feature to isObject validator @Eray Hanoğlu
|
|
325
|
-
|
|
326
|
-
### [v4.2.3](https://github.com/panates/valgen/compare/v4.2.2...v4.2.3) - 20 November 2023
|
|
327
|
-
|
|
328
|
-
#### 💬 General Changes
|
|
329
|
-
|
|
330
|
-
- Optimized error messages @Eray Hanoğlu
|
|
331
|
-
|
|
332
|
-
### [v4.2.2](https://github.com/panates/valgen/compare/v4.2.1...v4.2.2) - 15 November 2023
|
|
333
|
-
|
|
334
|
-
#### 💬 General Changes
|
|
335
|
-
|
|
336
|
-
- Changed "trim" option @Eray Hanoğlu
|
|
337
|
-
|
|
338
|
-
### [v4.2.1](https://github.com/panates/valgen/compare/v4.2.0...v4.2.1) - 15 November 2023
|
|
339
|
-
|
|
340
|
-
#### 💬 General Changes
|
|
341
|
-
|
|
342
|
-
- Fixed generating invalid date string @Eray Hanoğlu
|
|
343
|
-
|
|
344
|
-
### [v4.2.0](https://github.com/panates/valgen/compare/v4.1.0...v4.2.0) - 15 November 2023
|
|
345
|
-
|
|
346
|
-
#### 💬 General Changes
|
|
347
|
-
|
|
348
|
-
- Removed "format" option and added "precision" option to isDate validator @Eray Hanoğlu
|
|
349
|
-
- Added test for "label" option @Eray Hanoğlu
|
|
350
|
-
|
|
351
|
-
### [v4.1.0](https://github.com/panates/valgen/compare/v4.0.1...v4.1.0) - 31 October 2023
|
|
352
|
-
|
|
353
|
-
#### 💬 General Changes
|
|
354
|
-
|
|
355
|
-
- Updated validation messages. @Eray Hanoğlu
|
|
356
|
-
|
|
357
|
-
### [v4.0.1](https://github.com/panates/valgen/compare/v4.0.0...v4.0.1) - 24 October 2023
|
|
358
|
-
|
|
359
|
-
#### 💬 General Changes
|
|
360
|
-
|
|
361
|
-
- Added "coerce" option to isNull and isUndefined rules @Eray Hanoğlu
|
|
362
|
-
|
|
363
|
-
## [v4.0.0](https://github.com/panates/valgen/compare/v3.2.1...v4.0.0) - 17 August 2023
|
|
364
|
-
|
|
365
|
-
#### 💬 General Changes
|
|
366
|
-
|
|
367
|
-
- Initial release of v4.0.0-alpha.1 @Eray Hanoğlu
|
|
368
|
-
- Implemented all initial validators and tests @Eray Hanoğlu
|
|
369
|
-
- Updated dependencies @Eray Hanoğlu
|
|
370
|
-
- Better error handling @Eray Hanoğlu
|
|
371
|
-
- Updated deps @Eray Hanoğlu
|
|
372
|
-
- Added isBigint validator @Eray Hanoğlu
|
|
373
|
-
- Fixed isObject coerce issue @Eray Hanoğlu
|
|
374
|
-
- Improved isDateString @Eray Hanoğlu
|
|
375
|
-
- Updated dayjs @Eray Hanoğlu
|
|
376
|
-
- Updated deps @Eray Hanoğlu
|
|
377
|
-
- Updated deps @Eray Hanoğlu
|
|
378
|
-
- Fixed isObject coerce issue @Eray Hanoğlu
|
package/cjs/constants.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VALIDATE_NESTED_METADATA = exports.VALIDATE_METADATA = exports.preValidation = exports.postValidation = void 0;
|
|
4
|
-
exports.postValidation = Symbol('postValidation');
|
|
5
|
-
exports.preValidation = Symbol('preValidation');
|
|
6
|
-
exports.VALIDATE_METADATA = Symbol('VALIDATE_METADATA');
|
|
7
|
-
exports.VALIDATE_NESTED_METADATA = Symbol('VALIDATE_NESTED_METADATA');
|
package/cjs/core/constants.js
DELETED
package/cjs/core/context.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Context = void 0;
|
|
4
|
-
const omit_undefined_js_1 = require("../helpers/omit-undefined.js");
|
|
5
|
-
const validation_error_js_1 = require("./validation-error.js");
|
|
6
|
-
const VARIABLE_REPLACE_PATTERN = /{{([^}]*)}}/g;
|
|
7
|
-
const OPTIONAL_VAR_PATTERN = /^([^?]+)(?:\||(.*))?$/;
|
|
8
|
-
class Context {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.isRoot = true;
|
|
11
|
-
this.errors = [];
|
|
12
|
-
Object.assign(this, options);
|
|
13
|
-
}
|
|
14
|
-
fail(rule, message, value, details) {
|
|
15
|
-
const issue = (0, omit_undefined_js_1.omitUndefined)({
|
|
16
|
-
message: message instanceof Error ? message.message : String(message),
|
|
17
|
-
rule: rule.id,
|
|
18
|
-
root: this.root,
|
|
19
|
-
location: this.location,
|
|
20
|
-
context: this.context,
|
|
21
|
-
property: this.property,
|
|
22
|
-
index: this.index,
|
|
23
|
-
label: this.label,
|
|
24
|
-
value,
|
|
25
|
-
...details,
|
|
26
|
-
});
|
|
27
|
-
issue.value = value;
|
|
28
|
-
if (this.onFail) {
|
|
29
|
-
const x = this.onFail(issue, this);
|
|
30
|
-
if (!x)
|
|
31
|
-
return;
|
|
32
|
-
if (typeof x === 'object')
|
|
33
|
-
Object.assign(issue, x);
|
|
34
|
-
else
|
|
35
|
-
issue.message = String(x);
|
|
36
|
-
}
|
|
37
|
-
issue.message = ('' + issue.message).replace(VARIABLE_REPLACE_PATTERN, (x, g) => {
|
|
38
|
-
const m = OPTIONAL_VAR_PATTERN.exec(g);
|
|
39
|
-
if (!m)
|
|
40
|
-
return x;
|
|
41
|
-
const k = m[1];
|
|
42
|
-
let v = issue[k];
|
|
43
|
-
if (k === 'value') {
|
|
44
|
-
const s = String(issue.value);
|
|
45
|
-
return s.length < 30 ? s : s.substring(0, 30) + '..';
|
|
46
|
-
}
|
|
47
|
-
if (!v && k === 'label' && (this.location || this.property)) {
|
|
48
|
-
v = '`' + (this.location || this.property) + '`';
|
|
49
|
-
}
|
|
50
|
-
if (v != null)
|
|
51
|
-
return v;
|
|
52
|
-
if (m[2])
|
|
53
|
-
return m[2];
|
|
54
|
-
return m[1] === 'label' ? 'Value' : x;
|
|
55
|
-
});
|
|
56
|
-
this.errors.push(issue);
|
|
57
|
-
if (this.errors.length >= (this.maxErrors ?? Infinity)) {
|
|
58
|
-
throw new validation_error_js_1.ValidationError(this.errors);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
extend(options) {
|
|
62
|
-
const extended = {};
|
|
63
|
-
if (options) {
|
|
64
|
-
for (const [k, v] of Object.entries(options)) {
|
|
65
|
-
if (v !== undefined)
|
|
66
|
-
extended[k] = v;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
extended.isRoot = false;
|
|
70
|
-
Object.setPrototypeOf(extended, this);
|
|
71
|
-
return extended;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.Context = Context;
|
package/cjs/core/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./context.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./types.js"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./utilities.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./validation-error.js"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./validator.js"), exports);
|
package/cjs/core/types.js
DELETED