misund / get-relative-luminance

Get relative luminance from a color string.

Home Page:https://www.npmjs.com/package/get-relative-luminance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get relative luminance

Dependabot Status

get-relative-luminance calculates a CSS color's relative luminance based on this definition from W3C.

It doesn't handle transparency as of yet.

Installation

$ npm install get-relative-luminance

Usage

import getRelativeLuminance from 'get-relative-luminance'

getRelativeLuminance('rgb(255, 255, 255)') // 1
getRelativeLuminance('white') // 1
getRelativeLuminance('hsl(0, 0%, 0%)') // 0

Signature

;(
  color: string,
  {
    ignoreTransparency,
  }?: {
    ignoreTransparency?: boolean | undefined
  },
) => number

Contributing

I appreciate your issues and PRs on Github!

Testing

yarn build && yarn test

Releasing

This project uses np.

  1. Make sure your changes are in master
  2. Run yarn release
  3. Follow the interactive release guide

About

Get relative luminance from a color string.

https://www.npmjs.com/package/get-relative-luminance


Languages

Language:TypeScript 100.0%