Skip to content

Commit

Permalink
feat(inequality): add validator for inequality operator
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed May 24, 2023
1 parent cb247f8 commit caee113
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions combinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { LessThenValidator } from "./validators/operators/lt.ts";
import { LessThenOrEqualValidator } from "./validators/operators/lte.ts";
import { GreaterThenValidator } from "./validators/operators/gt.ts";
import { GreaterThenOrEqualValidator } from "./validators/operators/gte.ts";
import { InequalityValidator } from "./validators/operators/inequality.ts";
import { TypeValidator } from "./validators/operators/typeof.ts";
import { InstanceValidator } from "./validators/operators/instanceof.ts";
import { ValidDateValidator } from "./validators/date/valid_date.ts";
Expand All @@ -39,6 +40,7 @@ export const lt = /* @__PURE__ */ lazy(LessThenValidator);
export const lte = /* @__PURE__ */ lazy(LessThenOrEqualValidator);
export const gt = /* @__PURE__ */ lazy(GreaterThenValidator);
export const gte = /* @__PURE__ */ lazy(GreaterThenOrEqualValidator);
export const ne = /* @__PURE__ */ lazy(InequalityValidator);
export const and = /* @__PURE__ */ lazy(AndValidator);

// known
Expand Down
1 change: 1 addition & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export {
lte,
maxCount,
minCount,
ne,
nonEmpty,
nullish,
number,
Expand Down
21 changes: 21 additions & 0 deletions validators/operators/inequality.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license.
// This module is browser compatible.

import { shouldBeBut } from "../utils.ts";
import { ScalarValidator } from "../../utils.ts";

export class InequalityValidator<const A = unknown>
extends ScalarValidator<unknown, A> {
constructor(public value: A) {
super();
super.expect(shouldBeBut);
}

override is(input: unknown): input is A {
return input !== this.value;
}

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

0 comments on commit caee113

Please sign in to comment.