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/xojs/xo)
3 > Slice a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
8 $ npm install slice-ansi
14 const chalk = require('chalk');
15 const sliceAnsi = require('slice-ansi');
17 const string = 'The quick brown ' + chalk.red('fox jumped over ') +
18 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
20 console.log(sliceAnsi(string, 20, 30));
25 ### sliceAnsi(string, beginSlice, endSlice?)
31 String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk).
37 Zero-based index at which to begin the slice.
43 Zero-based index at which to end the slice.
47 - [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
48 - [cli-truncate](https://github.com/sindresorhus/cli-truncate) - Truncate a string to a specific width in the terminal
49 - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
53 - [Sindre Sorhus](https://github.com/sindresorhus)
54 - [Josh Junon](https://github.com/qix-)
60 <a href="https://tidelift.com/subscription/pkg/npm-slice_ansi?utm_source=npm-slice-ansi&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
64 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.