Open History to see the last commit
1/* oxlint-disable eslint/no-restricted-imports -- Resolves saved project icons by name, so it needs the whole set. */
2// Import lazily: one chunk avoids lucide-react/dynamic emitting about 1,900 icon chunks.
3import * as Lucide from "lucide-react";
4import type { LucideIcon } from "lucide-react";
5
6const iconComponents = new Set<unknown>(Object.values(Lucide.icons));
7const lucideExports: Record<string, unknown> = Lucide;
8
9// Match Lucide export naming to resolve deprecated aliases saved by older overrides.
10function toPascalName(name: string): string {
11 return name
12 .split("-")
13 .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
14 .join("");
15}
16
17// Lucide digit names can differ from this inverse; both forms resolve through toPascalName.
18function toKebabName(pascalName: string): string {
19 return (pascalName.match(/[A-Z][a-z]*|[0-9]+[a-z]*/g) ?? []).join("-").toLowerCase();
20}
21
22export const lucideIconNames: ReadonlyArray<string> = Object.keys(Lucide.icons).map(toKebabName);
23
24export function lucideIconByName(name: string): LucideIcon | undefined {
25 const icon = lucideExports[toPascalName(name)];
26 return iconComponents.has(icon) ? (icon as LucideIcon) : undefined;
27}