-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97a3492
commit 8ffe7f3
Showing
6 changed files
with
55 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describe, expect, it } from "bun:test" | ||
import { isLightColor } from './colors' | ||
|
||
describe('isLightColor', () => { | ||
it('should return true for a light color', () => { | ||
const hexa = '#FFFFFF' | ||
const result = isLightColor(hexa) | ||
expect(result).toBe(true) | ||
}) | ||
|
||
it('should return false for a dark color', () => { | ||
const hexa = '#000000' | ||
const result = isLightColor(hexa) | ||
expect(result).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { hexToRgba } from "@uiw/color-convert" | ||
|
||
|
||
export * from "@uiw/color-convert" | ||
|
||
/** | ||
* Check if a given color in hexadecimal format is a light color. | ||
* | ||
* @param hexa - The hexadecimal color code to check. | ||
* @returns A boolean indicating if the color is light. | ||
*/ | ||
export const isLightColor = (hexa: string) => { | ||
const { r, g, b, a } = hexToRgba(hexa) | ||
const brightness = r * 0.299 + g * 0.587 + b * 0.114 + (1 - a) * 255 | ||
|
||
return brightness > 186 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters