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 🙏

© 2024 – Pkg Stats / Ryan Hefner

formalistic

v2.0.0

Published

Handle form data and form validation

Downloads

50

Readme

formalistic   NPM version Coveralls Status Downloads

Model your form as an immutable data tree with validators and an explicit dirty/pristine state.

Installation | Usage | API | Changelog | Example Projects


Handling form state can be a pain. For this very reason, very many form libraries exist. Often times, these libraries are specific to one framework or the other, e.g. redux forms or Angular's form controllers. Other times, they constrain design choices by enforcing certain state management systems or custom components. This doesn't need to be the case.

With formalistic, you can model the conceptual idea of the form. Now, this sounds way more fancy than it actually is. Try to think about it this way: Look at the fields, how they are validated and how they structured and related. Remove the overhead of frameworks and components and model this with plain JavaScript. Turns out, when doing it this way, they are often pretty simple to reason about!

Installation

npm install --save formalistic

Usage

Formalistic is about modeling forms using plain JavaScript. The following example shows how this can be done for a simple login form.

import {createField, createMapForm, notBlankValidator} from 'formalistic';

const emailField = createField({
  value: '',
  validator(value) {
    if (isEmail(value)) {
      return null;
    }

    return [{
      severity: 'error',
      message: 'Please provide a valid email address.'
    }];
  }
});

const passwordField = createField({
  value: '',
  validator: notBlankValidator
});

const form = createMapForm()
    .put('email', emailField)
    .put('password', passwordField)

Forms are immutable and all interaction with forms, e.g. setting values on fields, will recreate the form. For instance, to update the value of the email field:

const updatedForm = form.updateIn(['email'], field =>
  field.setValue('[email protected]')
);

More details are available in the API documentation and the example apps

Why yet another library?

There is an unfortunately large amount of form libraries. I wasn't satisfied with the options available and I found that many of those made too many assumptions or imposed unnecessarily large restrictions. Here are a few bullet points which have driven the design of formalistic.

  • Do not dictate a framework, library or state management system.
  • Be interoperable and allow extensions for easier use with certain libraries.
  • Support different UX patterns, e.g. mark fields as dirty on change or mark fields as dirty on focus.
  • Support cross field validation.
  • Support efficient change detection for view and/or model diffing systems.