Skip to content

Instantly share code, notes, and snippets.

@meowabyte
Created March 15, 2025 10:17
Show Gist options
  • Save meowabyte/80161249c6fd1ef7e6ff63c26860a3c0 to your computer and use it in GitHub Desktop.
Save meowabyte/80161249c6fd1ef7e6ff63c26860a3c0 to your computer and use it in GitHub Desktop.
hex color to tm hex color
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