formatColor
Writes a colour as hex, rgb, hsl, Swift or NSColor code.
Details #
formatColor(color, format?) takes one or two arguments and returns text.
color is text parseColor can read, or a record with r, g, b (and optionally a).
hex(the default):#ff8000, or#ff800080when see-through.rgb:rgb(255, 128, 0), orrgba(255, 128, 0, 0.5).hsl:hsl(30, 100%, 50%), orhsla(...).swift:Color(red: 1.0, green: 0.502, blue: 0.0), withopacity:when see-through.nscolor:NSColor(srgbRed: 1.0, green: 0.502, blue: 0.0, alpha: 1.0).
Parameters #
Takes 1 to 2 arguments.
{{ formatColor(text, b?) }}
Examples #
formatColor("tomato", "rgb")→
rgb(255, 99, 71)formatColor("#f80", "swift")→
Color(red: 1.0, green: 0.533, blue: 0.0)Gotchas #
An unknown colour or format is an error:
formatColor() format should be hex, rgb, hsl, swift or nscolor.