Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mafintosh/ansi-split
Split a string into an array based on where an ansi code is present
https://github.com/mafintosh/ansi-split
Last synced: 12 days ago
JSON representation
Split a string into an array based on where an ansi code is present
- Host: GitHub
- URL: https://github.com/mafintosh/ansi-split
- Owner: mafintosh
- License: mit
- Created: 2017-10-02T10:35:54.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-02T12:28:55.000Z (about 7 years ago)
- Last Synced: 2024-10-16T23:28:17.119Z (28 days ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ansi-split
Split a string into an array based on where an ansi code is present
```
npm install ansi-split
```[![Build Status](https://travis-ci.org/mafintosh/ansi-split.svg?branch=master)](https://travis-ci.org/mafintosh/ansi-split)
## Usage
``` js
var ansiSplit = require('ansi-split')
var chalk = require('chalk')// prints ['hello world']
console.log(ansiSplit('hello world'))// prints ['', '\u001b[31m', 'hello', '\u001b[39m', ' world']
console.log(ansiSplit(chalk.red('hello') + ' world'))// prints ['', '\u001b[31m\u001b[1m', 'hello', '\u001b[22m\u001b[39m', ' ', '\u001b[32m', 'world', '\u001b[39m', '']
console.log(ansiSplit(chalk.red.bold('hello') + ' ' + chalk.green('world')))
```## API
#### `var array = ansiSplit(str)`
Splits a string everytime there is an ansi code present.
The result is an array where every even index is a non-ansi string and every odd index if an ansi string## License
MIT