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

easy-js-validator

v1.0.35

Published

A javascript validation package motivated by laravel default validator.

Readme

EASY-JS-VALIDATOR

This JavaScript validator package is inspired by Laravel's default validator.

How to use the Validator

const { Validator } = require('easy-js-validator');
const validator = new Validator({
    name: "Alice",
    age: "22",
    isMarried: false
});
const rules = {
    name: 'required|between:5,50|alpha',
    age: 'between:20,30',
    isMarried: 'boolean'
};
const errors = validator.validate(rules);

How to pass custom validation error messages

const messages = {
    name: {
        required: 'Please enter :attribute, it is required.',
        between: 'The lenght should be between 20 to 30 characters.',
    }
};
const errors = validator.validate(rules,messages);

Note: ":attribute" will be replace by the validating input name.

Available validation rules

required

The field under validation must be present in the input data and not empty. A field is "empty" if it meets one of the following criteria:

- The value is null.
- The value is an empty string.
- The value is an empty array or empty Countable object.
- The value is an uploaded file with no path.

integer

The field under validation must be an integer.

decimal:minDecimalPlaces,maxDecimalPlaces

The field under validation must be an decimal number. Both minDecimalPlaces and maxDecimalPlaces are optional fields. If neither is provided, the function will only check if the given value is a decimal. If only minDecimalPlaces is provided, it will validate that the value has exactly the specified number of decimal places. If both minDecimalPlaces and maxDecimalPlaces are provided, it will ensure the value has a number of decimal places within the specified range.

min:value

The field under validation must have a minimum value. Strings, numerics, arrays, and files are evaluated in the same fashion as the size rule.

max:value

The field under validation must have a maximum value. Strings, numerics, arrays, and files are evaluated in the same fashion as the size rule.

between

The field under validation must have a size between the given min and max (inclusive). Strings, numerics, arrays, and files are evaluated in the same fashion as the size rule.

email

The field under validation must be formatted as an email address.

boolean

The field under validation must be able to be cast as a boolean. Accepted input are true, false, 1, 0, "1", and "0".

date

The field under validation must be a valid.

in:option1,option2,...

The field under validation must be included in the given list of values.

not_in:option1,option2,...

The field under validation must not be included in the given list of values.

url

The field under validation must not be a start with either http:// or https://.

alpha

The field under validation must contains only English lowercase(a-z) and upprcase(A-Z) alphabets.

alpha_num

The field under validation must contains only English lowercase(a-z), upprcase(A-Z) alphabets and 0-9.

alpha_dash

The field under validation must contains only English lowercase(a-z), upprcase(A-Z) alphabets and '_'.

alpha_num_dash

The field under validation must contains only English lowercase(a-z), upprcase(A-Z) alphabets, 0-9 and '_'.

same:field

The given field must match the field under validation.

regex:pattern

The field under validation must match the given regular expression. Eg. regex:^[a-zA-Z]+$ //It will check if given iput contains lettrs between a-z and A-Z.

starts_with:option1,option2,...

The field under validation must start with one of the given values.

ends_with:option1,option2,...

The field under validation must end with one of the given values.