@coffeekraken/s-color
Clean and powerful class to handle colors. You can convert your color in and formats, manipulate it by desaturate it or whatever as well as access each properties of the color like "h", "s", "l", etc...
Install
npm i @coffeekraken/s-color
SColor
This SColor
class allows you to manipulate and convert colors with ease. Here's some of the features supported:
- Instanciate a color with any of these formats: hex, hsl(a) and rgb(a)
- Get color values like r, g, b, a, h, s and l
- Convert your color from and to any of these formats listed above.
- Get back your color in any format using the
toRgbaString
, toHexString
, etc... - Manipulate your color using these methods:
apply
: Apply some modifiers like "--darken 30 --alpha 0.2"desaturate
: Desaturate your color by x [0,100]saturate
: Saturate your color by x [0,100]greyscale
: Transform your color to greyscalespin
: Update the hue by x [-100,100]darken
: Darken your color by x [0,100]lighten
: Lighten your color by x [0,100]invert
: Invert your color
Usage
Here's how to use our implementation:
import __SConductor from '@coffeekraken/s-color';
const color = new __SColor('#ff0000').darken(20).invert();
console.log(color.toHexString());
console.log(color.toHslString());
API
For more information about the API of this class, please check our API documentation
Settings
SColorSettingsInterface
-
returnNewInstance
Specify if the methods returns by default a new SColor instance or the same
-
defaultFormat
Specify the default format of the color
License
Distributed under the MIT License. See LICENSE for more information.
Contact
Here's all the ways you can contact us listed: