# @colorblender/converter-ansi

> Convert RGB to Ansi16 / Ansi256 and vice versa.

Latest version **1.0.6** (published 2024-03-04) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @colorblender/converter-ansi
pnpm add @colorblender/converter-ansi
yarn add @colorblender/converter-ansi
bun add @colorblender/converter-ansi
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2024-03-04 |
| First published | 2024-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Skyleen |
| Maintainers | skyleen |
| Keywords | color, color-converter, colour, couleur, parser, convert, tiny, ansi, ansi16, ansi256 |

## Links

- npm: https://www.npmjs.com/package/@colorblender/converter-ansi
- Repository: https://github.com/Skyleen77/colorblender-converter-ansi
- Homepage: https://github.com/Skyleen77/colorblender-converter-ansi.git#README.md
- Issues: https://github.com/Skyleen77/colorblender-converter-ansi/issues
- npm.io page: https://npm.io/package/@colorblender/converter-ansi

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 1.0.6 (latest) — 2024-03-04
- 1.0.5 — 2024-03-04
- 1.0.4 — 2024-03-04
- 1.0.3 — 2024-03-04
- 1.0.2 — 2024-03-04
- 1.0.1 — 2024-03-04
- 1.0.0 — 2024-03-04

## README

<div align="center">
  <h1>Converter Ansi</h1>

  <p>Convert RGB to Ansi16 / Ansi256 and vice versa.</p>
</div>

## Installation

This package requires the installation of the main package [`@colorblender/converter`](https://www.npmjs.com/package/@colorblender/converter).

```bash
npm install @colorblender/converter @colorblender/converter-ansi
```

## Import

```javascript
import {
  rgbToAnsi16,
  rgbToAnsi256,
  ansi16ToRgb,
  ansi256ToRgb,
} from '@colorblender/converter-ansi';
```

## Usage

### Model conversions

You can convert between any of the supported color models.

```JavaScript
// ansi to rgb
ansi16ToRgb(ansi16: Ansi16Color, rounded?: boolean): RgbColor
ansi256ToRgb(ansi256: Ansi256Color, rounded?: boolean): RgbColor

// rgb to ansi
rgbToAnsi16(rgb: RgbColor): Ansi16Color
rgbToAnsi256(rgb: RgbColor): Ansi256Color
```

### Example

```typescript
import { rgbToAnsi16, ansi16ToRgb } from '@colorblender/converter-ansi';

rgbToAnsi16({
  r: 255,
  g: 255,
  b: 255,
});

// Rounded
ansi16ToRgb(167, true);
```

## Conversion

You can convert any compatible model to RGB format and vice versa.

To convert two compatible and different RGB models you will have to go through a sub-conversion. For example to convert a HEX value to ANSI16 you will have to do: HEX -> RGB -> ANSI16. This allows you to convert any compatible model to any other.

Keep in mind that large conversions may result in a loss of accuracy.

### Supported color models

- ANSI16: _number_
- ANSI256 _number_

## Issues

Please file an issue for bugs, missing documentation, or unexpected behavior.

[File an issue](https://github.com/Skyleen77/colorblender-converter-ansi/issues)

## License

MIT

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