jfairbank / revalidate

Elegant and composable validations
http://revalidate.jeremyfairbank.com
MIT License
363 stars 20 forks source link

Add index as argument to createValidator #62

Open monrus opened 5 years ago

monrus commented 5 years ago

Hi, this pull request allows use index of a current array element for compare with other fields of object in the array.

Example:

'stepTimeIntervals[].to': composeValidators(
    isRequired,
    createValidator(
      message => (value, allValues, idx) => {
        if (!allValues.stepTimeIntervals[idx] || value < allValues.stepTimeIntervals[idx].from) {
          return message
        }
      },
      field => `${field} must be more than from`
      )
  )('')

TODO: Checking use cases coverage and add tests

codecov-io commented 5 years ago

Codecov Report

Merging #62 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #62   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          30     30           
  Lines         225    225           
  Branches       62     62           
=====================================
  Hits          225    225
Impacted Files Coverage Δ
src/internal/internalCombineValidators.js 100% <100%> (ø) :arrow_up:
src/internal/createValidatorWithSingleError.js 100% <100%> (ø) :arrow_up:
src/createValidator.js 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fb3917d...70a0c28. Read the comment docs.