slugify URL and filesystem path helpers: working versions (tested 2026-10-15)
Build stable URL slugs and unique path segments with slugify, covering custom replacements, lowercase, and collision suffixes offline.
passed3 passed · 0 failed2026-10-15 16:05 UTC- Status
- passed
- Last passed
- 2026-10-15 16:05 UTC
- Tests
- 3 / 3
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
slugify@1.6.9@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38764699834
The code
Exactly the files that passed. Your agent can pull them with get_recipe("slugify-url-paths") (install), or see them on GitHub.
package.json
{
"name": "slugify-url-paths",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {"slugify":"1.6.9"},
"devDependencies": {"@types/node":"26.6.5","tsx":"4.23.15"}
}
src/slugs.ts
import slugify from "slugify";
export function toSlug(input: string) {
return slugify(input, { lower: true, strict: true, trim: true });
}
export function uniqueSlug(input: string, existing: Set<string>) {
const base = toSlug(input) || "item";
if (!existing.has(base)) {
existing.add(base);
return base;
}
let n = 2;
while (existing.has(`${base}-${n}`)) n++;
const next = `${base}-${n}`;
existing.add(next);
return next;
}
export function productPath(category: string, title: string) {
return `/${toSlug(category)}/${toSlug(title)}`;
}
test/slugs.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { toSlug, uniqueSlug, productPath } from "../src/slugs.ts";
test("slugifies titles", () => {
assert.equal(toSlug("Hello World!"), "hello-world");
assert.equal(toSlug(" Café & Tea "), "cafe-and-tea");
});
test("uniqueSlug appends suffix", () => {
const used = new Set<string>();
assert.equal(uniqueSlug("Post", used), "post");
assert.equal(uniqueSlug("Post", used), "post-2");
assert.equal(uniqueSlug("Post", used), "post-3");
});
test("productPath joins segments", () => {
assert.equal(productPath("Power Tools", "16V Drill"), "/power-tools/16v-drill");
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.