Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
The 'ansi' npm package provides a set of utilities for working with ANSI escape codes, which are used to control text formatting, color, and other output options on text terminals. This package allows you to manipulate text output in the terminal, making it more readable and visually appealing.
Text Formatting
This feature allows you to format text in the terminal. The example code demonstrates how to make text bold using the 'ansi' package.
const ansi = require('ansi');
const cursor = ansi(process.stdout);
cursor.bold().write('Bold text').reset();
Text Coloring
This feature allows you to change the color of the text in the terminal. The example code shows how to make text red using the 'ansi' package.
const ansi = require('ansi');
const cursor = ansi(process.stdout);
cursor.red().write('Red text').reset();
Cursor Positioning
This feature allows you to move the cursor to a specific position in the terminal. The example code demonstrates how to move the cursor to position (10, 5) and write text there using the 'ansi' package.
const ansi = require('ansi');
const cursor = ansi(process.stdout);
cursor.goto(10, 5).write('Text at position (10, 5)').reset();
Chalk is a popular package for styling terminal strings. It provides a simpler and more intuitive API for applying colors and styles to text. Unlike 'ansi', which focuses on low-level ANSI escape codes, 'chalk' abstracts these details away, making it easier to use.
Colors is another package for adding color and style to terminal output. It offers a wide range of color and style options and is known for its ease of use. Compared to 'ansi', 'colors' provides a more user-friendly API for common text styling tasks.
CLI-Color is a package that provides a comprehensive set of tools for styling terminal output. It supports nested styles and offers a rich set of features for text formatting and coloring. CLI-Color is more feature-rich compared to 'ansi', making it suitable for complex styling needs.
ansi.js
is a module for Node.js that provides an easy-to-use API for
writing ANSI escape codes to Stream
instances. ANSI escape codes are used to do
fancy things in a terminal window, like render text in colors, delete characters,
lines, the entire window, or hide and show the cursor, and lots more!
Stream
instance.Install with npm
:
$ npm install ansi
var ansi = require('ansi')
, cursor = ansi(process.stdout)
// You can chain your calls forever:
cursor
.red() // Set font color to red
.bg.grey() // Set background color to grey
.write('Hello World!') // Write 'Hello World!' to stdout
.bg.reset() // Reset the bgcolor before writing the trailing \n,
// to avoid Terminal glitches
.write('\n') // And a final \n to wrap things up
// Rendering modes are persistent:
cursor.hex('#660000').bold().underline()
// You can use the regular logging functions, text will be green:
console.log('This is blood red, bold text')
// To reset just the foreground color:
cursor.fg.reset()
console.log('This will still be bold')
// to go to a location (x,y) on the console
// note: 1-indexed, not 0-indexed:
cursor.goto(10, 5).write('Five down, ten over')
// to clear the current line:
cursor.horizontalAbsolute(0).eraseLine().write('Starting again')
// to go to a different column on the current line:
cursor.horizontalAbsolute(5).write('column five')
// Clean up after yourself!
cursor.reset()
(The MIT License)
Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Advanced ANSI formatting tool for Node.js
The npm package ansi receives a total of 455,235 weekly downloads. As such, ansi popularity was classified as popular.
We found that ansi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.