umt 2.17.0 → 2.18.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.
Files changed (30) hide show
  1. package/README.md +341 -347
  2. package/module/Validate/object/index.d.ts +1 -0
  3. package/module/Validate/object/index.js +1 -0
  4. package/module/Validate/object/index.js.map +1 -1
  5. package/module/Validate/object/intersection.d.ts +4 -2
  6. package/module/Validate/object/intersection.js.map +1 -1
  7. package/module/Validate/object/nullable.d.ts +8 -0
  8. package/module/Validate/object/nullable.js +21 -0
  9. package/module/Validate/object/nullable.js.map +1 -0
  10. package/module/Validate/object/union.d.ts +4 -2
  11. package/module/Validate/object/union.js.map +1 -1
  12. package/module/Validate/string/index.d.ts +1 -0
  13. package/module/Validate/string/index.js +1 -0
  14. package/module/Validate/string/index.js.map +1 -1
  15. package/module/Validate/string/oneOf.d.ts +32 -0
  16. package/module/Validate/string/oneOf.js +32 -0
  17. package/module/Validate/string/oneOf.js.map +1 -0
  18. package/module/es5/Validate/object/index.d.ts +1 -0
  19. package/module/es5/Validate/object/index.js +11 -0
  20. package/module/es5/Validate/object/intersection.d.ts +4 -2
  21. package/module/es5/Validate/object/intersection.js +6 -0
  22. package/module/es5/Validate/object/nullable.d.ts +8 -0
  23. package/module/es5/Validate/object/nullable.js +26 -0
  24. package/module/es5/Validate/object/union.d.ts +4 -2
  25. package/module/es5/Validate/object/union.js +6 -0
  26. package/module/es5/Validate/string/index.d.ts +1 -0
  27. package/module/es5/Validate/string/index.js +11 -0
  28. package/module/es5/Validate/string/oneOf.d.ts +32 -0
  29. package/module/es5/Validate/string/oneOf.js +45 -0
  30. package/package.json +4 -1
@@ -1,4 +1,5 @@
1
1
  export * from "./core";
2
2
  export * from "./intersection";
3
+ export * from "./nullable";
3
4
  export * from "./optional";
4
5
  export * from "./union";
@@ -1,5 +1,6 @@
1
1
  export * from "./core";
2
2
  export * from "./intersection";
3
+ export * from "./nullable";
3
4
  export * from "./optional";
4
5
  export * from "./union";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/object/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/object/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
@@ -1,6 +1,8 @@
1
1
  import type { UnionToIntersection } from "../../types/logic";
2
- import type { ValidateCoreReturnType } from "../../Validate/type";
3
- type ExtractValidatedType<V> = V extends (value: never) => ValidateCoreReturnType<infer T> ? T : never;
2
+ import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
3
+ type ExtractValidatedType<V> = V extends (value: never) => {
4
+ type: infer T;
5
+ } ? ValidateType<T> : never;
4
6
  /**
5
7
  * Creates an intersection validator that passes only if all given validators pass
6
8
  * @param validators - Validator functions to compose as an intersection (logical AND)
@@ -1 +1 @@
1
- {"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../../src/Validate/object/intersection.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAG1B,GAAG,UAAmB,EACtB,EAAE;IACF,OAAO,CACL,KAA4D,EAG5D,EAAE;QACF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,MAAM,GACV,SAKD,CAAC,KAAK,CAAC,CAAC;YACT,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACrB,OAAO;oBACL,QAAQ,EAAE,KAAK;oBACf,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,IAAI,EAAE,KAEL;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,KAEL;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../../src/Validate/object/intersection.ts"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAG1B,GAAG,UAAmB,EACtB,EAAE;IACF,OAAO,CACL,KAA4D,EAG5D,EAAE;QACF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,MAAM,GACV,SAKD,CAAC,KAAK,CAAC,CAAC;YACT,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACrB,OAAO;oBACL,QAAQ,EAAE,KAAK;oBACf,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,IAAI,EAAE,KAEL;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,KAEL;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ValidateCoreReturnType } from "../../Validate/type";
2
+ /**
3
+ * Wraps a validator to accept null values
4
+ * @template T - The type of value the wrapped validator expects
5
+ * @param {Function} validator - Validator function to make nullable
6
+ * @returns {Function} - Validator that passes for null or delegates to the wrapped validator
7
+ */
8
+ export declare const nullable: <T>(validator: (value: T) => ValidateCoreReturnType<T>) => ((value: T | null) => ValidateCoreReturnType<T | null>);
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Wraps a validator to accept null values
3
+ * @template T - The type of value the wrapped validator expects
4
+ * @param {Function} validator - Validator function to make nullable
5
+ * @returns {Function} - Validator that passes for null or delegates to the wrapped validator
6
+ */
7
+ export const nullable = (validator) => {
8
+ const nullableValidator = (value) => {
9
+ if (value === null) {
10
+ return {
11
+ validate: true,
12
+ message: "",
13
+ type: "null",
14
+ };
15
+ }
16
+ const result = validator(value);
17
+ return result;
18
+ };
19
+ return nullableValidator;
20
+ };
21
+ //# sourceMappingURL=nullable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nullable.js","sourceRoot":"","sources":["../../../src/Validate/object/nullable.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,SAAkD,EACO,EAAE;IAC3D,MAAM,iBAAiB,GAAG,CACxB,KAAe,EACmB,EAAE;QACpC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,EAAE;gBACX,IAAI,EAAE,MAAM;aACb,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC"}
@@ -1,5 +1,7 @@
1
- import type { ValidateCoreReturnType } from "../../Validate/type";
2
- type ExtractValidatedType<V> = V extends (value: never) => ValidateCoreReturnType<infer T> ? T : never;
1
+ import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
2
+ type ExtractValidatedType<V> = V extends (value: never) => {
3
+ type: infer T;
4
+ } ? ValidateType<T> : never;
3
5
  /**
4
6
  * Creates a union validator that passes if any of the given validators pass
5
7
  * @param validators - Validator functions to compose as a union (logical OR)
@@ -1 +1 @@
1
- {"version":3,"file":"union.js","sourceRoot":"","sources":["../../../src/Validate/object/union.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAGnB,GAAG,UAAmB,EACtB,EAAE;IACF,OAAO,CACL,KAAuC,EACmB,EAAE;QAC5D,IAAI,WAAW,GAAG,EAAE,CAAC;QACrB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,MAAM,GACV,SAGD,CAAC,KAAK,CAAC,CAAC;YACT,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACpB,OAAO;oBACL,QAAQ,EAAE,IAAI;oBACd,OAAO,EAAE,EAAE;oBACX,IAAI,EAAE,KAA2D;iBAClE,CAAC;YACJ,CAAC;YACD,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,WAAW;YACpB,IAAI,EAAE,KAA2D;SAClE,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"union.js","sourceRoot":"","sources":["../../../src/Validate/object/union.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAGnB,GAAG,UAAmB,EACtB,EAAE;IACF,OAAO,CACL,KAAuC,EACmB,EAAE;QAC5D,IAAI,WAAW,GAAG,EAAE,CAAC;QACrB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,MAAM,GACV,SAGD,CAAC,KAAK,CAAC,CAAC;YACT,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACpB,OAAO;oBACL,QAAQ,EAAE,IAAI;oBACd,OAAO,EAAE,EAAE;oBACX,IAAI,EAAE,KAA2D;iBAClE,CAAC;YACJ,CAAC;YACD,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,WAAW;YACpB,IAAI,EAAE,KAA2D;SAClE,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -4,5 +4,6 @@ export * from "./length";
4
4
  export * from "./minLength";
5
5
  export * from "./maxLength";
6
6
  export * from "./numberString";
7
+ export * from "./oneOf";
7
8
  export * from "./regexMatch";
8
9
  export * from "./uuid";
@@ -4,6 +4,7 @@ export * from "./length";
4
4
  export * from "./minLength";
5
5
  export * from "./maxLength";
6
6
  export * from "./numberString";
7
+ export * from "./oneOf";
7
8
  export * from "./regexMatch";
8
9
  export * from "./uuid";
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validate/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * String validation module for literal union (allowed values) check
3
+ * Provides validation functionality for checking if a string is one of the
4
+ * allowed literal values, useful for validating string literal union types
5
+ * such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
6
+ *
7
+ * The validator's return type carries the literal union through its `type`
8
+ * field directly (instead of going through `Types<T>` which would collapse
9
+ * to `"string"`), so consumers like `object()`, `union()`, and `intersection()`
10
+ * can preserve the literal union in their inferred types.
11
+ */
12
+ /**
13
+ * Return type produced by a `oneOf` validator. Structurally compatible with
14
+ * `ValidateCoreReturnType<unknown>`, but exposes the literal union directly
15
+ * via the `type` field so the inferred type can flow through `object()`,
16
+ * `union()`, and `intersection()` without being collapsed to `string`.
17
+ */
18
+ export interface OneOfReturnType<T extends string> {
19
+ validate: boolean;
20
+ message: string;
21
+ type: T;
22
+ }
23
+ /**
24
+ * Creates a top-level validator that checks if a string value is one of the
25
+ * given allowed literal values. The literal union is captured via `const T`
26
+ * and exposed through the `OneOfReturnType<T[number]>` return type.
27
+ * @template T - The tuple of allowed string literals
28
+ * @param {T} values - The tuple of allowed string values
29
+ * @param {string} [message] - Custom error message for validation failure
30
+ * @returns A validator function from `string` to `OneOfReturnType<T[number]>`
31
+ */
32
+ export declare const oneOf: <const T extends readonly string[]>(values: T, message?: string) => (value: string) => OneOfReturnType<T[number]>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * String validation module for literal union (allowed values) check
3
+ * Provides validation functionality for checking if a string is one of the
4
+ * allowed literal values, useful for validating string literal union types
5
+ * such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
6
+ *
7
+ * The validator's return type carries the literal union through its `type`
8
+ * field directly (instead of going through `Types<T>` which would collapse
9
+ * to `"string"`), so consumers like `object()`, `union()`, and `intersection()`
10
+ * can preserve the literal union in their inferred types.
11
+ */
12
+ /**
13
+ * Creates a top-level validator that checks if a string value is one of the
14
+ * given allowed literal values. The literal union is captured via `const T`
15
+ * and exposed through the `OneOfReturnType<T[number]>` return type.
16
+ * @template T - The tuple of allowed string literals
17
+ * @param {T} values - The tuple of allowed string values
18
+ * @param {string} [message] - Custom error message for validation failure
19
+ * @returns A validator function from `string` to `OneOfReturnType<T[number]>`
20
+ */
21
+ export const oneOf = (values, message) => {
22
+ const allowed = new Set(values);
23
+ return (value) => {
24
+ const isValid = allowed.has(value);
25
+ return {
26
+ validate: isValid,
27
+ message: isValid ? "" : (message ?? ""),
28
+ type: value,
29
+ };
30
+ };
31
+ };
32
+ //# sourceMappingURL=oneOf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oneOf.js","sourceRoot":"","sources":["../../../src/Validate/string/oneOf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAcH;;;;;;;;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,KAAK;SACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from "./core";
2
2
  export * from "./intersection";
3
+ export * from "./nullable";
3
4
  export * from "./optional";
4
5
  export * from "./union";
@@ -25,6 +25,17 @@ Object.keys(_intersection).forEach(function (key) {
25
25
  }
26
26
  });
27
27
  });
28
+ var _nullable = require("./nullable");
29
+ Object.keys(_nullable).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _nullable[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function get() {
35
+ return _nullable[key];
36
+ }
37
+ });
38
+ });
28
39
  var _optional = require("./optional");
29
40
  Object.keys(_optional).forEach(function (key) {
30
41
  if (key === "default" || key === "__esModule") return;
@@ -1,6 +1,8 @@
1
1
  import type { UnionToIntersection } from "../../types/logic";
2
- import type { ValidateCoreReturnType } from "../../Validate/type";
3
- type ExtractValidatedType<V> = V extends (value: never) => ValidateCoreReturnType<infer T> ? T : never;
2
+ import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
3
+ type ExtractValidatedType<V> = V extends (value: never) => {
4
+ type: infer T;
5
+ } ? ValidateType<T> : never;
4
6
  /**
5
7
  * Creates an intersection validator that passes only if all given validators pass
6
8
  * @param validators - Validator functions to compose as an intersection (logical AND)
@@ -4,6 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.intersection = void 0;
7
+ // Extract the validated value type by reading the validator's `type` field
8
+ // (and applying `ValidateType` to map type tags like "string" back to the
9
+ // runtime type). Reading the field directly lets validators that expose the
10
+ // literal union via the `type` field (such as `oneOf`) flow through
11
+ // intersection without being collapsed by `Types<T>`.
12
+
7
13
  /**
8
14
  * Creates an intersection validator that passes only if all given validators pass
9
15
  * @param validators - Validator functions to compose as an intersection (logical AND)
@@ -0,0 +1,8 @@
1
+ import type { ValidateCoreReturnType } from "../../Validate/type";
2
+ /**
3
+ * Wraps a validator to accept null values
4
+ * @template T - The type of value the wrapped validator expects
5
+ * @param {Function} validator - Validator function to make nullable
6
+ * @returns {Function} - Validator that passes for null or delegates to the wrapped validator
7
+ */
8
+ export declare const nullable: <T>(validator: (value: T) => ValidateCoreReturnType<T>) => ((value: T | null) => ValidateCoreReturnType<T | null>);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.nullable = void 0;
7
+ /**
8
+ * Wraps a validator to accept null values
9
+ * @template T - The type of value the wrapped validator expects
10
+ * @param {Function} validator - Validator function to make nullable
11
+ * @returns {Function} - Validator that passes for null or delegates to the wrapped validator
12
+ */
13
+ var nullable = exports.nullable = function nullable(validator) {
14
+ var nullableValidator = function nullableValidator(value) {
15
+ if (value === null) {
16
+ return {
17
+ validate: true,
18
+ message: "",
19
+ type: "null"
20
+ };
21
+ }
22
+ var result = validator(value);
23
+ return result;
24
+ };
25
+ return nullableValidator;
26
+ };
@@ -1,5 +1,7 @@
1
- import type { ValidateCoreReturnType } from "../../Validate/type";
2
- type ExtractValidatedType<V> = V extends (value: never) => ValidateCoreReturnType<infer T> ? T : never;
1
+ import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
2
+ type ExtractValidatedType<V> = V extends (value: never) => {
3
+ type: infer T;
4
+ } ? ValidateType<T> : never;
3
5
  /**
4
6
  * Creates a union validator that passes if any of the given validators pass
5
7
  * @param validators - Validator functions to compose as a union (logical OR)
@@ -4,6 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.union = void 0;
7
+ // Extract the validated value type by reading the validator's `type` field
8
+ // (and applying `ValidateType` to map type tags like "string" back to the
9
+ // runtime type). Reading the field directly lets validators that expose the
10
+ // literal union via the `type` field (such as `oneOf`) flow through union
11
+ // without being collapsed by `Types<T>`.
12
+
7
13
  /**
8
14
  * Creates a union validator that passes if any of the given validators pass
9
15
  * @param validators - Validator functions to compose as a union (logical OR)
@@ -4,5 +4,6 @@ export * from "./length";
4
4
  export * from "./minLength";
5
5
  export * from "./maxLength";
6
6
  export * from "./numberString";
7
+ export * from "./oneOf";
7
8
  export * from "./regexMatch";
8
9
  export * from "./uuid";
@@ -69,6 +69,17 @@ Object.keys(_numberString).forEach(function (key) {
69
69
  }
70
70
  });
71
71
  });
72
+ var _oneOf = require("./oneOf");
73
+ Object.keys(_oneOf).forEach(function (key) {
74
+ if (key === "default" || key === "__esModule") return;
75
+ if (key in exports && exports[key] === _oneOf[key]) return;
76
+ Object.defineProperty(exports, key, {
77
+ enumerable: true,
78
+ get: function get() {
79
+ return _oneOf[key];
80
+ }
81
+ });
82
+ });
72
83
  var _regexMatch = require("./regexMatch");
73
84
  Object.keys(_regexMatch).forEach(function (key) {
74
85
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * String validation module for literal union (allowed values) check
3
+ * Provides validation functionality for checking if a string is one of the
4
+ * allowed literal values, useful for validating string literal union types
5
+ * such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
6
+ *
7
+ * The validator's return type carries the literal union through its `type`
8
+ * field directly (instead of going through `Types<T>` which would collapse
9
+ * to `"string"`), so consumers like `object()`, `union()`, and `intersection()`
10
+ * can preserve the literal union in their inferred types.
11
+ */
12
+ /**
13
+ * Return type produced by a `oneOf` validator. Structurally compatible with
14
+ * `ValidateCoreReturnType<unknown>`, but exposes the literal union directly
15
+ * via the `type` field so the inferred type can flow through `object()`,
16
+ * `union()`, and `intersection()` without being collapsed to `string`.
17
+ */
18
+ export interface OneOfReturnType<T extends string> {
19
+ validate: boolean;
20
+ message: string;
21
+ type: T;
22
+ }
23
+ /**
24
+ * Creates a top-level validator that checks if a string value is one of the
25
+ * given allowed literal values. The literal union is captured via `const T`
26
+ * and exposed through the `OneOfReturnType<T[number]>` return type.
27
+ * @template T - The tuple of allowed string literals
28
+ * @param {T} values - The tuple of allowed string values
29
+ * @param {string} [message] - Custom error message for validation failure
30
+ * @returns A validator function from `string` to `OneOfReturnType<T[number]>`
31
+ */
32
+ export declare const oneOf: <const T extends readonly string[]>(values: T, message?: string) => (value: string) => OneOfReturnType<T[number]>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.oneOf = void 0;
7
+ /**
8
+ * String validation module for literal union (allowed values) check
9
+ * Provides validation functionality for checking if a string is one of the
10
+ * allowed literal values, useful for validating string literal union types
11
+ * such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
12
+ *
13
+ * The validator's return type carries the literal union through its `type`
14
+ * field directly (instead of going through `Types<T>` which would collapse
15
+ * to `"string"`), so consumers like `object()`, `union()`, and `intersection()`
16
+ * can preserve the literal union in their inferred types.
17
+ */
18
+
19
+ /**
20
+ * Return type produced by a `oneOf` validator. Structurally compatible with
21
+ * `ValidateCoreReturnType<unknown>`, but exposes the literal union directly
22
+ * via the `type` field so the inferred type can flow through `object()`,
23
+ * `union()`, and `intersection()` without being collapsed to `string`.
24
+ */
25
+
26
+ /**
27
+ * Creates a top-level validator that checks if a string value is one of the
28
+ * given allowed literal values. The literal union is captured via `const T`
29
+ * and exposed through the `OneOfReturnType<T[number]>` return type.
30
+ * @template T - The tuple of allowed string literals
31
+ * @param {T} values - The tuple of allowed string values
32
+ * @param {string} [message] - Custom error message for validation failure
33
+ * @returns A validator function from `string` to `OneOfReturnType<T[number]>`
34
+ */
35
+ var oneOf = exports.oneOf = function oneOf(values, message) {
36
+ var allowed = new Set(values);
37
+ return function (value) {
38
+ var isValid = allowed.has(value);
39
+ return {
40
+ validate: isValid,
41
+ message: isValid ? "" : message !== null && message !== void 0 ? message : "",
42
+ type: value
43
+ };
44
+ };
45
+ };
package/package.json CHANGED
@@ -37,6 +37,8 @@
37
37
  "ts-node": "10.9.2",
38
38
  "tsc-alias": "1.8.16",
39
39
  "typedoc": "0.28.19",
40
+ "typedoc-github-wiki-theme": "2.1.0",
41
+ "typedoc-plugin-markdown": "4.11.0",
40
42
  "typescript": "6.0.3",
41
43
  "typescript-eslint": "8.59.1"
42
44
  },
@@ -217,11 +219,12 @@
217
219
  "format": "nix develop --command make format",
218
220
  "lint": "nix develop --command make lint",
219
221
  "lint:ci": "nix develop --command make lint-ci",
222
+ "readme": "nix develop --command make readme",
220
223
  "test": "nix develop --command make test",
221
224
  "test-debug": "nix develop --command make test-debug",
222
225
  "ts-node": "nix develop --command make ts-node"
223
226
  },
224
227
  "type": "module",
225
228
  "types": "module/index.d.ts",
226
- "version": "2.17.0"
229
+ "version": "2.18.0"
227
230
  }