Coder Social home page Coder Social logo

zxcvbn-async's Introduction

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

zxcvbn-async's People

Contributors

xurei avatar

Stargazers

Afif Abdillah Jusuf avatar Masaki Hara avatar Jani Komulainen avatar Tahara Yoshinori avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

mlogan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.