Nimble Package Maestros

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

    2.3.0 • Public • Published

    shorten-repo-url

    Shorten GitHub links like GitHub shortens Issues and Commit links. Used on refined-github

    Demo

    Look at the tests to see what each URL is shortened to. GitLab URLs are mostly compatible but they're not officially supported.

    It works on any domain, so GitHub Enterprise is also supported.

    Install

    $ npm install shorten-repo-url
    

    Usage

    const shortenRepoUrl = require('shorten-repo-url');
    
    const HTML = shortenRepoUrl(
    	'https://github.com/nodejs/node/tree/v0.12/doc',
    	'https://github.com/nodejs/node' // same repo
    );
    //=> '<code>v0.12</code>' // repo-less URL
    
    const HTML = shortenRepoUrl(
    	'https://github.com/nodejs/node/tree/v0.12/doc',
    	'https://github.com' // not the same repo
    );
    //=> 'nodejs/node@<code>v0.12</code>' // URL with repo

    API

    shortenRepoUrl(url, currentUrl)

    Returns the shortened URL in HTML as a string like nodejs/node@<code>v0.12</code>.

    url

    Type: string

    The GitHub URL to shorten.

    currentUrl

    Type: string, like location.href

    The URL of the current page, to build relative URLs like <code>v0.12</code> instead of the longer nodejs/node@<code>v0.12</code>

    shortenRepoUrl.applyToLink(link, currentUrl)

    Automatically shorten the link's text if the text matches the URL, i.e. <a href="https://github.com">https://github.com</a>

    It will return true or false depending on whether the link was shortened.

    link

    Type: Element

    Example: shortenRepoUrl.applyToLink(document.querySelector(a))

    currentUrl

    Type: string, like location.href

    Same as before.

    License

    MIT © Federico Brigante

    Install

    npm i shorten-repo-url

    DownloadsWeekly Downloads

    49

    Version

    2.3.0

    License

    MIT

    Unpacked Size

    11.1 kB

    Total Files

    5

    Last publish

    Collaborators

    • fregante
    • refined-github