pub fn normalize(name: &str) -> StringExpand description
Normalizes name per PEP 503:
lowercases, then collapses any run of -, _, or . into a single -.
This matches the actual PyPI Simple API URL contract
(https://pypi.org/simple/<name>/) and what both poetry.lock and
uv.lock store, unlike the historical _-based key space this replaces.
Deliberate deviation from PEP 503’s own regex (re.sub(r"[-_.]+", "-", name).lower()): that regex collapses a leading or trailing
separator run into a single leading/trailing - ("_package_" ->
"-package-"), which this function strips entirely instead
("_package_" -> "package"). PyPI’s own package-name validation
regex forbids a name from starting or ending with a separator, so no
real published package name can exercise this difference — stripping
matches what a human clearly meant by a manifest name like _package_
better than preserving a leading/trailing hyphen would.
§Examples
use deps_pypi::name::normalize;
assert_eq!(normalize("Flask"), "flask");
assert_eq!(normalize("django_rest_framework"), "django-rest-framework");
assert_eq!(normalize("Pillow.Image"), "pillow-image");
assert_eq!(normalize("my__package"), "my-package");
assert_eq!(normalize("---"), "");