UNPKG

nope-validator

Version:
26 lines (25 loc) 1.22 kB
import { NopeReference } from './NopeReference'; import { AsyncRule, Context, Nil, Rule, Validatable } from './types'; export declare abstract class NopePrimitive<T> implements Validatable<T> { protected validationRules: (Rule<T> | AsyncRule<T>)[]; protected _type: string; protected _entry: T | undefined; getType(): string; protected isEmpty(entry: T | Nil): boolean; required(message?: string): this; notAllowed(message?: string): this; when(keys: string[] | string, conditionObject: { is: boolean | ((...args: any) => boolean); then: NopePrimitive<any>; otherwise: NopePrimitive<any>; }): this; oneOf(options: (T | NopeReference | Nil)[] | NopeReference, message?: string): this; notOneOf(options: (T | NopeReference | Nil)[], message?: string): this; test(rule: Rule<T> | AsyncRule<T>): this; /** * @param entry - The value to be validated * @param context - Used for internal reference resolving. Do not pass this. */ validate(entry?: T | Nil, context?: Record<string | number, unknown>): string | undefined; validateAsync(entry?: T | Nil, context?: Context): Promise<string | undefined>; }