#css-color #color #convert #css-class #color-string

parse-color

A crate that provides conversion from CSS color names or TailwindCSS classes to RGBA colors, in the form of [u8; 4]

3 releases

0.1.2 Oct 15, 2023
0.1.1 Oct 15, 2023
0.1.0 Oct 14, 2023

#959 in Web programming

Download history 1/week @ 2024-01-06 3/week @ 2024-01-13 41/week @ 2024-02-17 49/week @ 2024-02-24 13/week @ 2024-03-02 11/week @ 2024-03-09 5/week @ 2024-03-16 9/week @ 2024-03-23 44/week @ 2024-03-30 4/week @ 2024-04-06

64 downloads per month
Used in 2 crates

MIT/Apache

22KB
519 lines

parse-color

A crate that provides conversion from CSS color names or TailwindCSS classes to RGBA colors, in the form of [u8; 4].

Examples

assert_eq!(parse_color::parse("Red"), Some([255, 0, 0, 255]));
assert_eq!(parse_color::parse("Transparent"), Some([0, 0, 0, 0]));
assert_eq!(parse_color::parse("light coral"), Some([240, 128, 128, 255]));
assert_eq!(parse_color::parse("Rebecca-Purple"), Some([102, 51, 153, 255]));

// note the 0 value is only allowed on black/white/transparent
assert_eq!(parse_color::parse_tailwind("white", 0), Some([255, 255, 255, 255]));
assert_eq!(parse_color::parse_tailwind("sky", 400), Some([56, 189, 248, 255]));
assert_eq!(parse_color::parse_tailwind("fuchsia", 900), Some([112, 26, 117, 255]));

lib.rs:

A crate that provides conversion from CSS color names or TailwindCSS classes to RGBA colors, in the form of [u8; 4].

The main parsing functions are case-insensitive, and support cases like snake_case or kebab-case.

Examples

assert_eq!(parse_color::parse("Red"), Some([255, 0, 0, 255]));
assert_eq!(parse_color::parse("Transparent"), Some([0, 0, 0, 0]));
assert_eq!(parse_color::parse("light coral"), Some([240, 128, 128, 255]));
assert_eq!(parse_color::parse("Rebecca-Purple"), Some([102, 51, 153, 255]));

// note the 0 value is only allowed on black/white/transparent
assert_eq!(parse_color::parse_tailwind("white", 0), Some([255, 255, 255, 255]));
assert_eq!(parse_color::parse_tailwind("sky", 400), Some([56, 189, 248, 255]));
assert_eq!(parse_color::parse_tailwind("fuchsia", 900), Some([112, 26, 117, 255]));

No runtime deps

Features