Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slice-ansi

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slice-ansi

Slice a string with ANSI escape codes

  • 7.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is slice-ansi?

The slice-ansi npm package is designed for slicing strings with ANSI escape codes without breaking the visual appearance. This is particularly useful for terminal applications where text styling (like colors, bold, underline) is applied through ANSI escape codes. It allows developers to extract or truncate portions of the styled text without losing or corrupting the intended styles.

What are slice-ansi's main functionalities?

Slicing styled strings

This feature allows you to slice a string that contains ANSI escape codes, ensuring that the visual styling is preserved in the sliced string. The code sample demonstrates how to slice a string that starts with red-colored text and then resets to default color. The sliced result contains only the portion of the string within the specified range, along with the necessary ANSI codes to maintain the original styling.

const sliceAnsi = require('slice-ansi');
const input = '\u001B[31mThis is red\u001B[39m and this is not.';
const sliced = sliceAnsi(input, 0, 10);
console.log(sliced);

Other packages similar to slice-ansi

Keywords

FAQs

Package last updated on 29 Oct 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc