src/utils/components.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
export function makeComponentId(
cmd: unknown,
...parts: Array<string | number>
): string {
const name =
typeof cmd === "string"
? cmd
: cmd && typeof (cmd as { name?: string }).name === "string"
? (cmd as { name?: string }).name
: "";
if (!name) throw new Error("command name is required to make a component id");
if (parts.length === 0) return name;
return [name, ...parts.map(String)].join(":");
}
export function parseComponentId(customId: string) {
const [commandName, ...parts] = customId.split(":");
return { commandName, parts };
}
|