-
New Feature Request
-
Resolution: Unresolved
-
Trivial
-
None
-
5.0.0alpha1, 5.0.0alpha2
Most webhooks require to perform input param validation and such validations make as much as 50+% of webhook code. Additionaly there is no unification in validation logic / error messages etc.
It would be great to introduce built-in object that will implement unified validation logic like this:
var data = InputValidator.parse([ {fields: ['url', 'severity', 'title'], validator: 'required'}, {fields: ['url', 'title'], validator: 'string'}, {fields: 'title', validator: 'string', options: {'max': 100}}, {fields: 'severity', validator: 'integer', options: {'min': 1, 'max': 5}}, {fields: 'url', validator: function (value) { if (!value.endsWith('/')) { value += '/'; } return value; }}, {fields: 'title', validator: function (value) { if (value.trim() === '') { throw 'Bebebe, bad value, bebebe!'; } return value; }}, {fields: 'set', validator: 'boolean'} ]);