all files / src/ acceptance.js

100% Statements 13/13
100% Branches 14/14
100% Functions 3/3
100% Lines 8/8
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20   11× 11×   11× 22×           11×            
import Validators from './validators'
import { prepareMsg, prepare, memoize } from './helpers'
 
let acceptance = memoize(function ({ accept, message, msg, if: ifCond, unless } = {}) {
  msg = msg || message
 
  return prepare(ifCond, unless, false, function (value) {
    if (
      []
        .concat(accept || Validators.defaultOptions.accept)
        .map(String)
        .indexOf(value) < 0
    ) {
      return Validators.formatMessage(prepareMsg(msg, 'acceptance'))
    }
  })
})
 
export default acceptance