simple-body-validator
Version:
This package is inspired by Laravel validation, and aims to make body validation easier for Javascript developers
58 lines (57 loc) • 1.5 kB
TypeScript
import { ErrorMessage, Errors, Messages, GenericObject } from '../types';
declare class ErrorBag {
/**
* All of the registered messages.
*/
errors: Errors;
/**
* All Messages
*/
messages: Messages;
/**
* Stores the first error message
*/
firstMessage: string;
/**
* Specify whether error types should be returned or no
*/
withErrorTypes: boolean;
constructor(errors?: Errors, messages?: Messages, firstMessage?: string, withErrorTypes?: boolean);
/**
* Set withErrorTypes attribute to true
*/
addErrorTypes(): ErrorBag;
/**
* Add new recodrs to the errors and messages objects
*/
add(key: string, error: ErrorMessage): void;
/**
* Get the first error related to a specific key
*/
first(key?: string): string;
/**
* Get the error messages keys
*/
keys(): string[];
/**
* Get all the messages related to a specific key
*/
get(key: string, withErrorTypes?: boolean): ErrorMessage[] | string[];
/**
* Check if key exists in messages
*/
has(key: string): boolean;
/**
* Get all error messages
*/
all(allMessages?: boolean, withErrorTypes?: boolean): GenericObject;
/**
* Remove error messages
*/
clear(keys: string[]): ErrorBag;
/**
* Clone ErrorBag Instance
*/
clone(): ErrorBag;
}
export default ErrorBag;