Git Product home page Git Product logo

tidy-url's Introduction

โ™ก Tidy URL

A Node Package & Userscript that removes tracking or garbage parameters from URLs making them shorter, cleaner and a lot nicer to read.

NPM NPM NPM

Install:

You can use this automatically in the browser with the userscript.

NodeJS

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 link = TidyURL.clean('https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih?si=-k8RwDQwTCK923jxZuy07w&utm_source=copy-link');
console.log(link.url); // 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
TidyURL.validate('google.com'); // false (protocol is required!)

AMP & Redirects

By default, tidy-url will remove redirect parameters and AMP links if the rule supports it.
You can disable this feature with allow_redirects and allow_amp. Examples:

// These are the defaults.
TidyURL.allow_redirects = true;
TidyURL.allow_amp = false;

TidyURL.clean('https://www.google.com/amp/s/github.com');
TidyURL.clean('https://steamcommunity.com/linkfilter/?url=https://github.com');
// Result for both: https://github.com

More info about AMP on the wiki.

Note

You will always receive a valid response, even if nothing was modified. For example:

const link = TidyURL.clean('https://duckduckgo.com/this-is-fine');

link.url; // https://duckduckgo.com/this-is-fine
link.info.reduction; // 0 (percent)

Supported Sites

You can view all custom supported sites here.
However, the global rules will be enough to work with thousands of sites around the internet. You should be able to pass any URL for cleaning.
Request direct support for a website here

Response

The response will always be an object with details of what was cleaned or modified in the URL.
This can be used for debugging, testing or a simple way of letting users know they could have sent a shorter link.

{
    "url": "https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih",
    "info": {
        "original": "https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih?si=-k8RwDQwTCK923jxZuy07w&utm_source=copy-link",
        "reduction": 47,
        "difference": 47,
        "replace": [],
        "removed": [
            {
                "key": "utm_source",
                "value": "copy-link"
            },
            {
                "key": "si",
                "value": "-k8RwDQwTCK923jxZuy07w"
            }
        ],
        "match": [
            {
                "rules": ["si", "utm_source", "context"],
                "replace": [],
                "redirect": "",
                "name": "spotify.com",
                "match": "/open.spotify.com/i"
            }
        ],
        "decoded": null,
        "is_new_host": false,
        "full_clean": true
    }
}

Example

Turn these monstrosities:

https://poetsroad.bandcamp.com/?from=search&search_item_id=1141951669&search_item_type=b&search_match_part=%3F&search_page_id=1748155363&search_page_no=1&search_rank=1&search_sig=a9a9cbdfc454df7c2999f097dc8a216b

https://www.audible.com/pd/Project-Hail-Mary-Audiobook/B08G9PRS1K?plink=GZIIiCHG0Uo5V8ND&ref=a_hp_c9_adblp13nmpxxp13n-mpl-dt-c_1_2&pf_rd_p=164101a8-2aab-4c5e-91ee-1f39e10719e6&pf_rd_r=2Q5R6VH8HJAD48PSQRS4

https://www.amazon.com/Alexander-Theatre-Sessions-Poets-Fall/dp/B08NT852YT/ref=sr_1_1?dchild=1&keywords=Poets+of+the+fall&qid=1621684985&sr=8-1

https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih?si=-k8RwDQwTCK923jxZuy07w&utm_source=copy-link

https://www.aliexpress.com/item/1005001913861188.html?spm=a2g0o.productlist.0.0.b1c55e86sFKsxH&algo_pvid=b4648621-2371-4d1e-9a9c-89b4d6c59395&algo_expid=b4648621-2371-4d1e-9a9c-89b4d6c59395-0&btsid=0b0a556816216865399393168e562d&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

https://www.google.com/search?q=cat&source=hp&ei=AwGpYKzyE7uW4-EPy_CnSA&iflsig=AINFCbYAAAAAYKkPE4rmSi0Im0sHgmOVb3DYosyq2B0B&oq=cat&gs_lcp=Cgdnd3Mtd2l6EAMyBQguEJMCMgIILjICCAAyAggAMgIILjICCAAyAggAMgIILjICCC4yAgguOggIABDqAhCPAToLCC4QxwEQowIQkwI6CAguEMcBEKMCUNgEWIQHYMwIaAFwAHgAgAHIAYgB2ASSAQMyLTOYAQCgAQGqAQdnd3Mtd2l6sAEK&sclient=gws-wiz&ved=0ahUKEwjs_9PdrN3wAhU7yzgGHUv4CQkQ4dUDCAY&uact=5

https://www.emjcd.com/links-i/?d=eyJzdXJmZXIiOiIxMDAzMDQ3Mjg5ODMzODAxMDI6VlBTbFlUN3JBeHpsIiwibGFzdENsaWNrTmFtZSI6IkxDTEsiLCJsYXN0Q2xpY2tWYWx1ZSI6ImNqbyF4aTU5LXZ0Zm1nOTkiLCJkZXN0aW5hdGlvblVybCI6Imh0dHBzOi8vd3d3LnZ1ZHUuY29tL2NvbnRlbnQvbW92aWVzL2RldGFpbHMvTW9vbmxpZ2h0LVNlYXNvbi0xLzEzMzEyMCIsInNpZCI6IltzdWJpZF92YWx1ZV0iLCJ0eXBlIjoiZGxnIiwicGlkIjo5MDExNjczLCJldmVudElkIjoiMGFjZGE1ZDdmNzNlMTFlYzgyYWM3NDliMGExYzBlMGUiLCJjalNlc3Npb24iOiIyZjBjNGNjYi1lNmVmLTQ0YzItYjIzYy02NzNjZjY2MTZlMTYiLCJsb3lhbHR5RXhwaXJhdGlvbiI6MCwicmVkaXJlY3RlZFRvTGl2ZXJhbXAiOmZhbHNlLCJjakNvbnNlbnRFbnVtIjoiTkVWRVJfQVNLRUQifQ%3D%3D

Into these:

https://poetsroad.bandcamp.com/

https://www.audible.com/pd/Project-Hail-Mary-Audiobook/B08G9PRS1K

https://www.amazon.com/Alexander-Theatre-Sessions-Poets-Fall/dp/B08NT852YT

https://open.spotify.com/track/1hhZQVLXpg10ySFQFxGbih

https://www.aliexpress.com/item/1005001913861188.html

https://www.google.com/search?q=cat

https://www.vudu.com/content/movies/details/Moonlight-Season-1/133120

๐Ÿค Contributing

Contributions, issues and feature requests are welcome and greatly appreciated!
Feel free to check issues page. If you find a website that is not supported, please create an issue and I'll be more than happy to add it.

๐Ÿ‘ค Author

This project was made by Kain (ksir.pw)
Feel free to contact me if you have any trouble with this package.

tidy-url's People

Contributors

andreymarchuk avatar drkain avatar elonyavist avatar justin-guan avatar mahansky avatar rendomnet avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.