# @sil/color

> Type-safe color conversion and utilities for TypeScript/JavaScript

Latest version **0.6.0** (published 2026-07-12) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2026-07-12 |
| First published | 2022-07-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 |
| Dependencies | 0 |
| Unpacked size | 789 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sil van Diepen |
| Maintainers | hacobvandipyan, silvandiepen |
| Keywords | color, colors, convert, hsl, rgb, hex, hsv, cmyk, typescript |

## Links

- npm: https://www.npmjs.com/package/@sil/color
- Repository: https://github.com/silvandiepen/sil-color
- Homepage: https://github.com/silvandiepen/sil-color#readme
- Issues: https://github.com/silvandiepen/sil-color/issues
- npm.io page: https://npm.io/package/@sil/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.6.0 (latest) — 2026-07-12
- 0.5.1 — 2026-05-11
- 0.5.0 — 2025-02-14
- 0.4.14 — 2024-03-01
- 0.4.13 — 2024-02-21
- 0.4.12 — 2024-02-21
- 0.4.11 — 2024-02-21
- 0.4.10 — 2024-02-21
- 0.4.9 — 2024-02-20
- 0.4.8 — 2023-03-03
- 0.4.7 — 2023-03-02
- 0.4.6 — 2023-03-02
- 0.4.4 — 2023-03-01
- 0.4.3 — 2023-03-01
- 0.4.2 — 2023-02-22
- … 14 more at https://npm.io/package/@sil/color/versions

## README

# @sil/color

Type-safe color conversion and utilities for TypeScript/JavaScript. Convert between HEX, RGB(A), HSL(A), HSV(A), and CMYK; manipulate colors; format as strings; compute brightness; find nearest named colors; and generate random colors.

## Install

```
npm i @sil/color
```

## Quick Start

```ts
import {
  hexToRgb, rgbToHsl, hslToHex,
  toHex, toRGB, toHSL, toHSV, toCMYK,
  lighten, darken, mix, getType,
  toString, getHue, getLightness, getOpacity,
  getBrightness, nearestColor, getName, getRandomColor,
  ColorType, RGB, HSL
} from '@sil/color';

const rgb: RGB = hexToRgb('#ff0094');
const hsl: HSL = rgbToHsl(rgb) as HSL;
const hex: string = hslToHex(hsl);

const lighter = lighten('#336699', 10);   // +10 lightness
const label = toString(toRGB('#ff0'));    // "rgb(255, 255, 0)"
const lstar = getBrightness('#333');      // perceived lightness 0–100
const nearest = nearestColor('#f00', ['#111', '#f11', '#0f0']);
const name = getName('#F0F8FF');          // "Alice Blue"
const random = getRandomColor();          // e.g. "#12abef"
```

## Documentation

- API docs: generate locally with `npm run docs` (output to `docs/`).

## Examples

- See `examples/basic.ts` for end-to-end usage.

## Types (shapes)

- `HEX`: `'#rrggbb'`
- `RGB`: `{ r: 0–255, g: 0–255, b: 0–255 }`
- `RGBA`: `RGB` + `{ a: 0–1 }`
- `HSL`: `{ h: 0–360, s: 0–100, l: 0–100 }`
- `HSLA`: `HSL` + `{ a: 0–1 }`
- `HSV`: `{ h: 0–360, s: 0–100, v: 0–100 }`
- `HSVA`: `HSV` + `{ a: 0–1 }`
- `CMYK`: `{ c:0–100, m:0–100, y:0–100, k:0–100 }`
- `COLOR`: any of the above

## API Overview

- Convert (direct): `hexToRgb`, `hexToHsl`, `hexToHsv`, `hexToCmyk`, `rgbToHex`, `rgbToHsl`, `rgbToHsv`, `rgbToCmyk`, `hslToRgb`, `hslToHex`, `hslToHsv`, `hslToCmyk`, `hsvToRgb`, `hsvToHex`, `hsvToHsl`, `hsvToCmyk`, `cmykToRgb`, `cmykToHex`, `cmykToHsl`, `cmykToHsv`.
- Convert (to-helpers): `toHex`, `toRGB`, `toRGBA`, `toHSL`, `toHSLA`, `toHSV`, `toHSVA`, `toCMYK`, `toType(value, ColorType)`.
- Manipulation: `getType`, `setLightness`, `setSaturation`, `setOpacity`, `lighten`, `darken`, `mix`, `textColor`.
- Getters: `getHue`, `getSaturation`, `getLightness`, `getOpacity`, `getRed`, `getGreen`, `getBlue`.
- Strings: `toRgbString`, `toHslString`, `toHsvString`, `toString`.
- Validation: `isHex`, `isRGB`, `isRGBA`, `isHSL`, `isHSLA`, `isHSV`, `isHSVA`, `isCMYK`.
- Brightness: `getBrightness` (perceived L* 0–100).
- Names/Nearest: `getName(color)`, `nearestColor(color, colors)`.
- Random: `getRandomColor(options?)`.

Tips
- All functions are pure and TypeScript-typed (`strict` mode).
- Public API is exported from `src/index.ts`; tree-shake by importing what you need.

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