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 🙏

© 2025 – Pkg Stats / Ryan Hefner

cerebral-form

v0.1.24

Published

A boilerplate for Cerebral

Readme

#Cerebral Form

##Philosophy: The inputs are first class citizens, not the "form". You determine where their state lives, and what forms, if any, they connect to.

##Known Issue: If one input needs to be re-validated after another input changes, that can work via the "linkTo" option. The linkTo option currently only supports just 1 linked input per input.

##Usage: npm i -S cerebral-form

import InputWrapper from 'cerebral-form/InputWrapper'; //The wrapper is for react only, but could easily be ported to another UI lib
var MyInput = InputWrapper(function MyInput (props) {
  return (
        <input {...props}>
        </input>
    );
},{
  path: ['path','you','choose'], //the **only** required property. Input state is stored at this path
  form: 'form1', //or  ['form1','form2'] register the input with one or more forms
  validation: {
    'isEmail': "Please provide a valid email", //name and message of desired validation
    'userDefined': "This field must match another user defined field"
    'validationWithOptions': {
    	anything: 'canGoHere'
    	message: "This field must match another user defined field"
    }
  },
  asyncValidation: 'isNonGmail', //can only register 1 async validation per form
  validateImmediately: false, //by setting this to false, validation will only occur after the element has been visited, instead of on every change
  linkTo: ['anotherInput'] //re-run the validation for the input at path ['anotherInput'] whenever this element is modified
})

A list of available props available to the input are:

  • onChange: function onChange()
  • onBlur: function onBlur()
  • value: "hahah"
  • completed: false //false unless default value provided
  • errors: { isEmail: "Please provide a valid email" }
  • hasError: false
  • visited: false
  • checked: false

##Checking if a form has been completed:

import {formCompleted} from 'cerebral-form'; //this is a cerebral computed function
@Cerebral(formCompleted: formCompleted('form1')}) //use it like a normal computed function, passing the name of the form

##Hooking up the module + setting up validation:

import CerebralForm from 'cerebral-form';
import validator from 'validator'; 
controller.modules({
	cerebralForm: CerebralForm({
		validation: { //define simple validations here
			...validator, //use an external library like "validator" for many built in validations
			isEmail: function (value, state, options) { //define your own validations as well
				if (value.indexOf('@') > -1) {
					return true //no error
				} else {
					return false //error
				}
			}, 
			userDefined: function (value, state, options) {
				if (value === state.get('userDefinedString')) { //access any other values withing the state tree
					return true
				} else {
					return false
				}
			}
			validationWithOptions: function (value, state, options) {
				console.log(options.anything)
				// "canGoHere"
				return true;
			}
		},
		asyncValidation: { //define async validations here as cerebral action chains
			isNonGmail: [
		        [function({
		          input, output
		        }) {
		          //fake talking to backend
		          setTimeout(function() {
		            if (input.value.indexOf('gmail') > -1) {
		              output({
		                asyncError: {
		                  message: 'The email ' + input.value + ' cannot have gmail in the name'
		                }
		              })
		            } else {
		              output()
		            }
		          }, 300)
		        }]
		      ]
		}
	}),
});