A Deno library for expanding shortened URLs to their full form. This library provides a simple and efficient way to resolve shortened URLs to their final destination.
- Expands shortened URLs to their full form
- Follows all redirects to get the final destination
- Efficient HEAD requests (doesn't download response bodies)
- Full TypeScript support
- Proper error handling for invalid URLs and network issues
- Detailed URL parsing with query parameters, hash fragments, and other components
- Easy-to-use interface for URL component manipulation
import { expandUrl, expandUrlWithDetails } from "jsr:@varandas/expand-url";import { expandUrl } from "jsr:@varandas/expand-url";
try {
  const fullUrl = await expandUrl("https://bit.ly/example");
  console.log(fullUrl); // https://example.com/very/long/url
} catch (error) {
  console.error("Failed to expand URL:", error.message);
}import { expandUrlWithDetails } from "jsr:@varandas/expand-url";
try {
  const details = await expandUrlWithDetails(
    "https://bit.ly/example?theme=dark#section",
  );
  console.log(details.fullUrl); // https://example.com/path?theme=dark#section
  console.log(details.protocol); // https:
  console.log(details.hostname); // example.com
  console.log(details.pathname); // /path
  console.log(details.queryParams); // { theme: "dark" }
  console.log(details.hash); // section
} catch (error) {
  console.error("Failed to expand URL:", error.message);
}Check out the examples directory for more usage examples.
Expands a URL by following any redirects to get the final destination URL.
- url(string): The URL to expand
- Promise<string>: The expanded (final destination) URL
- Error: If the URL is invalid or if there's an error following redirects
Expands a URL and returns detailed information about its components.
- url(string): The URL to expand
- Promise<ExpandedUrl>: An object containing parsed URL components:- fullUrl(string): The complete expanded URL
- protocol(string): The URL protocol (e.g., 'https:')
- hostname(string): The hostname (e.g., 'example.com')
- pathname(string): The pathname (e.g., '/path/to/resource')
- queryParams(Record<string, string>): Parsed query parameters
- hash(string): The hash fragment without the # symbol
- port(string): The port number if specified
 
- Error: If the URL is invalid or if there's an error following redirects
# Run tests
deno task test
# Type checking
deno task check
# Development mode (watch for changes)
deno task dev
# Run example
deno task example.
βββ src/           # Source code
βββ test/          # Test files
βββ examples/      # Example usage
βββ mod.ts         # Main entry point
βββ deno.json      # Project configuration