lov icon indicating copy to clipboard operation
lov copied to clipboard

Validating values in an enum

Open kokujin opened this issue 9 years ago • 2 comments

How can I validate at least one of the following?

["cloudy" "sunny", "rainy"]

Thanks

kokujin avatar Aug 16 '16 18:08 kokujin

Something like this:

'use strict';

const lov = require( 'lov' );

let schema = {

    weather: lov.string().valid( 'cloudy', 'sunny', 'rainy' )
};

let value = {

    weather: 'sunny'
};

console.log(  lov.validate( value, schema ) );
// { error: null, value: { weather: 'sunny' } }

let unknownValue = {

    weather: 'tornado'
};

console.log(  lov.validate( unknownValue, schema ) );
// { error: [Error: weather: does not match valid value(s)],
//  value: { weather: 'tornado' } }

richardhyatt avatar Aug 16 '16 18:08 richardhyatt

Can we close this issue?

richardhyatt avatar Aug 26 '16 20:08 richardhyatt