fast-slice-ansi
v0.3.0
Published
A tiny and fast text slicing library which takes ANSI escapes into account.
Readme
fast-slice-ansi
A fast
String#slicewhich supports ANSI escape sequences.
Inspired by slice-ansi, this comes with various performance improvements.
Install
npm i -S fast-slice-ansiUsage
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: 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});License
MIT
