npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

unlock-client

v3.1.1

Published

A frontend javascript library for authenticating with Unlock

Downloads

2

Readme

Unlock

A client side library for authenticating with Unlock

This is a library to include in your frontend which will open a WebSocket connection to your Unlock enabled server and get you up and running with simple, socket-based, passwordless authentication.

It handles state management, UI, and allows users to sign up for Unlock directly from your site.

If you haven't set up your server for Unlock yet, check out the website for more information and documentation.

Build Status

Installing

Download unlock.css and unlock.js, then include them in the relevant places

...
<link rel="stylesheet" href="unlock.css" />
...
<script type="text/javascript" src="unlock.js"></script>
...

Unlock is also available via npm:

npm install unlock-client

Usage

This library exports an object, Unlock, to the global space which you interact with to create connections. The object has a single function init that you call with an options object to specify its behaviour.

You need to include an input element for the user's email address, as well as a div with the id unlock-button where you would like the button to appear. The input and button do not need to appear together. You should only include one instance of Unlock on a page.

...
<div>
    <input type="email" id="email" />
    <div id="unlock-button"></div>
</div>
...
<script>
Unlock.init({
    url: 'ws://localhost',
    email: '#email',
    onMessage: function(data){
        console.log(data);
    }
});
</script>
...

API

var unlocker=new Unlock(options)

Constructs a new Unlock object with the specified options. The behaviour can be set as follows:

| Name | Type | Attributes | Default | Description | | ---- | ---- | ---------- | ------- | ----------- | | url | string | required | - | The url for the socket to connect to. This is the url of your WebSocket server which communicates with Unlock. | | email | string | required | - | The id of the input element where the user enters their email address. Should contain a leading hash. For example: '#email' | | onMessage | function | required | - | A function to be called when the socket receices data. The function is passed one argument: onMessage(data) It is the data that was sent through the socket. If the data was JSON, Unlock will parse it first and onMessage will be called with the object, otherwise onMessage will be called with whatever was sent. Typical actions would be storing an authentication cookie and refreshing/redirecting, or handling any errors that occurred. You can then decide whether or not you'd like to close the socket connection from either end. | | submitOnEnter | boolean | optional | false | Set this to true if you would like users to be able to submit Unlock requests by pressing enter in the input specified by email | | whatsThis | boolean | optional | false | If this is true, it will add a link to Unlock to give new users a way to get acquainted with the system | | color | string | optional | '#2f81c6' | The background color of the button. Unlock will also automatically set the :hover and :active states to be lighter and darker than the specified color, respectively. Accepted inputs are hex (3 or 6 characters), and rgb() | | extra | object | optional | - | An object containing extra data to be sent through the socket. Sent to the server as extra along with the required type and email |

Compatibility

This library uses some modern features that browsers like IE11 don't support:

I would be happy to review pull requests to increase compatibility or start another repo for legacy browsers.

Running tests

Clone the repo and run

npm install
npm test

This will start an echo WebSocket server on localhost:3456 and stop it once the tests are finished

License

MIT

Copyright (c) 2019 Shane Brass