v0.3.0
Extract version number, module name, and more from ESM or TypeScript module URLs.
Repository
Current version released
3 years ago
Dependencies
std
Versions
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.
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
deno_x
: Deno third party modules
pattern:https://deno.land/x/<name>[@<tag>]/<path>
deno_std
: Deno standard library modules
pattern:https://deno.land/std[@<tag>]/<name>/<path>