Skip to content

Commit

Permalink
Add all validation rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Barfurth committed Jul 20, 2018
1 parent 6827169 commit 4ffbc95
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions v8n.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { first } from "./node_modules/rxjs/operator/first";
import { last } from "./node_modules/rxjs/operators";
import { empty } from "./node_modules/rxjs/Observer";
import { range } from "./node_modules/rxjs/observable/range";

// Type definitions for v8n
// Project: v8n
// Definitions by:
Expand All @@ -11,13 +16,50 @@ declare namespace v8n {
export interface Validation {
chain: Rule[];
invert?: boolean;
test(value: any): boolean;
check(value: any): never;
pattern(pattern: RegExp): Validation;
equal(expected: any): Validation;
exact(expected: any): Validation;
string(): Validation;
number(): Validation;
boolean(): Validation;
undefined(): Validation;
null(): Validation;
array(): Validation;
lowercase(): Validation;
vowel(): Validation;
consonant(): Validation;
first(item: any): Validation;
last(item: any): Validation;
empty(): Validation;
length(min: number, max?: number): Validation;
minLength(min: number): Validation;
maxLength(max: number): Validation;
negative(): Validation;
positive(): Validation;
between(min: number, max: number): Validation;
range(min: number, max: number): Validation;
lessThan(bound: number): Validation;
lessThanOrEqual(bound: number): Validation;
greaterThan(bound: number): Validation;
greaterThanOrEqual(bound: number): Validation;
even(): Validation;
odd(): Validation;
includes(expected: any): Validation;
integer(): Validation;
extend(newRules: object): void;
}
export interface Rule {
name: string;
fn: Function;
args?: any;
invert?: boolean;
}
export interface ValidationException extends Error {
rule: Rule;
value: any;
}
}

export = v8n;

0 comments on commit 4ffbc95

Please sign in to comment.