imbrn/v8n

How to validate items of an array of arrays ?

alexisab opened this issue · 2 comments

Hello !

I want to validate values of an array of arrays, something like this :

const value = [
  [0,1,2,3],
  [0,2],
  [0,3,4]
]

I tried this ...

{
                value: v8n()
                    .array()
                    .maxLength(8)
                    .every.array()
                    .every.number()
                    .positive(),
}

... but it didn't work.

Is it possible to validate this kind of array or sould I create my own custom rule ?

imbrn commented

Hey @alexisab, sorry for the delay.

So, by chaining array based modifiers, you can validate array items individually. I don't know if this is what you're looking for, but you could achieve that validation with something like this:

v8n()
    .array()
    .maxLength(8)
    .every.array()
    .every.every.number()
    .every.every.positive()

Thank you !