Analyse luminosity contrast ratio
Run npm install @smockle/contrast
to add contrast
to your project.
# Hexadecimal colors
$ contrast "#000000" "#FFFFFF"
# Shorthand hexadecimal colors
$ contrast "#000" "#FC0"
# equivalent to `$ contrast "#000000" "#FFCC00"`
$ contrast "#000" "#F8"
# equivalent to `$ contrast "#000000" "#F8F8F8"`
# Named colors
$ contrast black white
import { Contrast } from "@smockle/contrast";
// Hexadecimal colors
new Contrast("#000000", "#FFFFFF");
// => {
// foreground: {
// value: "000000",
// R: { value: "00" },
// G: { value: "00" },
// B: { value: "00" },
// },
// background: {
// value: "FFFFFF",
// R: { value: "FF" },
// G: { value: "FF" },
// B: { value: "FF" },
// },
// value: 21,
// }
// Shorthand hexadecimal colors
new Contrast("#000", "#FC0");
// equivalent to `new Contrast("#000000", "#FFCC00")`
new Contrast("#000", "#F8");
// equivalent to `new Contrast("#000000", "#F8F8F8")`
// Named colors
new Contrast("black", "white");
contrast
includes several unit tests. After cloning the contrast
repo locally, run npm install
in the project folder to install dependencies. Run npm test
to execute the tests.