Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/transforms/case.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, it, expect } from "vitest";
import { latinize, slugify, toTitleCase } from "./case";

describe("unicode case handling", () => {
it("should title-case words with Polish diacritics without mangling letters", () => {
const input = "Weryfikacja reżimu podatkowego";
expect(toTitleCase(input)).toBe("Weryfikacja Reżimu Podatkowego");
});

it("should strip combining marks while preserving letters, numbers, whitespace, and underscores", () => {
expect(latinize("Reżym 123_test")).toBe("Rezym 123_test");
});

it("should slugify Unicode words into a URL-friendly string", () => {
expect(slugify("Weryfikacja reżimu podatkowego")).toBe(
"weryfikacja-rezimu-podatkowego"
);
});
});
6 changes: 4 additions & 2 deletions src/transforms/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function toDotCase(text: string): string {
export function toTitleCase(text: string): string {
return perLine(text, (line) =>
line.replace(
/\b\w+/g,
/[\p{L}\p{N}]+/gu,
Comment thread
nilsandrey marked this conversation as resolved.
(w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
)
);
Expand Down Expand Up @@ -135,7 +135,9 @@ export function reverseLines(text: string): string {

/** Removes diacritic marks — e.g. "café" → "cafe", "Ñoño" → "Nono" */
export function latinize(text: string): string {
return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
return text
.normalize("NFD")
.replace(/[^\p{L}\p{N}_\s]+/gu, "");
Comment thread
nilsandrey marked this conversation as resolved.
}

/** URL-friendly slug: lowercase, ASCII, spaces→dashes */
Expand Down
Loading