Skip to content

Commit

Permalink
refactor: use shared types
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed May 26, 2023
1 parent e8eefad commit b6dddf4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
10 changes: 8 additions & 2 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
// This module is browser compatible.

import { Error } from "./constants.ts";
import { Display, Reporter, ValidationFailure, Validator } from "./types.ts";
import {
Display,
Reporter,
ValidationContext,
ValidationFailure,
Validator,
} from "./types.ts";
import { escapeStringRegex, isString } from "./deps.ts";

/** Validator constructor for scalar value. */
export abstract class ScalarValidator<In = unknown, A extends In = In>
extends Reporter<{ input: In }>
extends Reporter<ValidationContext<In>>
implements Validator<In, A> {
/** Whether the input is valid or not. */
abstract is(input: In): input is A;
Expand Down
10 changes: 7 additions & 3 deletions validators/iterable/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

import { isEmpty } from "../../deps.ts";
import { enumerate } from "../../iter_utils.ts";
import { Reporter, ValidationFailure, Validator } from "../../types.ts";
import {
Reporter,
ValidationContext,
ValidationFailure,
Validator,
} from "../../types.ts";

interface Context {
input: Iterable<unknown>;
interface Context extends ValidationContext<Iterable<unknown>> {
index: number;
item: unknown;
}
Expand Down
13 changes: 7 additions & 6 deletions validators/operators/not.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license.
// This module is browser compatible.

import { Reporter, ValidationFailure, Validator } from "../../types.ts";

export interface ReportContext<In = unknown> {
input: In;
}
import {
Reporter,
type ValidationContext,
ValidationFailure,
type Validator,
} from "../../types.ts";

export class NotValidator<in In = unknown, In_ extends In = In>
extends Reporter<ReportContext<In>>
extends Reporter<ValidationContext<In>>
implements Validator<In, In_> {
validator: Validator<In, In_>;

Expand Down

0 comments on commit b6dddf4

Please sign in to comment.