Skip to content
This repository was archived by the owner on Mar 1, 2025. It is now read-only.

Commit 17eaede

Browse files
committed
test: add tests for slugify
1 parent e4eb7f6 commit 17eaede

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ cli.command(
2727
})
2828
.strict().help(),
2929
async (args) => {
30-
const force = args.force ?? false;
30+
const _force = args.force ?? false;
3131
const versions = Array.isArray(args.versions) ? args.versions : [args.versions];
3232

3333
if (SUPPORTED_EMOJI_VERSIONS.every((v) => !versions.includes(v))) {

src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
export function slugify(val: string): string {
22
return val.normalize("NFD")
3+
.toLowerCase()
4+
.trim()
35
.replace(/[\u0300-\u036F]/g, "")
46
.replace(/\(.+\)/g, "")
5-
.trim()
67
.replace("&", "")
7-
.replace(/[\W_]+/g, "-").toLowerCase();
8+
.replace(/[\W_]+/g, "-")
9+
.replace(/^-+|-+$/g, "");
810
}

test/utils.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { describe, expect, it } from "vitest";
2+
import { slugify } from "../src/utils";
3+
4+
describe("slugify", () => {
5+
it("should convert string to slug format", () => {
6+
expect(slugify("Hello World")).toBe("hello-world");
7+
});
8+
9+
it("should remove diacritics", () => {
10+
expect(slugify("héllo wörld")).toBe("hello-world");
11+
});
12+
13+
it("should remove parentheses and their content", () => {
14+
expect(slugify("hello (world)")).toBe("hello");
15+
});
16+
17+
it("should trim whitespace", () => {
18+
expect(slugify(" hello world ")).toBe("hello-world");
19+
});
20+
21+
it("should remove ampersands", () => {
22+
expect(slugify("hello & world")).toBe("hello-world");
23+
});
24+
25+
it("should replace special characters with hyphens", () => {
26+
expect(slugify("hello_world!@#$%^")).toBe("hello-world");
27+
});
28+
29+
it("should convert to lowercase", () => {
30+
expect(slugify("HELLO WORLD")).toBe("hello-world");
31+
});
32+
});

0 commit comments

Comments
 (0)