fixes #2082, fixes #2066 - fallback to cuid2 if filename contains non-latin characters

This commit is contained in:
Amruth Pillai
2025-01-12 18:06:44 +01:00
parent 2d62504895
commit 6335ad1571
11 changed files with 54 additions and 36 deletions

View File

@ -30,17 +30,6 @@ export const extractUrl = (string: string) => {
return result ? result[0] : null;
};
export const kebabCase = (string?: string | null) => {
if (!string) return "";
return (
string
.match(/[A-Z]{2,}(?=[A-Z][a-z]+\d*|\b)|[A-Z]?[a-z]+\d*|[A-Z]|\d+/gu)
?.join("-")
.toLowerCase() ?? ""
);
};
export const generateRandomName = () => {
return uniqueNamesGenerator({
dictionaries: [adjectives, adjectives, animals],

View File

@ -6,7 +6,6 @@ import {
getInitials,
isEmptyString,
isUrl,
kebabCase,
processUsername,
} from "../string";
@ -40,16 +39,6 @@ describe("extractUrl", () => {
});
});
describe("kebabCase", () => {
it("converts a string to kebab-case", () => {
expect(kebabCase("fooBar")).toBe("foo-bar");
expect(kebabCase("Foo Bar")).toBe("foo-bar");
expect(kebabCase("foo_bar")).toBe("foo-bar");
expect(kebabCase("")).toBe("");
expect(kebabCase(null)).toBe("");
});
});
describe("generateRandomName", () => {
it("generates a random name", () => {
const name = generateRandomName();