• Version 7.1.0
  • Published
  • 7.95 kB
  • 2 dependencies
  • MIT license


npm i slice-ansi
yarn add slice-ansi
pnpm add slice-ansi


Slice a string with ANSI escape codes




function sliceAnsi

sliceAnsi: (string: string, startSlice: number, endSlice?: number) => string;
  • Slice a string with [ANSI escape codes](

    Parameter string

    A string with ANSI escape codes. Like one styled by [chalk](

    Parameter startSlice

    Zero-based index at which to start the slice.

    Parameter endSlice

    Zero-based index at which to end the slice.

    Example 1

    import chalk from 'chalk';
    import sliceAnsi from 'slice-ansi';
    const string = 'The quick brown ' +'fox jumped over ') +
    'the lazy ' +'dog and then ran away with the unicorn.');
    console.log(sliceAnsi(string, 20, 30));

Package Files (1)

Dependencies (2)

Dev Dependencies (5)

Peer Dependencies (0)

No peer dependencies.


To add a badge like this badgeto your package's README, use the codes available below.

You may also use to create a custom badge linking to

  • Markdown
  • HTML
    <a href=""><img src="" alt=""></a>