Skip to content

Commit

Permalink
Correctly kebabCase numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrausz committed Mar 4, 2025
1 parent d372e71 commit 0451c5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions packages/client/src/util/strings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, test } from "vitest";
import { kebabCase } from "./strings";

describe("kebabCase", () => {
test("Basic", () => {
expect(kebabCase("myPathName")).toBe("my-path-name");
});

test("Numbers", () => {
expect(kebabCase("v0")).toBe("v0");
expect(kebabCase("version123Path")).toBe("version123-path");
});
});
6 changes: 3 additions & 3 deletions packages/client/src/util/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export function kebabCase(str: string) {
return str
.split("")
.map((letter, idx) => {
return letter.toUpperCase() === letter
? `${idx !== 0 ? "-" : ""}${letter.toLowerCase()}`
: letter;
return letter.toLowerCase() === letter
? letter
: `${idx !== 0 ? "-" : ""}${letter.toLowerCase()}`;
})
.join("");
}

0 comments on commit 0451c5c

Please sign in to comment.