Skip to main content
Deno 2 is finally here 🎉️
Learn more

module_url

module_url is a library for extracting information from a TypeScript or ESM module URL. It provides parsers for various formats. It is implemented in TypeScript for Deno.

License Deno module Github
tag Build Code
coverage

Usage

Import a parser that supports all formats:

import { parse } from "https://deno.land/x/module_url/mod.ts";

Import a parser for a single format:

import { parse } from "https://deno.land/x/module_url/formats/deno_x.ts";

Use the parser to parse a URL:

import { parse } from "https://deno.land/x/module_url/mod.ts";

// Parse a URL.
const url = "https://deno.land/x/module_url@v1.2.3/mod.ts";
const { format, name, path, root, tag } = parse(url);

// Test the results.
console.assert(format === "deno_x");
console.assert(name === "module_url");
console.assert(path === "mod.ts");
console.assert(tag === "v1.2.3");
console.assert(base === "https://deno.land/x/module_url@v1.2.3/");

If the format is not supported by the parser, it throws an Error:

import { parse } from "https://deno.land/x/module_url/formats/deno_x.ts";

// This URL format is not supported by deno_x parser.
const url = "file:///home/user/example/mod.ts";
try {
  parse(url);
  // The line above should have thrown an error.
  console.assert(false);
} catch (error) {
  // Success!
}

Formats

These are the formats currently supported by module_url. This list might grow in the future.

Misc

  • unknown: catch-all for unknown formats
    pattern: (matches any valid URL)

  • local: local file system
    pattern: file:///**/<name>[@<tag>]/<path>

Deno

GitHub

  • github: raw files on GitHub
    pattern: https://raw.githubusercontent.com/*/<name>/<tag>/<path>