Skip to content

Commit

Permalink
feat(getLuminance): Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jcquinlan committed May 4, 2017
1 parent 11462f6 commit c026dd7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/color/getLuminance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ import curry from '../internalHelpers/_curry'
* // Styles as object usage
* const styles = {
* background: getLuminance('#CCCD64') >= getLuminance('#0000ff') ? '#CCCD64' : '#0000ff',
* background: getLuminance('rgba(58, 133, 255, 1)') >= getLuminance('rgba(255, 57, 149, 1)') ?
* background: getLuminance('rgba(58, 133, 255, 1)') >= getLuminance('rgba(255, 57, 149, 1)') ?
* 'rgba(58, 133, 255, 1)' :
* 'rgba(255, 57, 149, 1)',
* }
*
* // styled-components usage
* const div = styled.div`
* background: ${getLuminance('#CCCD64') >= getLuminance('#0000ff') ? '#CCCD64' : '#0000ff'};
* background: ${getLuminance('rgba(58, 133, 255, 1)') >= getLuminance('rgba(255, 57, 149, 1)') ?
* background: ${getLuminance('rgba(58, 133, 255, 1)') >= getLuminance('rgba(255, 57, 149, 1)') ?
* 'rgba(58, 133, 255, 1)' :
* 'rgba(255, 57, 149, 1)'};
*
*
*
*/
function getLuminance(color: string): number {
const rgbColor = parseToRgb(color);
const rgbColor = parseToRgb(color)
const [r, g, b] = Object.keys(rgbColor).map(key => {
const channel = rgbColor[key] / 255;
const channel = rgbColor[key] / 255
return channel <= 0.03928
? channel / 12.92
: Math.pow((channel + 0.055) / 1.055, 2.4);
});
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
: ((channel + 0.055) / 1.055) ** 2.4
})
return (0.2126 * r) + (0.7152 * g) + (0.0722 * b)
}

export default curry(getLuminance)

0 comments on commit c026dd7

Please sign in to comment.