From 44fef2d0ad4057adc1765798822e8d6e9d5303d9 Mon Sep 17 00:00:00 2001 From: Kurt Overmier Date: Wed, 23 Sep 2026 20:06:23 -0500 Subject: [PATCH 1/2] fix: collapse runs of separators into one dash --- src/slugify.ts | 2 +- tests/slugify.test.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/slugify.ts b/src/slugify.ts index 8ec9bea..1ca837f 100644 --- a/src/slugify.ts +++ b/src/slugify.ts @@ -2,6 +2,6 @@ export function slugify(input: string): string { return input .toLowerCase() - .replace(/[^a-z0-9]/g, '-') + .replace(/[^a-z0-9]+/g, '-') .replace(/^-+|-+$/g, ''); } diff --git a/tests/slugify.test.ts b/tests/slugify.test.ts index 9d9e656..da0880e 100644 --- a/tests/slugify.test.ts +++ b/tests/slugify.test.ts @@ -13,4 +13,9 @@ describe('slugify', () => { it('keeps digits', () => { expect(slugify('Release 2.44')).toBe('release-2-44'); }); + + it('collapses runs of separators into one dash', () => { + expect(slugify('a b')).toBe('a-b'); + expect(slugify('Hello -- World!')).toBe('hello-world'); + }); }); From 1e9894339f2e388d0aa2cdee302e985c8d7b9f14 Mon Sep 17 00:00:00 2001 From: Kurt Overmier Date: Wed, 23 Sep 2026 20:06:27 -0500 Subject: [PATCH 2/2] docs: mention separator collapse --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 15d0075..323150c 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,5 @@ verify it with an acceptance gate, and open a PR back here. `slugify` has a known bug: runs of separators produce repeated dashes (`slugify('a b')` returns `a--b`). + +Separator runs now collapse to one dash.