url.ts — astro Source File
Architecture documentation for url.ts, a typescript file in the astro codebase.
Entity Profile
Relationship Graph
Source Code
/**
* Placeholder base URL used when creating URL objects from relative paths.
* This avoids collisions with actual URLs (e.g., absolute asset prefixes like 'http://localhost:4321')
*/
const PLACEHOLDER_BASE = 'astro://placeholder';
/**
* Creates a URL object from a path or URL string, using a placeholder base for relative paths.
* This allows safe manipulation of URLs using the native URL API.
*
* @param pathOrUrl - A relative path (e.g., '/_astro/image.png') or absolute URL (e.g., 'https://cdn.example.com/...')
* @returns A URL object that can be safely manipulated
*/
export function createPlaceholderURL(pathOrUrl: string): URL {
return new URL(pathOrUrl, PLACEHOLDER_BASE);
}
/**
* Extracts the pathname and search parameters from a URL created with `createPlaceholderURL`.
* Removes the placeholder base, returning just the path and query string.
*
* @param url - A URL object created with `createPlaceholderURL`
* @returns The URL string without the placeholder base
*/
export function stringifyPlaceholderURL(url: URL): string {
return url.href.replace(PLACEHOLDER_BASE, '');
}
Domain
Subdomains
Source
Frequently Asked Questions
What does url.ts do?
url.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in url.ts?
url.ts defines 2 function(s): createPlaceholderURL, stringifyPlaceholderURL.
Where is url.ts in the architecture?
url.ts is located at packages/astro/src/assets/utils/url.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/assets/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free