"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_string = require('../primordials/string.js');

//#region src/url/parse.ts
/**
* @file URL parsing helpers — `parseUrl` (safe `new URL(...)` wrapper that
*   returns `undefined` instead of throwing) and `createRelativeUrl` (compose a
*   relative path against an optional base).
*/
const UrlCtor = URL;
/**
* Create a relative URL for testing.
*
* @example
*   ;```typescript
*   createRelativeUrl('/api/test') // 'api/test'
*   createRelativeUrl('/api/test', { base: 'https://example.com' }) // 'https://example.com/api/test'
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function createRelativeUrl(path, options) {
	const { base = "" } = {
		__proto__: null,
		...options
	};
	const relativePath = require_primordials_string.StringPrototypeReplace(path, /^\//, "");
	if (base) {
		let baseUrl = base;
		if (!require_primordials_string.StringPrototypeEndsWith(baseUrl, "/")) baseUrl += "/";
		return baseUrl + relativePath;
	}
	return relativePath;
}
/**
* Parse a value as a URL.
*
* @example
*   ;```typescript
*   parseUrl('https://example.com') // URL { href: 'https://example.com/' }
*   parseUrl('invalid') // undefined
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function parseUrl(value) {
	try {
		return new UrlCtor(value);
	} catch {}
}

//#endregion
exports.createRelativeUrl = createRelativeUrl;
exports.parseUrl = parseUrl;