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

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

Implemented the slugify URL-safe string helper exactly as specified in issue #2, using TDD at the natural seam.

What was built

  • src/slugify.ts: named export export function slugify(input: string): string. It lowercases the input, collapses runs of whitespace into a single dash (\s+-), drops every character outside [a-z0-9-] (so non-ASCII accents like é/à are removed, not transliterated), collapses consecutive dashes, and trims leading/trailing dashes. Non-slugifiable input collapses to "".
  • src/slugify_test.ts: 6 Deno.test cases using @std/assert's assertEquals, covering all five acceptance criteria ("Hello, World!"hello-world, " Multiple Spaces "multiple-spaces, "Déjà vu"dj-vu, """", "---a---b---"a-b) plus a boundary case ("!!!""") for the documented removal rule.

Process

  • Wrote the test first, confirmed it failed (module missing — red), then implemented slugify.ts and confirmed all 6 tests pass (green).
  • Followed existing repo conventions: relative import with .ts extension (./slugify.ts), @std/assert, Deno.test, and JSDoc-styled module header matching src/main.ts.
  • The frozen gate deno task ci (check + lint + test) is green: 7 files checked, 7 tests pass.
  • Committed only the two source files as a single logical commit (feat: add slugify() URL-safe string helper) on agent/issue-2; the surrounding CLI's scratch dir (.sandcastle/) was left untracked.

Self-review findings (no behaviour change needed)

  • Whitespace handling uses \s+ rather than the literal space only. The spec says "espaces"; \s+ is the conventional, more robust interpretation (tabs/newlines also become separators) and satisfies every acceptance criterion, so I kept it.
  • Added one test beyond the five listed criteria ("!!!"""). It is a legitimate boundary case of the explicit removal rule rather than new behaviour, so I kept it for coverage.
  • No residual follow-ups: the helper is standalone as required (no integration elsewhere), and accent transliteration is intentionally out of scope.

Run: https://code.voixdu.net/jleicher/ernest/actions/runs/10

Closes #2

Implemented the `slugify` URL-safe string helper exactly as specified in issue #2, using TDD at the natural seam. **What was built** - `src/slugify.ts`: named export `export function slugify(input: string): string`. It lowercases the input, collapses runs of whitespace into a single dash (`\s+` → `-`), drops every character outside `[a-z0-9-]` (so non-ASCII accents like `é`/`à` are removed, not transliterated), collapses consecutive dashes, and trims leading/trailing dashes. Non-slugifiable input collapses to `""`. - `src/slugify_test.ts`: 6 `Deno.test` cases using `@std/assert`'s `assertEquals`, covering all five acceptance criteria (`"Hello, World!"` → `hello-world`, `" Multiple Spaces "` → `multiple-spaces`, `"Déjà vu"` → `dj-vu`, `""` → `""`, `"---a---b---"` → `a-b`) plus a boundary case (`"!!!"` → `""`) for the documented removal rule. **Process** - Wrote the test first, confirmed it failed (module missing — red), then implemented `slugify.ts` and confirmed all 6 tests pass (green). - Followed existing repo conventions: relative import with `.ts` extension (`./slugify.ts`), `@std/assert`, `Deno.test`, and JSDoc-styled module header matching `src/main.ts`. - The frozen gate `deno task ci` (check + lint + test) is green: 7 files checked, 7 tests pass. - Committed only the two source files as a single logical commit (`feat: add slugify() URL-safe string helper`) on `agent/issue-2`; the surrounding CLI's scratch dir (`.sandcastle/`) was left untracked. **Self-review findings (no behaviour change needed)** - Whitespace handling uses `\s+` rather than the literal space ` ` only. The spec says "espaces"; `\s+` is the conventional, more robust interpretation (tabs/newlines also become separators) and satisfies every acceptance criterion, so I kept it. - Added one test beyond the five listed criteria (`"!!!"` → `""`). It is a legitimate boundary case of the explicit removal rule rather than new behaviour, so I kept it for coverage. - No residual follow-ups: the helper is standalone as required (no integration elsewhere), and accent transliteration is intentionally out of scope. Run: https://code.voixdu.net/jleicher/ernest/actions/runs/10 Closes #2
Transforms free-form text into a lowercase, dash-separated slug:
lowercase, whitespace runs -> single dash, drop non [a-z0-9-]
(non-ASCII accents removed, not transliterated), collapse and
trim dashes. Covers issue #2 acceptance criteria.
This pull request can be merged automatically.
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!8
No description provided.