Files
dev/third_party/pi/packages/codemode/src/identifier.ts
alexion 6081e3e325 chore(vendor): import pi 1.3.0
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree.

git-subtree-dir: third_party/pi

git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
2026-10-15 17:58:48 -04:00

13 lines
478 B
TypeScript

/**
* The identifier a script uses for a tool: characters that are not valid in a JavaScript
* identifier become `_`. `mcp__docs__search` stays as is, `my-tool` becomes `my_tool`.
*/
export function toCodemodeIdentifier(name: string): string {
let identifier = "";
for (const char of name) {
const valid = identifier === "" ? /^[A-Za-z_$]$/.test(char) : /^[A-Za-z0-9_$]$/.test(char);
identifier += valid ? char : "_";
}
return identifier === "" ? "_" : identifier;
}