1 # slice-ansi [![Build Status](https://travis-ci.org/chalk/slice-ansi.svg?branch=master)](https://travis-ci.org/chalk/slice-ansi) [![XO: Linted](https://img.shields.io/badge/xo-linted-blue.svg)](https://github.com/sindresorhus/xo)
3 > Slice a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
9 $ npm install slice-ansi
16 const chalk = require('chalk');
17 const sliceAnsi = require('slice-ansi');
19 const input = 'The quick brown ' + chalk.red('fox jumped over ') +
20 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
22 console.log(sliceAnsi(input, 20, 30));
28 ### sliceAnsi(input, beginSlice, [endSlice])
34 String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk).
40 Zero-based index at which to begin the slice.
46 Zero-based index at which to end the slice.
51 - [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
52 - [cli-truncate](https://github.com/sindresorhus/cli-truncate) - Truncate a string to a specific width in the terminal
53 - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
58 - [Sindre Sorhus](https://github.com/sindresorhus)
59 - [Josh Junon](https://github.com/qix-)