-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Array validation #13
Comments
For arrays you can use this approach. What do you have in mind? useSchema(
{
'users.name': (value, pointer) => value.length > 10,
},
{
users: [
name: 'Marco'
],
},
) |
That looks like a good start, @marcosvega91! I was thinking that useSchema([1, 2, 3], [1, 2, 3]) // OK! The complexity comes with describing a spec of expected data. // Validate each Array member against a predicate.
useSchema([1, 2, 3], (value) => !isNaN(value))
// Validate each Array member against a unique predicate.
useSchema(
[1, 'admin', { firstName: 'John' }],
() => [
(value) => !isNaN(value),
(value) => value === 'admin',
(value) => ({
// Regular schema validation
firstName: value => value === 'John'
})
]
) It gets more complex, when you wish to validate a portion of Array against a general predicate, and a portion against exact predicate functions. I think we should approach this from the specification point of view, defining what features should be supported. |
Array of course should be implemented 💯 |
Validating a tuple, for example: type UserInfo = [string, number]
const user: UserInfo = ['John', 32]
useSchema(user, [validateUsername, validateAge]) |
What
Need to support Array validation.
How
The text was updated successfully, but these errors were encountered: