# ansi-es6

> Module for modifying string with ANSI escape codes.

Latest version **0.2.2** (published 2018-12-16) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2018-12-16 |
| First published | 2018-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | brunnerh |
| Keywords | ansi, terminal, colors |

## Links

- npm: https://www.npmjs.com/package/ansi-es6
- Repository: https://github.com/brunnerh/ansi-es6
- npm.io page: https://npm.io/package/ansi-es6

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2018-12-16
- 0.2.1 — 2018-12-16
- 0.2.0 — 2018-12-16

## README

# ansi-es6

A small ES6 module utility library for creating [ANSI escaped](https://en.wikipedia.org/wiki/ANSI_escape_code) strings. Primarily useful for highlighting text with colors. Which colors are displayed and which codes are actually supported depends on the terminal being used.

## Installing

The module can be installed from [npm](https://www.npmjs.com/):

```shell
npm install ansi-es6
```

## Usage

The main function exposed by the module is `modify`, which takes a string and a list of modifiers as arguments and returns a new string in which the modifiers are applied at the beginning and all modifiers are reset at the end (this means the output *cannot* easily be nested in an already modified string).

Many of the common codes are provided as constants:
- Foreground colors, e.g. `FgGreen`, `FgBrightRed`, etc.
- Background colors, e.g. `BgGreen`, `BgBrightRed`, etc.
- Styles, e.g. `Italic`, `Bold`, `Underline`, etc.

```js
import { modify, FgGreen } from 'ansi-es6';

console.log(modify('Hello Green World', FgGreen));
```

There also is the function `code` which creates arbitrary escaped strings from numerical codes; most relevant codes should already exist in the form of the various constants however.

### Custom Colors

The functions `FgRgb` and `BgRgb` create foreground/background modifiers which correspond to arbitrary [RGB](https://en.wikipedia.org/wiki/RGB_color_model) color values. There are equivalent functions for [HSL](https://en.wikipedia.org/wiki/HSL_and_HSV) (which ultimately is converted to RGB).

```js
import { modify, FgHsl } from 'ansi-es6';

// Print a rainbow
for (let h = 0; h < 359; h++)
	console.log(modify("Hello Console", FgHsl(h, 1, 0.5)));
```

## Types and API Documentation

Type declarations (`.d.ts`) are provided by the module; these also contain function/argument descriptions. The constants for the most part are currently not documented but you can look up the codes [on Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters) for example.

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