Open this example in the interactive library
Source code
import {
URL,
domainToASCII,
domainToUnicode,
pathToFileURL,
fileURLToPath,
} from "node:url";
console.log(pathToFileURL("/tmp/report #1.txt", { windows: false }).href);
Sample output
file:///tmp/report%20%231.txt
