
//#region ../react-intlayer/dist/esm/@intlayer/editor-react/dist/esm/editor/dist/esm/compareUrls.mjs
/**
* Compare two URLs for equality.
* This function is used to determine if a message originates from the same origin.
*
* ```js
* // Example usage
* console.log(compareUrls("http://localhost:5173/", "http://localhost:5173")); // true
* console.log(compareUrls("http://localhost:5173", "http://localhost:5173?myParam=true")); // true
* console.log(compareUrls("http://localhost:5173/subpath", "http://localhost:5173")); // true
* console.log(compareUrls("http://localhost:5172", "http://localhost:5173")); // false
* ```
*
* @param url1 - The first URL to compare.
* @param url2 - The second URL to compare.
* @returns Whether the two URLs are equal.
*/
const compareUrls = (url1, url2) => {
	try {
		const parsedUrl1 = new URL(url1);
		const parsedUrl2 = new URL(url2);
		if (parsedUrl1.protocol !== parsedUrl2.protocol || parsedUrl1.hostname !== parsedUrl2.hostname || parsedUrl1.port !== parsedUrl2.port) return false;
		const path1 = parsedUrl1.pathname.replace(/\/$/, "");
		const path2 = parsedUrl2.pathname.replace(/\/$/, "");
		if (path1 !== "" && path2 !== "" && path1 !== path2) return false;
		return true;
	} catch (error) {
		console.error("Invalid URL(s)", error, {
			url1,
			url2
		});
		return false;
	}
};

//#endregion
exports.compareUrls = compareUrls;
//# sourceMappingURL=compareUrls.cjs.map