feat: add Deduplicator class for managing unique promises and implement icon library generator

This commit is contained in:
2026-03-17 16:07:24 +07:00 Unverified
parent b28ac7b9db
commit 54c8f48a4f
7 changed files with 3247 additions and 34 deletions
+53
View File
@@ -0,0 +1,53 @@
import { write } from "bun";
import { libraryRaw } from "@/assets/icons";
function toJsx(
name: string,
{ viewBox, svg }: { viewBox: string; svg: string },
) {
return ` "${name}": (props: SVGProps<SVGSVGElement>) => (<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="${viewBox}"
{...props}
>
<title>${name}</title>
${svg
.replaceAll("xlink:href", "xlinkHref")
.replace(
/<style([^>]*)>([^<]+)<\/style>/g,
(_, p, g) => `<style${p}>{${JSON.stringify(g)}}</style>`,
)
.replace(/class(="[^"]+")/g, "className$1")
.replace(
/style="([^"]+)"/g,
(_, g: string) =>
`style={${JSON.stringify(
Object.fromEntries(
g
.split(";")
.filter((e) => !e.startsWith("-"))
.map((r) => r.split(":"))
.map(([name, value]) => [
name.replace(/-([a-z])/g, (_, m: string) =>
m.toUpperCase(),
),
value,
]),
),
)}}`,
)}
</svg>),
`;
}
console.log(toJsx("Const", libraryRaw.Const));
write(
"result.tsx",
`import { SVGProps } from "react";
const library = {
${Object.entries(libraryRaw)
.map(([name, p]) => toJsx(name, p))
.join("\n")}
};`,
);