UNPKG

@valuer/main

Version:

Valuer is an advanced declarative value validator

41 lines (40 loc) 1.99 kB
import { TypeOf, Class } from "@valuer/types"; import { ValidationSole } from "./validators"; export declare type ValueKind = "any" | "void" | "non-void" | "defined" | "non-null" | "primitive" | "primitive-non-void" | "primitive-defined" | "primitive-non-null" | "composite" | "composite-non-void" | "composite-defined" | "composite-non-null"; export declare type NumberKind = "any" | "number" | "numeric" | "finite" | "non-integer" | "non-integer-finite" | "integer" | "integer-even" | "integer-odd" | "integer-safe" | "integer-even-safe" | "integer-odd-safe"; export declare type NumberSpectrum = "any" | "number" | "positive" | "negative" | "non-positive" | "non-negative" | "non-zero"; export declare type DescriptorName = string; export declare type DescriptorBase<Value = any> = { /** Expected value */ value: Value; /** Equal value */ equals: Value; /** Set of allowed values */ set: Value[]; /** Kind of value */ kind: ValueKind; /** Properties of composite value */ composite: Value extends object ? { [Key in keyof Value]?: Descriptive<Value[Key]>; } : never; /** Expected result of applying `typeof` to the value */ typeOf: TypeOf; /** Expected value's constructor */ instanceOf: Value extends object ? Class<Value> : never; /** Type of numeric value */ number: NumberKind; /** Allowed part of the number spectrum */ spectrum: NumberSpectrum; /** The smallest and the largest possible numeric values respectively */ range: number[]; /** Pattern to match against the string */ pattern: RegExp; /** Length of the string */ length: number; /** Min and max length of the string respectively */ lengthRange: number[]; }; export declare type Descriptor<Value = any> = Partial<DescriptorBase<Value>> & { [failure: string]: any; }; export declare type Descriptive<Value = any> = Descriptor<Value> | ValidationSole<Value>[];