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

@antonbarinov/ovalidator

v1.0.8

Published

Javascript objects validator

Downloads

33

Readme

Ovalidator

Javascript objects validator

Installation

npm i --save @antonbarinov/ovalidator

Quick start example

const { Validator, Validate } = require('@antonbarinov/ovalidator');

// Object that we want validate
let objToValidate = {
    a: "ssd",
    b: 19,
    c: {
        a: [1, 444]
    },
    f: [1, 2, 3, 4],
    g: [],
    i: {
        j: 1,
        s: 2
    },
    k: 'asd',
    l: { a: 2 },
    m: [
        { a: 2 },
        { a: 3 }
    ]
};

// custom validation function
const customFunc = (value) => {
    return (value === 'aaa' || value === 'aAa');
};

// custom error msg function
const customErrorMsgFunc = (objPathStr) => {
    return `${objPathStr} must be "aaa" or "aAa"`;
};

// Validation schema
let childSchema = {
    a: new Validator().typeInteger(),
    b: {
        a: new Validator().required(),
        b: {
            a: new Validator().required(),
        }
    },
    c: [new Validator().required().min(15)]
};

// Validation schema
let schema = {
    a: new Validator().typeString().customFunction(customFunc, customErrorMsgFunc),
    b: new Validator().required().min(12).max(20),
    c: childSchema,
    d: new Validator().required(),
    e: 123,
    f: [childSchema],
    g: [new Validator().required().min(15)],
    h: new Validator().required(),
    i: {
        j: [new Validator().required().min(15)],
    },
    l: new Validator().typeObject(),
    m: [new Validator().typeObject()],
    n: new Validator().default('THIS IS DEFAULT VALUE')
};


const errors = Validate(schema, objToValidate);
console.log('errors:');
console.log(errors);

console.log('\r\n');

// Validate empty object
const errors2 = Validate(schema, {});
console.log('errors2:');
console.log(errors2);

console.log('\r\n');

console.log('objToValidate:');
console.log(objToValidate);

Output

errors:
[ 'k is unexpected',
  'a must be "aaa" or "aAa"',
  'c.a must be integer',
  'c.b.a is required',
  'c.b.b.a is required',
  'c.c is required',
  'd is required',
  'f[0].b.a is required',
  'f[0].b.b.a is required',
  'f[0].c must be array',
  'f[1].b.a is required',
  'f[1].b.b.a is required',
  'f[1].c must be array',
  'f[2].b.a is required',
  'f[2].b.b.a is required',
  'f[2].c must be array',
  'f[3].b.a is required',
  'f[3].b.b.a is required',
  'f[3].c must be array',
  'g can not be empty array',
  'h is required',
  'i.s is unexpected',
  'i.j must be array' ]


errors2:
[ 'b is required',
  'c.b.a is required',
  'c.b.b.a is required',
  'c.c must be array',
  'd is required',
  'f[0].b.a is required',
  'f[0].b.b.a is required',
  'f[0].c must be array',
  'g is required',
  'h is required',
  'i.j must be array' ]


objToValidate:
{ a: 'ssd',
  b: 19,
  c: { a: [ 1, 444 ] },
  f: [ 1, 2, 3, 4 ],
  g: [],
  i: { j: 1, s: 2 },
  k: 'asd',
  l: { a: 2 },
  m: [ { a: 2 }, { a: 3 } ],
  n: 'THIS IS DEFAULT VALUE' }

Validate function

Validate(schema, objToValidate, allowUnexpectedFiends = false)

  • schema - validation schema
  • objToValidate - object to validate using validation schema
  • allowUnexpectedFiends - allow fields in objects that not described in validation schema (Default: false)

API

  • .required(errMsgFunction) - field is required.
  • .min(minVal, errMsgFunction) - minimum int or float value.
  • .max(maxVal, errMsgFunction) - maximum int or float value.
  • .minLength(minVal, errMsgFunction) - minimum string length.
  • .maxLength(maxVal, errMsgFunction) - maximum string length.
  • .default(defaultValue) - set defaultValue value if its undefined.
  • .typeInteger(errMsgFunction) - field type must be integer.
  • .typeFloat(errMsgFunction) - field type must be float.
  • .typeString(errMsgFunction) - field type must be string.
  • .typeObject(errMsgFunction) - field type must be object with any structure inside.
  • .regexp(regExp, errMsgFunction) - field must be valid with regular expression.
  • .customFunction(customFunc, errMsgFunction) - customFunc function must return true if field value is valid.

errMsgFunction - function for custom validator messages