Socket
Book a DemoInstallSign in
Socket

@c8/joi-validator-promised

Package Overview
Dependencies
Maintainers
5
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@c8/joi-validator-promised

A wrapper around Joi `validate` method which provides support for promises

1.0.9
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
5
Weekly downloads
 
Created
Source

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

Keywords

joi

FAQs

Package last updated on 29 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.