UNPKG

@valuer/main

Version:

Valuer is an advanced declarative value validator

55 lines (54 loc) 1.83 kB
import { Role } from "./types/role"; import { Config } from "./modules/configs"; import { Descriptor } from "./modules/descriptors"; import { Result } from "./modules/hooks"; import { ValidationSole } from "./modules/validators"; declare type ResultFactoryDirect<Value = any> = { /** * @example * const kind = "primitive"; * const mode = "check"; * * valuer.as({ kind }, { mode })(42, "The Answer") * valuer.as(kind)(42, "The Answer") */ (value: Value, role?: Role): Result<Value>; }; declare type ResultFactoryReverse<Value = any> = { /** * @example * const kind = "primitive"; * const mode = "check"; * * valuer(42, "The Answer").as({ kind }, { mode }) */ (descriptor: Descriptor<Value>, config?: Config): Result<Value>; /** * @example * valuer(42, "The Answer").as("primitive") */ (...validations: ValidationSole<Value>[]): Result<Value>; }; /** * @example * const kind = "primitive"; * const mode = "check"; * * valuer.as({ kind }, { mode })(42, "The Answer") */ declare function core<Value = any>(descriptor: Descriptor<Value>, config?: Config): ResultFactoryDirect<Value>; /** * @example * valuer.as("primitive")(42, "The Answer") */ declare function core<Value = any>(...validations: ValidationSole<Value>[]): ResultFactoryDirect<Value>; /** @private */ declare type Delegator = <Value>(value: Value, role?: Role) => { as: ResultFactoryReverse<Value>; }; export declare const valuer: Delegator & { as: typeof core; config: (config: Partial<import("./modules/configs").ConfigBase>) => import("./modules/configs").ConfigBase; define: <Value>(name: string, descriptive: import("./modules/descriptors").Descriptive<Value>) => never; }; export {};