Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tmcw/relative-luminance
Calculate the relative luminance of an RGB triplet color.
https://github.com/tmcw/relative-luminance
Last synced: 3 months ago
JSON representation
Calculate the relative luminance of an RGB triplet color.
- Host: GitHub
- URL: https://github.com/tmcw/relative-luminance
- Owner: tmcw
- Created: 2013-09-05T15:12:21.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2020-03-17T04:05:08.000Z (almost 5 years ago)
- Last Synced: 2024-10-12T04:16:49.008Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 29.3 KB
- Stars: 28
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-starred - tmcw/relative-luminance - Calculate the relative luminance of an RGB triplet color. (others)
README
[![Greenkeeper badge](https://badges.greenkeeper.io/tmcw/relative-luminance.svg)](https://greenkeeper.io/)
[![CircleCI](https://circleci.com/gh/tmcw/relative-luminance/tree/master.svg?style=svg)](https://circleci.com/gh/tmcw/relative-luminance/tree/master)## relative-luminance
npm install relative-luminance
Calculate the [relative luminance](http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef) of
an RGB triplet color.Note that as of 1.0.0, this module doesn't directly export a function if you're using
CommonJS: use the `default` export, like:```js
var luminance = require('relative-luminance').default;
```### API
##### Table of Contents
- [relativeLuminance](#relativeluminance)
- [Parameters](#parameters)
- [Examples](#examples)#### relativeLuminance
Given a 3-element array of R, G, B varying from 0 to 255, return the luminance
as a number from 0 to 1.##### Parameters
- `rgb` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>** 3-element array of a color
##### Examples
```javascript
var luminance = require('relative-luminance');
var black_lum = luminance([0, 0, 0]); // 0
```Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** luminance, between 0 and 1