# yiq

> Returns light when a color is dark and dark when a color is light (and a little more).

Latest version **4.0.0** (published 2020-06-25) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2020-06-25 |
| First published | 2018-06-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Luiz Felipe Gonçalves |
| Maintainers | lffg |
| Keywords | yiq, color, black, white, light, dark, color-convert |

## Links

- npm: https://www.npmjs.com/package/yiq
- Repository: https://github.com/lffg/yiq
- Homepage: https://github.com/lffg/yiq#readme
- Issues: https://github.com/lffg/yiq/issues
- npm.io page: https://npm.io/package/yiq

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

- 4.0.0 (latest) — 2020-06-25
- 4.0.0-1 (next) — 2020-06-25
- 4.0.0-0 — 2020-06-25
- 3.0.1 — 2019-06-12
- 3.0.0 — 2019-06-01
- 3.0.0-0 — 2019-06-01
- 2.1.0 — 2019-01-01
- 2.0.4 — 2018-12-31
- 2.0.2 — 2018-12-31
- 2.0.1 — 2018-12-31
- 2.0.0 — 2018-12-31
- 1.1.1 — 2018-12-31
- 1.1.0 — 2018-12-31
- 1.0.0 — 2018-06-03

## README

# YIQ

Returns light when a color is dark and dark when a color is light. 🎨

[![CI](https://github.com/lffg/yiq/workflows/CI/badge.svg)](https://github.com/lffg/errou/actions)
[![NPM](https://img.shields.io/npm/v/yiq.svg?logo=npm)](https://npmjs.org/package/yiq)
![Uses TypeScript](https://img.shields.io/badge/Uses-Typescript-294E80.svg)

## Installing

```shell
yarn add yiq

# If you're using NPM:
# npm install yiq --save
```

## Basic Usage

Just call the `yiq` function after importing it:

```typescript
import { yiq } from 'yiq';

console.log(yiq('#fff')); // #000
console.log(yiq('#000')); // #fff
```

## API

### `yiq`

`yiq` — Returns a light color when a color is dark and a dark color when a color is light.

#### Description

```typescript
function yiq(
  colorHex: string,
  options?: {
    colors?: {
      light: string;
      dark: string;
    };
    threshold?: number;
  }
): string;
```

The second argument (options) can be used to define the colors that the function will return:

```typescript
yiq('#fff', {
  colors: {
    light: '#f0f0f0',
    dark: '#333'
  }
}); // #333
```

It can also be used to define the threshold YIQ value at which the function switches between light and dark:

```typescript
yiq('#36d386', { threshold: 156 }); // #fff
```

The default options are:

- `options.colors.light`: `#fff`;
- `options.colors.dark`: `#000`;
- `options.threshold`: `128`.

## Authors and License

[lffg](https://github.com/lffg) and [contributors](https://github.com/lffg/yiq/graphs/contributors).

MIT License, see the included [MIT](https://github.com/lffg/yiq/blob/master/LICENSE) file.

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