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

predicado

v0.0.6

Published

Predicate Driven Validations

Downloads

33

Readme

Predicado ✅

build status npm version

Predicado is a small library for convenient predicate driven validations. It was built on top of the data.validation module from Folktale.

Getting Started

$ npm install predicado --save
import { validate } from "predicado";

const validations = [
  {
    error: "Must have email.",
    predicate: user => !!user.email
  },
  {
    error: "Must have password.",
    predicate: user => !!user.password
  }
];

const validUser = {
  email: "johndoe@gmail.com",
  password: "cupcake"
};

console.log(validate(validations, validUser));
// => Validation.Success({ email: "johndoe@gmail.com", password: "cupcake" })

const invalidUser = {
  email: "johndoe@gmail.com"
};

console.log(validate(validations, invalidUser));
// => Validation.Failure([ "Must have password." ])

Background

In summary, the validate function can be described as:

validate :: (validations, target) -> Validation

Its first argument validations is an array of validation objects, each containing an error property and a predicate property. An error could be any arbitrary object that will populate the validation results in case of failure. The predicate is a function to be called agains the target data structure. In the example above, there are two validations, one to check the presence of an email property and another one to check the presence of a password property in the target object.

The result returned by validate is a Validation container. The Validation concrete instances are of two possible subtypes: Success or Failure. When all of the predicates are true for a given target then validate returns a Success instance wrapping the target object. Otherwise it returns a Failure instance holding a list of all the corresponding errors.

From there you can manipulate the validation result by following the Validation API. Here is an example:

const onSuccess = user => "This user is totally valid!";
const onFailure = errors => "A valid user:\n" + errors.map(e => "* " + e).join("\n");

const message = validate(validations, invalidUser).fold(onFailure, onSuccess);

console.log(message);
// => A valid user:
// => * Must have an email.
// => * Must have a password.

Autocurry

The validate interface favors curry, so that you can define your custom validation functions in a point-free way:

import { validate } from "predicado";

const validations = [
  {
    error: "Must have email.",
    predicate: user => !!user.email
  },
  {
    error: "Must have password.",
    predicate: user => !!user.password
  }
];

const validateUser = validate(validations);

const validUser = {
  email: "johndoe@gmail.com",
  password: "cupcake"
};

console.log(validateUser(validUser));
// => Validation.Success({ email: "johndoe@gmail.com", password: "cupcake" })

const invalidUser = {
  email: "johndoe@gmail.com"
};

console.log(validateUser(invalidUser));
// => Validation.Failure([ "Must have password." ])

License

Feel free to use this code as you please.