Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating values in an enum #4

Open
kokujin opened this issue Aug 16, 2016 · 2 comments
Open

Validating values in an enum #4

kokujin opened this issue Aug 16, 2016 · 2 comments

Comments

@kokujin
Copy link

kokujin commented Aug 16, 2016

How can I validate at least one of the following?

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

Thanks

@richardhyatt
Copy link
Contributor

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
Copy link
Contributor

Can we close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants