Skip to main content

slug

Function slug 

Source
pub fn slug(identity: &str) -> String
Expand description

The deterministic, URL-safe reduction of an identity to one path segment.

Lowercase; every maximal run of characters outside [a-z0-9] becomes a single -; leading and trailing - are dropped. An identity that reduces to nothing (there is no such identity in a valid layer, because an identity is non-empty and a path always carries a letter) yields the empty string, and collisions reports it.

use majordomus_cli::entity::slug;
assert_eq!(slug("majordomus.scope-integrity@1"), "majordomus-scope-integrity-1");
assert_eq!(slug("---"), "");
assert_eq!(slug("A  B"), "a-b");