all files / src/ format.js

100% Statements 16/16
100% Branches 16/16
100% Functions 3/3
100% Lines 10/10
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18       41× 41×   41× 53× 35×          
import React from 'react'
import { FormattedMessage } from 'react-intl'
import { formatMessage, prepare, memoize, DEFAULT_ALLOW_BLANK } from './helpers'
 
 
export const INVALID_MSG = (<FormattedMessage id="form.errors.invalid" defaultMessage="is invalid" />)
 
let format = memoize(function ({ 'with': wit, without, message, msg, 'if': ifCond, unless, allowBlank=DEFAULT_ALLOW_BLANK }) {
  msg = formatMessage(msg || message)
 
  return prepare(ifCond, unless, allowBlank, function (value) {
    if ((wit && !value.match(wit)) || (without && value.match(without))) {
      return msg || INVALID_MSG
    }
  })
})
 
export default format