Skip to content

Instantly share code, notes, and snippets.

@ephraimduncan
Created September 30, 2020 13:10
Show Gist options
  • Save ephraimduncan/e5da46341483802ada7a99736edc5947 to your computer and use it in GitHub Desktop.
Save ephraimduncan/e5da46341483802ada7a99736edc5947 to your computer and use it in GitHub Desktop.
Onliner Functions to Add Colors to console logs
// Source: https://stackoverflow.com/a/46705010
const { r, g, b, w, c, m, y, k } = [
['r', 1],
['g', 2],
['b', 4],
['w', 7],
['c', 6],
['m', 5],
['y', 3],
['k', 0],
].reduce(
(cols, col) => ({
...cols,
[col[0]]: (f) => `\x1b[3${col[1]}m${f}\x1b[0m`,
}),
{}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment