The URI implementation that is used by VS Code and its extensions
npx @tessl/cli install tessl/npm-vscode-uri@3.1.0VSCode URI is a comprehensive URI implementation library specifically designed for Visual Studio Code and its extensions ecosystem. It offers robust parsing capabilities to decompose URI strings into their constituent components (scheme, authority, path, query, and fragment) following RFC 3986 standards, along with specialized utilities for path manipulation including joinPath, resolvePath, dirname, basename, and extname functions that use POSIX path semantics.
npm install vscode-uriimport { URI, Utils } from "vscode-uri";For CommonJS:
const { URI, Utils } = require("vscode-uri");import { URI, Utils } from "vscode-uri";
// Parse a URI from string
const uri = URI.parse('https://code.visualstudio.com/docs/extensions/overview#frag');
console.log(uri.scheme); // 'https'
console.log(uri.authority); // 'code.visualstudio.com'
console.log(uri.path); // '/docs/extensions/overview'
console.log(uri.fragment); // 'frag'
// Create URI from filesystem path
const fileUri = URI.file('/users/me/project/file.txt');
console.log(fileUri.toString()); // 'file:///users/me/project/file.txt'
// Path manipulation utilities
const joined = Utils.joinPath(fileUri, 'subfolder', 'another.txt');
const parent = Utils.dirname(fileUri);
const filename = Utils.basename(fileUri);VSCode URI is built around two main components:
Complete URI parsing, creation, and manipulation functionality following RFC 3986 standards. Supports parsing from strings, creating from filesystem paths, and building from components.
class URI {
readonly scheme: string;
readonly authority: string;
readonly path: string;
readonly query: string;
readonly fragment: string;
readonly fsPath: string;
static parse(value: string, strict?: boolean): URI;
static file(path: string): URI;
static from(components: UriComponents): URI;
static isUri(thing: any): thing is URI;
static revive(data: UriComponents | URI | undefined | null): URI | undefined | null;
with(change: {
scheme?: string;
authority?: string | null;
path?: string | null;
query?: string | null;
fragment?: string | null;
}): URI;
toString(skipEncoding?: boolean): string;
toJSON(): UriComponents;
}
interface UriComponents {
scheme: string;
authority: string;
path: string;
query: string;
fragment: string;
}POSIX-compatible path manipulation utilities for working with URI paths. All operations use forward slashes and follow POSIX path semantics regardless of platform.
namespace Utils {
function joinPath(uri: URI, ...paths: string[]): URI;
function resolvePath(uri: URI, ...paths: string[]): URI;
function dirname(uri: URI): URI;
function basename(uri: URI): string;
function extname(uri: URI): string;
}