Spaces:
Paused
Paused
Download lib/ai-utils.ts from Leon4gr45/paper2code-cli: direct link, hf CLI and curl.
- Browser
- Download file 768 Bytes
-
https://huggingface.co/spaces/Leon4gr45/paper2code-cli/resolve/main/lib/ai-utils.ts
- Command line
-
hf download hf://spaces/Leon4gr45/paper2code-cli/lib/ai-utils.ts
-
curl -L -o ai-utils.ts https://huggingface.co/spaces/Leon4gr45/paper2code-cli/resolve/main/lib/ai-utils.ts
768 Bytes
| /** | |
| * Extracts files from AI generated content using the <file path="...">...</file> format. | |
| */ | |
| export function extractFilesFromAI(content: string): { path: string; content: string }[] { | |
| const fileRegex = /<file path="([^"]+)">([\s\S]*?)<\/file>/g; | |
| const files: { path: string; content: string }[] = []; | |
| let match; | |
| while ((match = fileRegex.exec(content)) !== null) { | |
| const filePath = match[1]; | |
| const fileContent = match[2].trim(); | |
| files.push({ path: filePath, content: fileContent }); | |
| } | |
| return files; | |
| } | |
| /** | |
| * Sanitizes a string for use as a branch name. | |
| */ | |
| export function sanitizeBranchName(name: string): string { | |
| return name | |
| .toLowerCase() | |
| .replace(/[^a-z0-9]/g, '-') | |
| .replace(/-+/g, '-') | |
| .replace(/^-|-$/g, ''); | |
| } | |