all files / src/ format.js

100% Statements 15/15
100% Branches 14/14
100% Functions 3/3
100% Lines 9/9
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16     45× 45×   45× 73× 51×          
import messages from './messages'
import Validators from './index'
import { toObjectMsg, prepare, memoize } from './helpers'
 
 
let format = memoize(function ({ 'with': wit, without, message, msg, 'if': ifCond, unless, allowBlank }) {
  msg = toObjectMsg(msg || message)
 
  return prepare(ifCond, unless, allowBlank, function (value) {
    if ((wit && !value.match(wit)) || (without && value.match(without))) {
      return Validators.formatMessage(msg || messages.invalid)
    }
  })
})
 
export default format