You can use the library via JSDelivr at https://cdn.jsdelivr.net/gh/sargent-coding/colours/colours.js
There are 3 supported colour types: HEX
, RGBA
and HSLA
.
When making a hex colour, you can add the prefixes #
or 0x
, but hex prefixes aren't necessary. Hex colours can also be 3, 4, 6 or 8 digits long (not including the prefix).
When making a RGBA or HSLA colour, you should note that the alpha (transparency) parameter isn't necessary. Also, the alpha parameter uses the unit interval (0 to 1) instead of a percentage.
You can make a colour by using the new
keyboard:
new HEX("0x17f")
Getting the CSS value of a colour is really easy because every colour has a value getter property.
new HSLA(214, 100, 53).value // Returns hsla(214, 100, 53, 1)
You can convert colours by making a new colour with the old colour as the parameter. The colour classes are smart and can differentiate colours (1 parameter) from the typical parameters.
new RGBA(new HEX("#1177ff")).value // Returns rgba(17, 119, 255, 1)
All colours but HEX colours have a property for each letter that you can edit.
let newColour = new HSLA(214, 100, 53)
newColour.h = 69 // newColour is now {a: 1, h: 69, l: 53, s: 100}