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

validator-wrapper

v1.0.4

Published

A validator.js wrapper to support validation chaining and messages

Readme

Introduction

A Nodejs wrapper of validator.js to support validation chaining and messages

Version 1.0.3

  • Add f as the alias of prepare function
  • Add `x' as the alias of 'eval' function

Features

  • Method chaining
  • Batch validations with messages and additional info (tag)
  • Able to call any validation method of validator.js with options
valid_wrapper.prepare("isInt", { min: 10, max: 99 }).eval('Age must be between 10 and 99')

//use alias
valid_wrapper.f("isInt", { min: 10, max: 99 }).x('Age must be between 10 and 99')

Getting Started

Installation

npm install validator-wrapper

Usage

var valid_wrapper = require('validator-wrapper')

var data = {
    email : '[email protected]',
    email2: "bademail",
    firstname: "Triet",
    lastname: "",
    age: 1,
    password: "[email protected]",
    password2: "123456",
} 

//the default tag is 'danger', set options to change the default tag
valid_wrapper.options({tag: 1}) 

valid_wrapper.pick(data.email)
    .empty('Main email must be not empty') //this message will bot be included in the validation results
    .email('Main email is invalid') //this message will not be included in the validation results
    
    .pickNext(data.email2)
    .email('Second email is invalid')

    .pickNext(data.firstname)
    .empty('First name must be not empty') //this message will not be included in the validation results

    .pickNext(data.lastname)
    .length({min:3}, "Last name must has at least 3 characters")

    .pickNext(data.password)
    .equals(data.email, 'Password must be different from email', 'warning')
    .prepare("isAlpha").eval('Password contains letters a-zA-Z only')
    .diff(data.password2, 'Passwords do not match')
    
    .pickNext(data.age)
    .f("isInt", { min: 10, max: 99 }).x('Age must be between 10 and 99', 2)

    .pickNext(data.notexist)
    .empty('Notexist must be exist :)')

console.log(JSON.stringify(valid_wrapper.messages, null, 4))

/* ouput 

[
    {
        "message": "Second email is invalid",
        "tag": 1
    },
    {
        "message": "Last name must has at least 3 characters",
        "tag": 1
    },
    {
        "message": "Password must be different from email",
        "tag": "warning"
    },
    {
        "message": "Password contains letters a-zA-Z only",
        "tag": 1
    },
    {
        "message": "Passwords do not match",
        "tag": 1
    },
    {
        "message": "Age must be between 10 and 99",
        "tag": 2
    },
    {
        "message": "Notexist must be exist :)",
        "tag": 1
    }
]
*/

API references

functions

  • pick(content): set the first content for validating and clear existing messages
  • pickNext(content): set the next content for validating and keep existing messages
  • length(options, message[, tag]): if not valid, add the message into validation results
  • email(message[,tag]): if not email, add the message into validation results
  • empty(message[, tag]): if empty, add the message into validation results, and ignore other validations until pickNext
  • equals(target, message[, tag])
  • diff(target, message[, tag])
  • custom(condition, message[, tag]): if condition is true, add the message into validation results
  • prepare(method, options): select a method of validatorjs and its options that to be executed in eval method
    • Alias: ffunction
  • eval(message[, tag]): execute the method defined in the prepare function and add the message into validation results if the returned value of validator is false
    • Alias: x function

fields

  • messages contains the validation results
  • validator direct access to validatorjs module