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

validate-mini

v1.0.9

Published

Minimalistic validation library. Designed to be as little verbose as possible.

Readme

validate-mini

Minimalistic validation library. Designed to be as little verbose as possible.

Usage

Import the module

const { validate } = require("validate-mini");

Define a validation schema

const schema = {
    firstName: /[A-Z][a-z]{2,20}/,
    lastName: /[A-Z][a-z]{2,20}/,
};

Execute the validate() function, supplying your schema and the object to validate.

const validationResult = validate(schema, request.body);

The resulting object contains an isValid Boolean property. It indicates whether a validation error has been found or not, and messages for all properties that failed.

// No validation error
{ isValid: true }

// Validation errors
{
    isValid: false,
    firstName: "Invalid format",
    lastName: "Invalid format"
}

Supported validation rules

Specific String, Number or Boolean

To validate against specific String, Number or Boolean values:

const schema = {
    acceptTerms: true,
    verificationText: "I accept",
    rejectionCount: 0
};

RegExp

To validate against a RegExp:

const schema = {
    age: /^[1-9]{1, 2}$/
};

Function

For added flexibility, functions can be used for custom validation. Functions should either return a Boolean, or an object with an isValid Boolean property.

const moment = require("moment");

const schema = {
    dob: value => moment().diff(moment(value), "years") >= 18
};

Functions take at least one argument as parameter. This parameter represents the value of the corresponding property on the object to validate.

Checking against other properties

Functions can also take a second argument, representing the whole object being validated. This allows checking several properties in one function.


const schema = {
    password: /[A-Z]{8,24}/,
    confirmPassword: (value, input) => value === input.password,
};

Arrays

To apply validation rules on Array items:

const schema = {
    aliases: [
        // use any rule you want: RegExp, func, etc
        /[A-Z][a-z]{2,20}/
    ]
}

Objects

Rules can be combined to form complex objects:

const schema = {
    user: {
        name: /[A-Z][a-z]{2,20}/,
        id: /[a-f0-9]{8}/,
        options: {
            // ...
        }
    }
}

Utils

The library comes with a handful of built-in functions to help defining simple validation schemes.

To access the util functions:

const { validate, is, utils } = require("validate-mini");

const schema = {
    products: is.array,
    accept: is.boolean,
    amount: is.number,
    someObjecT: is.object,
    description: is.string,
    // Validate min and max length of Number value
    freeText: utils.length(0, 255),
    // List of acceptable values (enum like)
    status: utils.oneOf("success", "failure", "pending", "canceled"),
    // Validate min and max of Number value
    amount: utils.range(0, 100),
}

Note: When possible, avoid using utils.is, as it creates new functions on every call. Use the is.xxx functions instead.

Optional properties

By default, all rules require matching input. To mark rules as optional, use the optional(<rule>) function together with any rule you like.

const { validate, optional, utils } = require("validate-mini");

const schema = {
    middleName: optional(utils.is(String))
};

Chain several rules

Apply a sequence of rule using the pipe(<rules>) function:

const { validate, pipe } = require("validate-mini");

const schema = {
    password: pipe(/[A-Za-z]/, /[0-9]/, /.{8,255}/)
};