all files / src/ presence.js

100% Statements 14/14
100% Branches 18/18
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 17 18     24×     17×            
import Validators from './validators'
import { isFileList } from './file'
import { prepareMsg, prepare, memoize } from './helpers'
 
let presence = memoize(function ({ message, msg, if: ifCond, unless } = {}) {
  msg = msg || message
 
  return prepare(ifCond, unless, false, function (value) {
    if (
      typeof value === 'string' ? !value.trim() : isFileList(value) && !isNaN(value.length) ? !value.length : !value
    ) {
      return Validators.formatMessage(prepareMsg(msg, 'presence'))
    }
  })
})
 
export default presence