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

salvation

v1.2.1

Published

A pure JS form validation plugin

Downloads

49

Readme

Salvation npm npm downloads Bower npm

A lightweight, easy-to-use form validation tool, written entirely in JavaScript and with no library dependencies. Also, a work in progress.

Installation

Install with NPM
$ npm install salvation
Install with bower
$ bower install Salvation

Usage

Using Salvation is easy and requires very little effort to take advantage of the built-in validation rules. Just create the form elements and declare the validation rules in the data-validate attribute, like so:

<form id="form">
    <p><input type="text" name="username" data-validate="required"></p>
    <p><input type="password" name="password" data-validate="required, length" data-length="10" data-format="min"></p>
    <p><input type="text" name="email" data-validate="email"></p>
    <p><input type="text" name="birthday" data-validate="date" data-format="YY/MM/DD"></p>
    <p><input type="submit" /></p>
</form>

Add the following to the bottom of the page:

<script type="text/javascript">
     var salvation = new Salvation({
         element: document.getElementById("form")
     });
     // You can also call the plugin like this:
     document.getElementById("form").addSalvation({
         // Options
     });
</script>

Options

Salvation is highly adjustable. You can override default settings by passing options to the plugin, as outlined below:

Properties
    new Salvation({
        element         :   document.getElementById("element"),
        dateFormat      :   "MM/DD/YYYY",
        datePlaceholder :   true,
        onInvalidation  :   function (elements) { /* ... */ },
        onValidation    :   function (elements) { /* ... */ }
    });
  • element: The form element to validate. This property is required only when initializing plugin with constructor pattern (new-keyword).
  • dateFormat: Global formatting rule for date validation. This setting will be used if the local attribute data-format is not set on an element. If data-format is defined on one element, then the default format will be overridden on that individual element (default: mm/dd/yyyy).
  • datePlaceholder: If true, the date fields will display the date format they are set to (default: true).
  • onInvalidation: To override the default onInvalidation method, called when an element fails validation, define this property as a function. The method takes one parameter, which is an array containing the invalid form elements. The default method can be accessed by the user-overriden method with this.defaultOnInvalidation()).
  • onValidation: To override the default onValidation method, called when an element that previously failed validation has been validated. Must also be defineed as a function. The method takes one parameter, which is an array containing the form elements that passed validation. The default method can be accessed by the user-overriden method with this.defaultOnValidation()).
Attributes
    <input type="text" data-validate="required">
    <input type="text" data-validate="numeric, length" data-length="5" data-format="min">
    <input type="text" data-length="1,">
    <input type="text" data-validate="date" data-format="DD/MM/YYYY">
  • data-validate: Sets the validation rule. Can have multiple values (i.e. data-validate="required, numeric"). The built-in rules are as follows:
    • required: The field can not be empty.
    • numeric: The field can only contain numbers.
    • alphanumeric: The field can only contain letters, numbers and underscore.
    • date: The field value must be a valid date, formatted as specified by the data-format attribute (or the default formatting rule). Salvation will check upon validation if the inputed date actually exists.
    • email: The field value must be a valid e-mail address.
    • length: The field value must have a certain length (see below).
    • You can also create your own rules by setting a custom value to data-validate and passing a custom regular expression when initializing the plugin (see below for an example).
  • data-length: Specifies a minimum and/or maximum length, delimited by a comma. It is not required, although recommended, to be used with the data-validate="length" option.
    • Formatting:
      • 5: A single digit will set the maximum length.
      • 5,: A single digit, followed by a comma, sets the minimum length.
      • 5,10: Two digits, delimited by a comma, sets minimum and maximum length.
  • data-format: Formatting option for the date fields (i.e. data-format="YY/MM/DD"). This will override the default format. Can also be used to set the value of the length attribute to be either a maximum or minimum limit (data-format="min/max"). The data-length attribute must in that case only contain digits.

Customization

Salvation is also easily extendable and can take custom validation rules (as regular expressions). Below follows an example where we want to create a password field that requires at least one digit and a special character:

    <form id="form">
        <input type="password" name="password" data-validate="custom-password">
    </form>

    <script type="text/javascript">
        var salvation = new Salvation({
            element: document.getElementById("form")
        }, {
            custom-password: /(?=.*[0-9])(?=.*[\W])/
            // The custom rules must be a regular expression
            // and have the same name as specified in the
            // form element.
        });
    </script>

Author

  • Salvation was created by Ardalan Samimi.