yiq
Version:
Returns light when a color is dark and dark when a color is light (and a little more).
78 lines (54 loc) • 1.62 kB
Markdown
Returns light when a color is dark and dark when a color is light. 🎨
[](https://github.com/lffg/errou/actions)
[](https://npmjs.org/package/yiq)

```shell
yarn add yiq
```
Just call the `yiq` function after importing it:
```typescript
import { yiq } from 'yiq';
console.log(yiq('#fff')); // #000
console.log(yiq('#000')); // #fff
```
`yiq` — Returns a light color when a color is dark and a dark color when a color is light.
```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`: `
- `options.colors.dark`: `
- `options.threshold`: `128`.
[](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.