# @jrc03c/color

> a color class to help with converting from one notation to another (e.g., hex to rgb)

Latest version **0.0.16** (published 2025-10-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install @jrc03c/color
pnpm add @jrc03c/color
yarn add @jrc03c/color
bun add @jrc03c/color
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.16 |
| Published | 2025-10-24 |
| First published | 2022-10-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 41.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jrc03c |
| Maintainers | jrc03c |
| Keywords | color |

## Links

- npm: https://www.npmjs.com/package/@jrc03c/color
- npm.io page: https://npm.io/package/@jrc03c/color

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

- 0.0.16 (latest) — 2025-10-24
- 0.0.15 — 2025-05-17
- 0.0.14 — 2025-02-25
- 0.0.13 — 2025-02-13
- 0.0.12 — 2024-10-17
- 0.0.11 — 2024-10-10
- 0.0.10 — 2024-10-09
- 0.0.8 — 2024-10-06
- 0.0.6 — 2024-10-04
- 0.0.5 — 2022-10-21
- 0.0.4 — 2022-10-06
- 0.0.3 — 2022-10-05
- 0.0.2 — 2022-10-04
- 0.0.1 — 2022-10-04

## README

# Intro

This is just a little helper tool to convert between color representations (e.g., RGB to HSL).

# Installation

Install directly from the repo or from the NPM registry:

```bash
npm install --save https://github.com/jrc03c/color
npm install --save @jrc03c/color
```

Import into Node and/or a bundled application:

```js
const Color = require("@jrc03c/color")
```

Or insert in a script tag:

```html
<script src="node_modules/@jrc03c/color/dist/color.js"></script>
<script>
  const c = Color.fromRGB(0, 128, 255)
</script>
```

Alternatively, download from a CDN here: [https://unpkg.com/@jrc03c/color/dist/color.js](https://unpkg.com/@jrc03c/color/dist/color.js)

# Usage

## Creating colors

```js
const Color = require("@jrc03c/color")
const a = Color.fromCMYK(0.23, 0.45, 0.67, 0.89)
const b = Color.fromHex("#ffeedd") // with or without "#"
const c = Color.fromHSL(90, 0, 1)
const d = Color.fromHSV(180, 0.25, 0.75)
const e = Color.fromRGB(0, 128, 255)
const f = Color.random()
```

It's also possible to create colors by calling the constructor to instantiate a new `Color` and then setting the instance's component values as in the examples in the next section.

## Changing colors

```js
const Color = require("@jrc03c/color")
const c = new Color()

// set by cmyk values
c.cmyk = [0.23, 0.45, 0.67, 0.89]
c.cmyk = { c: 0.23, m: 0.45, y: 0.67, k: 0.89 }

// set by hex values (with or without "#")
c.hex = "#ffeedd"

// set by hsl values
c.hsl = [90, 0, 1]
c.hsl = { h: 90, s: 0, l: 1 }

// set by hsv values
c.hsv = [180, 0.25, 0.75]
c.hsv = { h: 180, s: 0.25, v: 0.75 }

// set by rgb values
c.rgb = [0, 128, 255]
c.rgb = { r: 0, g: 128, b: 255 }
```

## Getting color representations

```js
const Color = require("@jrc03c/color")
const c = new Color()
c.rgb = [0, 128, 255]

console.log(c.cmyk)
// {
//   c: 1,
//   m: 0.4980392156862745,
//   y: 0,
//   k: 0,
//   toCSSString: [Function (anonymous)]
// }

console.log(c.cmyk.toCSSString())
// 'cmyk(100.00%, 49.80%, 0.00%, 0.00%)'

console.log(c.hex)
// { value: '0080ff', toCSSString: [Function (anonymous)] }

console.log(c.hex.toCSSString())
// '#0080ff'

console.log(c.hsl)
// {
//   h: 209.88235294117646,
//   s: 1,
//   l: 0.5,
//   toCSSString: [Function (anonymous)]
// }

console.log(c.hsl.toCSSString())
// 'hsl(209.88deg, 100.00%, 50.00%)'

console.log(c.hsv)
// {
//   h: 209.88235294117646,
//   s: 1,
//   v: 1,
//   toCSSString: [Function (anonymous)]
// }

console.log(c.hsv.toCSSString())
// 'hsv(209.88deg, 100.00%, 100.00%)'

console.log(c.rgb)
// { r: 0, g: 128, b: 255, toCSSString: [Function (anonymous)] }

console.log(c.rgb.toCSSString())
// 'rgb(0.00, 128.00, 255.00)'
```

# To do

- Add a `print` method to display the color in the console

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