joiflowy

2.0.0 • Public • Published

joiflowy

Codeship Status for cdaringe/joiflowy

what

validate function inputs as concisely as possible, using the powerful joi

why

because writing defensive code can be tedious. in other words, writing code like:

if (!input.field || !input.otherField.deepField) throw new Error(${whatever})
if (!(input.otherField.deepField instanceof Function)) throw new TypeError(${whatever})

for all of the input combinations you want to protect against is often exhausting, incomplete, or too verbose. using joiflowy, you can quickly scaffold exactly what inputs will be accepted, and trash the usual boilerplate.

What's with the name?

"joiflowy" sounds close to joyfully. given that this package protects functions, a core control-flow mechanism, the combination of "joi" & "flow" only seemed appropriate.

usage

const jf = require('joiflowy')
const sum = jf((a, b) => (a + b), jf.joi.number(), jf.joi.number())
sum(1, 2) // ==> 3
sum(1, 'bananas') // ==> throws ValidationError

need joi.validate options? no problem

const jf = require('joiflowy')
const Joi = require('joi') // jf doesn't care which joi is used. jf.joi/jf.Joi/jf.j all ==> joi
const double = jf((a) => (a * 2), Joi.number(), { convert: false })
double(2) // ==> 4
double('2') // ==> throws ValidationError

/joiflowy/

    Package Sidebar

    Install

    npm i joiflowy

    Weekly Downloads

    1

    Version

    2.0.0

    License

    MIT

    Last publish

    Collaborators

    • cdaringe