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

validateMany should return null when all validations pass #40

Open
petr-egert opened this issue Feb 26, 2020 · 0 comments
Open

validateMany should return null when all validations pass #40

petr-egert opened this issue Feb 26, 2020 · 0 comments

Comments

@petr-egert
Copy link

validateMany currently returns an array of results ([null]), even if all subvalidations successfully pass. null should be returned directly to be consistent with validate and allow nesting of validate and validateMany calls.

validate({ 
  foo: [isRequired] 
})({ 
  foo: 'bar' 
}); // === null

validateMany({ 
  foo: [isRequired] 
})([{ 
  foo: 'bar' 
}]) // === [null], expected to be null

validate({
  arr: [
    validateMany({ 
      foo: [isRequired] 
    })
  ]
})({
  arr: [{ 
    foo: 'bar' 
  }]
}) // === {arr: [null]}, expected to be null

Of course when at least one validation fails, the structure should be kept as is to know which index is wrong.

Proposed fix:

const fixedValidateMany = validations => o(when(all(isNil), always(null)), validateMany(validations));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant