Hi Adam,
I skipped this article of yours last year. i just wanted to point one library that might also do the job and that i use everywhere. It's called Joi. Joi is a really powerfull validation library that covers everything you listed and a lot more.
Here are some of your article examples converted :
import Joi,{assert} from 'joi'; const statuses = ['open', 'closed', 'hold']; const myFunction = (status = '') => { assert(statuses,Joi.string().values(...statuses)); } const colors = { red: '#ff0000', green: '#00ff00', blue: '#0000ff', } const myFunction = (color = '') => { assert(color, Joi.string().values(Object.values(colors))); }
import Joi,{assert} from 'joi'; const myFunction = (balance = 0) => { assert(balance,Joi.number()); } const myFunction = (age = 0) => { assert(age,Joi.number().min(1).max(25)); } const myFunction = (id = 0) => { assert(age,Joi.number().min(1)); }
it's really powerfull, it can check anything with any complex schema. you can check emails, patterns, etc...
might be worth giving it a shot.
Also, FWIW, the NPM package for my version of this is now published here:
npmjs.com/package/@toolz/allow
Very cool - thanks for pointing this out!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Adam,
I skipped this article of yours last year. i just wanted to point one library that might also do the job and that i use everywhere. It's called Joi.
Joi is a really powerfull validation library that covers everything you listed and a lot more.
Here are some of your article examples converted :
it's really powerfull, it can check anything with any complex schema. you can check emails, patterns, etc...
might be worth giving it a shot.
Also, FWIW, the NPM package for my version of this is now published here:
npmjs.com/package/@toolz/allow
Very cool - thanks for pointing this out!