@codeparticle/formal
Version:
A <2kb library for validating data of any kind
30 lines (27 loc) • 959 B
TypeScript
import { ValidationM, ValidationActions } from './types/index.js';
declare class Fail implements Fail {
static of(value: any, errors?: string[]): Fail;
value: any;
errors: string[];
isSuccess: boolean;
/**
* This constructor allows us to coalesce errors from multiple failed checks into
* one, used when we fold out of this context.
*
*/
constructor(value: any, errors?: string[]);
/**
* The map function for Fail preserves the value without mapping anything over it, and accumulates errors on the side.
*/
map(): Fail;
/**
* The .chain() for Fail takes another Success or Fail, then combines the results.
*/
chain(validationM: (v: any, e?: string[]) => ValidationM): ValidationM;
/**
* After checks are done, this method is used to extract the value
* with a function that operates on it.
*/
fold({ onFail }: ValidationActions): any;
}
export { Fail };