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

valinor

v0.4.2

Published

A library for writing uncluttered, easy to read field and schema validations.

Readme

Valinor

A library for writing uncluttered, easy to read field and schema validations.

Get Started

Install with: npm i -P valinor

In your code:

const { v } = require('valinor');

// Validate one variable in place.
let result = v.int.between(0, 32).test(33);
console.log(result);

// Reuse one valinor.
let goodPwd = v.str.min(8);
console.log(
    goodPwd.test('abc'),
    goodPwd.test('abcdefgh'),
    goodPwd.test(null)
);

// Define a object schema valinor.
let schema = v.schema({
    name: v.str.match(/^[A-Z][a-z]+\ [A-Z][a-z]+$/),
    password: v.str.min(8),
    birth: v.date.min('2001-01-01').past
});

result = schema.test({
    name: 'John Doe',
    password: 'abcdefgh',
    birth: new Date('1999-01-01')
});

// Ignore empty/null values on optional valinors.
let schemaWithOpt = v.schema({
    firstName: v.str,
    lastName: v.opt.str
});

console.log(schemaWithOpt.test({
    firstName: 'John',
    lastName: null
}));

// Ensure you get only valdated keys of an object.
console.log(schemaWithOpt.test({
    firstName: 'John',
    unvalidated: 'This should not show up',
    lastName: 'Doe'
}).final);

// Define default values to show up in final object instead of blank optionals
let schemaWithOpt = v.schema({
    firstName: v.str,
    lastName: v.opt.str.def('Doe')
});

console.log(schemaWithOpt.test({
    firstName: 'John'
}).final);

v.test() method output is always an object with the following keys:

  • ok: Whether validation passed.
  • final: The input value after any modifications made by the Valinor. undefined unless all passed.
  • errs: Array containing all found validation errors. undefined if all passed.

Check the full rule reference for all the validations available.

Reporting Bugs

If you have found any problems with this module, please:

  1. Open an issue.
  2. Describe what happened and how.
  3. Also in the issue text, reference the label ~bug.

We will make sure to take a look when time allows us.

Proposing Features

If you wish to get that awesome feature or have some advice for us, please:

  1. Open an issue.
  2. Describe your ideas.
  3. Also in the issue text, reference the label ~proposal.

Contributing

If you have spotted any enhancements to be made and is willing to get your hands dirty about it, fork us and submit your merge request so we can collaborate effectively.

Method Reference

  • test ( input ): Returns true if the input is valid. Returns an array or problems otherwise.

Rule Reference

  • in ( array ): Check if value can be found inside given array.
  • num: Check if value is a number.
  • numeric: Check if value is a number or a numeric string.
  • bool: Check if value is a boolean.
  • boolLike: Check if value is a boolean or a boolean-like value.
  • date: Check if value is a date.
  • isoDate: Check if value is a ISO date string.
  • obj: Check if value is an object. Will fail for arrays, dates and JSON strings.
  • str: Check if value is a string.
  • arr: Check if value is array. Will fail for JSON strings.
  • match ( regex ): Check if value matches the given regex.
  • gt ( primitive | date | array ): Check if value or it's length is greater than subject.
  • lt ( primitive | date | array ): Check if value or it's length is less than subject.
  • min ( primitive | date | array ): Check if value or it's length is equal or greater than the subject.
  • max ( primitive | date | array ): Check if value or it's length is equal or less than the subject.
  • between ( primitive | date | array ): Check if value or it's length is inclusively inside the given range.
  • len ( string | array ): Check if length is exactly the given subject.
  • has ( string | object | array ): Check if the value contains the subject. For string, object and array it checks respectively substring, keys and values.
  • future ( date ): Check if a date is in the future.
  • past ( date ): Check if a date is in the past.
  • today ( date ): Check if a date time is today.
  • schema ( object ): Check if object's keys follows all their respective Valinor rules.
  • every ( array ): Check if all array elements match a given Valinor rules.
  • some ( array ): Check if any values of the array match given rules. Also picks only the valid values.
  • opt: Mark the Valinor as optional, so skipping any validations for null, undefined or '' values.
  • not ( Valinor ): Negates the given rules.
  • dif ( primitive | date | array ): Check if values are sctrictly different. In Arrays, consider also order of elements.
  • def ( value ): Set a default value to show up on final object in case the valinor is optional and validates an empty value.
  • alter ( fn ): Mutates the input value acording to given funcion (fn) in a pipeline fashion before it reaches the next rule.
  • values ( Valinor ): Check if all value in an object match given rules.
  • keys ( Valinor ): Check if all keys in an object match given rules.