Skip to content

Commit

Permalink
feat(value): add validator for value
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed May 17, 2023
1 parent f44ff99 commit d64083f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions validators/value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license.
// This module is browser compatible.

import { format, ScalarValidator } from "../utils.ts";
import type { Assert } from "../types.ts";
import error from "./error.json" assert { type: "json" };

export class ValueValidator<Out = unknown> extends ScalarValidator
implements Assert<unknown, Out> {
declare [Assert.symbol]: Out;
constructor(public value: Out) {
super();
super.expect(({ input }) => format(error.should_be_but, this, input));
}

is(input: unknown): boolean {
return input === this.value;
}

toString(): string {
return `${this.value}`;
}
}

0 comments on commit d64083f

Please sign in to comment.