valgen 5.18.2 → 5.19.1
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/{types/index.d.ts → index.d.ts} +63 -59
- package/{esm/index.js → index.js} +10 -1
- package/package.json +9 -25
- package/{types/rules → rules}/type-rules/is-date.d.ts +6 -6
- package/{esm/rules → rules}/type-rules/is-date.js +21 -10
- package/CHANGELOG.md +0 -384
- 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/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) {
|
|
@@ -1,65 +1,69 @@
|
|
|
1
|
+
import { Context, ExecutionOptions } from './core/index.js';
|
|
2
|
+
import { DatePrecision } from './rules/index.js';
|
|
1
3
|
import * as vg from './rules/index.js';
|
|
2
4
|
export * from './constants.js';
|
|
3
5
|
export * from './core/index.js';
|
|
4
6
|
export type { IsObject } from './rules/type-rules/is-object.js';
|
|
5
|
-
declare const isAlpha: import("./core/validator.js").Validator<string, string,
|
|
6
|
-
declare const isAlphanumeric: import("./core/validator.js").Validator<string, string,
|
|
7
|
-
declare const isAny: import("./core/validator.js").Validator<any, any,
|
|
8
|
-
declare const isArray: import("./core/validator.js").Validator<unknown[], unknown,
|
|
9
|
-
declare const isAscii: import("./core/validator.js").Validator<string, string,
|
|
10
|
-
declare const isBase64: import("./core/validator.js").Validator<string, string,
|
|
11
|
-
declare const isBigint: import("./core/validator.js").Validator<bigint, unknown,
|
|
12
|
-
declare const isBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown,
|
|
13
|
-
declare const isBtcAddress: import("./core/validator.js").Validator<string, string,
|
|
14
|
-
declare const isCreditCard: import("./core/validator.js").Validator<string, string,
|
|
15
|
-
declare const isDate: import("./core/validator.js").Validator<Date, string | number | Date,
|
|
16
|
-
declare const isDateString: import("./core/validator.js").Validator<string, string | number | Date,
|
|
17
|
-
declare const isDecimal: import("./core/validator.js").Validator<string, string,
|
|
18
|
-
declare const isDefined: import("./core/validator.js").Validator<any, unknown,
|
|
19
|
-
declare const isEAN: import("./core/validator.js").Validator<string, string,
|
|
20
|
-
declare const isEmail: import("./core/validator.js").Validator<string, string,
|
|
21
|
-
declare const isEmpty: import("./core/validator.js").Validator<any, any,
|
|
22
|
-
declare const isETHAddress: import("./core/validator.js").Validator<string, string,
|
|
23
|
-
declare const isFQDN: import("./core/validator.js").Validator<string, string,
|
|
24
|
-
declare const isHex: import("./core/validator.js").Validator<string, string,
|
|
25
|
-
declare const isHexColor: import("./core/validator.js").Validator<string, string,
|
|
26
|
-
declare const isIBAN: import("./core/validator.js").Validator<string, string,
|
|
27
|
-
declare const isInteger: import("./core/validator.js").Validator<number, unknown,
|
|
28
|
-
declare const isIP: import("./core/validator.js").Validator<string, string,
|
|
29
|
-
declare const isIPRange: import("./core/validator.js").Validator<string, string,
|
|
30
|
-
declare const isISSN: import("./core/validator.js").Validator<string, string,
|
|
31
|
-
declare const isJWT: import("./core/validator.js").Validator<string, string,
|
|
32
|
-
declare const isLowercase: import("./core/validator.js").Validator<string, string,
|
|
33
|
-
declare const isMACAddress: import("./core/validator.js").Validator<string, string,
|
|
34
|
-
declare const isMobilePhone: import("./core/validator.js").Validator<string, string,
|
|
35
|
-
declare const isNotEmpty: import("./core/validator.js").Validator<any, any,
|
|
36
|
-
declare const isNotNull: import("./core/validator.js").Validator<unknown, unknown,
|
|
37
|
-
declare const isNotNullish: import("./core/validator.js").Validator<unknown, unknown,
|
|
38
|
-
declare const isNull: import("./core/validator.js").Validator<null, unknown,
|
|
39
|
-
declare const isNullish: import("./core/validator.js").Validator<null, unknown,
|
|
40
|
-
declare const isNumber: import("./core/validator.js").Validator<number, unknown,
|
|
7
|
+
declare const isAlpha: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
8
|
+
declare const isAlphanumeric: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
9
|
+
declare const isAny: import("./core/validator.js").Validator<any, any, ExecutionOptions>;
|
|
10
|
+
declare const isArray: import("./core/validator.js").Validator<unknown[], unknown, ExecutionOptions>;
|
|
11
|
+
declare const isAscii: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
12
|
+
declare const isBase64: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
13
|
+
declare const isBigint: import("./core/validator.js").Validator<bigint, unknown, ExecutionOptions>;
|
|
14
|
+
declare const isBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, ExecutionOptions>;
|
|
15
|
+
declare const isBtcAddress: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
16
|
+
declare const isCreditCard: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
17
|
+
declare const isDate: import("./core/validator.js").Validator<Date, string | number | Date, ExecutionOptions>;
|
|
18
|
+
declare const isDateString: import("./core/validator.js").Validator<string, string | number | Date, ExecutionOptions>;
|
|
19
|
+
declare const isDecimal: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
20
|
+
declare const isDefined: import("./core/validator.js").Validator<any, unknown, ExecutionOptions>;
|
|
21
|
+
declare const isEAN: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
22
|
+
declare const isEmail: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
23
|
+
declare const isEmpty: import("./core/validator.js").Validator<any, any, ExecutionOptions>;
|
|
24
|
+
declare const isETHAddress: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
25
|
+
declare const isFQDN: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
26
|
+
declare const isHex: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
27
|
+
declare const isHexColor: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
28
|
+
declare const isIBAN: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
29
|
+
declare const isInteger: import("./core/validator.js").Validator<number, unknown, ExecutionOptions>;
|
|
30
|
+
declare const isIP: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
31
|
+
declare const isIPRange: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
32
|
+
declare const isISSN: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
33
|
+
declare const isJWT: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
34
|
+
declare const isLowercase: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
35
|
+
declare const isMACAddress: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
36
|
+
declare const isMobilePhone: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
37
|
+
declare const isNotEmpty: import("./core/validator.js").Validator<any, any, ExecutionOptions>;
|
|
38
|
+
declare const isNotNull: import("./core/validator.js").Validator<unknown, unknown, ExecutionOptions>;
|
|
39
|
+
declare const isNotNullish: import("./core/validator.js").Validator<unknown, unknown, ExecutionOptions>;
|
|
40
|
+
declare const isNull: import("./core/validator.js").Validator<null, unknown, ExecutionOptions>;
|
|
41
|
+
declare const isNullish: import("./core/validator.js").Validator<null, unknown, ExecutionOptions>;
|
|
42
|
+
declare const isNumber: import("./core/validator.js").Validator<number, unknown, ExecutionOptions>;
|
|
41
43
|
declare const isObject: vg.IsObject.Validator<object, string | object>;
|
|
42
|
-
declare const isObjectId: import("./core/validator.js").Validator<string | vg.ObjectIdLike | Uint8Array<ArrayBufferLike>, unknown,
|
|
43
|
-
declare const isPort: import("./core/validator.js").Validator<number, string | number,
|
|
44
|
-
declare const isString: import("./core/validator.js").Validator<string, unknown,
|
|
45
|
-
declare const isSWIFT: import("./core/validator.js").Validator<string, string,
|
|
46
|
-
declare const isTime: import("./core/validator.js").Validator<string, string | Date,
|
|
47
|
-
declare const isUndefined: import("./core/validator.js").Validator<any, unknown,
|
|
48
|
-
declare const isUppercase: import("./core/validator.js").Validator<string, string,
|
|
49
|
-
declare const isURL: import("./core/validator.js").Validator<string, string,
|
|
50
|
-
declare const isUUID: import("./core/validator.js").Validator<string, string,
|
|
51
|
-
declare const isUUID1: import("./core/validator.js").Validator<string, string,
|
|
52
|
-
declare const isUUID2: import("./core/validator.js").Validator<string, string,
|
|
53
|
-
declare const isUUID3: import("./core/validator.js").Validator<string, string,
|
|
54
|
-
declare const isUUID4: import("./core/validator.js").Validator<string, string,
|
|
55
|
-
declare const isUUID5: import("./core/validator.js").Validator<string, string,
|
|
56
|
-
declare const toArray: import("./core/validator.js").Validator<any[], any,
|
|
57
|
-
declare const toBigint: import("./core/validator.js").Validator<bigint, unknown,
|
|
58
|
-
declare const toBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown,
|
|
59
|
-
declare const toDate: import("./core/validator.js").Validator<Date, string | number | Date,
|
|
60
|
-
declare const toDateString:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
declare const
|
|
64
|
-
declare const
|
|
44
|
+
declare const isObjectId: import("./core/validator.js").Validator<string | vg.ObjectIdLike | Uint8Array<ArrayBufferLike>, unknown, ExecutionOptions>;
|
|
45
|
+
declare const isPort: import("./core/validator.js").Validator<number, string | number, ExecutionOptions>;
|
|
46
|
+
declare const isString: import("./core/validator.js").Validator<string, unknown, ExecutionOptions>;
|
|
47
|
+
declare const isSWIFT: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
48
|
+
declare const isTime: import("./core/validator.js").Validator<string, string | Date, ExecutionOptions>;
|
|
49
|
+
declare const isUndefined: import("./core/validator.js").Validator<any, unknown, ExecutionOptions>;
|
|
50
|
+
declare const isUppercase: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
51
|
+
declare const isURL: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
52
|
+
declare const isUUID: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
53
|
+
declare const isUUID1: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
54
|
+
declare const isUUID2: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
55
|
+
declare const isUUID3: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
56
|
+
declare const isUUID4: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
57
|
+
declare const isUUID5: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
|
|
58
|
+
declare const toArray: import("./core/validator.js").Validator<any[], any, ExecutionOptions>;
|
|
59
|
+
declare const toBigint: import("./core/validator.js").Validator<bigint, unknown, ExecutionOptions>;
|
|
60
|
+
declare const toBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, ExecutionOptions>;
|
|
61
|
+
declare const toDate: import("./core/validator.js").Validator<Date, string | number | Date, ExecutionOptions>;
|
|
62
|
+
declare const toDateString: (input: Date | string | number, options?: ExecutionOptions & {
|
|
63
|
+
trim?: DatePrecision;
|
|
64
|
+
}, ctx?: Context) => any;
|
|
65
|
+
declare const toInteger: import("./core/validator.js").Validator<number, unknown, ExecutionOptions>;
|
|
66
|
+
declare const toNumber: import("./core/validator.js").Validator<number, unknown, ExecutionOptions>;
|
|
67
|
+
declare const toString: import("./core/validator.js").Validator<string, unknown, ExecutionOptions>;
|
|
68
|
+
declare const toTime: import("./core/validator.js").Validator<string, string | Date, ExecutionOptions>;
|
|
65
69
|
export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
|
|
@@ -56,7 +56,16 @@ 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
|
|
59
|
+
const toDateStringValidators = new Map();
|
|
60
|
+
const toDateString = (input, options, ctx) => {
|
|
61
|
+
const trim = options?.trim ?? 'seconds';
|
|
62
|
+
let validator = toDateStringValidators.get(trim);
|
|
63
|
+
if (!validator) {
|
|
64
|
+
validator = vg.isDateString({ coerce: true, trim });
|
|
65
|
+
toDateStringValidators.set(trim, validator);
|
|
66
|
+
}
|
|
67
|
+
return validator(input, options, ctx);
|
|
68
|
+
};
|
|
60
69
|
const toInteger = vg.isInteger({ coerce: true });
|
|
61
70
|
const toNumber = vg.isNumber({ coerce: true });
|
|
62
71
|
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.1",
|
|
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",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ValidationOptions } from '../../core/index.js';
|
|
2
|
-
type
|
|
2
|
+
export type DatePrecision = 'year' | 'yr' | 'month' | 'mo' | 'day' | 'd' | 'hours' | 'hr' | 'minutes' | 'min' | 'seconds' | 'sec' | 'milliseconds' | 'ms' | 'tz';
|
|
3
3
|
export interface IsDateOptions extends ValidationOptions {
|
|
4
|
-
trim?:
|
|
4
|
+
trim?: DatePrecision;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Validates if value is a "Date" instance or ISO 8601 formatted date string.
|
|
@@ -10,9 +10,10 @@ export interface IsDateOptions extends ValidationOptions {
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function isDate(options?: IsDateOptions): import("../../core/validator.js").Validator<Date, string | number | Date, import("../../core/types.js").ExecutionOptions>;
|
|
12
12
|
export interface IsDateStringOptions extends ValidationOptions {
|
|
13
|
-
precisionMin?:
|
|
14
|
-
precisionMax?:
|
|
15
|
-
trim?:
|
|
13
|
+
precisionMin?: DatePrecision;
|
|
14
|
+
precisionMax?: DatePrecision;
|
|
15
|
+
trim?: DatePrecision;
|
|
16
|
+
timeZone?: boolean | number;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Validates if value is DFS (date formatted string).
|
|
@@ -20,4 +21,3 @@ export interface IsDateStringOptions extends ValidationOptions {
|
|
|
20
21
|
* @validator isDateString
|
|
21
22
|
*/
|
|
22
23
|
export declare function isDateString(options?: IsDateStringOptions): import("../../core/validator.js").Validator<string, string | number | Date, import("../../core/types.js").ExecutionOptions>;
|
|
23
|
-
export {};
|
|
@@ -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 = {
|