1.0.9 • Published 10 years ago

@c8/joi-validator-promised v1.0.9

Weekly downloads
13
License
MIT
Repository
github
Last release
10 years ago

Validator

A wrapper around Joi validate method which provides support for promises

Example

'use strict'

const Validator = require('@c8/joi-validator-promised')

const opts = {
 abortEarly: true
}
const myValidator = new Validator(opts)

const joiSchema = {
     id: Joi.number().min(1),
     name: Joi.string()
}

const data = {
 id: 2,
 name: 'C8 Management'
}

// Using the promise
myValidator.validate(data, joiSchema).then(
    (result) => {
     //do something
    },
    (err) => {
     throw new Validator.ValidationError('A validation error occurred')
    }
)

// Validate Synchronously i.e. with the standard Joi validate method
let result = myValidator.validateSync(data, joiSchema)

//If there is no error
if (!result) {
// Do something
} else {
   throw new Validator.ValidationError('A validation error occurred')
}

As this package is simply a wrapper around Joi validate method, the opts object that is passed to the constructor supports all Joi options

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago