# is-dark-color

> Detects if a hex color is dark or light. It is based on the w3 documentation for color luminance: https://www.w3.org/TR/WCAG20/#relativeluminancedef

Latest version **1.2.0** (published 2018-07-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-dark-color
pnpm add is-dark-color
yarn add is-dark-color
bun add is-dark-color
```

## 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.2.0 |
| Published | 2018-07-06 |
| First published | 2018-06-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Gion |
| Maintainers | gion |
| Keywords | color, luminance, dark, light |

## Links

- npm: https://www.npmjs.com/package/is-dark-color
- Repository: https://github.com/gion/is-dark-color
- Homepage: https://github.com/gion/is-dark-color#readme
- Issues: https://github.com/gion/is-dark-color/issues
- npm.io page: https://npm.io/package/is-dark-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

- 1.2.0 (latest) — 2018-07-06
- 1.1.0 — 2018-06-06
- 1.0.2 — 2018-06-06
- 1.0.1 — 2018-06-06
- 1.0.0 — 2018-06-06

## README

# is-dark-color
Detects if a hex color is dark or light. It is based on the w3 documentation for color luminance: https://www.w3.org/TR/WCAG20/#relativeluminancedef.

Useful when trying to make the text color visible on certain background colors.
This is why I needed this: ![this is why I needed this](https://media.giphy.com/media/5wFScs9NRRffxzPI2l/giphy.gif "This is why I needed this")


## Installation
`npm i -S is-dark-color`

## Usage
> es6 snippet


```javascript
import isDarkColor from 'is-dark-color'

// obvious
const whiteIsDark = isDarkColor('#ffffff') // false
const blackIsDark = isDarkColor('#000000') // true

const someColor = '#ff9900' // some sort of orange
console.log(isDarkColor(someColor)) // try it to find out
```

Optionally, you can override the return value for certain colors:
```javascript
import isDarkColor from 'is-dark-color'

const options = {
  override: {
    '#319FB5': true,
    '#383939': false,
  }
}

isDarkColor('#319FB5') // false
isDarkColor('#319FB5', options) // true
```

## Credits
Inspired from
 - https://stackoverflow.com/a/3943023/491075
 - https://stackoverflow.com/a/5624139/491075
 - https://www.w3.org/TR/WCAG20/#relativeluminancedef

## LICENCE
[MIT](./LICENCE)

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