Skip to content

Instantly share code, notes, and snippets.

@peterblazejewicz
Created December 30, 2019 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterblazejewicz/d183659348820883e286de6d456d284e to your computer and use it in GitHub Desktop.
Save peterblazejewicz/d183659348820883e286de6d456d284e to your computer and use it in GitHub Desktop.
onecolor
// This contains sample code which tests the typings. This code does not run, but it is type-checked.
import * as one from "onecolor";
import onecolor = require("onecolor");
one.color('#a9d91d') // Regular hex syntax
// Contrustor
const color = onecolor('red');
// Serialization methods:
color.hex();
color.css();
color.cssa();
color.toString();
color.toJSON();
// Getters
color.red();
color.green();
color.blue();
color.hue();
color.saturation();
color.value();
color.lightness();
color.alpha();
color.cyan();
color.magenta();
color.yellow();
color.black();
// Setters
color.red(1);
color.green(1);
color.blue(1);
color.hue(1);
color.saturation(1);
color.value(1);
color.lightness(1);
color.alpha(1);
color.cyan(1);
color.magenta(1);
color.yellow(1);
color.black(1);
// Adjusters
color.red(1, true);
color.green(1, true);
color.blue(1, true);
color.hue(1, true);
color.saturation(1, true);
color.value(1, true);
color.lightness(1, true);
color.alpha(1, true);
color.cyan(1, true);
color.magenta(1, true);
color.yellow(1, true);
color.black(1, true);
// Comparison with other color objects, returns true or false (epsilon defaults to 1e-9):
color.equals(color);
onecolor('rgba(10, 20, 30, .8)')
.green(.4)
.saturation(.2)
.alpha() // 0.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment