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
13 lines
478 B
TypeScript
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;
|
|
}
|