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

link-cleaner-js

v1.0.0

Published

Remove tracking code, search parameters, and other junk from web links.

Readme

Link Cleaner JS & Link Cleaner CLI

Link Cleaner JS is a JavaScript library for removing tracking variables and other unnecessary junk from URLs. In environments without CORS restrictions, it can also un-shorten links like bit.ly URLs.

Link Cleaner CLI is a command-line application that uses the JavaScript library in a Node.js runtime, allowing you to clean and un-shorten links on any Windows, macOS, or Linux system. It can be used in a terminal, or easily integrated into Bash scripts and other automations.

This library is primarily built for the Link Cleaner web app.

This is a work in progress!

NPM version NPM weekly downloads NPM downloads for all time jsDelivr weekly hits

The technical details

Link Cleaner works by removing all parameters from a given URL, excluding the q parameter typically used for the current search query, then adds back any parameters known to be required for the current domain or URL path.

For example, a video shared from YouTube might have a link like this:

https://www.youtube.com/watch?v=wAUK9hVgmNI&si=nd8_1Ne2bf&t=20

Link Cleaner preserves the v parameter for the video ID, and the t parameter for the current timestamp, while deleting the si parameter used as a tracking variable:

https://www.youtube.com/watch?v=wAUK9hVgmNI&t=20

If a page requires parameters other than q to load, and Link Cleaner does not already have an override for it, the cleaned link will not work. Please create issues for broken domains/links so they can be fixed.

In the asynchronous cleaning mode, Link Cleaner makes a GET request to the provided link to follow any redirects, then cleans the final resolved URL.

How to install the CLI

Link Cleaner CLI works on Windows, macOS, and Linux with the Node.js runtime.

Windows

Press the Win + X keyboard shortcut, and select Windows PowerShell (Admin) or Terminal (Admin). Next, copy the below command, paste it into the window (Ctrl+V), and press the Enter/Return key:

winget install -e --id OpenJS.NodeJS.LTS

Open a new PowerShell Admin window or Terminal tab, then run this command:

npm install -g link-cleaner-js

If you get an error that running scripts is disabled, use this command to allow signed scripts, then try the install command again:

Set-ExecutionPolicy RemoteSigned

You can run linkcleaner -help to verify Link Cleaner is installed.

Linux

The process for installing Node.js and NPM varies by distribution. Here's how to do it on Ubuntu-like distros:

sudo apt install nodejs npm

Then, install Link Cleaner from NPM:

npm install -g link-cleaner-js

You can run linkcleaner -h to verify Link Cleaner is installed.

macOS

Install the Homebrew package manager, then open a new Terminal window/tab and run this command to install Node.js and NPM:

brew install node

Then, install Link Cleaner from NPM:

npm install -g link-cleaner-js

You can run linkcleaner -h to verify Link Cleaner is installed.

How to use the CLI

The basic usage is running the linkcleaner command with the URL in quotes, like this:

linkcleaner "https://youtu.be/wAUK9hVgmNI?si=d5DS29nU8fOzWfqP&t=2"

You can use additional options, like -b or --bluesky to convert Bluesky posts into FixEmbed links:

linkcleaner -b "https://bsky.app/profile/corbin.io/post/3mry2hm5qps2y"

For un-shortening links, like bit.ly URLs or Reddit's /s post links, use the -u or --unshorten options:

linkcleaner -u "https://www.reddit.com/r/vscode/s/y8wM23uuT3"

You can also use pipes. This example on macOS will read a URL from the clipboard, unshorten and clean it, then copy the result to the clipboard:

pbpaste | linkcleaner -u | pbcopy

Run linkcleaner -h to see all available options.

How to install the JS library

The Link Cleaner library is an extension of the native URL interface, so it's a small package (~5KB minified) and has no dependencies.

Current compatibility: > 0.15%, not dead, maintained node versions

For local project installation, you can use NPM:

npm install link-cleaner-js

For static web pages or web apps, copy the linkcleaner.js or linkcleaner.min.js scripts in the dist directory to your project, or use a CDN like this:

<script src="https://unpkg.com/link-cleaner-js@1/dist/linkcleaner.min.js"></script>

How to use the JS library

First, import the library in your script, using require for CommonJS projects or import for ES Modules projects:

// CommonJS
const linkCleaner = require("link-cleaner-js");
// ES Modules
import * as linkCleaner from "link-cleaner-js";

For a regular web page or web app, you just need linkcleaner.js or linkcleaner.min.js in a script tag placed before your main script in the HTML structure, then call it with linkCleaner.clean().

The basic clean() function accepts either a string or a URL object:

let urlObj = new URL("http://example.com?a=123");
let cleaned = linkCleaner.clean(urlObj);

let urlString = "http://example.com?a=123";
let cleaned = linkCleaner.clean(urlString);

The output is always a new URL object. You can convert it to a string afterwards, if needed:

let link = linkCleaner.clean("http://example.com?a=123");
let linkStr = link.toString();

You can pass options to it in the second parameter, like this:

let link = linkCleaner.clean("https://music.youtube.com/watch?v=Gyk5F5gYKzY", {
    convertYouTubeMusic: true,
    shortenYouTube: true
})

There is also a cleanAsync() function, which attempts to un-shorten the input URL first, then cleans the result. It's a Promise function that must be called with await, since it makes a GET request to the target URL.

This mode is required for bit.ly URLs, Reddit's /s post links, and other URLs that completely obscure the destination:

let link = linkCleaner.clean("https://www.reddit.com/r/vscode/s/y8wM23uuT3");
// Output: https://www.reddit.com/r/vscode/s/y8wM23uuT3

let link = await linkCleaner.cleanAsync("https://www.reddit.com/r/vscode/s/y8wM23uuT3");
// Output: https://www.reddit.com/r/vscode/comments/1uxx68q/visual_studio_code_1129_release_notes/

This will not work in a standard web browser due to CORS restrictions. You can use it in a Node.js project, the background script of a WebExtension (with host_permissions set to <all_urls>), and other runtimes that don't enforce CORS.