// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { isWindows } from "./_os.ts";
import { toFileUrl as posixToFileUrl } from "./posix/to_file_url.ts";
import { toFileUrl as windowsToFileUrl } from "./windows/to_file_url.ts";

/**
 * Converts a path string to a file URL.
 *
 * ```ts
 * import { toFileUrl } from "@std/path/to-file-url";
 *
 * // posix
 * toFileUrl("/home/foo"); // new URL("file:///home/foo")
 *
 * // win32
 * toFileUrl("\\home\\foo"); // new URL("file:///home/foo")
 * toFileUrl("C:\\Users\\foo"); // new URL("file:///C:/Users/foo")
 * toFileUrl("\\\\127.0.0.1\\home\\foo"); // new URL("file://127.0.0.1/home/foo")
 * ```
 * @param path to convert to file URL
 */
export function toFileUrl(path: string): URL {
  return isWindows ? windowsToFileUrl(path) : posixToFileUrl(path);
}

// denoCacheMetadata={"headers":{"age":"1649987","cache-control":"public, max-age=31536000, immutable","access-control-expose-headers":"*","cross-origin-resource-policy":"cross-origin","accept-ranges":"bytes","etag":"\"2419f80bf2e75c78103e54b824f081a3\"","content-type":"text/typescript","x-jsr-backend":"modules","content-length":"871","server":"cloudflare","vary":"Origin","x-content-type-options":"nosniff","x-robots-tag":"noindex","cf-cache-status":"HIT","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=R48d4cOqNgo9P665f7cr7Gyr62V0zb6GER5M6iIb3hHxgx0cTkam7erWEh66HsVvRXZdMrrGlZKUzchXUVJmMC9%2Fzcvy19p5m4a6UlhNee4CnG%2BOKBLBFCc%3D\"}]}","cf-ray":"a223e657ba3f7db6-LAX","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","date":"Tue, 28 Jul 2026 12:31:15 GMT","access-control-allow-origin":"*","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","set-cookie":"__cf_bm=wDh.ScZha47ljt9iOPEqtYnHmN7tlhIpJd4ptFuEnSA-1785241875.1512928-1.0.1.1-PhWpWr2e8.gaQVH5ffiWHV7IPBQvCui5TmtHg97jfVQCWoXeossTYEmTOFVm46X8em8WDU54LMR6F7y0EJf56u8N6nZv.LO.FBjdJgCpjufa0SKEPjg3haBVWqMjfrM1; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","alt-svc":"h3=\":443\"; ma=86400"},"url":"https://jsr.io/@std/path/0.224.0/to_file_url.ts","time":1785241875}