readme.md
 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)
 2  
 3  > Slice a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
 4  
 5  ## Install
 6  
 7  ```
 8  $ npm install slice-ansi
 9  ```
10  
11  ## Usage
12  
13  ```js
14  const chalk = require('chalk');
15  const sliceAnsi = require('slice-ansi');
16  
17  const string = 'The quick brown ' + chalk.red('fox jumped over ') +
18  	'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
19  
20  console.log(sliceAnsi(string, 20, 30));
21  ```
22  
23  ## API
24  
25  ### sliceAnsi(string, beginSlice, endSlice?)
26  
27  #### string
28  
29  Type: `string`
30  
31  String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk).
32  
33  #### beginSlice
34  
35  Type: `number`
36  
37  Zero-based index at which to begin the slice.
38  
39  #### endSlice
40  
41  Type: `number`
42  
43  Zero-based index at which to end the slice.
44  
45  ## Related
46  
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
50  
51  ## Maintainers
52  
53  - [Sindre Sorhus](https://github.com/sindresorhus)
54  - [Josh Junon](https://github.com/qix-)
55  
56  ---
57  
58  <div align="center">
59  	<b>
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>
61  	</b>
62  	<br>
63  	<sub>
64  		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
65  	</sub>
66  </div>