ow
ow copied to clipboard
Env variable to turn off validation?
I think very specific validators, while potentially useful, could end up costing a lot at runtime. What if there were a way to instantiate a copy of ow
that can be ignored?
The API could look something like:
import _ow from 'ow'
const ow = _ow.ignoreIf(process.env.NODE_ENV === 'production')
function veryExpensiveValidator(obj) {
// ...
}
// doesn't do anything when NODE_ENV is production
ow(someObj, obj => ow.is(obj))
Why? What's the use case? Why wouldn't you trust data in development, but suddenly in production the data would always be correct?
I’ve worked on a game dev project where we did this for performance reasons. It’s quite a widely used approach, so offering the option might help this library’s adoption, even if the authors don’t use it themselves.
@SamVerschueren in general I think it makes plenty of sense actually; this is the default behavior for production React builds, for example (propTypes are not checked). The reasoning being that type error warning messages are useful to developers, but not very useful to end users.
However I can see how certain uses of this library wouldn't benefit from such an approach, for example if you're using try/catch to perform backup behavior when the data doesn't match the primary expected shape.
But if you're like me, you just want to use these validation messages to let users know when they're using an API incorrectly.