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

easevalidation

v0.28.2

Published

An easy to use / easy to extend javascript validation library

Readme

easevalidation

Install

npm install easevalidation

easevalidation is an easy to extend javascript validation library that supports multiple types of validators: functional validation, schema based, chained validators etc.

It comes bundled with all lodash is* validators (like isPlainObject, isFinite etc), all the validator.js validators and the date-related validators date-fns comes with. On top of that, it features some commonly used validators you can find here.

You test the input data using the test function:

import { test, validators } from 'easevalidation';

const { isNumber, isMin, isMax } = validators;

const isValid = test(isNumber(), isMin(10), isMax(15))(13); // true

Or you can use a chained validator:

import { test, number } from 'easevalidation';

const isValid1 = test(
  number()
    .isMin(10)
    .isMax(15),
)(13);

// or

const isValid2 = number()
  .isMin(10)
  .isMax(15)
  .test(13);

// isValid1 === isValid2 === true

You can also validate an object by a schema:

import { test, validators } from 'easevalidation';

const { isSchema, isEmail, isRequired, isString, isLength } = validators;

const schema = isSchema({
  email: [isEmail()],
  password: [isRequired(), isString(), isLength({ min: 5 })],
});

const isValid = test(schema)({
  email: '[email protected]',
  password: '12345',
});

Or:

import { test, validators } from 'easevalidation';

const { isPlainObject, isProperty, isEmail, isRequired, isString, isLength } = validators;

const schema = [
  isPlainObject(),
  isProperty('email', isEmail()),
  isProperty('password', isRequired(), isString(), isLength({ min: 5 })),
];

const isValid = test(schema)({
  email: '[email protected]',
  password: '12345',
});

While easevalidation comes prebuilt with many validators, creating your own validators is an easy job.

import { createValidator, test } from 'easevalidation';

const isBetween = createValidator('isBetween', (value, min, max) => min <= value && value <= max);

const isValid = test(isBetween(10, 15))(13); // true

Validators can also update the value they receive for testing.

import { createValidator, test } from 'easevalidation';
import { ObjectID as objectId } from 'mongodb';

const isObjectId = createValidator(
  'isObjectId',
  value => objectId.isValid(value),
  value => objectId(value),
);

const isValid = test(isObjectId())('5bf6cd3e766582a5bf892519');

As you can see, the signature of createValidator is:

createValidator(String code, Function validate, [Function updateValue, Function validateConfig])

Keep in mind that updateValue will run after validate function tests the value and only if it returns true (value passes validation).

Only code and validate are required, the rest of arguments are optional. validateConfig is a function that can be used to validate the configuration the validate function will receive.

Another way to update the value is by returning an object from validate:

import { createValidator, test } from 'easevalidation';
import { ObjectID as objectId } from 'mongodb';

const isObjectId = createValidator('isObjectId', value => ({
  isValid: objectId.isValid(value),
  value: objectId(value),
}));

const isValid = test(isObjectId())('5bf6cd3e766582a5bf892519');

Sometimes you may want to get access to the final updated value, besides just testing it.

import { createValidator, test, validators } from 'easevalidation';
import { ObjectID as objectId } from 'mongodb';

const { isSchema, isString, isNumber, isMin } = validators;

const isObjectId = createValidator('isObjectId', value => ({
  isValid: objectId.isValid(value),
  value: objectId(value),
}));

const validate = test(
  isSchema({
    name: isString(),
    age: [isNumber(), isMin(20)],
    id: isObjectId(),
  }),
);

const isValid = validate({
  name: 'John Doe',
  age: '22',
  id: '5bf6cd3e766582a5bf892519',
});

const { value } = validate;

// In this case `isValid` will be `true` and `value` will be:

{
  name: 'John Doe',
  age: 22, // number
  id: ObjectId('5bf6cd3e766582a5bf892519') // object
}

Instead of building a validation function like we did above, you can use validate:

import { createValidator, validate, validators } from 'easevalidation';
import { ObjectID as objectId } from 'mongodb';

const { isSchema, isString, isNumber, isMin } = validators;

try {
  const value = validate(
    isSchema({
      name: isString(),
      age: [isNumber(), isMin(20)],
      id: isObjectId(),
    }),
  )({
    name: 'John Doe',
    age: '22',
    id: '5bf6cd3e766582a5bf892519',
  });
} catch (err) {
  // won't get here, because it passes validation
}