🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@colorblender/converter-ansi

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@colorblender/converter-ansi

Convert RGB to Ansi16 / Ansi256 and vice versa.

latest
Source
npmnpm
Version
1.0.6
Version published
Maintainers
1
Created
Source

Converter Ansi

Convert RGB to Ansi16 / Ansi256 and vice versa.

Installation

This package requires the installation of the main package @colorblender/converter.

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

Import

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

Usage

Model conversions

You can convert between any of the supported color models.

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

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

License

MIT

Keywords

color

FAQs

Package last updated on 04 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts