🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

fast-slice-ansi

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-slice-ansi

A tiny and fast text slicing library which takes ANSI escapes into account.

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

fast-slice-ansi

A fast String#slice which supports ANSI escape sequences.

Inspired by slice-ansi, this comes with various performance improvements.

Install

npm i -S fast-slice-ansi

Usage

import {sliceAnsi} from 'fast-slice-ansi';
import {styleText} from 'node:util';

const input = `Hello ${styleText('blue', 'blue')} world`;

const result = sliceAnsi(input, 6);
// result: '\u001b[34mblue\u001b[39m world'

Options

An options object can be passed which has the following properties:

  • visual: If true (default), slices operate against the visual representation of the string (e.g. a surrogate pair is counted as one character)

Example:

sliceAnsi(input, 0, 3, {visual: false});

License

MIT

Keywords

slice

FAQs

Package last updated on 01 Oct 2025

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