npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

shorten-repo-url

v5.2.1

Published

Shorten GitHub URLs like GitHub shortens Issues and Commit URLs

Downloads

250

Readme

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>. If a data-original-href attribute is present, it will be used when comparing the link’s text and when generating the shortened URL.

Note: this function will never change the href of the link, it only changes the text.

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