@costilladante/password-validator
Version:
A customizable React password validator component with accessibility features
67 lines • 2.29 kB
TypeScript
/**
* Base abstract class for password validation rules.
* Each rule must implement a `validate` method returning `null` if the password is valid,
* or an error message if not.
*/
export declare abstract class Rule {
name: string;
message: string;
/**
* @param name - A name for the rule
* @param message - The message to return when validation fails
*/
constructor(name: string, message: string);
/**
* Validates the password against the rule.
* @param password - The password to validate
* @returns `null` if valid, or an error message if invalid
*/
abstract validate(password: string): string | null;
}
/**
* A rule that validates using a RegExp.
*/
export declare class RegExpRule extends Rule {
private pattern;
/**
* @param name - A name for the rule
* @param message - The message to return when validation fails
* @param pattern - The regular expression to validate the password against
*/
constructor(name: string, message: string, pattern: RegExp);
/** @inheritdoc */
validate(password: string): string | null;
}
/**
* A rule that validates the password using a custom function.
*/
export declare class FunctionRule extends Rule {
private validator;
/**
* @param name - A name for the rule
* @param message - The message to return when validation fails
* @param validator - A function that returns true if the password is valid
*/
constructor(name: string, message: string, validator: (password: string) => boolean);
/** @inheritdoc */
validate(password: string): string | null;
}
/**
* A set of validation rules to be applied to a password.
*/
export declare class RuleSet {
rules: Rule[];
/**
* Validates the password against all rules.
* @param password - The password to validate
* @returns An array of error messages for each failed rule, or an empty array if all pass
*/
constructor(rules: Rule[]);
/**
* Validates the password against all rules.
* @param password - The password to validate
* @returns An array of error messages for each failed rule, or an empty array if all pass
*/
validate(password: string): string[];
}
//# sourceMappingURL=ruleTypes.d.ts.map