https://github.com/danilosampaio/substr-ansi
Get the `String#substr` correctly handling ansi escape codes.
https://github.com/danilosampaio/substr-ansi
ansi-escape-codes substring
Last synced: about 2 months ago
JSON representation
Get the `String#substr` correctly handling ansi escape codes.
- Host: GitHub
- URL: https://github.com/danilosampaio/substr-ansi
- Owner: danilosampaio
- License: mit
- Created: 2015-07-30T01:14:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-08-03T23:45:09.000Z (over 9 years ago)
- Last Synced: 2025-02-15T14:07:49.386Z (2 months ago)
- Topics: ansi-escape-codes, substring
- Language: JavaScript
- Homepage:
- Size: 121 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# substr-ansi [](https://travis-ci.org/danilosampaio/substr-ansi)
> Get the `String#substr` correctly handling ansi escape codes.
## Install
```
$ npm install --save substr-ansi
```## Usage
```js
var substrAnsi = require('substr-ansi');console.log(substrAnsi('\u001b[47mHi\u001b[49m', 0, 2));
//=> Hi
Note that the ansi code are preserved: \u001b[47mHi\u001b[49m'\u001b[47mHi\u001b[49m'.substr(0, 2) results in a broken string:
//=> \u001b[substrAnsi('\u001b[0m\u001b[31m\u001b[47mHello', 0, 5);
//=> Hello (visible text)
Complete string: `\u001b[0m\u001b[31m\u001b[47mHello`
```## API
### substrAnsi(str, start[, length])
#### str
*Required*
Type: `string`The original string that will be used to extract a section from it.
##### start
Type: `integer`
Default: `0`Location at which to begin extracting characters.
##### length
Type: `integer`
Default: `str.length`Optional. The number of characters to extract.
## License
MIT © [Danilo Sampaio](http://github.org/danilosampaio)