Geraint

Results 81 comments of Geraint

I've been referring to this as "coercive validation", and have something like it in my [PHP validator](https://github.com/geraintluff/jsv4-php) - is that the kind of thing you're thinking of? Also when it...

OK - it seems to me like logic for this would greatly increase complexity. A separate branch, maybe, possibly published as `tv4-coerce`?

Hmm - actually, it could be done fairly simply using a plugin/extension. Call `validateMultiple()`, fix errors, rinse, repeat. Keep some kind of signature from the errors to prevent endless loops....

Well, it's not been clearly defined, but for me "coercive validation" means that it takes some (possibly invalid) input, and produces something that is valid. So it would definitely strip...

@Bartvds - I should also note that the addon-based approach I described could also work in "one pass" for simple modifications (e.g. type-casting, removing non-defined properties if "banUnknownProperties" is enabled)....

I started a separate project to explore these: https://github.com/geraintluff/tv4-coerce It works by recursive "validate and fix". The actual core of the implementation is [very small](https://github.com/geraintluff/tv4-coerce/blob/master/main.js), and the bulk of the...

I've duplicated your comment as geraintluff/tv4-coerce#1, and made a response there.

@mitar: If I'm understanding correctly, that kind of type-juggling is what [this example](https://github.com/geraintluff/tv4-coerce/blob/master/coerce-standard.js#L4-L16) from `tv4-coerce` does, in a limited way. The problem with a callback midway through validation is that...

In the general case, you will need to re-validate everything anyway at least once, because there might be interdependencies (e.g. by changing the type of a sub-property, you end up...

Nice suggestion making it an option - I'll work on that.