All files is-fsa.js

92.31% Statements 12/13
90% Branches 9/10
100% Functions 1/1
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54        1x 1x           1x                     1x                         12x         11x 11x 24x         11x 2x     9x    
/**
 * Module Dependencies
 */
 
var isObject = require('./is-object')
var keys = Object.keys
 
/**
 * Whitelisted keys
 */
 
var whitelist = {
  type: 1,
  meta: 1,
  error: 1,
  payload: 1
}
 
/**
 * Export `isFSA`
 */
 
module.exports = isFSA
 
/**
 * Check if the value is an action
 *
 * Spec: https://github.com/acdlite/flux-standard-action#actions
 *
 * @param {Mixed} value
 * @return {Boolean}
 */
 
function isFSA (value) {
  // value must be an object and have a type
  if (!isObject(value) || !value.type) return false
 
  // if any properties on the object are
  // not part of the whitelist fail then
  // return false
  var props = keys(value)
  for (var i = 0, prop; (prop = props[i]); i++) {
    Iif (!whitelist[prop]) return false
  }
 
  // lastly check that if value.error is "true"
  // that our payload is error-like
  if (value.error === true) {
    return value.payload.message && value.payload.name
  }
 
  return true
}