Skip to content

Node Package

Kain edited this page Mar 11, 2022 · 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:

{
  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
  }
}
Clone this wiki locally