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

he-validation

v2.1.0

Published

validate your inputs against some roles you defined, inspired from Laravel Validation

Downloads

25

Readme

he-validation

@licence GPL v3

Install

# npm install he-validation --save

quick How to use

require the Core

const ValidatorCore = require('he-validator');

create new instance from Core

const Validator = new ValidatorCore;

after that you are ready to make your validation like so

first prepare your Inputs Object which contains all inputs that you need to validate it can be req.body if you use Express js or any Object

const Inputs = req.body;
// OR
const Inputs = {
    "input": "value"
}

then you need to prepare the Roles that will contains all your validation roles

const Roles = {
    // any Role you need with it's options
    "input": ["required", "min:3", "max:100", "numeric"]
}

finally run the Validator

const validation = Validator.make(Inputs, Roles);

the Validator by Default returns Promise

validation.then(() => {
    // the Validator success with NO Errors at All
}, (errors) => {
    // the Validator failed and all Errors passed here
});

Go Deep Into Rabbit Hole

if you need to add custom Roles or Extend the Validator

first method => you can create Object contains your Custom Roles then pass it to the constractor.

const RolesObject = {
    "new_role": (options) => {
        return new Promise((resolve, reject) => {
            if(validationPassed === true){
                return resolve();
            }

            return reject("$s failed with error message");
        });
    },
    "another_awesome_role": ...
};

// create new instance from Core
const Validator = new ValidatorCore(RolesObject);

second method => you can add or register custom Role after Intiating the Validator by using register method

Validator.register("customRoleName", (options) => {});

all registerd roles must have Handler that accept options parameter that contains value, params, inputs and roles

  1. value => the value that User passed into Inputs Object.
  2. params => any additional params passed to the role
  3. inputs => all user inputs in it's original shap in case you need to access another value.
  4. roles => the main RolesObject in case you need to interact with any Other Role.

Notice: any error message should contain $s that will replaced with the input name

Overwrite

if there is a case when you need to replace exist role with new one with the same name .. in other words you need to Overwrite exist Role you can do this by add :force to the name of the Role. but Notice that this is NOT Recommended because there is some Roles Depend on other Roles so be careful when you do this Overwriting thing.

Validator.register("required:force", (options) => {});

this will force the Validator to Unregister the Old required Role and add Yours.

Availabile Roles

License

This project is licensed under the GPL v3 License - see the LICENSE.md file for details

I'm Welcoming with any comment or advise or you can open new issue on github