(text: string)
| 80 | * Rejects URLs, MIME types, versions, and dotted identifiers like `console.log`. |
| 81 | */ |
| 82 | export const looksLikeWorkspaceFilePath = (text: string): boolean => { |
| 83 | const trimmed = text.trim(); |
| 84 | if (!trimmed || /\s/.test(trimmed) || /^https?:\/\//i.test(trimmed)) { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | let path = trimmed.replace(/\\/g, "/").replace(/^\.\//, ""); |
| 89 | path = path.replace(/:(\d+)(-\d+)?$/, ""); |
| 90 | |
| 91 | if ( |
| 92 | /^(application|audio|image|text|video|font|multipart|message|model)\/[\w.+-]+$/i.test( |
| 93 | path, |
| 94 | ) |
| 95 | ) { |
| 96 | return false; |
| 97 | } |
| 98 | if (/^v?\d+(\.\d+){1,3}([-+][\w.]+)?$/i.test(path)) { |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | const lastSegment = path.includes("/") ? (path.split("/").pop() ?? "") : path; |
| 103 | return WORKSPACE_FILE_EXTENSION.test(lastSegment); |
| 104 | }; |
| 105 | |
| 106 | /** |
| 107 | * Returns the basename (top-level folder/file name) from a path string, |
no outgoing calls
no test coverage detected