Skip to content

Commit

Permalink
feat(gte): add validator for greater than or equal operator
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed May 24, 2023
1 parent f42a6f4 commit 629919b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions combinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AndValidator } from "./validators/operators/and.ts";
import { EqualityValidator } from "./validators/operators/eq.ts";
import { LessThenValidator } from "./validators/operators/lt.ts";
import { GreaterThenValidator } from "./validators/operators/gt.ts";
import { GreaterThenOrEqualValidator } from "./validators/operators/gte.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 @@ -35,6 +36,7 @@ export const nullish = /* @__PURE__ */ new NullishValidator();
export const eq = /* @__PURE__ */ lazy(EqualityValidator);
export const lt = /* @__PURE__ */ lazy(LessThenValidator);
export const gt = /* @__PURE__ */ lazy(GreaterThenValidator);
export const gte = /* @__PURE__ */ lazy(GreaterThenOrEqualValidator);
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 @@ -10,6 +10,7 @@ export {
empty,
eq,
gt,
gte,
instance,
int,
item,
Expand Down
20 changes: 20 additions & 0 deletions validators/operators/gte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license.
// This module is browser compatible.

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

export class GreaterThenOrEqualValidator<In> extends ScalarValidator<In> {
constructor(public base: In) {
super();
super.expect(shouldBeBut);
}

override is(input: In): input is In {
return input >= this.base;
}

override toString(): string {
return `>= ${this.base}`;
}
}

0 comments on commit 629919b

Please sign in to comment.