A Webpack/Browserify/... asynchronous loader for zxcvbn
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.
$ npm install zxcvbn
zxcvbn-async
provides two modes of operation : async and mimic sync.
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.
var zxcvbnAsync = require('zxcvbn-async');
zxcvbnAsync.load({}, function(err, zxcvbn) {
var results = zxcvbn(password, user_inputs);
});
var zxcvbnAsync = require('zxcvbn-async');
zxcvbnAsync.load({})
.then((zxcvbn) => {
var results = zxcvbn(password, user_inputs);
});
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
}
Loads the library if not done yet.
options
:
sync
: Iftrue
, uses the mimic sync mode. (default:false
)libUrl
: If set, the path of the library (default: the latest version from CDNJS, currently4.4.2
)libIntegrity
: If set, the integrity checksum for libUrl. Subresource Integrity
cb
: function(err, zxcvbn)
err
: error object, if anyzxcvbn
: thezxcvbn
function (See the zxcvbn docs for details)
- Write tests