export type RuleFunction = (arg: T) => boolean | string; type ValidRuleKeys = { [K in keyof T]: T[K] extends RuleFunction ? (ReturnType extends boolean | string ? K : never) : never; }[keyof T]; /** the name of a valid rule based on the return type of getRules */ export type RulesName = ValidRuleKeys; /** either allow a rule name or a rule function */ export type RuleType = (RulesName | RuleFunction)[]; /** A rule's error text, or a function building it from the rule's parameters. */ export type RuleMessage

= string | ((params: P) => string); export interface RuleMessages { eq: RuleMessage<{ nb: number; }>; neq: RuleMessage<{ nb: number; }>; gt: RuleMessage<{ nb: number; }>; gte: RuleMessage<{ nb: number; }>; lt: RuleMessage<{ nb: number; }>; lte: RuleMessage<{ nb: number; }>; email: RuleMessage; isCode: RuleMessage; isDateBetweenHours: RuleMessage<{ minHour: number; maxHour: number; include: boolean; }>; isInteger: RuleMessage; isNumber: RuleMessage; isSlug: RuleMessage; isWeekDay: RuleMessage; lowercase: RuleMessage; isUrl: RuleMessage; isUrlSecured: RuleMessage; isUrlProtocol: RuleMessage<{ protocols: string[]; }>; maxLength: RuleMessage<{ length: number; }>; minLength: RuleMessage<{ length: number; }>; phone: RuleMessage; required: RuleMessage; isAfterDay: RuleMessage<{ date: Date; include: boolean; }>; isAfterToday: RuleMessage<{ include: boolean; }>; isBetweenDays: RuleMessage<{ minDate: Date; maxDate: Date; include: boolean; }>; } /** `FR` takes French numbers, national or `+33`; `E164` an international `+` number, separators allowed. */ export declare const PHONE_FORMATS: { FR: RegExp; E164: RegExp; }; export type PhoneFormat = keyof typeof PHONE_FORMATS | RegExp; export interface IsUrlOptions { /** Accepted `URL.protocol` values, colon included. Defaults to `http:` and `https:`. */ protocols?: string[]; } declare function compareNumber(comparator: 'lt' | 'gt' | 'gte' | 'lte' | 'eq' | 'neq', nb: number): RuleFunction; export declare class Rules { static compareNumber: typeof compareNumber; /** Replaces some or all of the default messages, e.g. with translations; later rule calls use them. */ static setMessages: (messages: Partial) => void; /** Puts every message back to its English default. */ static resetMessages: () => void; /** Wraps any rule so a failure reads `message` instead, built from the value when a function. */ static withMessage: (rule: RuleFunction, message: string | ((value: T) => string)) => RuleFunction; static email: (value?: string | null) => boolean | string; static isCode: (value?: string | null) => boolean | string; static isDateBetweenHours: (minHour?: number, maxHour?: number, include?: boolean) => (date?: Date | null) => string | true; static isInteger: (strict?: boolean) => (value?: string | number | null) => boolean | string; static isNumber: (value?: string | number | null) => boolean | string; static isSlug: (value?: string | null) => boolean | string; static isWeekDay: (date?: Date | null) => string | true; static lowercase: (value?: string | null) => boolean | string; /** `secured` alone requires `https:`; options pick the accepted protocols. */ static isUrl: (str: string, secured?: boolean | IsUrlOptions) => true | string; static max: (nb: number, eq?: boolean) => RuleFunction; static maxLength: (length: number) => (value?: string | readonly unknown[] | null) => string | true; static min: (nb: number, eq?: boolean) => RuleFunction; static minLength: (length: number) => (value?: string | readonly unknown[] | null) => string | true; static nonEmptyString: (value?: string | null) => boolean | string; static nonZero: (value?: number | null) => boolean | string; /** French numbers by default; `format` takes `E164` or a pattern of your own. */ static phone: (value?: string | number | null, format?: PhoneFormat) => boolean | string; static required: (value?: unknown) => boolean | string; static isAfterDay: (date: Date, include?: boolean) => (value?: Date | null) => string | true; static isAfterToday: (include?: boolean) => (value?: Date | null) => string | true; static isBetweenDays: (minDate: Date, maxDate: Date, include?: boolean) => (value?: Date | null) => string | true; } export {}; //# sourceMappingURL=rule.d.ts.map