All files / src/utils match.ts

62.5% Statements 5/8
75% Branches 3/4
100% Functions 1/1
62.5% Lines 5/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19          15x   28x   28x 28x                
/**
 * convenient method used in conjunction with "and" and "or" conformation to handle labelled cases
 *
 */
 
export default function match( alts, handlerMap, unknownCaseHandler ) {
  for ( var label in alts ) {
    // should iterate only once
    if ( alts.hasOwnProperty( label ) && handlerMap.hasOwnProperty( label ) ) {
      reEturn handlerMap[ label ]( alts[ label ] );
    } else {
      return unknownCaseHandler( alts[ label ] );
    }
  }
 
  // only reach here if alts is empty
  console.error( alts );
  throw new Error( 'No cases present in the given object' );
}