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

@himanshu-sorathiya/omnival

v1.4.4

Published

OmniVal, Your all in one validator package for doing any kind of validation with great DX by providing advance custom options.

Readme

@himanshu-sorathiya/omnival

OmniVal is an all-in-one validator package designed for JavaScript and TypeScript with a focus on developer experience. It provides a chainable, class-based API for validating strings, numbers, and booleans with advanced customization options for error handling.

Installation

npm install @himanshu-sorathiya/omnival

Core Concepts

  • Type Safety: Built with TypeScript to provide full autocomplete for all validation methods.
  • Fail-Fast Type Checking: If the initial type check (string, number, boolean) fails, validation stops immediately to prevent side effects.
  • Aggregated Rule Validation: Once the type is confirmed, all chained rules are executed. Even if one rule fails, the library continues checking the rest to provide a complete report of all violations.
  • Order Independent: Methods can be chained in any order.

Basic Usage

Primitive validations

import v from '@himanshu-sorathiya/omnival';

// Successful validation
const result = v.number().positive().max(15).validate(10);
// Returns: { isValid: true, data: 10 }

// Failed validation with multiple errors
const failure = v.number().max(15).positive().min(5).validate(-10);

/*
Returns:
{
  isValid: false,
  errors: [
    {
      rule: 'positive',
      message: '-10 is not a positive number',
      code: 'NOT_POSITIVE',
      meta: { ... }
    },
    {
      rule: 'min',
      message: '-10 is smaller than 5',
      code: 'TOO_SHORT',
      meta: { ... }
    }
  ]
}
*/

Object validations

// Successful validation
const result = v
	.object({
		role: v.string().lowercase(),
		stars: v.number().positive(),
	})
	.validate({ role: 'admin', stars: 5 });
// Returns: { isValid: true, data: { role: 'admin', stars: 5 } }

// Failed validation with multiple errors
const failure = v
	.object({
		id: v.string(),
		organization: v.object({
			name: v.string().minLength(5),
			metrics: v.object({
				revenue: v.number().minValue(10000),
				employees: v.number().maxValue(100),
			}),
		}),
	})
	.validate({
		id: 'org_123',
		organization: {
			name: 'Ace',
			metrics: {
				revenue: 5000,
				employees: 150,
			},
		},
	});
/*
Returns:
{
  isValid: false,
  errors: [
    {
      path: 'organization.name',
      rule: 'minLength',
      message: 'length of "Ace"(3) is smaller than required 5 length',
      code: 'TOO_SHORT',
      meta: [Object]
    },
    {
      path: 'organization.metrics.revenue',
      rule: 'minValue',
      message: '5000 is smaller than 10000',
      code: 'TOO_SHORT',
      meta: [Object]
    },
    {
      path: 'organization.metrics.employees',
      rule: 'maxValue',
      message: '150 is bigger than 100',
      code: 'TOO_LONG',
      meta: [Object]
    }
  ]
}
*/

API Reference

v.string()

Starts a string validation chain.

  • .minLength(length) - Checks if string length is >= length.
  • .maxLength(length) - Checks if string length is <= length.
  • .equals(value) - Checks for exact string match.
  • .length(value) - Checks if the string length is exactly equal to value.
  • .startsWith(prefix) - Checks if the string begins with the specified prefix.
  • .endsWith(suffix) - Checks if the string ends with the specified suffix.
  • .includes(substring) - Checks if the string contains the specified substring.
  • .uppercase() - Checks if all alphabetic characters in the string are uppercase.
  • .lowercase() - Checks if all alphabetic characters in the string are lowercase.
  • .alphabets() - Checks if all characters in the string are alphabets.
  • .numbers() - Checks if all characters in the string are numbers.

v.number()

Starts a number validation chain.

  • .minValue(value) - Checks if value is >= min.
  • .maxValue(value) - Checks if value is <= max.
  • .positive() - Checks if value is > 0.
  • .negative() - Checks if value is < 0.
  • .equals(value) - Checks for exact number match.
  • .integer() - Checks if the value is a whole number without a decimal component.
  • .multipleOf(step) - Checks if the value is perfectly divisible by the provided step.

v.boolean()

Starts a boolean validation chain.

  • .equals(value) - Checks for exact boolean match.

v.object(shape)

Starts an object structural definition.

Customizing Errors

Every validation method accepts an optional second argument. This allows you to override the default error messages and codes to fit your application's error-handling strategy.

Using a String

Pass a string to replace only the default message.

v.number().positive('Value must be greater than zero');

Using an Object

Pass an object to replace the message, the code, or both.

v.number().min(5, {
	code: 'CUSTOM_MIN_ERROR',
	message: 'The value provided is too low',
});

Error Object Structure

When validation fails, the errors array contains objects with the following structure:

| Property | Type | Description | | -------- | ------ | -------------------------------------------------------- | | path | string | The path of the property that failed (Only for objects). | | rule | string | The name of the rule that failed. | | message | string | The error message (default or custom). | | code | string | The error code for programmatic handling. | | meta | object | Additional context (e.g., expected vs actual values). |

License

MIT