[#2] Add slugify() string helper #3

Open
ernest wants to merge 1 commit from agent/issue-2 into main
Collaborator

Summary

Adds slugify(input: string): string in src/slugify.ts — a self-contained
helper that converts free-form text to a URL-safe slug:

  • lowercases the input
  • deletes non-ASCII and non-alphanumeric characters (not transliterated, per spec)
  • collapses runs of spaces and dashes into a single dash
  • trims leading/trailing dashes

Seven tests in src/slugify_test.ts cover all five acceptance criteria from
the spec plus two regression cases discovered during review (see below).
deno task ci is green.

Step ordering — why delete first, then collapse

The intuitive order (spaces → dashes, then strip non-alnum) introduced a
correctness bug found during self-review: a non-ASCII character flanked by
dashes (e.g. "a-é-b") acts as a barrier in the collapse pass, so the two
surrounding dashes are never merged. When the character is deleted in the next
pass, two adjacent dashes remain with nothing left to collapse them.

The fix reorders to: delete non-slug chars first (keeping spaces), then
collapse all separator runs. After deletion, any consecutive dashes are visible
to the collapse pass and are merged correctly. Two regression tests pin this
behaviour: "a-é-b""a-b" and "-é-a""a".

Residual findings / deliberate omissions

  • Unicode dashes (, , etc.) are deleted rather than converted to
    dashes. The spec explicitly lists only ASCII spaces as separator inputs and
    says to delete non-[a-z0-9-] characters. Treating Unicode punctuation as
    word separators is out of scope.
  • Transliteration (é → e) is explicitly out of scope per the spec
    ("Comportement figé : on supprime les non-ASCII").

Closes #2

## Summary Adds `slugify(input: string): string` in `src/slugify.ts` — a self-contained helper that converts free-form text to a URL-safe slug: - lowercases the input - deletes non-ASCII and non-alphanumeric characters (not transliterated, per spec) - collapses runs of spaces and dashes into a single dash - trims leading/trailing dashes Seven tests in `src/slugify_test.ts` cover all five acceptance criteria from the spec plus two regression cases discovered during review (see below). `deno task ci` is green. ## Step ordering — why delete first, then collapse The intuitive order (spaces → dashes, then strip non-alnum) introduced a correctness bug found during self-review: a non-ASCII character flanked by dashes (e.g. `"a-é-b"`) acts as a barrier in the collapse pass, so the two surrounding dashes are never merged. When the character is deleted in the next pass, two adjacent dashes remain with nothing left to collapse them. The fix reorders to: delete non-slug chars first (keeping spaces), then collapse all separator runs. After deletion, any consecutive dashes are visible to the collapse pass and are merged correctly. Two regression tests pin this behaviour: `"a-é-b"` → `"a-b"` and `"-é-a"` → `"a"`. ## Residual findings / deliberate omissions - **Unicode dashes** (`—`, `–`, etc.) are deleted rather than converted to dashes. The spec explicitly lists only ASCII spaces as separator inputs and says to delete non-`[a-z0-9-]` characters. Treating Unicode punctuation as word separators is out of scope. - **Transliteration** (`é → e`) is explicitly out of scope per the spec ("Comportement figé : on supprime les non-ASCII"). Closes #2
Transforms free-form text into a URL-safe slug:
- lowercases input
- deletes non-ASCII and non-alphanumeric characters (not transliterated)
- collapses runs of spaces and dashes into a single dash
- trims leading/trailing dashes

Step ordering (delete junk first, then collapse separators) is
intentional: it prevents non-ASCII chars flanked by dashes from
leaving consecutive interior dashes after deletion (e.g. "a-é-b"
would otherwise become "a--b").

Closes #2
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin agent/issue-2:agent/issue-2
git switch agent/issue-2
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jleicher/aitonomous!3
No description provided.