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

validate-for

v1.0.9

Published

A simple library that uses the builder pattern to validate values and objects in js

Readme

Install

TODO....

Use

Validate-this leverages the builder pattern to handle validation for both entire objects and single values. At the heart of this project is the rule builder class. To create a new rule use the rule method.

const myRule = rule();

Once you have an instance of a ruleBuilder you will be able to use its builder methods to build out custom validation rules. Such as:

const myRuleWithConstraint = myRule.must(..)
const myRuleWithContext = myRule.withContext(..)
const myRuleWithDisplayName = myRule.withDisplayName(..)
const myRuleWithGetter = myRule.withGetter(..)

Each of these methods will return a new instance of the rule with the requested method applied to only the new instance. This is to make it easier to chain rule together like so:

const ctx = {prop:'I am hungry'}
const myRule = rule()
  .must((value)=> !!value)  //Make sure the value is truthy
  .must((value,ctx)=> value !== ctx.prop) // Make sure the value is not equal prop
  .withContext(ctx,true) // Sets the context and makes sure the reference to the original model is preserved

ctx.prop2 = 'I am Full'

const myRule2 = myRule
  .withContext(ctx) // Sets the context to be cloned each time this will preserve the state of the context when withContext was called
  .must((value, ctx)=> value !=== ctx.prop2 )

Building rules like this can make it easy to share common configuration such as all fields are required.

Now to evaluate a rule you have 3 helper functions

const myRule = rule.must(v=>v)

// To evaluate against a value all you have to do is pass the value,
// unless the rule needs a context to run.
// If a context is required then an error will be returned with
// cannotEvaluate flag set to true.  
const resultOfSimpleValueCheck = myRule.evaluate(1);

//To evaluate against a model you must have a getter set. Otherwise undefined will be returned
const resultOfValidationForAContext = myRule.withGetter('count').evaluateFor({count:2}) 

const func = myRule
  .must((_,ctx) => ctx.prop.innerProp.contains('I eat squid for breakfast'))
  .withGetter(ctx=>prop.innerProp)
  .withContext({prop:{innerProp:'Not today!'}})
  .asFunc();

// returns {name:null, error:'Property is Invalid', isInvalid:true}
const result = func(1)

In addition to the ruleBuilder class