TypeScript library for color conversion between multiple formats.
This library supports the following formats :
- (s)RGB
- HSL
- HSB (or HSV)
- CMYK
- YUV (BT.470, BT.601, BT.709 profiles)
- CIE XYZ
To convert from a format to another, you can use the appropriate "converter" to do so :
- RgbConverter,
- HslConverter,
- HsbConverter,
- CmykConverter,
- YuvConverter,
- CieXyzConverter
These are not classes, but namespaces regrouping conversion functions.
Image you'd like to convert a RGB value to HSB, you can use the following code:
import { Rgb, RgbConverter } from "@lgs-code/colorimetry";
const rgb = new Rgb(252, 186, 3);
const hsb = RgbConverter.RgbToHsb(rgb);
// will output "44.10°, 98.81%, 98.82%"
console.log(`${hsb.h.toFixed(2)}°, ${(hsb.s * 100).toFixed(2)}%, ${(hsb.b * 100).toFixed(2)}%`);
The same principle apply to any conversion you'd like to perform.
For the list of of available classes and features, please review the documentation here.
The tools used in this library are :
- TypeScript => mostly for configuring compiler options
- ESLint => code rules and formatters
- Prettier => code formatting rules
- Rollup => to create bundles in various format like UMD, Common Js and ES Modules
- Jest => writing and executing unit tests
- TypeDoc => generating the documentation
Feel free to contribute by adding new features or color formats :)