globalbrain / sefirot

Global Brain Design System.
https://sefirot.globalbrains.com
MIT License
151 stars 12 forks source link

[Validation] Add "Integer" rule #561

Open kiaking opened 1 week ago

kiaking commented 1 week ago

Add validation rule to validate the given number is integer (no decimals). Vuelidate has this built in validator, but I guess it would be easy to implement our own with Number.isInteger(v).

cuebit commented 1 week ago

What do you mean by no decimals? Number.isInteger will still recognise e.g. 1.0 (but not 1.1, etc) as a valid integer.

Isn't this essentially positiveInteger?

That said, positiveInteger and negativeInteger are identical. Not sure if this was a heuristic choice...

kiaking commented 1 week ago

Ah yeah we had positiveInteger... 🤔

What do you mean by no decimals? Number.isInteger will still recognise e.g. 1.0 (but not 1.1, etc) as a valid integer.

Good point. I think we can accept 1.0. This rule should verify that the value can be treated as integer. In our case, in Go for example.

func main() {
    var n int
    n = 1
    n = 1.0 // This works
    n = 1.1 // This is not

    fmt.Printf("%d", n)
}