all files / src/ acceptance.js

100% Statements 17/17
100% Branches 16/16
100% Functions 3/3
100% Lines 11/11
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21       11× 11×     11×   11× 19× 10×          
import React from 'react'
import { FormattedMessage } from 'react-intl'
import { formatMessage, prepare, memoize } from './helpers'
 
export const ACCEPT = ['1', 'true']
 
 
let acceptance = memoize(function ({ accept=ACCEPT, message, msg, 'if': ifCond, unless }={}) {
  msg = formatMessage(msg || message)
     || <FormattedMessage id="form.errors.acceptance" defaultMessage="must be accepted" />
 
  accept = [].concat(accept).map(String)
 
  return prepare(ifCond, unless, false, function (value) {
    if (accept.indexOf(value) < 0) {
      return msg
    }
  })
})
 
export default acceptance