
Product
Introducing Module Reachability: Focus on the Vulnerabilities That Matter
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
strip-ansi
Advanced tools
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.
Strip ANSI escape codes from a string
$ npm install strip-ansi
import stripAnsi from '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 180,277,833 weekly downloads. As such, strip-ansi popularity was classified as popular.
We found that strip-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.
Product
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Company News
Socket is bringing best-in-class reachability analysis into the platform — cutting false positives, accelerating triage, and cementing our place as the leader in software supply chain security.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.