Repository: withastro/astro
File: packages/internal-helpers/src/remote.ts (TypeScript)

Code before:
export type RemotePattern = {
	hostname?: string;
	pathname?: string;
	protocol?: string;
	port?: string;
};

/**
 * Evaluates whether a given URL matches the specified remote pattern based on protocol, hostname, port, and pathname.
 *
 * @param {URL} url - The URL object to be matched against the remote pattern.
 * @param {RemotePattern} remotePattern - The remote pattern object containing the protocol, hostname, port, and pathname to match.
 * @return {boolean} Returns true if the URL matches the given remote pattern; otherwise, returns false.
 */
export function matchPattern(url: URL, remotePattern: RemotePattern): boolean {
	return (
		matchProtocol(url, remotePattern.protocol) &&
		matchHostname(url, remotePattern.hostname, true) &&
		matchPort(url, remotePattern.port) &&
		matchPathname(url, remotePattern.pathname, true)
	);
}

/**
 * Checks if the given URL's port matches the specified port. If no port is provided, it returns true.
 *
 * @param {URL} url - The URL object whose port will be checked.
 * @param {string} [port] - The port to match against the URL's port. Optional.
 * @return {boolean} True if the URL's port matches the specified port or if no port is provided; otherwise, false.
 */
export function matchPort(url: URL, port?: string): boolean {
	return !port || port === url.port;
}

/**
 * Compares the protocol of the provided URL with a specified protocol.
 *
 * @param {URL} url - The URL object whose protocol needs to be checked.

Review comment (suggestion):
```suggestion
 * @return {boolean} Returns `true` if the URL matches the given remote pattern; otherwise, `false`.
```

Code after:
export type RemotePattern = {
	hostname?: string;
	pathname?: string;
	protocol?: string;
	port?: string;
};

/**
 * Evaluates whether a given URL matches the specified remote pattern based on protocol, hostname, port, and pathname.
 *
 * @param {URL} url - The URL object to be matched against the remote pattern.
 * @param {RemotePattern} remotePattern - The remote pattern object containing the protocol, hostname, port, and pathname to match.
 * @return {boolean} Returns `true` if the URL matches the given remote pattern; otherwise, `false`.
 */
export function matchPattern(url: URL, remotePattern: RemotePattern): boolean {
	return (
		matchProtocol(url, remotePattern.protocol) &&
		matchHostname(url, remotePattern.hostname, true) &&
		matchPort(url, remotePattern.port) &&
		matchPathname(url, remotePattern.pathname, true)
	);
}

/**
 * Checks if the given URL's port matches the specified port. If no port is provided, it returns `true`.
 *
 * @param {URL} url - The URL object whose port will be checked.
 * @param {string} [port=] - The port to match against the URL's port. Optional.
 * @return {boolean} Returns `true` if the URL's port matches the specified port or if no port is provided; otherwise, `false`.
 */
export function matchPort(url: URL, port?: string): boolean {
	return !port || port === url.port;
}

/**
 * Compares the protocol of the provided URL with a specified protocol.
 *
 * @param {URL} url - The URL object whose protocol needs to be checked.