Skip to content

Node Package

Kain edited this page May 22, 2021 · 4 revisions

Install

npm install tidy-url

Require

import { TidyURL } from 'tidy-url';
// or
const { TidyURL } = require('tidy-url');

Usage

Then pass it a URL and let the magic happen:

const cleaned = TidyURL.clean('https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih?si=-k8RwDQwTCK923jxZuy07w&utm_source=copy-link');
console.log(cleaned); // https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih

Validating

You can validate a URL using the validate function.

TidyURL.validate('https://example.com'); // true
TidyURL.validate('cat'); // false

Note

If the URL is not supported the original URL will be returned. You can view all supported sites here

Debug

Turning on debug will print information to the console as the cleaner works.

TidyURL.debug = true;  
TidyURL.clean('https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih?si=-k8RwDQwTCK923jxZuy07w&utm_source=copy-link');

Output:

Target: https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih?si=-k8RwDQwTCK923jxZuy07w&utm_source=copy-link
Origin: https://open.spotify.com
Matched Global (/.*/)
Matched spotify (/open.spotify.com/i)
Deleted 2 items: si utm_source
Final: https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih
Clone this wiki locally