Skip to content

A Webpack/Browserify/... asynchronous loader for zxcvbn

License

Notifications You must be signed in to change notification settings

xurei/zxcvbn-async

Repository files navigation

zxcvbn-async

npm GitHub issues GitHub license Codacy grade

Donate

A Webpack/Browserify/... asynchronous loader for zxcvbn

Motivation

As the zxcvbn docs states, the zxcvbn package should not be included in your bundle.

This modules loads the library from CDNJS (by default) when it is required by your application.

Installation

$ npm install zxcvbn

Usage

zxcvbn-async provides two modes of operation : async and mimic sync.

Async mode (recommended)

This mode is the typical one when working with async code in JS. It's the recommended one for a new project or if you don't have to rewrite a lot of code.

With Old-school callbacks

var zxcvbnAsync = require('zxcvbn-async');

zxcvbnAsync.load({}, function(err, zxcvbn) {
    var results = zxcvbn(password, user_inputs);
});

With Promises

var zxcvbnAsync = require('zxcvbn-async');

zxcvbnAsync.load({})
.then((zxcvbn) => {
    var results = zxcvbn(password, user_inputs);
});

Mimic sync

This mode mimics the synchronous loading of zxcvbn. If you try to use it before the library has loaded, the result object will be filled with -1 values.

var zxcvbnAsync = require('zxcvbn-async');
var zxcvbn = zxcvbnAsync.load({ sync: true });

If the library hasn't loaded yet, the result will be :

result = {
	guesses: -1,
	guesses_log10: -1,
	crack_times_seconds: -1,
	crack_times_display: -1,
	score: -1,
	feedback: null,
	sequence: [],
	calc_time: 0
}

API

zxcvbnAsync.load(options, cb)

Loads the library if not done yet.

options :

  • sync : If true, uses the mimic sync mode. (default: false)
  • libUrl : If set, the path of the library (default: the latest version from CDNJS, currently 4.4.2)
  • libIntegrity : If set, the integrity checksum for libUrl. Subresource Integrity

cb : function(err, zxcvbn)

  • err : error object, if any
  • zxcvbn : the zxcvbn function (See the zxcvbn docs for details)

Contributors

TODO

  • Write tests

About

A Webpack/Browserify/... asynchronous loader for zxcvbn

Resources

License

Stars

Watchers

Forks

Packages

No packages published