Files
SnowLuma/.pnpm-store/v11/files/80/609b5e27039bd692bcdf66b7538401129122378b30865db80f44a926e2c7c8545030ce6f7e30112af25b1e825f1c305ec4bbd4e5b46ea30f6eb5c80cfae9fb
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

58 lines
2.2 KiB
Plaintext

import Matching from './Matching.mjs';
import { TimeEstimates } from './TimeEstimates.mjs';
import Feedback from './Feedback.mjs';
import Options from './Options.mjs';
export { default as debounce } from './utils/debounce.mjs';
import Scoring from './scoring/index.mjs';
export { MatcherBaseClass } from './types.mjs';
const time = () => new Date().getTime();
class ZxcvbnFactory {
constructor(options = {}, customMatchers = {}) {
this.options = new Options(options, customMatchers);
this.scoring = new Scoring(this.options);
this.matching = new Matching(this.options);
this.feedback = new Feedback(this.options);
this.timeEstimates = new TimeEstimates(this.options);
}
estimateAttackTimes(guesses) {
return this.timeEstimates.estimateAttackTimes(guesses);
}
getFeedback(score, sequence) {
return this.feedback.getFeedback(score, sequence);
}
createReturnValue(resolvedMatches, password, start) {
const matchSequence = this.scoring.mostGuessableMatchSequence(password, resolvedMatches);
const calcTime = time() - start;
const attackTimes = this.estimateAttackTimes(matchSequence.guesses);
return {
calcTime,
...matchSequence,
...attackTimes,
feedback: this.getFeedback(attackTimes.score, matchSequence.sequence)
};
}
main(password, userInputs) {
const userInputsOptions = this.options.getUserInputsOptions(userInputs);
return this.matching.match(password, userInputsOptions);
}
check(password, userInputs) {
const reducedPassword = password.substring(0, this.options.maxLength);
const start = time();
const matches = this.main(reducedPassword, userInputs);
if (matches instanceof Promise) {
throw new Error('You are using a Promised matcher, please use `zxcvbnAsync` for it.');
}
return this.createReturnValue(matches, reducedPassword, start);
}
async checkAsync(password, userInputs) {
const reducedPassword = password.substring(0, this.options.maxLength);
const start = time();
const matches = await this.main(reducedPassword, userInputs);
return this.createReturnValue(matches, reducedPassword, start);
}
}
export { Options, ZxcvbnFactory };
//# sourceMappingURL=index.mjs.map