Nostalgic Perogi Monogramming

    tidy-url
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.9 • Public • Published

    ♡ 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

    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"
                }
            ],
            "is_new_host": false
        }
    }

    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
    

    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
    

    🤝 Contributing

    Contributions, issues and feature requests are welcome!
    Feel free to check issues page.

    👤 Author

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

    Install

    npm i tidy-url

    DownloadsWeekly Downloads

    99

    Version

    1.2.9

    License

    ISC

    Unpacked Size

    70.3 kB

    Total Files

    22

    Last publish

    Collaborators

    • kainsir