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

    Function getUriScheme

    • guesses the scheme of a url string. see UriScheme for more details.

      Parameters

      • path: string

      Returns UriScheme

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

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

      eq(fn("C:/Users/me/path/to/file.txt"), "local")
      eq(fn("~/path/to/file.txt"), "local")
      eq(fn("/usr/me/path/to/file.txt"), "local")
      eq(fn("path/to/file.txt"), "relative")
      eq(fn("./path/to/file.txt"), "relative")
      eq(fn("../path/to/file.txt"), "relative")
      eq(fn("file:///c://users/me/path/to/file.txt"), "file")
      eq(fn("file:///usr/me/path/to/file.txt"), "file")
      eq(fn("jsr:@user/path/to/file"), "jsr")
      eq(fn("jsr:/@user/path/to/file"), "jsr")
      eq(fn("npm:lib/path/to/file"), "npm")
      eq(fn("npm:/lib/path/to/file"), "npm")
      eq(fn("npm:/@scope/lib/path/to/file"), "npm")
      eq(fn("node:http"), "node")
      eq(fn("node:fs/promises"), "node")
      eq(fn("data:text/plain;charset=utf-8;base64,aGVsbG8="), "data")
      eq(fn("blob:https://example.com/4800d2d8-a78c-4895"), "blob")
      eq(fn("http://google.com/style.css"), "http")
      eq(fn("https://google.com/style.css"), "https")
      eq(fn(""), undefined)