We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 77020b4 commit 12bde9aCopy full SHA for 12bde9a
1 file changed
validators/enum.ts
@@ -0,0 +1,20 @@
1
+import { AssertiveScalarValidator } from "../utils.ts";
2
+import { displayOr, shouldBeBut } from "./utils.ts";
3
+
4
+export class EnumValidator<const T>
5
+ extends AssertiveScalarValidator<unknown, T> {
6
+ values: [T, T, ...T[]];
7
+ constructor(v1: T, v2: T, ...values: readonly T[]) {
8
+ super();
9
+ super.expect(shouldBeBut);
10
+ this.values = [v1, v2, ...values];
11
+ }
12
13
+ is(input: unknown): input is T {
14
+ return (this.values as unknown[]).includes(input);
15
16
17
+ toString(): string {
18
+ return `one of ${displayOr(...this.values)}`;
19
20
+}
0 commit comments