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

import { isWindows } from "./_os.ts";
import { fromFileUrl as posixFromFileUrl } from "./posix/from_file_url.ts";
import { fromFileUrl as windowsFromFileUrl } from "./windows/from_file_url.ts";

/**
 * Converts a file URL to a path string.
 *
 * ```ts
 * import { fromFileUrl } from "@std/path/from-file-url";
 *
 * // posix
 * fromFileUrl("file:///home/foo"); // "/home/foo"
 *
 * // win32
 * fromFileUrl("file:///home/foo"); // "\\home\\foo"
 * fromFileUrl("file:///C:/Users/foo"); // "C:\\Users\\foo"
 * fromFileUrl("file://localhost/home/foo"); // "\\\\localhost\\home\\foo"
 * ```
 * @param url of a file URL
 */
export function fromFileUrl(url: string | URL): string {
  return isWindows ? windowsFromFileUrl(url) : posixFromFileUrl(url);
}

// denoCacheMetadata={"headers":{"x-robots-tag":"noindex","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","set-cookie":"__cf_bm=5E9LOB6bDKy_7qmPT5nr6FOwg7E0E0GMEfiGE1.ncDg-1785241875.1404433-1.0.1.1-WtsVK322qpBMl4mX5pCARZ.hIkEjJ_ohNH6FVv8kglbU_u4OpIC8glS2m6mkB1ZY31NQrgIBBufPSskxNjqQqugOGw1OiUf926NI5lYihw2Oi7BCa9MVqsr4WRpKLRuc; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","content-length":"861","cf-cache-status":"HIT","cross-origin-resource-policy":"cross-origin","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=ew9e%2F2CPRnUCfFiSpGae4p6tVb9Yw4LVXY4Xcu7i5%2B88IYSV759uH0X88jFBDTULwhqYMQUTzUXrC56wdInW4Un6qf2o01nI%2BbrRN9tU8Yyx3%2F3b85zahtA%3D\"}]}","cache-control":"public, max-age=31536000, immutable","content-type":"text/typescript","etag":"\"745356b1101771903e15703834402d2b\"","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';","x-content-type-options":"nosniff","x-jsr-backend":"modules","age":"3654297","cf-ray":"a223e6579a157db6-LAX","vary":"Origin","alt-svc":"h3=\":443\"; ma=86400","access-control-expose-headers":"*","server":"cloudflare","date":"Tue, 28 Jul 2026 12:31:15 GMT","access-control-allow-origin":"*","accept-ranges":"bytes"},"url":"https://jsr.io/@std/path/0.224.0/from_file_url.ts","time":1785241875}