Skip to content

interaktivgmbh/colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Interaktiv Colors

code style: ts-standard Version: 1.2.2

Color converter for JavaScript/TypeScript.

Installation

# using yarn
$ yarn add @interaktiv.de/colors

# using npm
$ npm i -S @interaktiv.de/colors

Usage

import Color from '@interaktiv/colors'

// Create new instance of Colors with hex code #ff6f61
const color = new Color('#ff6f61');

// set text color of all elements with class "coral" to hsl-string of color
[...document.querySelectorAll('.coral')]
  .forEach(element => element.style.color = color.hsl)

// function that checks whether the input color is light
const isColorLight = (color: Color|string): boolean => {
  if (color instanceof Color) return color.luminance > 0.5
  
  return (new Color(color).lumincance) > 0.5
}