-
Notifications
You must be signed in to change notification settings - Fork 19
Node Package
Kain edited this page Mar 11, 2022
·
4 revisions
npm install tidy-url
import { TidyURL } from 'tidy-url';
// or
const { TidyURL } = require('tidy-url');
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
You can validate a URL using the validate
function.
TidyURL.validate('https://example.com'); // true
TidyURL.validate('cat'); // false
If the URL is not supported the original URL will be returned. You can view all supported sites here
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:
{
url: 'https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih',
info: {
original: 'https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih?si=-k8RwDQwTCK923jxZuy07w&utm_source=copy-link',
reduction: 47,
replace: [],
remove: [
'ga_source', 'ga_medium',
'ga_term', 'ga_content',
'ga_campaign', 'ga_place',
'utm_campaign', 'utm_source',
'utm_medium', 'utm_content',
'utm_term', 'gclid',
'gclsrc', 'si',
'utm_source', 'context'
],
match: [ [Object], [Object] ],
custom: false
}
}
Questions? Comments? Need help?
Feel free to contact me on Discord: drkain