Skip to content

Instantly share code, notes, and snippets.

@JoeStanton
Last active September 16, 2017 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoeStanton/40300d38d56f9b527bb809b235cfc4bf to your computer and use it in GitHub Desktop.
Save JoeStanton/40300d38d56f9b527bb809b235cfc4bf to your computer and use it in GitHub Desktop.
import {SuitType} from "./types";
import {generateSchema} from "flow-runtime";
const validate = (value, type) => {
return joi.validate(value, generateSchema(type), {
abortEarly: false
});
}
// Validation calls
console.log(validate("Carrot", SuitType));
// Output
// {
// error: [ValidationError: "value" must be one of [Diamonds, Clubs, Hearts, Spades]],
// value: 'Carrot'
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment