Getter / Setter
Channel methods in xcolor serve as both getter and setter — call without arguments to read, with arguments to set:
const color = xcolor('#ff6600')
color.red() // 255 — getter
color.red(200) // setter, returns this for chaining
color.red() // 200RGB Channels
red() / r()
Get or set the red channel (0–255).
xcolor('#3b82f6').red() // 59
xcolor('#3b82f6').red(200) // set red to 200
xcolor('#3b82f6').r() // 59 — aliasgreen() / g()
Get or set the green channel (0–255).
xcolor('#3b82f6').green() // 130
xcolor('#3b82f6').green(255) // set green to 255blue() / b()
Get or set the blue channel (0–255).
xcolor('#3b82f6').blue() // 246
xcolor('#3b82f6').blue(0) // set blue to 0alpha() / a() / opacity()
Get or set the opacity (0–1).
xcolor('#3b82f6').alpha() // 1
xcolor('#3b82f6').alpha(0.5) // set to semi-transparent
xcolor('#3b82f680').a() // ≈ 0.5 — 8-digit hex parses alpha (128 / 255)HSL Channels
hue() / h()
Get or set the hue (0–360).
xcolor('#ff0000').hue() // 0
xcolor('#ff0000').hue(120) // becomes greensaturation() / s()
Get or set the HSL saturation (0–100).
xcolor('#ff0000').saturation() // 100
xcolor('#ff0000').saturation(50) // reduce saturationlightness() / l()
Get or set the HSL lightness (0–100).
xcolor('#ff0000').lightness() // 50
xcolor('#ff0000').lightness(80) // lightenCompound Getter / Setter
rgb(r, g, b)
Without arguments, returns an { r, g, b, a } object. With arguments, sets channels; omitted channels keep their current values:
xcolor('#ff0000').rgb() // { r: 255, g: 0, b: 0, a: 1 }
xcolor('#ff0000').rgb(0, 128, 255) // set all three channelshsl(h, s, l)
Without arguments, returns an { h, s, l, a } object. With arguments, sets channels; omitted channels keep their current values:
xcolor('#ff0000').hsl() // { h: 0, s: 100, l: 50, a: 1 }
xcolor('#ff0000').hsl(210, 80, 60)hex(value)
Without arguments, returns a hex string: 6 digits when fully opaque, 8 digits when alpha < 1. With an argument, sets the color from a hex string:
xcolor('#ff0000').hex() // '#ff0000'
xcolor('#ff0000').hex('#00ff00') // becomes greenAlias Summary
All aliases are fully equivalent to the original methods — use whichever feels more natural to you:
| Method | Alias |
|---|---|
red() | r() |
green() | g() |
blue() | b() |
alpha() | a(), opacity() |
hue() | h() |
saturation() | s() |
lightness() | l() |
Chaining Example
Getter/setter methods and manipulation methods can be freely combined:
xcolor('#ff0000')
.hue(210) // set hue
.saturation(80) // set saturation
.lighten(10) // manipulation method
.alpha(0.9) // set opacity
.toRgbString() // final output