lov
lov copied to clipboard
Validating values in an enum
How can I validate at least one of the following?
["cloudy" "sunny", "rainy"]
Thanks
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' } }
Can we close this issue?