npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

urlpurify

v1.1.0

Published

Unwrap redirect, affiliate, and tracking wrapper URLs and strip tracking parameters. Turn noisy links into clean, direct URLs.

Readme

urlpurify

codecov npm version license

Unwrap redirect, affiliate, and tracking wrapper URLs and strip tracking parameters. Turn noisy links into clean, direct URLs.

URLs collected from feeds, emails, and social platforms rarely point straight at their destination: they pass through search-engine redirects, email security gateways, affiliate networks, and AMP caches, and carry analytics parameters that bloat the link and leak data. urlpurify ships 70+ unwrappers for known wrapper services and a list of 150+ known tracking parameters, plus a composite cleanUrl() that applies both. It has zero dependencies and runs in any modern JavaScript runtime, including browsers.

Installation

npm install urlpurify

Quick Start

import { cleanUrl } from 'urlpurify'

cleanUrl('https://www.google.com/url?q=https%3A%2F%2Fexample.com%2Fpost%3Futm_source%3Dnewsletter')
// => 'https://example.com/post'

API

cleanUrl(url, options?)

Unwraps redirect wrappers (repeatedly, since wrappers can nest), then strips tracking parameters. When the input cannot be parsed as a URL or nothing applies, the input string is returned unchanged, so the result is always safe to display.

import { cleanUrl, defaultUnwrappers, unwrapWebArchive } from 'urlpurify'

const cleaned = cleanUrl(url, {
  // Unwrappers to apply, first match wins per pass (omit to use defaults).
  unwrappers: [...defaultUnwrappers, unwrapWebArchive],
  // Param names (matched case-insensitively) or anchored regexes tested against the
  // lowercased name (omit to use defaults).
  trackingParams: ['fbclid', /^utm_[a-z0-9_-]+$/],
  // Maximum number of unwrap passes for nested wrappers. Defaults to 3.
  maxUnwrapDepth: 3,
})

unwrapUrl(url, unwrappers?)

Applies the unwrappers in order (one pass) and returns the first extracted target, or undefined when none match or the input cannot be parsed.

stripTrackingParams(url, trackingParams?)

Removes matching query parameters and returns the cleaned URL. The input is returned unchanged when nothing matches or it cannot be parsed.

createParamExtractor(config)

Builds an unwrapper for the common case where the target URL sits in a query parameter:

import { cleanUrl, createParamExtractor, defaultUnwrappers } from 'urlpurify'

const unwrapExample = createParamExtractor({
  hosts: 'go.example.com', // Also accepts an array of hosts or a regex.
  params: ['target'],
})

cleanUrl(url, { unwrappers: [...defaultUnwrappers, unwrapExample] })

For wrappers that encode the target (base64 path segments, custom escaping), write a plain function of type UrlUnwrapper: it receives a URL and returns the target string or undefined.

Defaults

defaultTrackingParams is the combined default list for cleanUrl and stripTrackingParams: literal names plus family regexes like /^utm_[a-z0-9_-]+$/ that cover vendor namespaces where new variants keep appearing. Its parts are exported separately as trackingParamsLiterals (strings only, for consumers that need a plain string list) and trackingParamsPatterns. defaultUnwrappers is exported alongside. defaultUnwrappers enables a conservative subset of the catalog (search-engine redirects and social-platform shims); everything else is exported individually for explicit opt-in.

Unwrappers

Enabled by default:

| Unwrapper | Description | | --- | --- | | unwrapBing | Bing search-result redirect (www.bing.com/ck/a?u=a1<base64url>) | | unwrapFacebookShim | Facebook link shim (l.facebook.com/l.php?u=<target>) | | unwrapGoogle | Google redirect (google.<TLD>/url?url=<target> or ?q=<target>) | | unwrapGoogleAmpViewer | Google AMP viewer (www.google.<TLD>/amp/s/<host>/<path>) | | unwrapGoogleNews | Google News legacy redirect (news.google.<TLD>/news/url?url=<target>) | | unwrapGoogleNewsModern | Google News modern article URLs (news.google.com/articles/<base64>) | | unwrapGoogleScholar | Google Scholar search-result redirect (scholar.google.<TLD>/scholar_url?url=<target>) | | unwrapInstagramShim | Instagram outbound link shim (l.instagram.com with ?u=<target>) | | unwrapRedditOut | Reddit outbound click tracker (out.reddit.com/?url=<target>) | | unwrapVkAway | VK away redirect (vk.com/away.php?to=<target>) | | unwrapYahooSearch | Yahoo Search redirect (r.search.yahoo.com/.../RU=<target>/RK=...) | | unwrapYouTube | YouTube external redirect (www.youtube.com/redirect?q=<target>) |

Many more are available for explicit opt-in: email security gateways (Outlook SafeLinks, Proofpoint, Mimecast), affiliate networks (Awin, Skimlinks, Commission Junction), CJK platforms, AMP caches, and others. See src/unwraps for the full catalog, each documented in its source file.