Sha256: a23461737baaf905e0d4e78f7f51e1e3b3677ecf8e6df22056fb1e4c5a23ccad

Contents?: true

Size: 636 Bytes

Versions: 3

Compression:

Stored size: 636 Bytes

Contents

var Joi = require('../');


var schema = {
    type: Joi.string().required(),
    subtype: Joi.alternatives()
        .when('type', {is: 'video', then: Joi.valid('mp4', 'wav')})
        .when('type', {is: 'audio', then: Joi.valid('mp3')})
        .when('type', {is: 'image', then: Joi.valid('jpg', 'png')})
        .when('type', {is: 'pdf'  , then: Joi.valid('document')})
};


Joi.assert({ type: 'video', subtype: 'mp4' }, schema); // Pass
Joi.assert({ type: 'video', subtype: 'wav' }, schema); // Pass
Joi.assert({ type: 'other', subtype: 'something' }, schema); // Fail
Joi.assert({ type: 'audio', subtype: 'mp4' }, schema); // Fail

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/hapi/node_modules/joi/examples/multipleWhen.js
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/hapi/node_modules/joi/examples/multipleWhen.js
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/hapi/node_modules/joi/examples/multipleWhen.js