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 🙏

© 2025 – Pkg Stats / Ryan Hefner

valivalue

v1.0.3

Published

A library to quickly validate values!

Readme

ValiValue

Easy and opinionated validation.

Installation

npm install valivalue

Usage

Default validator

ValiValue exports a default validator that can be used to perform some pre-implemented validations on:

Validation methods follow a simple format:

validator.[type].[method]([value to validate], [validation parameter, ...], [subject], [error message factory])

// examples
import valivalue from "valivalue";

validator.timestamps.validateIsInFuture(DateTime.fromMillis(), "Delivery date");
validator.strings.validateMinAndMaxLength("John", 2, 64, "First name");
validator.numbers.validateMinValue(
  5, 
  12, 
  'Age', 
  (subject, value, min) => `${subject} should at least be ${min}, but was ${value}.`
);

If validation fails, an error will be thrown with a human-readable message:

import validator from "valivalue";

// Throws error with message "My object is null.".
validator.objects.validateNotNull(null, "My object");

// Throws error with message "Your object is undefined.".
validator.objects.validateNotNull(null, "Your object");

// Throws error with message "Age must be a positive number.".
validator.numbers.validateIsPositive(-1, "Age");

Values that are nullable (objects, strings and timestamps) are not automatically validated that they are not null or undefined. You should validate this using the objects validator:

import valivalue from "valivalue";

valivalue.objects.validateNotNull(null);
valivalue.objects.validateNotUndefined(undefined);
valivalue.objects.validateNotNullOrUndefined({});

null and undefined are 2 different things for the objects validator.

Reporting validator

Valivalue also exports a reporting validator, which does not throw but returns an error report:

import { reporting } from "valivalue";

const { numbers } = reporting;

const validationReport = numbers.validateIsEven(1);

const isSuccess = validationReport.isSuccess();
const isFailure = validationReport.isFailure();
const validatedValue = validationReport.value;
const validationError = validationReport.error;

validationReport.throw(); // Only throws if the validation failed.

Chainable validator

Valivalue also exports a chainable validator, which returns itself after each validation and keeps track of all validation failures:

import { chainable } from "valivalue";

const firstName = "Some input value";

const result = chainable()
                  .objects.validateNotNullOrUndefined(firstName, 'First name')
                  .strings.validateMinAndMaxLength(firstName, 1, 32, 'First name')
                  .strings.validateDoesNotContainCaseInsensitive(firstName, [ /* a list of swear words */], 'First name');

if (result.isFailure()) {
  console.error('Validation failed', results.errors);
}

If you call throw on the chainable validator, the first validation error is thrown.

You can also configure the chainable validator to throw directly on a failed validation:

import { chainable } from "valivalue";

chainable(true)
  .strings.validateNotEmpty("") // Throws directly, does not continue validation
  .numbers.validateIsEven(1);