Created
March 15, 2025 10:17
-
-
Save meowabyte/80161249c6fd1ef7e6ff63c26860a3c0 to your computer and use it in GitHub Desktop.
hex color to tm hex color
This file contains hidden or 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
const hexToCol = (hex) => { | |
hex = hex.replace(/^#/, "") | |
if (hex.length === 3) hex = hex.split("").map(c => c.repeat(2)).join("") | |
return Array.from(hex.matchAll(/[0-9a-fA-F]{2}/g)).map(m => parseInt(m[0], 16)) | |
} | |
const hexToTmColor = (hex) => hexToCol(hex).map(n => Math.floor(n / 17)) | |
const hexToTmcolorHex = (hex) => hexToTmColor(hex).map(n => n.toString(16).toUpperCase()).join("") | |
const hex = "#FD66CC" | |
const tmColor = hexToTmcolor(hex) | |
console.log(`HEX ${hex} is TM ${tmColor}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment