Skip to content

Commit

Permalink
fix: vsc icons
Browse files Browse the repository at this point in the history
  • Loading branch information
gronxb committed Sep 14, 2024
1 parent 374bc6b commit c214c3d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/utils/generateIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ export const generateIconCode = async (
typescript: boolean
) => {
const path = import.meta
.resolve("react-icons")
.replace("file://", "")
.replace("/index.mjs", `/${prefix}/index.mjs`);
.resolve(`react-icons/${prefix}`)
.replace("file://", "");

const reactIconsCode = await fs.readFile(path, "utf8");

Expand Down
12 changes: 8 additions & 4 deletions src/utils/groupIconsByPrefix.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { separateCamelCase } from "./separateCamelCase";

export const groupIconsByPrefix = (icons: string[]) => {
const groupedIcons = icons.reduce((acc, icon) => {
const prefix = icon.slice(0, 2).toLowerCase();
if (!acc[prefix]) {
acc[prefix] = [];
const [prefix] = separateCamelCase(icon);
const lowerPrefix = prefix.toLowerCase();
if (!acc[lowerPrefix]) {
acc[lowerPrefix] = [];
}
acc[prefix].push(icon);

acc[lowerPrefix].push(icon);
return acc;
}, {} as Record<string, string[]>);

Expand Down
27 changes: 27 additions & 0 deletions src/utils/separateCamelCase.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { separateCamelCase } from "./separateCamelCase";
import { expect, describe, it } from "vitest";

describe("separateCamelCase", () => {
it("should separate camel case", () => {
expect(separateCamelCase("helloWorld")).toStrictEqual(["hello", "World"]);
expect(separateCamelCase("Lia500Px")).toStrictEqual([
"Lia",
"5",
"0",
"0",
"Px",
]);
expect(separateCamelCase("HiAcademicCap")).toStrictEqual([
"Hi",
"Academic",
"Cap",
]);
expect(separateCamelCase("Bs0CircleFill")).toStrictEqual([
"Bs",
"0",
"Circle",
"Fill",
]);
});
expect(separateCamelCase("VscAccount")).toStrictEqual(["Vsc", "Account"]);
});
16 changes: 16 additions & 0 deletions src/utils/separateCamelCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const separateCamelCase = (name: string) => {
const result = [];
let currentWord = "";

for (const char of name) {
if (char === char.toUpperCase() && currentWord) {
result.push(currentWord);
currentWord = char;
} else {
currentWord += char;
}
}

result.push(currentWord);
return result;
};

0 comments on commit c214c3d

Please sign in to comment.