A fast
String#slicewhich supports ANSI escape sequences.
Inspired by slice-ansi, this comes with various performance improvements.
npm i -S fast-slice-ansiimport {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'An options object can be passed which has the following properties:
visual: Iftrue(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});MIT