Open History to see the last commit
1import type { ServerProviderSkill } from "@t3tools/contracts";
2
3export type InlineSkill = Pick<ServerProviderSkill, "name" | "displayName">;
4
5export function formatProviderSkillDisplayName(
6 skill: Pick<ServerProviderSkill, "name" | "displayName">,
7): string {
8 return skill.displayName?.trim() || skill.name;
9}
10
11const SKILL_TOKEN_REGEX =
12 /(^|\s)\p{Sc}(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/gu;
13
14export function* matchInlineSkills<Skill extends InlineSkill>(
15 text: string,
16 skills: readonly Skill[],
17) {
18 for (const match of text.matchAll(SKILL_TOKEN_REGEX)) {
19 const name = match[2] ?? "";
20 const skill = skills.find((candidate) => candidate.name === name);
21 if (!skill) continue;
22 const start = match.index + (match[1]?.length ?? 0);
23 yield { start, end: match.index + match[0].length, skill, rawText: `$${name}` };
24 }
25}