GithubHelp home page GithubHelp logo

maxnachlinger / joi-fp Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 8 KB

Provides a few wrappers around Joi's validate(), attempt() and assert() functions with their arguments re-ordered for easier currying / partial application

JavaScript 100.00%

joi-fp's Introduction

joi-fp

Provides a few wrappers around Joi's validate(), attempt() and assert() functions with their arguments re-ordered for easier currying / partial application

travis standard npm

Installation:

npm i joi-fp

What problem does this solve?

When using functions like joi.validate(), you will almost always have values for schema and/or options before you have the value being validated. This little library re-orders the arguments of joi.validate(), joi.attempt() and joi.assert() allowing you to pass the data you have initially, well, initially :) This library also has a few versions of these functions with fixed arities to make currying and partial application easier.

Quick Example

const _ = require('lodash')
const joi = require('joi-fp')(require('joi'))

// example with currying
const validateInput = _.curry(joi.validateFp3)({
  name: joi.string().required()
})({allowUnknown: true});

validateInput({name: 'Max', color: 'blue'})
// { error: null, value: { name: 'Max', color: 'blue' } }

// example with partial application
const validateInputAgain = _.partial(joi.validateFp, {
  name: joi.string().required()
}, {allowUnknown: true});

validateInputAgain({name: 'Max', color: 'blue'}, (err, value) => {
  console.log(err, value) // null { name: 'Max', color: 'blue' }
})

Functions

// fixed arity for easy currying / partial application
validateFp2 (schema, value)
validateFp3 (schema, optionsOrValue, optionsOrCallback)
validateFp (schema, options, value, callback)

attemptFp2 (schema, value)
attemptFp (schema, message, value)

assertFp2 (schema, value)
assertFp (schema, message, value)

joi-fp's People

Contributors

maxnachlinger avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.