Skip to content

validateMany should return null when all validations pass #40

Description

@petr-egert

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));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions