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

js-validation-helper

v0.0.1

Published

a javascript validation helper to easily validate your data

Readme

JavaScript Validator

a validation helper to easily validate your data


Installation

with npm

npm install @baabouj/validator

with yarn

yarn add @baabouj/validator

with pnpm

pnpm install @baabouj/validator

Usage

first let’s import the validator from the package :

using ES modules

import validator from "@baabouj/validator";

using CommonJs

const validator = require("@baabouj/validator");

Now that you imported it, the validator provides you with 2 function :

  • validate

used to validate fields within an object

const validated = validator.validate(
  {
    name: "John Doe",
    age: 20,
    email: "[email protected]",
    password: "secret",
  },
  {
    name: "required", // with single rule
    age: "required|number|gt:18", // with multiple rules
    email: ["required", "email"], // with an array of rules
    password: [
      ["required", "Password is required"],
      ["min:6", "Password must be at least 6 characters long"],
    ], // with custom error messages
  }
);

on case of validation didn’t succussed, the validate function returns an object containing each unvalidated field as a key and an array of error messages for that field as a value.

on validation succussed, the validate function returns null.

  • check

used to validate a single field

const checked = validator.check(23, "number|gte:18");
// or
const checked = validator.check(23, ["number", "gte:18"]);
// or provide your custom error message
const checked = validator.check(23, [
  "number",
  ["gte:18", "You must be at least 18 years old"],
]);

on case of validation didn’t succussed, the check function returns an array of error messages.

on success, the check function returns null.

Rules

  • required

    checks if the field is not empty
  • empty

    checks if the field is empty
  • email

    checks if the field is a valid email address
  • phone

    checks if the field is a valid phone number
  • url

    checks if the field is a valid url
  • length:{length}

    checks if the field’s length is equal to the given length
  • min:{length}

    checks if the field’s length is greater than the given length
  • max:{length}

    checks if the field’s length is less than the given length
  • number

    checks if the field is a number
  • boolean

    checks if the field is a boolean
  • string

    checks if the field is a string
  • array

    checks if the field is an array
  • object

    checks if the field is an object
  • function

    checks if the field is a function
  • null

    checks if the field is null
  • undefined

    checks if the field is undefined
  • in:{item},{item} (...)

    checks if the field is in the given list
  • nin:{item},{item} (...)

    checks if the field is not in the given list
  • eq:{value}

    checks if the field is equal to the given value
  • neq:{value}

    checks if the field is not equal to the given value
  • gt:{value}

    checks if the field is greater than the given value
  • gte:{value}

    checks if the field is greater than or equal to the given value
  • lt:{value}

    checks if the field is less than the given value
  • lte:{value}

    checks if the field is less than or equal to the given value
  • between:{min},{max}

    checks if the field is between the given values
  • contains:{value}

    checks if the field contains the given value
  • sw:{value}

    checks if the field starts with the given value
  • ew:{value}

    checks if the field ends with the given value
  • regex:{regex}

    checks if the field matches the given regex pattern
  • not:{rule}

    checks if the field does not match the given rule