Support Unicode capture slugs

This commit is contained in:
Codex
2026-07-13 03:25:11 +00:00
parent 3ed933fb35
commit 2020f8e356
3 changed files with 30 additions and 5 deletions
+23
View File
@@ -0,0 +1,23 @@
import assert from "node:assert/strict";
import test from "node:test";
import { slugify } from "../dist/slug.js";
test("preserves Unicode letters and numbers", () => {
assert.equal(slugify("多喝水减肥效果"), "多喝水减肥效果");
assert.equal(slugify("减肥 Plan 2026"), "减肥-plan-2026");
});
test("normalizes punctuation and Latin accents", () => {
assert.equal(slugify(" Café — healthy choices! "), "cafe-healthy-choices");
});
test("uses the fallback when no letters or numbers remain", () => {
assert.equal(slugify("🎉 !!!"), "chatgpt-share");
assert.equal(slugify("🎉", "capture"), "capture");
});
test("limits slugs to 80 Unicode code points without a trailing separator", () => {
assert.equal(slugify(`${"界".repeat(79)} hello`), "界".repeat(79));
assert.equal(Array.from(slugify("界".repeat(100))).length, 80);
});