@oazmi/kitchensink - v0.9.13
    Preparing search index...

    Function fileUrlToLocalPath

    • convert the input file-url to a filesystem local-path. however, if the input uri is not a file url (for instance "C:/x/y/z", or "http://hello.com"), then undefined will be returned.

      if you are looking to convert any potential file-url back to a filesystem local-path, then the ensureFileUrlIsLocalPath function would be better suited for your need.

      Parameters

      • file_url: string | URL

      Returns undefined | string

      import { assertEquals } from "jsr:@std/assert"

      // aliasing our functions for brevity
      const
      fn = fileUrlToLocalPath,
      eq = assertEquals

      eq( fn("file:///C:/Users/me/projects/"), "C:/Users/me/projects/")
      eq( fn("file:///C:\\Users\\me/projects/"), "C:/Users/me/projects/")
      eq( fn("file:///sys/etc/bin/deno.so"), "/sys/etc/bin/deno.so")
      eq( fn("file:///sys\\etc/bin\\deno.so"), "/sys/etc/bin/deno.so")
      eq( fn("file://localhost/C:/Users/me/projects/"), "C:/Users/me/projects/")
      eq( fn("file://localhost/sys/etc/bin/deno.so"), "/sys/etc/bin/deno.so")
      eq(fn(new URL("file:///C:/Users/me/projects/")), "C:/Users/me/projects/")
      eq(fn(new URL("file:///sys/etc/bin/deno.so")), "/sys/etc/bin/deno.so")
      eq(fn(new URL("file://localhost/C:/Users/me/projects/")), "C:/Users/me/projects/")
      eq(fn(new URL("file://localhost/sys/etc/bin/deno.so")), "/sys/etc/bin/deno.so")

      // everything below is not a file-url, and therefore cannot be converted.
      eq( fn("http://localhost:8000/hello/world/"), undefined)
      eq( fn("C:/Users/me/projects/"), undefined)
      eq( fn("/sys/etc/bin/deno.so"), undefined)
      eq( fn(""), undefined)