/** * Defines the configuration criteria used to validate a password. * @typedef {Object} PasswordRules * @property {boolean} requireLowercase - Whether lowercase letters are required. * @property {boolean} requireUppercase - Whether uppercase letters are required. * @property {boolean} requireNumbers - Whether numeric digits are required. * @property {boolean} requireSpecial - Whether special characters (@$!%*?&) are required. * @property {number} minLength - The minimum allowed length of the password. * @property {number} maxLength - The maximum allowed length of the password. */ export type PasswordRules = { /** * - Whether lowercase letters are required. */ requireLowercase: boolean; /** * - Whether uppercase letters are required. */ requireUppercase: boolean; /** * - Whether numeric digits are required. */ requireNumbers: boolean; /** * - Whether special characters (@$!%*?&) are required. */ requireSpecial: boolean; /** * - The minimum allowed length of the password. */ minLength: number; /** * - The maximum allowed length of the password. */ maxLength: number; }; export type PasswordStrength = 'strong' | 'medium' | 'weak'; export type HashText = (text: string) => Promise; export type ValidationResult = { /** * - Indicates if the password meets all configured requirements. */ isValid: boolean; /** * - Classification of the password strength. */ strength: PasswordStrength; /** * - List of error messages describing which requirements were not met. */ errors: string[]; /** * - List of error codes corresponding to the failed requirements. */ errorCodes: number[]; /** * - The number of requirements successfully met. */ score: number; /** * - The total number of points available based on the configuration. */ totalPossiblePoints: number; }; export type CustomValidator = { /** * - Unique identifier for the validator. */ id: string; /** * - Human-readable name of the validator. */ name: string; /** * - A function that takes a string and returns a ValidationResult. */ validate: (value: string) => ValidationResult; }; export type ManagerValidationResult = { /** * - True if all validators returned isValid: true. */ allPassed: boolean; /** * - The array of individual ValidationResult objects from each validator. */ details: ValidationResult[]; }; /** * Represents the qualitative assessment of a password's security level. * @typedef {'strong' | 'medium' | 'weak'} PasswordStrength */ /** * Represents an asynchronous callback function used to hash a string. * @callback HashText * @param {string} text - The plain text string to be hashed. * @returns {Promise} A promise that resolves to the resulting hashed string. */ /** * Represents the detailed outcome of a password validation check. * @typedef {Object} ValidationResult * @property {boolean} isValid - Indicates if the password meets all configured requirements. * @property {PasswordStrength} strength - Classification of the password strength. * @property {string[]} errors - List of error messages describing which requirements were not met. * @property {number[]} errorCodes - List of error codes corresponding to the failed requirements. * @property {number} score - The number of requirements successfully met. * @property {number} totalPossiblePoints - The total number of points available based on the configuration. */ /** * Defines the structure for a custom password validation object. * @typedef {Object} CustomValidator * @property {string} id - Unique identifier for the validator. * @property {string} name - Human-readable name of the validator. * @property {(value: string) => ValidationResult} validate - A function that takes a string and returns a ValidationResult. */ /** * Defines the result of executing multiple validators. * @typedef {Object} ManagerValidationResult * @property {boolean} allPassed - True if all validators returned isValid: true. * @property {ValidationResult[]} details - The array of individual ValidationResult objects from each validator. */ /** * A utility class for validating passwords against customizable security rules. */ declare class TinyPasswordValidator { #private; /** * Provides access to the raw regex pattern string. * @returns {string} */ static get fullPatternString(): string; /** * Provides access to the internal method that generates the RegExp instance. * @returns {function} */ static get getFullPattern(): Function; /** * Provides access to the static hashing function. * @returns {HashText} The current hashing function. */ static get hashText(): HashText; /** * Sets a new static hashing function. * @param {HashText} value - The new hashing function to be used. * @throws {TypeError} If the provided value is not a function. */ static set hashText(value: HashText); /** @returns {boolean} Whether lowercase letters are required. */ get requireLowercase(): boolean; /** @returns {boolean} Whether uppercase letters are required. */ get requireUppercase(): boolean; /** @returns {boolean} Whether numeric digits are required. */ get requireNumbers(): boolean; /** @returns {boolean} Whether special characters are required. */ get requireSpecial(): boolean; /** @returns {number} The minimum allowed length of the password. */ get minLength(): number; /** @returns {number} The maximum allowed length of the password. */ get maxLength(): number; /** * Adds a new validator to the manager. * @param {CustomValidator} validator - The validator object to add. * @throws {TypeError} If the validator does not match the CustomValidator typedef. */ add(validator: CustomValidator): void; /** * Removes a validator by its unique ID. * @param {string} id - The ID of the validator to remove. * @throws {TypeError} If the ID is not a string. */ remove(id: string): void; /** * Reorders the validators list by moving an item from one index to another. * @param {number} oldIndex - The current index of the validator. * @param {number} newIndex - The target index for the validator. * @throws {TypeError} If indices are not integers. * @throws {RangeError} If indices are out of bounds. */ reorder(oldIndex: number, newIndex: number): void; /** * Sorts the validators using a custom comparator function. * @param {(a: CustomValidator, b: CustomValidator) => number} comparator - A function that defines the sort order. * @throws {TypeError} If the comparator is not a function. */ sort(comparator: (a: CustomValidator, b: CustomValidator) => number): void; /** * Clears all validators from the manager. */ clear(): void; /** * Gets the total number of validators currently registered. * @returns {number} */ get size(): number; /** * Initializes a new instance of the TinyPasswordValidator with optional custom rules. * @param {Object} [customRules={}] - Initial configuration for the validator. * @param {boolean} [customRules.requireLowercase=true] - If true, at least one lowercase letter is required. * @param {boolean} [customRules.requireUppercase=true] - If true, at least one uppercase letter is required. * @param {boolean} [customRules.requireNumbers=true] - If true, at least one numeric digit is required. * @param {boolean} [customRules.requireSpecial=true] - If true, at least one special character (@$!%*?&) is required. * @param {number} [customRules.minLength=8] - The minimum allowed length of the password. * @param {number} [customRules.maxLength=128] - The maximum allowed length of the password. */ constructor(customRules?: { requireLowercase?: boolean; requireUppercase?: boolean; requireNumbers?: boolean; requireSpecial?: boolean; minLength?: number; maxLength?: number; }, hashText?: null); /** * Getter to access the current rules. * @returns {PasswordRules} */ get rules(): PasswordRules; /** * Setter to update rules with strict validation. * @param {PasswordRules} newRules - New configuration to merge. * @throws {TypeError} If the provided rules are invalid. */ set rules(newRules: PasswordRules); /** * Setter to update rules partialy with strict validation. * @param {Partial} newRules - New configuration to merge. * @throws {TypeError} If the provided rules are invalid. */ setRules(newRules: Partial): void; /** * Executes all registered validators against a single password. * @param {string} password - The password to be validated. * @returns {ManagerValidationResult} * @throws {TypeError} If the password is not a string. */ execute(password: string): ManagerValidationResult; /** * Validates a password based on the configured rules. * @param {string} password - The password to be validated. * @returns {ValidationResult} * @throws {TypeError} If the provided password is not a string. */ validate(password: string): ValidationResult; } export default TinyPasswordValidator; //# sourceMappingURL=TinyPasswordValidator.d.mts.map