@nethesis/vue-components
Version:
This library contains: - a collection of Vue 3 components based on [Flowbite](https://flowbite.com/) - a set of utility functions
63 lines • 2.42 kB
TypeScript
import { type ComputedRef, type MaybeRefOrGetter } from 'vue';
/**
* A single password rule: a stable key, the text shown to the user and the predicate that
* decides whether the password satisfies it.
*/
export type NePasswordRequirement = {
key: string;
label: string;
validate: (password: string) => boolean;
};
/**
* A requirement paired with the outcome of its predicate for the current password.
*
* Note this is a plain boolean: whether an unmet requirement should look merely pending or
* clearly failed is a presentation concern, handled by NePasswordRequirements' showErrors prop.
*/
export type NePasswordRequirementStatus = {
key: string;
label: string;
met: boolean;
};
/**
* Overrides for the labels of the default requirements. The library ships no i18n, so
* translated strings are supplied by the caller.
*/
export type NePasswordRequirementLabels = {
minLength?: string;
uppercase?: string;
lowercase?: string;
number?: string;
specialCharacter?: string;
};
/**
* The five requirements from the design, as a plain array.
*
* Exported so that callers can compose on top of them instead of rebuilding the set: spread the
* result, append or drop rules, and pass it back as the `requirements` option of
* usePasswordRequirements.
*/
export declare function defaultPasswordRequirements({ minLength, labels }?: {
minLength?: number;
labels?: NePasswordRequirementLabels;
}): NePasswordRequirement[];
/**
* Evaluates a set of password requirements against a password, reactively.
*
* Pair it with NePasswordRequirements to render the checklist, and gate form submission on
* isValid.
*
* @param password the password to check, as a plain string, ref or getter
* @param options.minLength minimum length for the default `minLength` requirement (defaults to 8)
* @param options.labels label overrides for the default requirements, for i18n
* @param options.requirements replaces the default requirements entirely
*/
export declare function usePasswordRequirements(password: MaybeRefOrGetter<string>, options?: {
minLength?: MaybeRefOrGetter<number>;
labels?: MaybeRefOrGetter<NePasswordRequirementLabels>;
requirements?: MaybeRefOrGetter<NePasswordRequirement[]>;
}): {
requirements: ComputedRef<NePasswordRequirementStatus[]>;
isValid: ComputedRef<boolean>;
};
//# sourceMappingURL=usePasswordRequirements.d.ts.map