Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
You would get the greatest benefit by using a static typechecker like TypeScript or Flow in combination with a dynamic validator like Joi or Ajv. It works roughly like this:
Define a static type
Define a validator function for that type, using Joi or Ajv as the underlying validation tool
Make the validator function return the input value cast to the static type (if validation succeeded) or the validation error (if validation failed)
For example:
interfacePerson{id:string;name:string;}constpersonValidator:Validator<Person>=Validator(Joi.object().keys({id:Joi.string(),name:Joi.string()}),);...constresult=personValidator.validate(personObj);if(resultinstanceofValidationError){...}else{// Now we know 100% that result is a valid Person with id and name}
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.
You would get the greatest benefit by using a static typechecker like TypeScript or Flow in combination with a dynamic validator like Joi or Ajv. It works roughly like this:
For example: