umt 2.19.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/module/Validate/any/core.d.ts +21 -0
- package/module/Validate/any/core.js +19 -0
- package/module/Validate/any/core.js.map +1 -0
- package/module/Validate/any/index.d.ts +1 -0
- package/module/Validate/any/index.js +2 -0
- package/module/Validate/any/index.js.map +1 -0
- package/module/Validate/array/arrayOf.d.ts +12 -4
- package/module/Validate/array/arrayOf.js +2 -2
- package/module/Validate/array/arrayOf.js.map +1 -1
- package/module/Validate/array/index.d.ts +0 -1
- package/module/Validate/array/index.js +0 -1
- package/module/Validate/array/index.js.map +1 -1
- package/module/Validate/bigint/core.d.ts +24 -0
- package/module/Validate/bigint/core.js +37 -0
- package/module/Validate/bigint/core.js.map +1 -0
- package/module/Validate/bigint/index.d.ts +1 -0
- package/module/Validate/bigint/index.js +2 -0
- package/module/Validate/bigint/index.js.map +1 -0
- package/module/Validate/date/core.d.ts +14 -0
- package/module/Validate/date/core.js +29 -0
- package/module/Validate/date/core.js.map +1 -0
- package/module/Validate/date/index.d.ts +1 -0
- package/module/Validate/date/index.js +2 -0
- package/module/Validate/date/index.js.map +1 -0
- package/module/Validate/file/core.d.ts +13 -0
- package/module/Validate/file/core.js +32 -0
- package/module/Validate/file/core.js.map +1 -0
- package/module/Validate/file/index.d.ts +1 -0
- package/module/Validate/file/index.js +2 -0
- package/module/Validate/file/index.js.map +1 -0
- package/module/Validate/function/core.d.ts +75 -0
- package/module/Validate/function/core.js +66 -0
- package/module/Validate/function/core.js.map +1 -0
- package/module/Validate/function/index.d.ts +1 -0
- package/module/Validate/function/index.js +2 -0
- package/module/Validate/function/index.js.map +1 -0
- package/module/Validate/index.d.ts +11 -0
- package/module/Validate/index.js +11 -0
- package/module/Validate/index.js.map +1 -1
- package/module/Validate/instanceof/core.d.ts +19 -0
- package/module/Validate/instanceof/core.js +32 -0
- package/module/Validate/instanceof/core.js.map +1 -0
- package/module/Validate/instanceof/index.d.ts +1 -0
- package/module/Validate/instanceof/index.js +2 -0
- package/module/Validate/instanceof/index.js.map +1 -0
- package/module/Validate/map/core.d.ts +24 -0
- package/module/Validate/map/core.js +57 -0
- package/module/Validate/map/core.js.map +1 -0
- package/module/Validate/map/index.d.ts +1 -0
- package/module/Validate/map/index.js +2 -0
- package/module/Validate/map/index.js.map +1 -0
- package/module/Validate/never/core.d.ts +22 -0
- package/module/Validate/never/core.js +23 -0
- package/module/Validate/never/core.js.map +1 -0
- package/module/Validate/never/index.d.ts +1 -0
- package/module/Validate/never/index.js +2 -0
- package/module/Validate/never/index.js.map +1 -0
- package/module/Validate/object/core.d.ts +22 -4
- package/module/Validate/object/core.js +5 -3
- package/module/Validate/object/core.js.map +1 -1
- package/module/Validate/object/index.d.ts +4 -0
- package/module/Validate/object/index.js +4 -0
- package/module/Validate/object/index.js.map +1 -1
- package/module/Validate/object/intersection.d.ts +5 -2
- package/module/Validate/object/intersection.js.map +1 -1
- package/module/Validate/object/nullable.d.ts +12 -2
- package/module/Validate/object/nullable.js +2 -2
- package/module/Validate/object/nullable.js.map +1 -1
- package/module/Validate/object/omit.d.ts +22 -0
- package/module/Validate/object/omit.js +33 -0
- package/module/Validate/object/omit.js.map +1 -0
- package/module/Validate/object/optional.d.ts +31 -3
- package/module/Validate/object/optional.js +7 -5
- package/module/Validate/object/optional.js.map +1 -1
- package/module/Validate/object/partial.d.ts +25 -0
- package/module/Validate/object/partial.js +29 -0
- package/module/Validate/object/partial.js.map +1 -0
- package/module/Validate/object/pick.d.ts +21 -0
- package/module/Validate/object/pick.js +29 -0
- package/module/Validate/object/pick.js.map +1 -0
- package/module/Validate/object/required.d.ts +22 -0
- package/module/Validate/object/required.js +30 -0
- package/module/Validate/object/required.js.map +1 -0
- package/module/Validate/set/core.d.ts +24 -0
- package/module/Validate/set/core.js +47 -0
- package/module/Validate/set/core.js.map +1 -0
- package/module/Validate/set/index.d.ts +1 -0
- package/module/Validate/set/index.js +2 -0
- package/module/Validate/set/index.js.map +1 -0
- package/module/Validate/string/oneOf.d.ts +10 -7
- package/module/Validate/string/oneOf.js +5 -3
- package/module/Validate/string/oneOf.js.map +1 -1
- package/module/Validate/templateLiteral/core.d.ts +55 -0
- package/module/Validate/templateLiteral/core.js +68 -0
- package/module/Validate/templateLiteral/core.js.map +1 -0
- package/module/Validate/templateLiteral/index.d.ts +1 -0
- package/module/Validate/templateLiteral/index.js +2 -0
- package/module/Validate/templateLiteral/index.js.map +1 -0
- package/module/Validate/type.d.ts +19 -5
- package/module/Validate/unknown/core.d.ts +21 -0
- package/module/Validate/unknown/core.js +16 -0
- package/module/Validate/unknown/core.js.map +1 -0
- package/module/Validate/unknown/index.d.ts +1 -0
- package/module/Validate/unknown/index.js +2 -0
- package/module/Validate/unknown/index.js.map +1 -0
- package/module/es5/Validate/any/core.d.ts +21 -0
- package/module/es5/Validate/any/core.js +36 -0
- package/module/es5/Validate/any/index.d.ts +1 -0
- package/module/es5/Validate/any/index.js +16 -0
- package/module/es5/Validate/array/arrayOf.d.ts +12 -4
- package/module/es5/Validate/array/arrayOf.js +10 -4
- package/module/es5/Validate/array/index.d.ts +0 -1
- package/module/es5/Validate/array/index.js +0 -11
- package/module/es5/Validate/bigint/core.d.ts +24 -0
- package/module/es5/Validate/bigint/core.js +65 -0
- package/module/es5/Validate/bigint/index.d.ts +1 -0
- package/module/es5/Validate/bigint/index.js +16 -0
- package/module/es5/Validate/date/core.d.ts +14 -0
- package/module/es5/Validate/date/core.js +35 -0
- package/module/es5/Validate/date/index.d.ts +1 -0
- package/module/es5/Validate/date/index.js +16 -0
- package/module/es5/Validate/file/core.d.ts +13 -0
- package/module/es5/Validate/file/core.js +39 -0
- package/module/es5/Validate/file/index.d.ts +1 -0
- package/module/es5/Validate/file/index.js +16 -0
- package/module/es5/Validate/function/core.d.ts +75 -0
- package/module/es5/Validate/function/core.js +125 -0
- package/module/es5/Validate/function/index.d.ts +1 -0
- package/module/es5/Validate/function/index.js +16 -0
- package/module/es5/Validate/index.d.ts +11 -0
- package/module/es5/Validate/index.js +121 -0
- package/module/es5/Validate/instanceof/core.d.ts +19 -0
- package/module/es5/Validate/instanceof/core.js +40 -0
- package/module/es5/Validate/instanceof/index.d.ts +1 -0
- package/module/es5/Validate/instanceof/index.js +16 -0
- package/module/es5/Validate/map/core.d.ts +24 -0
- package/module/es5/Validate/map/core.js +81 -0
- package/module/es5/Validate/map/index.d.ts +1 -0
- package/module/es5/Validate/map/index.js +16 -0
- package/module/es5/Validate/never/core.d.ts +22 -0
- package/module/es5/Validate/never/core.js +35 -0
- package/module/es5/Validate/never/index.d.ts +1 -0
- package/module/es5/Validate/never/index.js +16 -0
- package/module/es5/Validate/object/core.d.ts +22 -4
- package/module/es5/Validate/object/core.js +14 -2
- package/module/es5/Validate/object/index.d.ts +4 -0
- package/module/es5/Validate/object/index.js +44 -0
- package/module/es5/Validate/object/intersection.d.ts +5 -2
- package/module/es5/Validate/object/intersection.js +6 -0
- package/module/es5/Validate/object/nullable.d.ts +12 -2
- package/module/es5/Validate/object/nullable.js +2 -2
- package/module/es5/Validate/object/omit.d.ts +22 -0
- package/module/es5/Validate/object/omit.js +39 -0
- package/module/es5/Validate/object/optional.d.ts +31 -3
- package/module/es5/Validate/object/optional.js +12 -3
- package/module/es5/Validate/object/partial.d.ts +25 -0
- package/module/es5/Validate/object/partial.js +33 -0
- package/module/es5/Validate/object/pick.d.ts +21 -0
- package/module/es5/Validate/object/pick.js +45 -0
- package/module/es5/Validate/object/required.d.ts +22 -0
- package/module/es5/Validate/object/required.js +33 -0
- package/module/es5/Validate/set/core.d.ts +24 -0
- package/module/es5/Validate/{array → set}/core.js +30 -27
- package/module/es5/Validate/set/index.d.ts +1 -0
- package/module/es5/Validate/set/index.js +16 -0
- package/module/es5/Validate/string/oneOf.d.ts +10 -7
- package/module/es5/Validate/string/oneOf.js +8 -6
- package/module/es5/Validate/templateLiteral/core.d.ts +55 -0
- package/module/es5/Validate/templateLiteral/core.js +114 -0
- package/module/es5/Validate/templateLiteral/index.d.ts +1 -0
- package/module/es5/Validate/templateLiteral/index.js +16 -0
- package/module/es5/Validate/type.d.ts +19 -5
- package/module/es5/Validate/unknown/core.d.ts +21 -0
- package/module/es5/Validate/unknown/core.js +34 -0
- package/module/es5/Validate/unknown/index.d.ts +1 -0
- package/module/es5/Validate/unknown/index.js +16 -0
- package/package.json +1 -1
- package/module/Validate/array/core.d.ts +0 -14
- package/module/Validate/array/core.js +0 -43
- package/module/Validate/array/core.js.map +0 -1
- package/module/es5/Validate/array/core.d.ts +0 -14
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set validation core module
|
|
3
|
+
* Provides validation for `Set` instances. The validator can optionally
|
|
4
|
+
* delegate to a per-element validator, mirroring how `arrayOf()` validates
|
|
5
|
+
* each element of an array.
|
|
6
|
+
*
|
|
7
|
+
* The function is exported as `set_` because the top-level `Object` module
|
|
8
|
+
* already exposes a `set` runtime helper.
|
|
9
|
+
*/
|
|
10
|
+
import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
11
|
+
type ExtractValidatedType<V> = V extends (value: never) => {
|
|
12
|
+
type: infer T;
|
|
13
|
+
} ? ValidateType<T> : never;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Set validator. When a per-element validator is supplied, every
|
|
16
|
+
* element of the set must satisfy it; iteration short-circuits at the first
|
|
17
|
+
* failure and surfaces the failing message.
|
|
18
|
+
* @template IV - Validator for set elements
|
|
19
|
+
* @param {IV} [itemValidator] - Validator applied to every element
|
|
20
|
+
* @param {string} [message] - Custom error message for type validation
|
|
21
|
+
* @returns {Function} - Validator function for Set instances
|
|
22
|
+
*/
|
|
23
|
+
export declare const set_: <IV extends (value: any) => ValidateCoreReturnType<unknown> = (value: unknown) => ValidateCoreReturnType<unknown>, T = ExtractValidatedType<IV>>(itemValidator?: IV, message?: string) => (value: Set<T>) => ValidateCoreReturnType<Set<T>>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set validation core module
|
|
3
|
+
* Provides validation for `Set` instances. The validator can optionally
|
|
4
|
+
* delegate to a per-element validator, mirroring how `arrayOf()` validates
|
|
5
|
+
* each element of an array.
|
|
6
|
+
*
|
|
7
|
+
* The function is exported as `set_` because the top-level `Object` module
|
|
8
|
+
* already exposes a `set` runtime helper.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Creates a Set validator. When a per-element validator is supplied, every
|
|
12
|
+
* element of the set must satisfy it; iteration short-circuits at the first
|
|
13
|
+
* failure and surfaces the failing message.
|
|
14
|
+
* @template IV - Validator for set elements
|
|
15
|
+
* @param {IV} [itemValidator] - Validator applied to every element
|
|
16
|
+
* @param {string} [message] - Custom error message for type validation
|
|
17
|
+
* @returns {Function} - Validator function for Set instances
|
|
18
|
+
*/
|
|
19
|
+
export const set_ = (itemValidator, message) => {
|
|
20
|
+
return (value) => {
|
|
21
|
+
if (!(value instanceof Set)) {
|
|
22
|
+
return {
|
|
23
|
+
validate: false,
|
|
24
|
+
message: message ?? "",
|
|
25
|
+
type: value,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (itemValidator) {
|
|
29
|
+
for (const item of value) {
|
|
30
|
+
const result = itemValidator(item);
|
|
31
|
+
if (!result.validate) {
|
|
32
|
+
return {
|
|
33
|
+
validate: false,
|
|
34
|
+
message: result.message,
|
|
35
|
+
type: value,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
validate: true,
|
|
42
|
+
message: "",
|
|
43
|
+
type: value,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/Validate/set/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAOlB,aAAkB,EAClB,OAAgB,EAChB,EAAE;IACF,OAAO,CAAC,KAAa,EAAkC,EAAE;QACvD,IAAI,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,OAAO,IAAI,EAAE;gBACtB,IAAI,EAAE,KAAK;aACZ,CAAC;QACJ,CAAC;QACD,IAAI,aAAa,EAAE,CAAC;YAClB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,MAAM,GACV,aAID,CAAC,IAAI,CAAC,CAAC;gBACR,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;oBACrB,OAAO;wBACL,QAAQ,EAAE,KAAK;wBACf,OAAO,EAAE,MAAM,CAAC,OAAO;wBACvB,IAAI,EAAE,KAAK;qBACZ,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,KAAK;SACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/set/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -5,20 +5,23 @@
|
|
|
5
5
|
* such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
|
|
6
6
|
*
|
|
7
7
|
* The validator's return type carries the literal union through its `type`
|
|
8
|
-
* field
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* field as a `LiteralBrand<T>` so that consumers like `object()`, `union()`,
|
|
9
|
+
* and `intersection()` can preserve the literal union in their inferred types.
|
|
10
|
+
* The brand also prevents collisions with reserved type tags such as
|
|
11
|
+
* `"string"`, `"number"`, or `"boolean"` when an allowed value happens to
|
|
12
|
+
* match one of those tag strings.
|
|
11
13
|
*/
|
|
14
|
+
import type { LiteralBrand } from "../../Validate/type";
|
|
12
15
|
/**
|
|
13
16
|
* Return type produced by a `oneOf` validator. Structurally compatible with
|
|
14
|
-
* `ValidateCoreReturnType<unknown>`, but exposes the literal union
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
+
* `ValidateCoreReturnType<unknown>`, but exposes the literal union via a
|
|
18
|
+
* `LiteralBrand` so the inferred type can flow through `object()`, `union()`,
|
|
19
|
+
* and `intersection()` without being collapsed by `ValidateType`.
|
|
17
20
|
*/
|
|
18
21
|
export interface OneOfReturnType<T extends string> {
|
|
19
22
|
validate: boolean;
|
|
20
23
|
message: string;
|
|
21
|
-
type: T
|
|
24
|
+
type: LiteralBrand<T>;
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
24
27
|
* Creates a top-level validator that checks if a string value is one of the
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
|
|
6
6
|
*
|
|
7
7
|
* The validator's return type carries the literal union through its `type`
|
|
8
|
-
* field
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* field as a `LiteralBrand<T>` so that consumers like `object()`, `union()`,
|
|
9
|
+
* and `intersection()` can preserve the literal union in their inferred types.
|
|
10
|
+
* The brand also prevents collisions with reserved type tags such as
|
|
11
|
+
* `"string"`, `"number"`, or `"boolean"` when an allowed value happens to
|
|
12
|
+
* match one of those tag strings.
|
|
11
13
|
*/
|
|
12
14
|
/**
|
|
13
15
|
* Creates a top-level validator that checks if a string value is one of the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oneOf.js","sourceRoot":"","sources":["../../../src/Validate/string/oneOf.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"oneOf.js","sourceRoot":"","sources":["../../../src/Validate/string/oneOf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAgBH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,MAAS,EACT,OAAgB,EAChB,EAAE;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,CAAC;IACxC,OAAO,CAAC,KAAa,EAA8B,EAAE;QACnD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO;YACL,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC;YACvC,IAAI,EAAE,KAAgC;SACvC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template literal validation core module
|
|
3
|
+
* Provides a validator that checks whether a string matches a template
|
|
4
|
+
* literal pattern composed of string fragments and primitive validators
|
|
5
|
+
* (string / number / boolean / bigint). The runtime check is performed by
|
|
6
|
+
* an auto-generated regular expression assembled from the parts, while the
|
|
7
|
+
* inferred type is the corresponding TypeScript template literal type.
|
|
8
|
+
*/
|
|
9
|
+
import type { ValidateType } from "../../Validate/type";
|
|
10
|
+
type AnyValidator = (value?: any) => {
|
|
11
|
+
type: unknown;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Allowed parts of a template literal definition. Each element is either a
|
|
15
|
+
* string literal that must appear verbatim, or a primitive validator whose
|
|
16
|
+
* accepted shape is converted to a regex fragment at construction time.
|
|
17
|
+
*/
|
|
18
|
+
export type TemplateLiteralPart = string | AnyValidator;
|
|
19
|
+
type ExtractValidatorTag<V> = V extends (value: never) => {
|
|
20
|
+
type: infer T;
|
|
21
|
+
} ? T : never;
|
|
22
|
+
type TagToTemplate<T> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T extends "bigint" ? bigint : ValidateType<T>;
|
|
23
|
+
type PartToTemplate<P> = P extends string ? P : TagToTemplate<ExtractValidatorTag<P>>;
|
|
24
|
+
/**
|
|
25
|
+
* Builds the template literal type produced by joining `Parts`. Each part is
|
|
26
|
+
* mapped to either its literal string value or to the runtime type that the
|
|
27
|
+
* corresponding validator accepts.
|
|
28
|
+
*/
|
|
29
|
+
export type BuildTemplateLiteral<Parts extends readonly TemplateLiteralPart[]> = Parts extends readonly [
|
|
30
|
+
infer Head,
|
|
31
|
+
...infer Tail extends readonly TemplateLiteralPart[]
|
|
32
|
+
] ? `${Extract<PartToTemplate<Head>, string | number | bigint | boolean>}${BuildTemplateLiteral<Tail>}` : "";
|
|
33
|
+
/**
|
|
34
|
+
* Return type produced by a `templateLiteral` validator. Preserves the
|
|
35
|
+
* literal template string type through the `type` field so consumers like
|
|
36
|
+
* `union()`, `intersection()`, and `SchemaToInterface` can recover it.
|
|
37
|
+
* @template T - The inferred template literal type
|
|
38
|
+
*/
|
|
39
|
+
export interface TemplateLiteralReturnType<T extends string> {
|
|
40
|
+
validate: boolean;
|
|
41
|
+
message: string;
|
|
42
|
+
type: T;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates a validator that checks whether a value matches a template literal
|
|
46
|
+
* pattern. Each part is either a string literal that must appear verbatim or
|
|
47
|
+
* a primitive validator (string / number / boolean / bigint) that contributes
|
|
48
|
+
* a regex fragment.
|
|
49
|
+
* @template Parts - Tuple describing the template parts
|
|
50
|
+
* @param {Parts} parts - Tuple of literal strings and primitive validators
|
|
51
|
+
* @param {string} [message] - Custom error message for validation failure
|
|
52
|
+
* @returns {Function} - Validator function for template literal strings
|
|
53
|
+
*/
|
|
54
|
+
export declare const templateLiteral: <const Parts extends readonly TemplateLiteralPart[]>(parts: Parts, message?: string) => (value: BuildTemplateLiteral<Parts>) => TemplateLiteralReturnType<BuildTemplateLiteral<Parts>>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template literal validation core module
|
|
3
|
+
* Provides a validator that checks whether a string matches a template
|
|
4
|
+
* literal pattern composed of string fragments and primitive validators
|
|
5
|
+
* (string / number / boolean / bigint). The runtime check is performed by
|
|
6
|
+
* an auto-generated regular expression assembled from the parts, while the
|
|
7
|
+
* inferred type is the corresponding TypeScript template literal type.
|
|
8
|
+
*/
|
|
9
|
+
const escapeRegex = (input) => input.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw `\$&`);
|
|
10
|
+
const tagToPattern = (tag) => {
|
|
11
|
+
switch (tag) {
|
|
12
|
+
case "string": {
|
|
13
|
+
return ".*?";
|
|
14
|
+
}
|
|
15
|
+
case "number": {
|
|
16
|
+
return String.raw `-?(?:\d+\.\d+|\d+(?:\.\d*)?|\.\d+)`;
|
|
17
|
+
}
|
|
18
|
+
case "boolean": {
|
|
19
|
+
return "(?:true|false)";
|
|
20
|
+
}
|
|
21
|
+
case "bigint": {
|
|
22
|
+
return String.raw `-?\d+`;
|
|
23
|
+
}
|
|
24
|
+
default: {
|
|
25
|
+
return ".+?";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const detectValidatorTag = (validator) => {
|
|
30
|
+
const result = validator();
|
|
31
|
+
return result?.type;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Creates a validator that checks whether a value matches a template literal
|
|
35
|
+
* pattern. Each part is either a string literal that must appear verbatim or
|
|
36
|
+
* a primitive validator (string / number / boolean / bigint) that contributes
|
|
37
|
+
* a regex fragment.
|
|
38
|
+
* @template Parts - Tuple describing the template parts
|
|
39
|
+
* @param {Parts} parts - Tuple of literal strings and primitive validators
|
|
40
|
+
* @param {string} [message] - Custom error message for validation failure
|
|
41
|
+
* @returns {Function} - Validator function for template literal strings
|
|
42
|
+
*/
|
|
43
|
+
export const templateLiteral = (parts, message) => {
|
|
44
|
+
let pattern = "^";
|
|
45
|
+
for (const part of parts) {
|
|
46
|
+
pattern +=
|
|
47
|
+
typeof part === "string"
|
|
48
|
+
? escapeRegex(part)
|
|
49
|
+
: `(?:${tagToPattern(detectValidatorTag(part))})`;
|
|
50
|
+
}
|
|
51
|
+
pattern += "$";
|
|
52
|
+
const regex = new RegExp(pattern);
|
|
53
|
+
return (value) => {
|
|
54
|
+
if (typeof value !== "string" || !regex.test(value)) {
|
|
55
|
+
return {
|
|
56
|
+
validate: false,
|
|
57
|
+
message: message ?? "",
|
|
58
|
+
type: value,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
validate: true,
|
|
63
|
+
message: "",
|
|
64
|
+
type: value,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/Validate/templateLiteral/core.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAyDH,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE,CAC5C,KAAK,CAAC,UAAU,CAAC,qBAAqB,EAAE,MAAM,CAAC,GAAG,CAAA,KAAK,CAAC,CAAC;AAE3D,MAAM,YAAY,GAAG,CAAC,GAAY,EAAU,EAAE;IAC5C,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,KAAK,CAAC;QACf,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,MAAM,CAAC,GAAG,CAAA,oCAAoC,CAAC;QACxD,CAAC;QACD,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,MAAM,CAAC,GAAG,CAAA,OAAO,CAAC;QAC3B,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,SAAuB,EAAW,EAAE;IAC9D,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,OAAO,MAAM,EAAE,IAAI,CAAC;AACtB,CAAC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAG7B,KAAY,EACZ,OAAgB,EAChB,EAAE;IACF,IAAI,OAAO,GAAG,GAAG,CAAC;IAClB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO;YACL,OAAO,IAAI,KAAK,QAAQ;gBACtB,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;gBACnB,CAAC,CAAC,MAAM,YAAY,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;IACxD,CAAC;IACD,OAAO,IAAI,GAAG,CAAC;IACf,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IAElC,OAAO,CACL,KAAkC,EACsB,EAAE;QAC1D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACpD,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,OAAO,IAAI,EAAE;gBACtB,IAAI,EAAE,KAAK;aACZ,CAAC;QACJ,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,KAAK;SACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/templateLiteral/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export type _Types<T> = T extends string ? "string" : T extends number ? "number" : T extends boolean ? "boolean" : T;
|
|
2
2
|
export type _Types2<T> = T extends undefined ? "undefined" : T extends null ? "null" : T;
|
|
3
|
+
export type _Types3<T> = T extends bigint ? "bigint" : T;
|
|
3
4
|
/**
|
|
4
5
|
* Maps TypeScript types to their string literal representations
|
|
5
6
|
* @template T - The type to map
|
|
6
|
-
* @returns "string" for string, "number" for number, "boolean" for boolean, or the original type T otherwise
|
|
7
|
+
* @returns "string" for string, "number" for number, "boolean" for boolean, "bigint" for bigint, or the original type T otherwise
|
|
7
8
|
*/
|
|
8
|
-
export type Types<T> = T extends string | number | boolean ? _Types<T> : T extends undefined | null ? _Types2<T> : T;
|
|
9
|
+
export type Types<T> = T extends string | number | boolean ? _Types<T> : T extends undefined | null ? _Types2<T> : T extends bigint ? _Types3<T> : T;
|
|
9
10
|
/**
|
|
10
11
|
* Core validation result type including validation status, message, and type information
|
|
11
12
|
* @template T - The type being validated
|
|
@@ -29,15 +30,28 @@ export interface ValidateReturnType<T> {
|
|
|
29
30
|
* @template T - The type of value to validate
|
|
30
31
|
*/
|
|
31
32
|
export type ValidateFunctionType<T> = (value: T) => boolean;
|
|
33
|
+
declare const LITERAL_BRAND: unique symbol;
|
|
34
|
+
/**
|
|
35
|
+
* Branded literal type used by validators (such as `oneOf`) that need to keep
|
|
36
|
+
* a string literal verbatim through `ValidateType`. The brand prevents the
|
|
37
|
+
* literal from colliding with reserved type tags like `"string"`, `"number"`,
|
|
38
|
+
* or `"boolean"` when the same string also happens to name a primitive type.
|
|
39
|
+
* @template T - The literal value preserved by the brand
|
|
40
|
+
*/
|
|
41
|
+
export type LiteralBrand<T extends string> = T & {
|
|
42
|
+
readonly [LITERAL_BRAND]: T;
|
|
43
|
+
};
|
|
32
44
|
export type _ValidateType<T> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T;
|
|
33
45
|
export type _ValidateType2<T> = T extends "undefined" ? undefined : T extends "null" ? null : T;
|
|
46
|
+
export type _ValidateType3<T> = T extends "bigint" ? bigint : T extends "any" ? any : T extends "unknown" ? unknown : T extends "never" ? never : T;
|
|
34
47
|
/**
|
|
35
48
|
* Maps string literal type names back to their TypeScript types
|
|
36
|
-
* @template T - The string literal type name ("string", "number", "boolean")
|
|
37
|
-
* @returns The corresponding TypeScript type
|
|
49
|
+
* @template T - The string literal type name ("string", "number", "boolean", "bigint", "undefined", "null", "any", "unknown", "never")
|
|
50
|
+
* @returns The corresponding TypeScript type, the unwrapped literal when `T` is a `LiteralBrand`, or the original type `T` when no tag matches
|
|
38
51
|
*/
|
|
39
|
-
export type ValidateType<T> = T extends "string" | "number" | "boolean" ? _ValidateType<T> : T extends "undefined" | "null" ? _ValidateType2<T> : T;
|
|
52
|
+
export type ValidateType<T> = T extends LiteralBrand<infer L> ? L : T extends "string" | "number" | "boolean" ? _ValidateType<T> : T extends "undefined" | "null" ? _ValidateType2<T> : T extends "bigint" | "any" | "unknown" | "never" ? _ValidateType3<T> : T;
|
|
40
53
|
export type SchemaToInterface<T extends (value: any) => ValidateCoreReturnType<any>> = ValidateType<ReturnType<T>["type"]>;
|
|
41
54
|
export type OptionalKeys<T> = {
|
|
42
55
|
[K in keyof T]: undefined extends T[K] ? K : never;
|
|
43
56
|
}[keyof T];
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unknown validation core module
|
|
3
|
+
* Provides a validator that accepts any value but exposes it as `unknown`
|
|
4
|
+
* to keep callers honest about narrowing before use.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Return type produced by an `unknown` validator. Exposes the literal
|
|
8
|
+
* `"unknown"` tag through the `type` field so `ValidateType<"unknown">` can
|
|
9
|
+
* map it back to the `unknown` runtime type when consumed by downstream
|
|
10
|
+
* helpers.
|
|
11
|
+
*/
|
|
12
|
+
export interface UnknownReturnType {
|
|
13
|
+
validate: boolean;
|
|
14
|
+
message: string;
|
|
15
|
+
type: "unknown";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a validator that accepts any value but typed as unknown
|
|
19
|
+
* @returns {Function} - Validator that always succeeds
|
|
20
|
+
*/
|
|
21
|
+
export declare const unknown: () => ((value: unknown) => UnknownReturnType);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unknown validation core module
|
|
3
|
+
* Provides a validator that accepts any value but exposes it as `unknown`
|
|
4
|
+
* to keep callers honest about narrowing before use.
|
|
5
|
+
*/
|
|
6
|
+
const unknownValidator = (_value) => ({
|
|
7
|
+
validate: true,
|
|
8
|
+
message: "",
|
|
9
|
+
type: "unknown",
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Creates a validator that accepts any value but typed as unknown
|
|
13
|
+
* @returns {Function} - Validator that always succeeds
|
|
14
|
+
*/
|
|
15
|
+
export const unknown = () => unknownValidator;
|
|
16
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/Validate/unknown/core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH,MAAM,gBAAgB,GAAG,CAAC,MAAe,EAAqB,EAAE,CAAC,CAAC;IAChE,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,SAAS;CAChB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,GAA4C,EAAE,CACnE,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/unknown/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Any validation core module
|
|
3
|
+
* Provides a validator that accepts any value, useful when a position in a
|
|
4
|
+
* schema needs to remain wide open while still participating in `object()`,
|
|
5
|
+
* `union()`, `intersection()`, and other compositional helpers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Return type produced by an `any` validator. Exposes the literal `"any"`
|
|
9
|
+
* tag through the `type` field so `ValidateType<"any">` can map it back to
|
|
10
|
+
* the `any` runtime type when consumed by downstream helpers.
|
|
11
|
+
*/
|
|
12
|
+
export interface AnyReturnType {
|
|
13
|
+
validate: boolean;
|
|
14
|
+
message: string;
|
|
15
|
+
type: "any";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a validator that accepts any value
|
|
19
|
+
* @returns {Function} - Validator that always succeeds
|
|
20
|
+
*/
|
|
21
|
+
export declare const any: () => ((value: any) => AnyReturnType);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.any = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Any validation core module
|
|
9
|
+
* Provides a validator that accepts any value, useful when a position in a
|
|
10
|
+
* schema needs to remain wide open while still participating in `object()`,
|
|
11
|
+
* `union()`, `intersection()`, and other compositional helpers.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Return type produced by an `any` validator. Exposes the literal `"any"`
|
|
16
|
+
* tag through the `type` field so `ValidateType<"any">` can map it back to
|
|
17
|
+
* the `any` runtime type when consumed by downstream helpers.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// biome-ignore lint/suspicious/noExplicitAny: signature mirrors the return type
|
|
21
|
+
var anyValidator = function anyValidator(_value) {
|
|
22
|
+
return {
|
|
23
|
+
validate: true,
|
|
24
|
+
message: "",
|
|
25
|
+
type: "any"
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a validator that accepts any value
|
|
31
|
+
* @returns {Function} - Validator that always succeeds
|
|
32
|
+
*/
|
|
33
|
+
// biome-ignore lint/suspicious/noExplicitAny: any() must accept and infer any value
|
|
34
|
+
var any = exports.any = function any() {
|
|
35
|
+
return anyValidator;
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _core = require("./core");
|
|
7
|
+
Object.keys(_core).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _core[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _core[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import type { ValidateCoreReturnType } from "../../Validate/type";
|
|
1
|
+
import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
2
|
+
type ExtractValidatedType<V> = V extends (value: never) => {
|
|
3
|
+
type: infer T;
|
|
4
|
+
} ? ValidateType<T> : never;
|
|
2
5
|
/**
|
|
3
6
|
* Creates an array validator that validates every element with a single validator
|
|
4
|
-
* @template
|
|
5
|
-
* @param {
|
|
7
|
+
* @template V - The validator function applied to each element (its return `type` field carries the element type)
|
|
8
|
+
* @param {V} validator - Validator applied to each element (e.g. an object validator)
|
|
6
9
|
* @param {string} [message] - Custom error message for array type validation
|
|
7
10
|
* @returns {Function} - Validator function for arrays whose elements satisfy the given validator
|
|
8
11
|
*/
|
|
9
|
-
export declare const arrayOf: <
|
|
12
|
+
export declare const arrayOf: <V extends (value: never) => {
|
|
13
|
+
type: unknown;
|
|
14
|
+
message: string;
|
|
15
|
+
validate: boolean;
|
|
16
|
+
}>(validator: V, message?: string) => (values: ExtractValidatedType<V>[]) => ValidateCoreReturnType<ExtractValidatedType<V>[]>;
|
|
17
|
+
export {};
|
|
@@ -8,10 +8,16 @@ var _isArray = require("../../Validate/isArray");
|
|
|
8
8
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
9
9
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
10
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
11
|
+
// Extract the validated value type by reading the validator's `type` field
|
|
12
|
+
// (and applying `ValidateType` to map type tags like "string" back to the
|
|
13
|
+
// runtime type). Reading the field directly lets validators that expose the
|
|
14
|
+
// literal union via the `type` field (such as `oneOf`) flow through arrayOf
|
|
15
|
+
// without being collapsed to `string`.
|
|
16
|
+
|
|
11
17
|
/**
|
|
12
18
|
* Creates an array validator that validates every element with a single validator
|
|
13
|
-
* @template
|
|
14
|
-
* @param {
|
|
19
|
+
* @template V - The validator function applied to each element (its return `type` field carries the element type)
|
|
20
|
+
* @param {V} validator - Validator applied to each element (e.g. an object validator)
|
|
15
21
|
* @param {string} [message] - Custom error message for array type validation
|
|
16
22
|
* @returns {Function} - Validator function for arrays whose elements satisfy the given validator
|
|
17
23
|
*/
|
|
@@ -28,8 +34,8 @@ var arrayOf = exports.arrayOf = function arrayOf(validator, message) {
|
|
|
28
34
|
_step;
|
|
29
35
|
try {
|
|
30
36
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
31
|
-
var
|
|
32
|
-
var result = validator(
|
|
37
|
+
var _value = _step.value;
|
|
38
|
+
var result = validator(_value);
|
|
33
39
|
if (!result.validate) {
|
|
34
40
|
return {
|
|
35
41
|
validate: false,
|
|
@@ -13,15 +13,4 @@ Object.keys(_arrayOf).forEach(function (key) {
|
|
|
13
13
|
return _arrayOf[key];
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
});
|
|
17
|
-
var _core = require("./core");
|
|
18
|
-
Object.keys(_core).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _core[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return _core[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
16
|
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigInt validation core module
|
|
3
|
+
* Provides the base validation functionality for bigint values
|
|
4
|
+
*/
|
|
5
|
+
import type { ValidateReturnType } from "../../Validate/type";
|
|
6
|
+
/**
|
|
7
|
+
* Return type produced by a `bigint` validator. Structurally compatible with
|
|
8
|
+
* `ValidateCoreReturnType<bigint>`, but exposes the literal `"bigint"` tag
|
|
9
|
+
* through the `type` field so `ValidateType<"bigint">` can map it back to the
|
|
10
|
+
* `bigint` runtime type when consumed by `object()`, `union()`, and friends.
|
|
11
|
+
*/
|
|
12
|
+
export interface BigIntReturnType {
|
|
13
|
+
validate: boolean;
|
|
14
|
+
message: string;
|
|
15
|
+
type: "bigint";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a bigint validator with optional validation rules
|
|
19
|
+
* @template T - Array of validation rules for bigints
|
|
20
|
+
* @param {T} [option] - Array of validation functions to apply
|
|
21
|
+
* @param {string} [message] - Custom error message for type validation
|
|
22
|
+
* @returns {Function} - Validator function that checks if the value is a bigint and applies validation rules
|
|
23
|
+
*/
|
|
24
|
+
export declare const bigint: <T extends ValidateReturnType<bigint>[]>(option?: T, message?: string) => (value: bigint) => BigIntReturnType;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bigint = void 0;
|
|
7
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
8
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
9
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
10
|
+
/**
|
|
11
|
+
* BigInt validation core module
|
|
12
|
+
* Provides the base validation functionality for bigint values
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Return type produced by a `bigint` validator. Structurally compatible with
|
|
17
|
+
* `ValidateCoreReturnType<bigint>`, but exposes the literal `"bigint"` tag
|
|
18
|
+
* through the `type` field so `ValidateType<"bigint">` can map it back to the
|
|
19
|
+
* `bigint` runtime type when consumed by `object()`, `union()`, and friends.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a bigint validator with optional validation rules
|
|
24
|
+
* @template T - Array of validation rules for bigints
|
|
25
|
+
* @param {T} [option] - Array of validation functions to apply
|
|
26
|
+
* @param {string} [message] - Custom error message for type validation
|
|
27
|
+
* @returns {Function} - Validator function that checks if the value is a bigint and applies validation rules
|
|
28
|
+
*/
|
|
29
|
+
var bigint = exports.bigint = function bigint() {
|
|
30
|
+
var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
31
|
+
var message = arguments.length > 1 ? arguments[1] : undefined;
|
|
32
|
+
return function (value) {
|
|
33
|
+
if (typeof value !== "bigint") {
|
|
34
|
+
return {
|
|
35
|
+
validate: false,
|
|
36
|
+
message: message !== null && message !== void 0 ? message : "",
|
|
37
|
+
type: "bigint"
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
var _iterator = _createForOfIteratorHelper(option),
|
|
41
|
+
_step;
|
|
42
|
+
try {
|
|
43
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
44
|
+
var rule = _step.value;
|
|
45
|
+
if (!rule.validate(value)) {
|
|
46
|
+
var _rule$message;
|
|
47
|
+
return {
|
|
48
|
+
validate: false,
|
|
49
|
+
message: (_rule$message = rule.message) !== null && _rule$message !== void 0 ? _rule$message : "",
|
|
50
|
+
type: "bigint"
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
_iterator.e(err);
|
|
56
|
+
} finally {
|
|
57
|
+
_iterator.f();
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
validate: true,
|
|
61
|
+
message: "",
|
|
62
|
+
type: "bigint"
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core";
|