Created
January 3, 2024 08:47
-
-
Save Exponential-Workload/dbd0be5da7aa1da7ce500c5b9c57b700 to your computer and use it in GitHub Desktop.
hex to ansi
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
// only works for 6-digit hex codes, separated by newlines | |
const hexToRgb = v=>v.split('\n').map(line=>line.split('').map((char,idx,v)=>idx%2===0?Number(`0x${char}${v[idx+1]}`):'')).map(a=>a.filter(v=>typeof v === 'number')) | |
const hexToAnsi = v=>hexToRgb(v).map(r=>`\x1b[38;2;${r.join(';')}m`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment