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

form-validations

v1.1.0

Published

Form validation done right

Readme

Build Status NPM version

Form validation in 1KB

A library that makes form validation fun again. When trying out various different form validation libraries, I didn't found one where one could easily change different rules, and customize the error messages as well.

Simple example:

import { validString } from "form-validations";

const isString = validString("not a string"); // Simple helper for custom messages

isString("hello world!"); // Returns: []. No errors means field is valid
isString(1234); // Returns: ["not a string"]

A more complex example with chained validations:

import { chain, firstError, validString } from "form-validations";

const isString = validString("not a string");

// Custom validator
function isHello(value) {
  if (!/hello/g.test(value)) {
    return "value does not contain 'hello'";
  }

  return true;
};

// Collect all errors
const validate = chain(isString, isHello);

validate("hello world!"); // Returns: []. No errors means field is valid
validate(1234); // Returns: ["not a string", "value does not contain 'hello'"]

// Stop on first error
const validate = firstError(isString, isHello);
validate(1234); // Returns: ["not a string"]

This library was built to allow easy chaining of validations.

API

chain(...validators): string[]

Easily chain validators together. Each validator can push an error message to the resulting array.

firstError(...validators): string[]

Contrary to chain this function will stop at the first validator that returns an error. The resulting string array will always have a length of 1.

Available validations

Each validation function must return either true or an error message of type string.

| Validation | Check if | |---|---| | validString | ...value is a string | | validNumber | ...value is a number | | validBool | ...value is a boolean | | validDateFormat | ...value has format: YYYY-MM-DD | | validDateTimeFormat | ...value has format: YYYY-MM-DD hh:mm:ss | | validDateUTCFormat | ...value has format YYYY-MM-DDThh:mm:ssZ | | oneOf | ...value is inside the specified array | | required | ...value is not empty, undefined or null|

Available normalizers

Often you need to normalize data when dealing with form elements.

import { normalizeBoolean } from "form-validations";

normalizeBoolean("false"); // returns false;
normalizeBoolean(1); // returns true;
normalizeBoolean([]); // returns false;

| Normalize | description | |---|---| | normalizeBoolean | Returns a boolean |

LICENSE

MIT, see LICENSE.md