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

jforms

v0.0.5

Published

A package to create forms with validation and filtering.

Readme

jForms

A package to create Bootstrap compatible forms with validation and filtering for NodeJS.

You can use this package with the ExpressJS framework or any other framework of your choice.

For validation and filtering, you can use the validator (npm install validator) package, it comes with several handy methods. You can also use your own functions of course.

This package was build in a quick and dirty way to suit my needs for several projects, and it's still a great way to get started. Any improvements or suggestions are welcome.

Installation

npm install jforms

Using jForms

var validator = require('validator'); // Not required but preferred since it comes with many validation functions
var jForms = require('jforms');

// Create the form
var myForm = new jForms({
	firstname: {
		label: 'firstname'
	},
	email: {
		label: "Email",
		required: true,
		filters: [
			validator.trim, 
			function(val){ // Custom filter
				return val.toLowerCase();
			}
		],
		validators: [
			validator.isEmail
		]
	},
	submit: {
		value: "Send",
		icon: "fa fa-check",
		className: "btn btn-primary"
	}
});

// Handle data
var data = { // Some dummy data to test against
	firstname: 'John Doe',
	email: '[email protected]'
};
myForm.handle(data, function(errors, filteredValues){
	if(errors){
		console.log("Invalid data");
	}
});

Displaying the form

jForms has the toString method defined so you can just print out your form variable to display the form.

console.log(myForm);
// or
console.log(myForm.toString());

Full example

var v = require('validator');
var jForms = require('jforms');

var formJSON = {
  firstname: {
    label: "First name",
    required: true,
    validators: [v.isAlpha],
    filters: [v.trim],
    message: "Please enter your first name",
    placeholder: "Your full name"
  },
  lastname: {
    label: "Last name",
    required: true,
    message: "Please enter your last name"
  },
  password: {
    label: "Password",
    type: "password",
    required: true
  },
  message: {
    label: 'Message',
    value: 'Hello World',
    type: 'textarea',
    filters: [v.trim],
    rows: 10
  },
  gender: {
    label: 'Gender',
    type: 'radio',
    value: 'f',
    options: {
      m: 'Male',
      f: 'Female',
    }
  },
  color: {
    label: 'Color',
    type: 'checkbox',
    value: ['red', 'blue'],
    options: {
      red: 'Red',
      green: 'Green',
      blue: 'Blue',
    }
  },
  region: {
    label: 'City',
    type: 'select',
    value: 'ny',
    name: "city", // This will override the key used for this field
    options: {
      '': 'Select your region',
      ny: 'New York',
      cal: 'California',
    }
  },
  submit: {
    value: "Send message",
    className: "btn btn-primary",
    icon: 'fa fa-check'
  }
};

var myForm = new jForms(formJSON);

myForm.enctype = "multipart/form-data";
myForm.method = "post";
myForm.className = "form-horizontal";
myForm.leftSize = "col-sm-2"; // Size for label in horizontal forms
myForm.rightSize = "col-sm-10"; // Size for field in horizontal forms
myForm.id = "myForm";

console.log("Is form valid ? " + myForm.isValid); // Useless before calling 'handle' method
console.log("Was the form submitted ? " + myForm.isSubmitted);

myForm.handle(req.body, function(errors, values){
	if(errors){
		console.log("Invalid form");
	}
	else{
		// Save data maybe ?
	}      
});