An open API service indexing awesome lists of open source software.

https://github.com/11ways/color

Color
https://github.com/11ways/color

Last synced: 3 months ago
JSON representation

Color

Awesome Lists containing this project

README

        


@11ways/color





Mac/Linux Build Status



Windows Build status



Codecov Coverage report



Known Vulnerabilities



Dependency Status




Latest version on npm



Project license





🌈 Color type for JavaScript



Coded with ❤️ by Jelle De Loecker.

## Introduction

Working with color instances

## Install

```bash
npm install @11ways/color
```

## Usage

```js
var Color = require('@11ways/color');
```

## API

### Constructors

```js
var yellow = new Color('yellow');
var yellow = new Color('#ffff00');
var yellow = new Color('hsla(60, 100%, 50%, 1)');
var yellow = new Color({r: 255, g: 255, b: 0});
```

### #luminosity ⇒ `number`

The WCAG luminosity of the color.
This can also be used as a setter, though it will only attempt to approximate it.

### #whiten(ratio) ⇒ `this`

Using the HWB model,
whiten the current color by adding the current whiteness * the given ratio.

If the whiteness is currently 0, the ratio is added as-is.

### #blacken(ratio) ⇒ `this`

Using the HWB model,
blacken the current color by adding the current blakcness * the given ratio.

If the blackness is currently 0, the ratio is added as-is.

### #lighten(ratio) ⇒ `this`

Using the HSL model,
lighten the current color by adding the current lightness * the given ratio.

If the lightness is currently 0, the ratio is added as-is.

### #darken(ratio) ⇒ `this`

Using the HSL model,
darken the current color by subtracting the current lightness * the given ratio.

If the lightness is currently 0, nothing is changed.

### #contrast(other_color) ⇒ `number`

Calculate the contrast between this and the other color.

### #makeReadable(other_color, target_contrast = 7.1, allow_changing_other_color = true) ⇒ `boolean`

Make this readable on the given color.

## Contributing
Contributions are REALLY welcome.
Please check the [contributing guidelines](.github/contributing.md) for more details. Thanks!

## Authors
- **Jelle De Loecker** - *Follow* me on *Github* ([:octocat:@skerit](https://github.com/skerit)) and on *Twitter* ([🐦@skeriten](http://twitter.com/intent/user?screen_name=skeriten))

See also the list of [contributors](https://github.com/11ways/color/contributors) who participated in this project.

## License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/11ways/color/LICENSE) file for details.