Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
strip-ansi
Advanced tools
Strip ANSI escape codes from a string
Weekly downloads
Package description
The strip-ansi npm package is used to remove ANSI escape codes from strings. These codes are often used to provide coloring and formatting in terminal output, but they can be problematic when the text needs to be processed without these codes, such as logging to a file or displaying in a GUI.
Strip ANSI escape codes from a string
This feature allows you to remove any ANSI escape codes from a given string, leaving only the plain text without any formatting or color.
const stripAnsi = require('strip-ansi');
const coloredString = '\u001B[4mUnicorn\u001B[0m';
const strippedString = stripAnsi(coloredString);
console.log(strippedString); // 'Unicorn'
Chalk is a popular npm package that allows you to style terminal text with colors and other effects. While it is primarily used to add ANSI codes to strings, it also provides methods to strip color from strings, which can be used as an alternative to strip-ansi for this specific purpose.
ansi-regex is a package that provides a regular expression to match ANSI escape codes. It can be used in combination with string replace functions to remove ANSI codes from strings, similar to what strip-ansi does, but requires a bit more manual work.
ansi-colors is another library for styling terminal strings with ANSI colors. It also includes functionality to strip ANSI codes from strings. It is a lightweight alternative to chalk and can be used in place of strip-ansi for removing ANSI codes.
Readme
Strip ANSI escape codes from a string
$ npm install strip-ansi
const stripAnsi = require('strip-ansi');
stripAnsi('\u001B[4mUnicorn\u001B[0m');
//=> 'Unicorn'
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
//=> 'Click'
Available as part of the Tidelift Subscription.
The maintainers of strip-ansi and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
FAQs
Strip ANSI escape codes from a string
The npm package strip-ansi receives a total of 126,317,366 weekly downloads. As such, strip-ansi popularity was classified as popular.
We found that strip-ansi demonstrated a healthy version release cadence and project activity because the last version was released less than 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
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.