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

reformer-username

v0.1.1

Published

Field plugin for reformer, that handles the annoying problem of username validataion in forms.

Readme

reformer-username

A plugin for reformer to handle the super annoying problem of username validation testing while filling out a form.

The problems:

  1. You want to run a debounced check as a user is typing into the field.
  2. You want to validate that with some server-side check. But, you also have to account for the fact that results may come back out of order. So we only care about results for requests that checked the current data.
  3. You want a hard enforcement check before submitting the form.
  4. You want to support existing data in the form and not check if it's just the same value as when you started.
  5. If it violates simple formatting rules you don't want to do the server-side check at all.
  6. You want to be able to customize a message saying that the username they picked is, or isn't available.
  7. You want to be able to show that container whenever something relevant is happening, but not if there's nothing wrong.
  8. You want to be able to show a spinner or some type of loading graphic when the server checks are happening.

Installing

You can grab it on npm and use it with browserify:

npm i reformer-username

Or just grab the file from dist/reformer.usernamefield.js which will work with AMD or as a standalone.

How to use

var profileForm = new Reformer({
    // pass existing data to form if it exists
    data: existingData,
    fields: [
        // our plugin returns a normal field definition
        // but with all our extra magic.
        // Any options you pass to the plugin that the
        // plugin doesn't use, simply gets passed onto
        // the field definition like reformer does normally.
        // So you can pass any valid field options in here too
        // such as the `fieldContainer` in this example or
        // a `setup` function, etc.
        reformerUsernameField({
            // normal field definition stuff
            name: 'username',
            label: 'Username',
            fieldContainer: $('.userNameField')[0],
            placeholder: 'helpy',
            // whether or not to test if we have the same value as
            // or initial data for the form.
            ignoreSame: true,

            // this will get called with the first argument being:
            //  - true if we checked and it's available
            //  - false if we checked and it's not available
            //  - '' if nothing has been entered, or if the value is unchanged from original data
            
            // so you might do something like what follows:
            handleResult: function (pass, passedMessage) {
                var message;
                var messageEl = $('#message');
                var messageWrapper = $('#messageWrap');

                if (pass === true) {
                    messageWrapper.show();
                    message = "Sweet, '" + this.value + "' is available!";
                    messageEl.removeClass('error').text(message);
                } else if (pass === false) {
                    messageWrapper.show();
                    message = passedMessage || "Sorry, '" + this.value + "' is taken.";
                    messageEl.addClass('error').text(message);
                } else {
                    messageEl.removeClass('error');
                    messageWrapper.hide();
                }
            },
            // whatever your actual serverside check is
            // the plugin will handle debouncing this and 
            // making sure only the correct result is used
            // It's just your job to supply the test that
            // takes the value and calls a callback
            asyncTest: function (val, cb) {
                $.get('/checkname?name=' + val, function (res) {
                    cb(res.available);
                });
            },
            // You can also supply a syncronous test. You should
            // return a string describing the error if it fails.
            syncTest: function (val) {
                if (!val.match(/^[a-zA-Z0-9_]+$/)) {
                    return 'Can only contain numbers, letters, and underscores.';
                }
            }
        }),
        // you just continue defining normal fields as follows
        {
            name: 'firstName',
            label: 'First name',
            placeholder: 'Helpy',
            fieldContainer: $('.firstNameContainer')[0],
            tests: [
                {
                    message: 'Must be less than 20 characters.',
                    test: function (val) {
                        return val.length <= 20;
                    }
                },
                {
                    message: 'Please enter your first name.',
                    test: function (val) {
                        return !!val.length;
                    }
                }
            ]
        }
    ],
    submit: function () {
        // our normal submit handler
    },
    error: function () {
        // normal global error handler
    }
};

// render our form
profileForm.render({
    formEl: $('form'),
    fieldContainer: $('.fields')
});

#misc

If you like this, follow @HenrikJoreteg :)

#license

MIT