hex
The hex() function converts a CSS-style hex color string into a 24-bit RGBColorValue. Accepts 6-digit ("#ff8800") and 3-digit shorthand ("#f80") formats, with or without the # prefix.
Signature
function hex(hexStr: string): RGBColorValue
Parameters
hexStr: A hex color string. Accepts:- 6-digit:
"#ff8800"or"ff8800" - 3-digit shorthand:
"#f80"or"f80"(expands to"ff8800")
- 6-digit:
Return Value
Returns an RGBColorValue object: { __type: "rgb", r: number, g: number, b: number }
Usage
import { s, hex } from "ts-better-console";
// 6-digit hex
console.log(s("Brand", { color: hex("#3b82f6") }));
// 3-digit shorthand
console.log(s("Short", { color: hex("#f80") }));
// Without # prefix
console.log(s("No hash", { color: hex("ff8800") }));
// As background
console.log(s("bg", { backgroundColor: hex("#1a1a28") }));
Want to support this project?
If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.
Want to contribute to this project?
Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!