Parse the destination before deduplicating a resource link
A useful project directory needs two separate answers: where will this link navigate, and what counts as the same resource? Treating those questions as one string-replacement operation creates subtle mistakes. A substring such as agprolabs.com can appear inside an unrelated hostname. Removing every query parameter can merge two different resources. Changing the destination while counting it can…
The function resourceLink validates and processes a resource link before returning an object with an explicit rejection reason or a navigation address and identity. It requires the URL to be an absolute HTTPS address and does not infer a base URL or add a protocol. The function parses the URL, compares the hostname against approved domains, and validates the path against a blocked set.
It allows www aliases and rejects credentials and non-default ports. Query parameters are preserved, while selected administrative paths are excluded. The function returns an object with the original URL and a separate identity for reporting, stripping www, ignoring the fragment, and removing utm_ parameters. The identity is not a universal canonicalization rule, and different websites may route them differently.
The MDN URL reference documents the parsed properties used by the function. The example does not fetch pages or certify content, and it does not act as an SSRF defense or complete security boundary.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.