https://github.com/11ways/color
Color
https://github.com/11ways/color
Last synced: 3 months ago
JSON representation
Color
- Host: GitHub
- URL: https://github.com/11ways/color
- Owner: 11ways
- License: mit
- Created: 2019-08-01T16:30:16.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-21T12:44:50.000Z (almost 5 years ago)
- Last Synced: 2025-01-31T16:36:19.477Z (4 months ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
@11ways/color
🌈 Color type for JavaScript
## 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.