Something went wrong. Try again.
[READ-ONLY]
a fast, modern browser for the npm registry forked from npmx.dev/npmx.dev
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637import type { LocationQueryValue } from 'vue-router'import { withoutProtocol, withoutTrailingSlash } from 'ufo'
/** * Normalize a URL for comparison by removing protocol, www prefix, * trailing slashes, hash fragments, and common git tree paths. * * Uses ufo utilities where possible, with additional handling for * www prefix and git-specific paths that ufo's isEqual doesn't cover. */export function normalizeUrlForComparison(url: string): string { let normalized = withoutProtocol(url).toLowerCase() normalized = withoutTrailingSlash(normalized) normalized = normalized .replace(/^www\./, '') .replace(/#.*$/, '') .replace(/\/tree\/(head|main|master)(\/|$)/i, '/') return withoutTrailingSlash(normalized)}
/** * Check if two URLs point to the same resource. * Handles differences in protocol (http/https), www prefix, * trailing slashes, and common git branch paths. */export function areUrlsEquivalent(url1: string, url2: string): boolean { return normalizeUrlForComparison(url1) === normalizeUrlForComparison(url2)}
export function normalizeSearchParam(query?: LocationQueryValue | LocationQueryValue[]): string { if (!query) return ''
if (typeof query === 'string') return query
return normalizeSearchParam(query[0])}