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

another-simple-validator

v0.2.3

Published

Simple JS form validator

Readme

another-simple-validator

Simple JS form validator is style-agnostic form field validator. Styling of inputs responding to their validity state is up to you, library provides only js logic for validation. By default it will add .dirty class to inputs which were manipulated by user, and .error class to mark invalid ones, but you can change these classes in library config.

Demo

  1. Clone repository
  2. Run npm install
  3. Run npm run dev

You should see test form, which you can modify to your needs to test validator.

Basics

Installation

With npm

Run npm i another-simple-validator.

import SimpleVal from 'another-simple-validator';
const form = new SimpleVal({});

Classic js

  1. Download simpleval.dist.js from dist directory and copy it into your project directory
  2. Include it in html:
<script src="./simpleval.dist.js"></script>
  1. Create form object with SimpleVal constructor
const form = new SimpleVal({
  ...formOptions
});

Supported field types

  • inputs: text, email, password
  • select-one
  • textarea
  • radio
  • checkbox

Available validators

{
  minLength: 6,
  maxLength: 10,
  numericality: true,
  regex: /^[^\D]\d{0,9}((\.|,)\d{1,})?$/
}

Configuration

First we create form fields with unique name and id attributes for each field (except for radio buttons where we use one name for whole group of buttons).

<select id="form__subject" name="subject">
  <option disabled selected value>Select subject</option>
  <option value="subject-1">Subject #1</option>
  <option value="subject-2">Subject #2</option>
</select>

<input type="text" id="form__name" name="name" />
<input type="email" id="form__email" name="email" />

<input type="radio" id="radio1" name="radiogroup" value="radio1" />
<label for="radio1">Radio #1</label>
<input type="radio" id="radio2" name="radiogroup" value="radio2" />
<label for="radio2">Radio #2</label>

We also have to add a button that will handle form submision. By default I have added .disabled class to the btn, which will be toggled during validations.

<button type="submit" class="form__btn disabled">Submit</button>

Next, we setup our form by passing options object to new Form constructor.

import Form from './scripts/simpleval.dist.js';

const formConfig = {
  fields: [
    {
      selector: '#form__subject',
      options: {
        required: true
      }
    },
    {
      selector: '#form__name'
    },
    {
      selector: '#form__email',
      options: {
        required: true
      }
    },
    {
      selector: 'radiogroup',
      options: {
        type: 'radio',
        required: true
      }
    }
  ],
  submitBtn: {
    selector: '.form__btn',
    onSubmit: sendForm,
    disabledClass: '.disabled'
  }
}

const form = new Form(formConfig);

And that's basically all, we should have our form validations up and ready.

Form configuration object

Here you can see form config object with all currently available options and their default values:

const formConfig = {
  fields: [
    {
      selector: '#fieldId',             // any selector that can be used with document.querySelector function in JS
      options: {
        validators = {},
        required = false,
        touched = false,                // we can pass 'touched' state on form creation if for example we prepopulate form with value
        ignoreDefaults = false,         // this will ignore default validators, currently applied only to email inputs
        validateAutomatically = true    // we can turn off automatic validation if we want to validate only by force
      }
    },
    {
      // radio buttons and checkboxes do not accept any validators except for 'required' option
      selector: 'radiogroup',
      options: {
        type: 'radio',                  // for radio buttons it is required to pass 'type' option
        required: true
      }
    }
  ],
  submitBtn: {
    selector: '.btnClass',
    onSubmit: (values) => console.log('Callback function called on successfull form submit. Returns object will {field: value} pairs'),
    disabledClass: '.disabled'          // class to add when button should be disabled (form invalid)
  },
  errorClass: '.err',                   // class to add on error
  dirtyClass: '.drr'                    // class to add to touched inputs
}