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

aj-validator

v1.1.5

Published

Simple and extensible validator library for node.js.

Downloads

42

Readme

aj-validator

Simple and extensible validator library for node.js.

Installation

ES6

import validator from 'aj-validator'

No ES6

var validator = require('aj-validator');

Basic usage

let is_valid = validator.email('[email protected]');
console.log(is_valid); // true


let is_valid = validator.max('some text', 4); // Passing parameters
console.log(is_valid); // false

Validate multiple fields

api.post('/user', (req, res) => {
  
  // validationRules expect to be an object with: 
  // key = field_to_validate
  // value = rules_separate_by_pipe:rule_parameters 
  
  let validationRules = {
    username: 'required|email|min:6',
    name: 'required|min:2',
    description: 'required|max:255'
  };
  
  let is_valid = validator.validate(req.body, validationRules);
  console.log(is_valid); // true|false

  let errors = validator.getErrors(); // Retriving validation errors
  console.log(errors); // {name: ["required"], username: ["Invalid Email provided", "Less than 6 characters are not allowed"]}

});

Create custom validators

// customValidator expect to be an object with: 
// name = Validator name
// message = Message to display in case validation fails
  
let customValidator = {
  name: 'custom',
  message: 'Message to display in case validation fails'
};

// .make() method expect 2 parameters:
// customValidator object {name: '', message: ''}
// fn callback receiving value(string) to validate and parameters(string, number or array)
// Should return true|false

validator.make(customValidator, (val, ruleParams) => val.length >= ruleParams );

let validationRules = {
  username: 'required|custom',
  name: 'required|min:2',
};

let is_valid = validator.validate(req.body, validationRules);
console.log(is_valid); // true|false

Customize messages to display

let customMessages = {
  'required':'Message to be display only on fields if required rule fail',
  'required.username': 'Message to be displayed only on username field if required rule fail',
};

let validationRules = {
  username: 'required|email|min:6',
  name: 'required|min:2'
};

let fieldsToValidate = {
  name: '',
  username: ''
};

let is_valid = validator.validate(fieldsToValidate, validationRules, customMessages);
console.log(is_valid); // true|false

let errors = validator.getErrors(); // Retriving validation errors
console.log(errors); // {name: ["Message to be display only on fields if required rule fail"], 
                     //  username: [Message to be displayed only on username field if required rule fail]}

Validators built-in

Validator | Parameter | Description --------- | --------- | ----------- required | none | The field under validation must be present in the input data and not empty email | none | The field under validation must be formatted as an e-mail address max       | integer | The field under validation must be less than or equal to a maximum value min       | integer | The field under validation must have a minimum value json | none | The field under validation must be a valid JSON string url | none | The field under validation must be a valid URL date | none | The field under validation must be a valid date according to javascript Date object integer | none | The field under validation must be an integer