validation.ts
Advanced tools
Comparing version 0.0.29 to 0.0.30
@@ -10,2 +10,3 @@ export interface Validator<T> { | ||
tagged<TAG extends number>(this: Validator<number>): Validator<TAG>; | ||
optional(): Validator<T | undefined>; | ||
} | ||
@@ -30,4 +31,4 @@ export declare type Ok<VALUE> = { | ||
export declare function isOk<VALUE>(result: Result<unknown, VALUE>): result is Ok<VALUE>; | ||
export declare type Any = Validator<Value>; | ||
export declare type TypeOf<V extends Any> = V['T']; | ||
export declare type AnyValidator = Validator<Value>; | ||
export declare type TypeOf<V extends AnyValidator> = V['T']; | ||
export interface ValidationError { | ||
@@ -76,3 +77,3 @@ readonly message: string; | ||
export declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(a: Validator<A>, b: Validator<B>, c: Validator<C>, d: Validator<D>, e: Validator<E>, f: Validator<F>, g: Validator<G>, h: Validator<H>, i: Validator<I>, j: Validator<J>, k: Validator<K>, l: Validator<L>): Validator<[A, B, C, D, E, F, G, H, I, J, K, L]>; | ||
export declare type Props = Record<string, Any>; | ||
declare type Props = Record<string, AnyValidator>; | ||
declare type Unpack<P extends Props> = { | ||
@@ -97,3 +98,3 @@ [K in keyof P]: P[K]['T']; | ||
export declare function dictionary<K extends string, V>(domain: Validator<K>, codomain: Validator<V>): Validator<Record<K, V>>; | ||
export declare type Literal = string | number | boolean | null | undefined; | ||
declare type Literal = string | number | boolean | null | undefined; | ||
export declare function literal<V extends Literal>(value: V): Validator<V>; | ||
@@ -125,5 +126,5 @@ export declare function intersection<A, B>(a: Validator<A>, b: Validator<B>): Validator<A & B>; | ||
export declare function optional<V>(validator: Validator<V>): Validator<V | undefined>; | ||
export declare function recursion<T>(definition: (self: Validator<T>) => Any): Validator<T>; | ||
export declare function recursion<T>(definition: (self: Validator<T>) => AnyValidator): Validator<T>; | ||
export declare const isoDate: Validator<Date>; | ||
export declare function errorDebugString(errors: ValidationError[]): string; | ||
export { nullValidator as null, undefinedValidator as undefined }; |
@@ -47,2 +47,5 @@ "use strict"; | ||
return this; | ||
}, | ||
optional: function () { | ||
return optional(this); | ||
} | ||
@@ -49,0 +52,0 @@ }; |
@@ -10,2 +10,3 @@ export interface Validator<T> { | ||
tagged<TAG extends number>(this: Validator<number>): Validator<TAG>; | ||
optional(): Validator<T | undefined>; | ||
} | ||
@@ -30,4 +31,4 @@ export declare type Ok<VALUE> = { | ||
export declare function isOk<VALUE>(result: Result<unknown, VALUE>): result is Ok<VALUE>; | ||
export declare type Any = Validator<Value>; | ||
export declare type TypeOf<V extends Any> = V['T']; | ||
export declare type AnyValidator = Validator<Value>; | ||
export declare type TypeOf<V extends AnyValidator> = V['T']; | ||
export interface ValidationError { | ||
@@ -76,3 +77,3 @@ readonly message: string; | ||
export declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(a: Validator<A>, b: Validator<B>, c: Validator<C>, d: Validator<D>, e: Validator<E>, f: Validator<F>, g: Validator<G>, h: Validator<H>, i: Validator<I>, j: Validator<J>, k: Validator<K>, l: Validator<L>): Validator<[A, B, C, D, E, F, G, H, I, J, K, L]>; | ||
export declare type Props = Record<string, Any>; | ||
declare type Props = Record<string, AnyValidator>; | ||
declare type Unpack<P extends Props> = { | ||
@@ -97,3 +98,3 @@ [K in keyof P]: P[K]['T']; | ||
export declare function dictionary<K extends string, V>(domain: Validator<K>, codomain: Validator<V>): Validator<Record<K, V>>; | ||
export declare type Literal = string | number | boolean | null | undefined; | ||
declare type Literal = string | number | boolean | null | undefined; | ||
export declare function literal<V extends Literal>(value: V): Validator<V>; | ||
@@ -125,5 +126,5 @@ export declare function intersection<A, B>(a: Validator<A>, b: Validator<B>): Validator<A & B>; | ||
export declare function optional<V>(validator: Validator<V>): Validator<V | undefined>; | ||
export declare function recursion<T>(definition: (self: Validator<T>) => Any): Validator<T>; | ||
export declare function recursion<T>(definition: (self: Validator<T>) => AnyValidator): Validator<T>; | ||
export declare const isoDate: Validator<Date>; | ||
export declare function errorDebugString(errors: ValidationError[]): string; | ||
export { nullValidator as null, undefinedValidator as undefined }; |
@@ -31,2 +31,5 @@ //-------------------------------------- | ||
return this; | ||
}, | ||
optional() { | ||
return optional(this); | ||
} | ||
@@ -33,0 +36,0 @@ }; |
{ | ||
"name": "validation.ts", | ||
"version": "0.0.29", | ||
"version": "0.0.30", | ||
"sideEffects": false, | ||
@@ -38,3 +38,9 @@ "description": "Validation for TypeScript", | ||
"author": "AlexGalays", | ||
"homepage": "https://github.com/AlexGalays/validation.ts" | ||
"homepage": "https://github.com/AlexGalays/validation.ts", | ||
"prettier": { | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true | ||
} | ||
} |
54166
918