support for sanitization
See original GitHub issueNot sure whether this in scope of the library, but for example io-ts
, joi
, yup
all etc. can sanitize values (i.e. coerce them within certain boundaries) which is actually useful in some use cases. It would be nice if runtypes could do that too. joi
and yup
all do sanitization for some of their built in types and in io-ts
one can do sanitization in the validator function of custom types by passing the sanitized value to t.success(sanitizedValue)
.
I was actually looking at all the above mentioned libraries incl. runtypes for the use case of API validation. While I really wanted to use io-ts or runtypes (I use typescript everywhere) but I decided against the use of runtypes because of the lack of sanitization and it wasn’t clear to me how to create custom types, and against io-ts because of the lack of an ability to create validation specific error messages.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:5 (2 by maintainers)
I packaged my filtering into a small lib in case it’s useful for anyone else.
runtypes-filter
.Usage:
That makes sense. I think it should be possible to write such a function against runtype’s
Reflect
API. If so, I would say that it makes sense to define it as a separate library, so as to keep the core of runtypes as simple as possible. What do you think?