New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@colorblender/converter

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@colorblender/converter

A powerful and fully typed color conversion library.

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Converter

The most complete and fully typed color conversion library.

Installation

npm install @colorblender/converter

Import

import { hexToRgb ,rgbToHex, ... } from '@colorblender/converter';

Usage

Model conversions

You can convert between any of the supported color models.

// model you want to rgb
colorToRgb(colorValue: {{ColorType}}, rounded?: boolean): RgbColor

// rgb to model you want
rgbToColor(rgb: RgbColor, rounded?: boolean): {{ColorType}}

// Alpha
alphaToHex(alpha: number): string;
hexToAlpha(hexAlpha: string, rounded?: boolean): string;

Example

import { rgbToHsl } from '@colorblender/converter';

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

// Rounded
rgbToHsl(
  {
    r: 167,
    g: 40,
    b: 13,
  },
  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 HSL you will have to do: HEX -> RGB -> HSL. This allows you to convert any compatible model to any other.

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

For package size reasons, some conversions in less common models are separated into external packages, but require having this package to work.

Supported color models

  • HEX: string
  • RGB { r: number, g: number, b: number }
  • HSL { h: number, s: number, l: number }
  • HSV { h: number, s: number, v: number }
  • HWB { h: number, w: number, b: number }
  • HCG { h: number, c: number, g: number }
  • HSI { h: number, s: number, i: number }
  • CMYK { c: number, m: number, y: number, k: number }
  • XYZ { x: number, y: number, z: number }
  • LAB { l: number, a: number, b: number }
  • LCH { l: number, c: number, h: number }
  • APPLE { r: number, g: number, b: number }
  • GRAY number
  • ANSI16 number - package @colorblender/converter-ansi
  • ANSI256 number - package @colorblender/converter-ansi
  • NAME string - package @colorblender/converter-name
  • RAL string - package @colorblender/converter-ral
  • HKS string - package @colorblender/converter-hks

Issues

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

File an issue

License

MIT

Keywords

FAQs

Package last updated on 05 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc