-
Notifications
You must be signed in to change notification settings - Fork 2
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
ca55a69
commit 4022917
Showing
11 changed files
with
221 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,6 @@ | ||
declare module "emoji-dictionary" { | ||
export function getUnicode(name: string): string; | ||
export function getName(unicode: string): string; | ||
export function getShortcode(unicode: string): string; | ||
export function getAllNames(): string[]; | ||
} |
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,32 @@ | ||
const getContrastColor = (hexColor: string): string => { | ||
hexColor = hexColor.replace(/^#/, ''); | ||
|
||
const r = parseInt(hexColor.substring(0, 2), 16); | ||
const g = parseInt(hexColor.substring(2, 4), 16); | ||
const b = parseInt(hexColor.substring(4, 6), 16); | ||
|
||
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255; | ||
|
||
const colors = [ | ||
{ color: '#000000', luminance: 0 }, // black | ||
{ color: '#FFFFFF', luminance: 1 }, // white | ||
{ color: '#FF0000', luminance: 0.2126 }, // red | ||
{ color: '#00FF00', luminance: 0.7152 }, // green | ||
{ color: '#0000FF', luminance: 0.0722 }, // blue | ||
]; | ||
|
||
let bestColor = colors[0]; | ||
let bestContrast = 0; | ||
|
||
for (const color of colors) { | ||
const contrast = Math.abs(luminance - color.luminance); | ||
if (contrast > bestContrast) { | ||
bestContrast = contrast; | ||
bestColor = color; | ||
} | ||
} | ||
|
||
return bestColor.color; | ||
}; | ||
|
||
export default getContrastColor; |
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,7 @@ | ||
import emoji from "emoji-dictionary"; | ||
|
||
const replaceEmoticons = (text: string) => { | ||
return text.replace(/:\w+:/g, (match) => emoji.getUnicode(match) || match); | ||
}; | ||
|
||
export default replaceEmoticons; |
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