
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
A quality library for the ANSI color/style management.
npm install ansicolor
Other tools lack consistency, failing to solve the simple hierarchy problem:
require ('colors') // most popular color utility
console.log (('foo'.cyan + 'bar').red)

WTF, bar is not rendered red! It sucks. Ansicolor arranges styles in stack and reconstructs proper linear form from that stack:
require ('ansicolor').nice // .nice for unsafe String extensions
console.log (('foo'.cyan + 'bar').red)

Nice!
Other tools provide output (rendering), but not input (parsing). Inspection of ANSI colors in arbitrary strings is essential when implementing cross-platform logging — that works not only in terminal, but in browsers too. Modern browsers support color logging with console.log, but it does not understand ANSI colors — having a proprietary CSS-based format instead.
Ansicolor solves that problem by converting color codes to argument lists that are understandable by browser's consoles:
parsed = color.parse ('foo' + ('bar'.red.underline.bright.inverse + 'baz').bgGreen)
parsed.browserConsoleArguments /* = [
"%cfoo%cbar%cbaz",
"",
"font-weight: bold;font-style: underline;background:rgba(255,51,0,1);color:rgba(0,204,0,1);",
"background:rgba(0,204,0,1);"
] */
console.log (...parsed.browserConsoleArguments) // prints with colors in Chrome!
String wrapping (safe):
color = require ('ansicolor')
console.log ('foo' + color.green (color.inverse (color.bgBrightCyan ('bar')) + 'baz') + 'qux')
String wrapping (unsafe):
require ('ansicolor').nice
console.log ('foo'.red.bright + 'bar'.bgYellow.underline.dim)
All supported options:
'foreground colors'
.black.red.green.yellow.blue.magenta.cyan.white
'background colors'
.bgBlack.bgRed.bgGreen.bgYellow.bgBlue.bgMagenta.bgCyan.bgWhite
'bright background colors'
.bgBrightBlack.bgBrightRed.bgBrightGreen.bgBrightYellow.bgBrightBlue.bgBrightMagenta.bgBrightCyan.bgBrightWhite
'styles'
.bright.dim.italic.underline.inverse // italic may lack support on your platform
Parsing arbitrary strings styled with ANSI escape codes:
parsed = color.parse ('foo'.bgBrightRed + 'bar')
Will return a pseudo-array of styled spans (iterable with for ... of and convertable to an array with spread operator):
[{ css: 'background:rgba(255,51,0,1);', text: 'foo' },
{ css: '', text: 'bar' } ])]
Converting parsed array to argument list (acceptable by Chrome's console.log):
console.log (...parsed.browserConsoleArguments)
Happy logging!
FAQs
Fork of ansicolor with CSS closer to that used in devtools and a few fixes
We found that ansicolour demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.