Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/tmcw/relative-luminance

Calculate the relative luminance of an RGB triplet color.
https://github.com/tmcw/relative-luminance

Last synced: about 2 months ago
JSON representation

Calculate the relative luminance of an RGB triplet color.

Awesome Lists containing this project

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