Goethe
Immutable color utility with conversion and manipulation. Basically an immutable version of MoOx/color but fully functional / immutable.
Usage
To install the latest version:
npm install --save goethe
Then? Just go crazy :)
; const very = ;const easy = ;const usage = easy;
You can call .toString([mode])
manually, but goethe has valueOf set. That means
that the colors can be converted to RGB(A) CSS strings automatically.
Goethe also supports Adam Morse's nicer palette for the web, also known as Colors.css. Here's how to use it:
; const blue = ; blue // #0074D9
Note that the npm colors.css
package is listed as an optional dependency for
Goethe.
Constructors
You can input a lot into Goethe's Color
constructor.
CSS Color String
RGB or RGBA array
RGB(A) object
The opacity a
is optional and is set to 1
by default.
Setters
colorcolorcolorcolor // And for completenesscolorcolorcolorcolor
Getters
colorcolorcolorcolor // For completenesscolorcolorcolorcolor colorcolorcolorcolor // Luminance between 0 and 1color colorcolor // These all convert to { r: 0, g: 0, b: 0, a: 0}colorcolorcolor
There are some special methods to convert the Color to a string:
.toString()
converts the color to an RGB(A) string by default. You can
change that behavior by setting the argument to one of these modes:
- hex
- percent
- keyword
- hsl
There's also a .valueOf()
method that converts the Color to an RGB(a) string
if JavaScript casts it to a string. This allows you to use the object without
explicitly converting it.
Methods
// Relatively change opacity by a factorcolorcolor // Relatively change saturation by a factorcolorcolor // Get the grayscale of a colorcolorcolor // Rotate huecolorcolor // Rotates by 180 degrees // Relatively change brightness by a factorcolorcolor // Returns the contrast ratio of two colors which is a value between 0 and 21color // Mixes the second color to the first by the factorcolor // Whiten / Blacken color by factorcolorcolor // Copy / Clone colorcolorcolor // Check whether an object is a ColorColor