# colorable

> Color combination contrast tester

Latest version **1.0.5** (published 2015-02-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install colorable
pnpm add colorable
yarn add colorable
bun add colorable
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2015-02-16 |
| First published | 2015-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2067 |
| Author | Brent Jackson |
| Maintainers | jxnblk |
| Keywords | color, contrast, wcag, accessibility |

## Links

- npm: https://www.npmjs.com/package/colorable
- Repository: https://github.com/jxnblk/colorable
- Issues: https://github.com/jxnblk/colorable/issues
- npm.io page: https://npm.io/package/colorable

## Dependencies (4)

- [color](https://npm.io/package/color.md) ^0.7.3
- [lodash](https://npm.io/package/lodash.md) ^3.1.0
- [get-css](https://npm.io/package/get-css.md) ^0.2.0
- [cssstats](https://npm.io/package/cssstats.md) ^1.2.1

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

- 1.0.5 (latest) — 2015-02-16
- 1.0.4 — 2015-02-07
- 1.0.3 — 2015-02-06
- 1.0.2 — 2015-02-06
- 1.0.1 — 2015-02-06
- 1.0.0 — 2015-02-06

## README

# Colorable

Take a set color palette and get contrast values for every possible combination – 
useful for finding safe color combinations with predefined colors
and includes pass/fail scores for the
[WCAG accessibility guidelines](http://www.w3.org/TR/WCAG20/#visual-audio-contrast).

## Getting Started

```bash
npm i --save colorable
```

## Usage

Pass an array of color strings or an object with color strings as values. 

```js
var colorable = require('colorable')

var colors = {
  red: 'red',
  green: 'green',
  blue: 'blue'
}

var result = colorable(colors, { compact: true, threshold: 0 })
```

Returns an array of colors with combinations for all other colors and their
[WCAG contrast](http://www.w3.org/TR/WCAG20/#visual-audio-contrast)
values.

```json
[
  {
    "hex": "#FF0000",
    "name": "red",
    "combinations": [
      {
        "hex": "#008000",
        "name": "green",
        "contrast": 1.28483997166146,
        "accessibility": {
          "aa": false,
          "aaLarge": false,
          "aaa": false,
          "aaaLarge": false
        }
      },
      {
        "hex": "#0000FF",
        "name": "blue",
        "contrast": 2.148936170212766,
        "accessibility": {
          "aa": false,
          "aaLarge": false,
          "aaa": false,
          "aaaLarge": false
        }
      }
    ]
  },
  ...
]
```

### Accessibility object

Each key is a boolean value indicating if the color contrast meets the following criteria:
- `aa` - greater than 4.5 (for normal sized text)
- `aaLarge` - greater than 3 ([for bold text or text larger than 24px](http://www.w3.org/TR/WCAG20/#larger-scaledef))
- `aaa` - greater than 7 
- `aaaLarge` - greater than 4.5 

---

## Options

### `compact`

_Type: Boolean (default: `false`)_

If set to `true`, the result will be a smaller object that only includes hex value color strings, a name for each color (if an object is passed to the function), contrast, and accessibility values.
When set to `false`, the result also includes the entire [harthur/color](https://www.npmjs.com/package/color) object for each color, which includes other properties and methods for color manipulation.

### `threshold`

_Type: Number (default: `0`)_

When set, the colorable function only returns combinations that have a contrast above this value. This is useful for only seeing combinations that pass a minimum contrast level.

### `uniq`

_Type: Boolean (default: true)_

When set to `true`, the array of colors is passed through lodash.uniq to remove duplicates.


---

MIT License

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