Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
ANSI stream control of position, style, and color via fluent API.
ansi2 sends ANSI escape codes to a writable stream to:
npm install --save ansi2
// wrap a writable stream
var ansi = require('ansi2')(process.stdout)
// write a string to stream.
// it's affected by the current color/style/position.
// default styling + color:
ansi.write('boring default text')
// reset the foreground, background, and styling.
ansi.reset()
// Or, reset only the foreground:
ansi.resetFg()
// Or, reset only the background:
ansi.resetBg()
// all functions are chainable:
ansi.reset().blue().blackBg().write('blah').reset().write('\n')
Available colors as functions:
Use the "bright" versions of those by adding suffix "Bright" to the function name.
Apply the color to the background by adding suffix "Bg" to the function name.
Apply both suffixes for a bright background (add suffix "BrightBg").
Other color functions accept RGB values and CSS style hex codes:
rgb(r, g, b)
- Also has a background version as rgbBg(r, g, b)
hex(string)
- Also has a background version as hexBg(string)
. May have a hash symbol prefix, or not.Color functions called with an argument will change the color and then write the string.
ansi.blue().write('blue text')
// Or, use a shorthand, provide the text to the color function:
ansi.blue('blue text')
// still using blue for foreground.
// change the background now.
// standard colors have a "background" version
// by adding 'Bg' to their function name.
ansi.blackBg().write('blue on black text')
// or specify colors via RGB or hex values.
// all these change the color to red.
ansi.rgb(255, 0, 0)
ansi.hex('FF0000')
ansi.hex('#FF0000')
Available styles as functions:
Reset the style by adding suffix "Reset" to the function name.
Style functions called with an argument will change the style and then write the string.
ansi.bold().write('bold text')
// Or, use a shorthand, provide the text to the color function:
ansi.bold('bold text')
ansi.italic()
// then, undo the bold styling only, retaining italic.
ansi.boldReset()
Available position functions:
// example using default, this will move up one line:
ansi.up()
// example specifying amount to move, this moves up 5 lines:
ansi.up(5)
// moves to the top left:
ansi.goto()
// moves to line 5 column 7:
ansi.goto(7, 5) // think (x, y)
// erase current line and then write new content:
ansi.restartLine().write('new text overwriting current line')
// or, restart back at a certain column to overwrite only the later part:
ansi.write('label: some text') // shows whole string
.restartLine(7).write('new text') // shows: label: new text
FAQs
ansi2
The npm package ansi2 receives a total of 7 weekly downloads. As such, ansi2 popularity was classified as not popular.
We found that ansi2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.