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

formdb

v0.2.0

Published

HTML form data binding with zero dependencies

Downloads

38

Readme

formdb

A simple HTML form data API with zero dependencies.

What is this?

Have you ever wanted to treat an HTML form as a data store? Well, I have, and everything else that I came across had big dependencies like jQuery. formdb provides a simple API for getting and setting data in a plain old HTML form using plain old DOM JavaScript.

An Example

<form>
  <p><label>Name: <input type="text" name="name"></label></p>
  <p><label>Age:
    <select name="age">
      <option>young</option>
      <option>old</option>
      <option value="">prefer not to say</option>
    </select></label>
  </p>
  <p>Skills:
    <label><input name="skills" value="js"> JavaScript</label>
    <label><input name="skills" value="python"> Python</label>
    <label><input name="skills" value="ruby"> Ruby</label>
  </p>
</form>
<script src="formdb.js"></script>
<script>

// create a Form instance bound to the CSS selector 'form'
var form = formdb.Form('form');

// set some properties
form.set('name', 'Alf');
form.set('age', 'old');
form.set('skills', ['js', 'python']);
form.set('xxx', 'blah blah blah');

// the values of the properties will come directly from the form
form.get('name') === 'Joe';
form.get('xxx') === null;

// or set multiple properties
form.setData({
  name: 'E.T.',
  age: 'young',
  skills: ['ruby']
});

// get all of the input values
var data = form.getData();

// listen for changes to any property
form.on('change', function(data, e) {
});

// or listen for changes to a specific one a la Backbone
form.on('change:name', function(name, e) {
});

</script>

Note: formdb only pays attention to form inputs with a name attribute. All of your inputs should have name attributes anyway. :trollface:

Form objects

Form objects created with the formdb.Form() constructor can get and set data in their respective HTML form.

formdb.Form(selector)

Create a new Form object bound to the HTML form identified by CSS selector. This works with or without the new keyword:

var form = formdb.Form(selector);
// or
var form = new formdb.Form(selector);

form.get(key)

Get the value of one or more fields with the name attribute equal to key. The returned value may differ depending on the type of the inputs:

  • checkbox inputs (<input type="checkbox" name>):
    • if there's only one checked, the value will be the input's value iff it is checked (true if it has no value)
    • if there are more than one checkbox checked, the value will be an array of the the checked inputs' values
  • radio inputs (<input type="radio" name>):
    • like checkboxes, the value will be undefined if the input is not checked; otherwise, the value will be the inputs value or true if it has none
  • select-one inputs (<select name>):
    • Because select inputs without the multiple attribute cannot be unset, the value will always be the value of the input's selected option.
  • select-multiple inputs (<select multiple name>):
    • Multi-select inputs will always be expressed as an array of option values. If no options are selected, the value will be an empty array.
  • all other inputs are assumed to have a value property which is returned as-is.

form.set(key, value)

Set the value of one or more fields with the name attribute equal to key. The rules for form.get() apply here, with one notable exception:

  • checkbox inputs (<input type="checkbox" name>):
    • If there are multiple checkboxes with the same name and only one is checked, the return value will be a string literal (the value of the checked box).

form.getData()

Returns an object with key/value pairs for each of the uniquely named inputs in the form.

form.setData(data)

Sets input values for each key in the object data according to the rules described in form.set().

form.on(event, callback)

Listen for events on the form. These ones are handled specially:

  • change: this adds a change listener to the underlying form element and calls callback(data, e) with the form's data.
  • change:{key}: this adds a change listener to the underlying form that calls callback(value, e) with the changed input's value if its name is equal to key.

form.off(event, callback)

Remove a listener added with form.on(). You'll need to keep a reference to your callback function in order to remove it:

var onchange = function(data) { /* ... */ };
form.on('change', onchange);
form.off('change', onchange);

Contributing

Wanna help make this better? Awesome! Here's how:

  1. Fork this repo
  2. Run npm install --dev to install the development dependencies
  3. Run npm test to run the tests
  4. Issue a pull request
  5. Profit?