r2g icon indicating copy to clipboard operation
r2g copied to clipboard

get colors in script with no deps

Open ORESoftware opened this issue 7 years ago • 1 comments

https://github.com/nodejs/node/issues/21789

ORESoftware avatar Jul 13 '18 07:07 ORESoftware

const colors = {
  'bold': [1, 22],
  'italic': [3, 23],
  'underline': [4, 24],
  'inverse': [7, 27],
  'white': [37, 39],
  'grey': [90, 39],
  'black': [30, 39],
  'blue': [34, 39],
  'cyan': [36, 39],
  'green': [32, 39],
  'magenta': [35, 39],
  'red': [31, 39],
  'yellow': [33, 39]
};

function stylize(color, str) {
  const [start, end] = colors[color];
  return `\u001b[${start}m${str}\u001b[${end}m`;
}

ORESoftware avatar Jul 13 '18 07:07 ORESoftware