From 93e84f850c9d6261c148d08dd76c79ca02205907 Mon Sep 17 00:00:00 2001 From: HARISH R Date: Sat, 8 Aug 2026 19:16:26 +0530 Subject: [PATCH] feat: add slugify text helper (#2) --- src/demo_toolkit/text.py | 4 ++++ tests/test_text.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/demo_toolkit/text.py b/src/demo_toolkit/text.py index 05e5fc8..e0b4985 100644 --- a/src/demo_toolkit/text.py +++ b/src/demo_toolkit/text.py @@ -11,3 +11,7 @@ def title_case(value: str) -> str: """Capitalize words while collapsing repeated whitespace.""" return " ".join(part.capitalize() for part in value.split()) + +def slugify(value: str) -> str: + """Convert a string into a URL-friendly slug.""" + return "-".join(value.strip().lower().split()) \ No newline at end of file diff --git a/tests/test_text.py b/tests/test_text.py index a37c895..8b46e1b 100644 --- a/tests/test_text.py +++ b/tests/test_text.py @@ -1,4 +1,5 @@ from demo_toolkit.text import normalize_username, title_case +from demo_toolkit.text import normalize_username, slugify, title_case def test_normalize_username_lowercases_value(): @@ -7,3 +8,6 @@ def test_normalize_username_lowercases_value(): def test_title_case_collapses_whitespace(): assert title_case(" github engineer demo ") == "Github Engineer Demo" + +def test_slugify_converts_spaces_to_hyphens(): + assert slugify(" Hello World ") == "hello-world"