uniform-team / Uniform-Validation-Language

A logic language to simplify and improve online form validation.
Apache License 2.0
1 stars 0 forks source link

Number / Integer Type(s) #64

Open dgp1130 opened 7 years ago

dgp1130 commented 7 years ago

Need some way of representing numeric values. JavaScript just has the Number type, though there may be some advantage to us supporting an integer type as well. We should certainly have some way of verifying that a value is an integer, though we can do that with a distinct type or with some kind of round function or regex.

number: year; // Declare as a number

year {
    // How to validate as an integer?
    valid: year >= 2000;
}

Currently we only support the string and boolean types. Nice thing about both of those is that they can never be invalid. A text box can be an empty string, but that it is still a string. A check box can be checked or not, but both are valid booleans.

For numbers, the user can input "hello" which is not a valid number. I'm not entirely sure how we want the Uniform code to respond to that case. We have a couple options:

  1. Set year to be null. We can then define each operator to reject nulls in the way that most makes sense, ie. null > x => null. We can then allow the programmer to compare against null and change their logic accordingly to handle it.
  2. throw an error. We can break out of the expression and treat the statement as having thrown an error. However, there's no real way for developers to catch the exception and handle it which could make logic more difficult.

I don't really care for either solution here, is there a more elegant way we might be able to handle this?