2017-08-14 05:01:11 +02:00
|
|
|
# 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)
|
2017-05-28 00:38:50 +02:00
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
> Slice a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
|
2017-05-28 00:38:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
## Install
|
|
|
|
|
|
|
|
```
|
2017-08-14 05:01:11 +02:00
|
|
|
$ npm install slice-ansi
|
2017-05-28 00:38:50 +02:00
|
|
|
```
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
|
2017-05-28 00:38:50 +02:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
```js
|
2017-08-14 05:01:11 +02:00
|
|
|
const chalk = require('chalk');
|
|
|
|
const sliceAnsi = require('slice-ansi');
|
2017-05-28 00:38:50 +02:00
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
const input = 'The quick brown ' + chalk.red('fox jumped over ') +
|
2017-05-28 00:38:50 +02:00
|
|
|
'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
|
|
|
|
|
|
|
|
console.log(sliceAnsi(input, 20, 30));
|
|
|
|
```
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
|
2017-05-28 00:38:50 +02:00
|
|
|
## API
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
### sliceAnsi(input, beginSlice, [endSlice])
|
2017-05-28 00:38:50 +02:00
|
|
|
|
|
|
|
#### input
|
|
|
|
|
|
|
|
Type: `string`
|
|
|
|
|
|
|
|
String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk).
|
|
|
|
|
|
|
|
#### beginSlice
|
|
|
|
|
|
|
|
Type: `number`
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
Zero-based index at which to begin the slice.
|
2017-05-28 00:38:50 +02:00
|
|
|
|
|
|
|
#### endSlice
|
|
|
|
|
|
|
|
Type: `number`
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
Zero-based index at which to end the slice.
|
2017-05-28 00:38:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
## Related
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
|
|
|
|
- [cli-truncate](https://github.com/sindresorhus/cli-truncate) - Truncate a string to a specific width in the terminal
|
2017-05-28 00:38:50 +02:00
|
|
|
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
|
|
|
|
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
## Maintainers
|
|
|
|
|
|
|
|
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
|
|
- [Josh Junon](https://github.com/qix-)
|
|
|
|
|
|
|
|
|
2017-05-28 00:38:50 +02:00
|
|
|
## License
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
MIT
|