parse_color/lib.rs
1//! A crate that provides conversion from CSS color names
2//! or TailwindCSS classes to RGBA colors, in the form of `[u8; 4]`.
3//!
4//! The main parsing functions are case-insensitive,
5//! and support cases like `snake_case` or `kebab-case`.
6//!
7//! # Examples
8//! ```
9//! assert_eq!(parse_color::parse("Red"), Some([255, 0, 0, 255]));
10//! assert_eq!(parse_color::parse("Transparent"), Some([0, 0, 0, 0]));
11//! assert_eq!(parse_color::parse("light coral"), Some([240, 128, 128, 255]));
12//! assert_eq!(parse_color::parse("Rebecca-Purple"), Some([102, 51, 153, 255]));
13//!
14//! // note the 0 value is only allowed on black/white/transparent
15//! assert_eq!(parse_color::parse_tailwind("white", 0), Some([255, 255, 255, 255]));
16//! assert_eq!(parse_color::parse_tailwind("sky", 400), Some([56, 189, 248, 255]));
17//! assert_eq!(parse_color::parse_tailwind("fuchsia", 900), Some([112, 26, 117, 255]));
18//! ```
19mod colors;
20#[cfg(feature="tailwind")]
21mod tailwind;
22
23pub use colors::{parse, parse_flat_lower};
24pub use tailwind::{parse_tailwind, parse_tailwind_flat_lower};