All files / atom/progressBar/src/ProgressBarLine usePercentage.js

100% Statements 11/11
93.33% Branches 14/15
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 171x 8x 8x 1x   7x 1x   7x 1x 1x   7x        
const usePercentage = ({percentage, mainBarPercentage, extraBarPercentage}) => {
  const response = []
  if (Array.isArray(percentage) && percentage.length >= 0 && percentage.every(number => typeof number === 'number')) {
    return percentage
  }
  if (typeof mainBarPercentage === 'number') {
    response.push(mainBarPercentage)
  }
  if (typeof extraBarPercentage === 'number') {
    response[1] = extraBarPercentage
    response[0] = response[0] === undefined ? 0 : response[0]
  }
  return response.length === 0 && typeof percentage === 'number' ? [percentage] : response
}
 
export default usePercentage