Skip to content
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

Add support for validation of array of non-object values #85

Closed
jakubkoci opened this issue Jul 15, 2017 · 3 comments
Closed

Add support for validation of array of non-object values #85

jakubkoci opened this issue Jul 15, 2017 · 3 comments

Comments

@jakubkoci
Copy link

At first, thanks for your good job with this library I really like it.

I would like to be able to validate property which has array of strings for example.

const input = {
  users: [
    'foobar', 
    'longerstring'
  ]
}

const validationRules = {
  users: [[ 
    array => array.every(item => item.length > 6), 
    'Every item in array must be string with at least 5 characters' 
  ]],
}

const validationResult = spected(validationRules, input)

And it would return this:

{ users: true }

or this:

{ users: [ 'Every item in array must be string with at least 5 characters' ] }

depending on validation predicate and input data.

Currently, it retuns error:

TypeError: Invalid attempt to destructure non-iterable instance

I have tried to avoid validation of such property by omitting it from validation rules (that would be also nice to be able to do that, such as with other properties according to docs), but it also returns error:

TypeError: Cannot read property '0' of undefined
@busypeoples
Copy link
Owner

I will have a look at the issue.

@busypeoples
Copy link
Owner

busypeoples commented Jul 16, 2017

Yes, will add support for this use case in 0.5. Thanks for the very valuable input!

@busypeoples
Copy link
Owner

Updated to 0.5, this should work now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants