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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@motet-a/validate

v0.1.1

Published

[![Build Status](https://travis-ci.org/motet-a/validate.svg?branch=master)](https://travis-ci.org/motet-a/validate) [![Coverage Status](https://coveralls.io/repos/github/motet-a/validate/badge.svg?branch=master)](https://coveralls.io/github/motet-a/valida

Downloads

4

Readme

Build Status Coverage Status

Data validation for Node.js

Oh no, yet another validation library, there are thousands…

Well, I was unable to find the perfect validation library. I like these ones:

  • prop-types. This one is truly great. It’s not the most customizable, not the most chainable and it’s not really suitable outside React, but it perfectly does its job.

  • Joi. Chainable but a bit bloated. You can do a lot with Joi, but it’s not so simple, you can’t always guess what it does without reading the documentation.

This library is an attempt to write a cleaner and simplified Joi, using modern JS features.

Drawbacks

Since it uses Reflect, it is hard to use it in old environments.

How-to

First of all:

const V = require('@motet-a/validate')

V is a validation function which returns its argument, requires a value and throws on error:

V(123) // → 123
V(0) // → 0
V(null) // → throws V.ValidationError
V(undefined) // → throws V.ValidationError

Of course, you can allow null and undefined:

V.optional(null) // → null
V.optional(undefined) // → undefined

You can restrict the type:

V.string('valid') // → 'valid'
V.string(123) // → throws
V.number(NaN) // → throws
V.number(123) // → 123
V.number.integer(123) // → 123
V.object({}) // → {}
V.bool(false) // → false

V.integer is a shortcut for V.number.integer.

V is a validator, V.string is a new validator. Every validator is immutable.

You can mix up everything:

V.optional.string(null) // → null
V.string.optional(null) // → null

You can restrict types of objects and arrays:

V.array.of(V.number.positive)([-1]) // throws (number not positive)
V.object.of(V.string.lower)

You can also shape objects, use rexgexp, extract and reuse field validators and much more. See the examples/ directory.

Inspirations

Joi and prop-types.