# ansi-split

> Split a string into an array based on where an ansi code is present

Latest version **1.0.1** (published 2017-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install ansi-split
pnpm add ansi-split
yarn add ansi-split
bun add ansi-split
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-10-02 |
| First published | 2017-10-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/ansi-split
- Repository: https://github.com/mafintosh/ansi-split
- Issues: https://github.com/mafintosh/ansi-split/issues
- npm.io page: https://npm.io/package/ansi-split

## Dependencies (1)

- [ansi-regex](https://npm.io/package/ansi-regex.md) ^3.0.0

## Recent versions

- 1.0.1 (latest) — 2017-10-02
- 1.0.0 — 2017-10-02

## 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

---
_Source: https://npm.io/package/ansi-split · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
