index.esm.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Matching from './Matching.esm.js';
  2. import scoring from './scoring/index.esm.js';
  3. import TimeEstimates from './TimeEstimates.esm.js';
  4. import Feedback from './Feedback.esm.js';
  5. import zxcvbnOptions from './Options.esm.js';
  6. export { Options } from './Options.esm.js';
  7. export { default as debounce } from './debounce.esm.js';
  8. const time = () => new Date().getTime();
  9. const createReturnValue = (resolvedMatches, password, start) => {
  10. const feedback = new Feedback();
  11. const timeEstimates = new TimeEstimates();
  12. const matchSequence = scoring.mostGuessableMatchSequence(password, resolvedMatches);
  13. const calcTime = time() - start;
  14. const attackTimes = timeEstimates.estimateAttackTimes(matchSequence.guesses);
  15. return {
  16. calcTime,
  17. ...matchSequence,
  18. ...attackTimes,
  19. feedback: feedback.getFeedback(attackTimes.score, matchSequence.sequence)
  20. };
  21. };
  22. const main = (password, userInputs) => {
  23. if (userInputs) {
  24. zxcvbnOptions.extendUserInputsDictionary(userInputs);
  25. }
  26. const matching = new Matching();
  27. return matching.match(password);
  28. };
  29. const zxcvbn = (password, userInputs) => {
  30. const start = time();
  31. const matches = main(password, userInputs);
  32. if (matches instanceof Promise) {
  33. throw new Error('You are using a Promised matcher, please use `zxcvbnAsync` for it.');
  34. }
  35. return createReturnValue(matches, password, start);
  36. };
  37. const zxcvbnAsync = async (password, userInputs) => {
  38. const usedPassword = password.substring(0, zxcvbnOptions.maxLength);
  39. const start = time();
  40. const matches = await main(usedPassword, userInputs);
  41. return createReturnValue(matches, usedPassword, start);
  42. };
  43. export { zxcvbn, zxcvbnAsync, zxcvbnOptions };
  44. //# sourceMappingURL=index.esm.js.map