UNPKG

guarder

Version:

Guarder provides simple validation logic to reduce clutter with inline guard statements

52 lines 2.16 kB
import { Guard } from './types/Guard'; import { Instantiable } from './types/Instantiable'; /** * Guarder provides various guards which can be used for quick validation of data */ declare class Guarder { /** * Default built-in guards */ private static guards; /** * Returns the property if the property is not null. Throws an error if the property is null. */ static null<T = unknown>(property: T, message?: string, error?: Instantiable<Error>): T; /** * Returns the property if the property is not undefined. Throws an error if the property is undefined. */ static undefined<T = unknown>(property: T, message?: string, error?: Instantiable<Error>): T; /** * Returns the property if the property is not an empty string, object, array, undefined or null. Throws an error if * the criteria is not met. */ static empty<T = unknown>(property: T, message?: string, error?: Instantiable<Error>): T; /** * Returns the property if the property does not evaluate to false in a type coercion */ static falsy<T = unknown>(property: T, message?: string, error?: Instantiable<Error>): T; /** * Returns the property if the property passes the custom guards validation logic and will throw an Argument Error or * custom error if specified */ static custom<T = unknown>(guardName: string, property: T, message?: string, error?: Instantiable<Error>): T; /** * Returns the property if the property passes the custom guards validation logic and will throw an Argument Error or * custom error if specified */ static guard<T = unknown>(guard: Instantiable<Guard>, property: T, message?: string, error?: Instantiable<Error>): T; /** * Get all registered guards */ static getRegisteredGuards(): string[]; /** * Remove a guard from the guard map */ static unregisterGuard(guardName: string): void; /** * Register custom unique guard in the guard map */ static registerGuard(guardName: string, guard: Instantiable<Guard>): void; } export { Guarder }; //# sourceMappingURL=Guarder.d.ts.map