Skip to content

Commit

Permalink
Don't calculate unnecessary contrast ratios
Browse files Browse the repository at this point in the history
  • Loading branch information
darekkay committed Nov 23, 2020
1 parent 36fb0ae commit 896d22f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

- :rocket: Ignore invalid colors.
- :rocket: Don't calculate unnecessary contrast ratios.
- :hammer: Replace TravisCI with GitHub Actions.

## [1.1.0] - 2020-10-28
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ const verifyContrastRatio = (palette, magicNumber) => {

palette.forEach((color1) => {
palette.forEach((color2) => {
const contrastRatio = color1.onecolorValue.contrast(color2.onecolorValue);

if (color1.grade > color2.grade) {
return; // don't compare same colors to each other
}

const contrastRatio = color1.onecolorValue.contrast(color2.onecolorValue);

if (Math.abs(color1.grade - color2.grade) >= magicNumber.value) {
if (contrastRatio < magicNumber.ratio) {
violations.push({ color1, color2, contrastRatio });
Expand Down

0 comments on commit 896d22f

Please sign in to comment.