-
Notifications
You must be signed in to change notification settings - Fork 18
Node Package
Kain edited this page May 22, 2021
·
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:
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
Questions? Comments? Need help?
Feel free to contact me on Discord: drkain