# moo-color

> A modern TypeScript library for color parsing, conversion, and manipulation.

Latest version **2.0.0** (published 2026-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install moo-color
pnpm add moo-color
yarn add moo-color
bun add moo-color
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-04-01 |
| First published | 2018-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 1 |
| Unpacked size | 249.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | archcoster@gmail.com |
| Maintainers | archco |
| Keywords | color, color-conversion, color-manipulation, hex, rgb, hsl, hwb, hsv, cmyk, wcag, typescript |

## Links

- npm: https://www.npmjs.com/package/moo-color
- Repository: https://github.com/archco/moo-color
- Homepage: https://github.com/archco/moo-color#readme
- Issues: https://github.com/archco/moo-color/issues
- npm.io page: https://npm.io/package/moo-color

## Dependencies (1)

- [color-name](https://npm.io/package/color-name.md) ^2.0.0

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

- 2.0.0 (latest) — 2026-04-01
- 1.0.3 — 2022-04-03
- 1.0.2 — 2019-12-31
- 1.0.1 — 2019-12-14
- 1.0.0 — 2019-10-17
- 0.2.4 — 2018-08-19
- 0.2.3 — 2018-07-25
- 0.2.2 — 2018-06-11
- 0.2.1 — 2018-06-11
- 0.2.0 — 2018-05-16
- 0.1.3 — 2018-03-30
- 0.1.2 — 2018-03-12
- 0.1.1 — 2018-03-02
- 0.1.0 — 2018-02-03

## README

# MooColor

[![CI](https://github.com/archco/moo-color/actions/workflows/node.js.yml/badge.svg)](https://github.com/archco/moo-color/actions/workflows/node.js.yml)
[![npm version](https://badge.fury.io/js/moo-color.svg)](https://www.npmjs.com/package/moo-color)
[![Downloads](https://img.shields.io/npm/dm/moo-color.svg)](https://www.npmjs.com/package/moo-color)

A modern TypeScript library for color parsing, conversion, and manipulation.

- **Immutable** — every manipulation method returns a new instance; the original is never mutated.
- **WCAG 2.1 compliant** — `luminance` and `contrastRatio` use the correct sRGB linearization.
- **Dual build** — ships ESM, CJS, and IIFE bundles out of the box.
- **Fully typed** — ships its own `.d.ts` including Template Literal Types for color strings.

## Install

```sh
npm install moo-color
```

## Usage

### ESM / TypeScript

```ts
import { MooColor } from 'moo-color';

const red = new MooColor('#ff0000');

// Manipulation returns a NEW instance — original is untouched
const light = red.lighten(20);
console.log(red.toHex());    // '#ff0000'
console.log(light.toHex());  // '#ff6666'

// Method chaining
new MooColor('hsl(0, 100%, 50%)')
  .rotate(120)
  .saturate(10)
  .toHex('short'); // '#00ff22' (approximately)
```

### CommonJS

```js
const { MooColor } = require('moo-color');

const color = new MooColor('rgb(255, 128, 0)');
console.log(color.toHsl()); // 'hsl(30, 100%, 50%)'
```

### Browser (IIFE via `<script>`)

```html
<script src="https://unpkg.com/moo-color/dist/moo-color.global.js"></script>
<script>
  const color = new MooColor('hsl(200, 80%, 50%)');
  console.log(color.toHex()); // '#1aa3e8'
</script>
```

## Quick Examples

```ts
// Parsing — accepts hex, rgb, hsl, hwb, hsv, cmyk, named colors, transparent
new MooColor('#f00');
new MooColor('rgba(255, 0, 0, 0.5)');
new MooColor('hsl(0, 100%, 50%)');
new MooColor('red');

// Formatting
const c = new MooColor('red');
c.toHex();          // '#ff0000'
c.toHex('short');   // '#f00'
c.toHex('name');    // 'red'
c.toRgb();          // 'rgb(255, 0, 0)'
c.toHsl();          // 'hsl(0, 100%, 50%)'
c.toHwb();          // 'hwb(0, 0%, 0%)'

// WCAG 2.1 contrast
const white = new MooColor('#fff');
const black = new MooColor('#000');
black.contrastRatioWith(white);   // 21
black.isContrastEnough(white);    // true (≥ 4.5)

// Random color
const rand = MooColor.random({ hue: [0, 60], white: 20 });
```

## API

Please see [MooColor API](https://github.com/archco/moo-color/tree/master/docs#moocolor-api).

## Change Log

[CHANGELOG.md](https://github.com/archco/moo-color/blob/master/CHANGELOG.md)

## License

[MIT License](https://github.com/archco/moo-color/blob/master/LICENSE)

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