(iconPath: string, basePath: string)
| 8 | * @returns 标准化后的图标路径 |
| 9 | */ |
| 10 | export function normalizeIconPath(iconPath: string, basePath: string): string { |
| 11 | // 如果是 base64,直接返回 |
| 12 | if (iconPath.startsWith('data:')) { |
| 13 | return iconPath |
| 14 | } |
| 15 | |
| 16 | // 如果是 http/https,直接返回 |
| 17 | if (iconPath.startsWith('http://') || iconPath.startsWith('https://')) { |
| 18 | return iconPath |
| 19 | } |
| 20 | |
| 21 | // 如果已经是 file:// 协议,直接返回 |
| 22 | if (iconPath.startsWith('file:///')) { |
| 23 | return iconPath |
| 24 | } |
| 25 | |
| 26 | // 否则认为是相对路径,转换为绝对路径 |
| 27 | const absolutePath = path.join(basePath, iconPath) |
| 28 | return pathToFileURL(absolutePath).href |
| 29 | } |
no outgoing calls
no test coverage detected