Skip to content

Commit

Permalink
Merge pull request #91 from dittowords/reed/dit-5759-component-folder…
Browse files Browse the repository at this point in the history
…-dev-ids-do-not-handle-emojis-well

DIT-5759: component folder dev IDs properly exclude emojis
  • Loading branch information
rtbarnes authored Jan 19, 2024
2 parents ed421a2 + 8e5c876 commit 354e1c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ async function downloadAndSave(

const nameExt = getFormatExtension(format);
const nameBase = "components";
const nameFolder = `__${componentFolder.name}`;

// we need to clean the folder name by itself first, otherwise we can
// end up with "empty" words and weird hyphenation.
const nameFolder = `__${cleanFileName(componentFolder.name)}`;
const namePostfix = `__${variantApiId || "base"}`;

const fileName = cleanFileName(
Expand Down
11 changes: 11 additions & 0 deletions lib/utils/cleanFileName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { cleanFileName } from "./cleanFileName";

describe("cleanFileName tests", () => {
it("correctly cleans emojis", () => {
const folderName = "👍Good Folder";
expect(cleanFileName(folderName)).toEqual("good-folder");

const fileName = "👍 Good Folder";
expect(cleanFileName(fileName)).toEqual("good-folder");
});
});
10 changes: 6 additions & 4 deletions lib/utils/cleanFileName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export function cleanFileName(fileName: string): string {
return fileName
.replace(/\s{1,}/g, "-")
.replace(/[^a-zA-Z0-9-_.]/g, "")
.toLowerCase();
let parts = fileName.split(/\s{1,}/g);
parts = parts.map((part) =>
part.replace(/[^a-zA-Z0-9-_.]/g, "").toLowerCase()
);
parts = parts.filter((part) => part !== "");
return parts.join("-");
}

0 comments on commit 354e1c7

Please sign in to comment.