Appearance
此函数可确保正确解码百分比编码字符,并确保跨平台有效的绝对路径字符串。
import { fileURLToPath } from "node:url"; const __filename = fileURLToPath(import.meta.url); new URL("file:///C:/path/").pathname; // 错误: /C:/path/ fileURLToPath("file:///C:/path/"); // 正确: C:\path\ (Windows)