UNPKG

insta-toc

Version:

Simultaneously generate, update, and maintain a table of contents for your notes in real time.

33 lines (24 loc) 1 kB
import { icons } from "lucide-svelte/icons"; import { describe, expect, test } from "vitest"; type LucideIconComponent<T extends keyof typeof icons> = (typeof icons)[T]; function getLucideIcon<T extends keyof typeof icons>(name: T): LucideIconComponent<T> { return icons[name]; } function normalizeIconName(name: LucideIconComponent<keyof typeof icons>): string { const iconName: string = typeof name === "string" ? name : name.name; return iconName .replace(/(?<!^)([A-Z])/g, "-$1") .replace(/([a-zA-Z])(\d)/g, "$1-$2") .replace(/_/g, "-") .toLowerCase(); } describe("lucide icon helpers", () => { test("returns the requested icon component", () => { const icon = getLucideIcon("ArrowDown"); expect(icon).toBe(icons.ArrowDown); }); test("normalizes icon component names into kebab-case", () => { const normalized = normalizeIconName(icons.ChevronDown); expect(normalized).toBe("chevron-down"); }); });