New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

shorten-repo-url

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shorten-repo-url

Shorten GitHub URLs like GitHub shortens Issues and Commit URLs

  • 5.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25
decreased by-40.48%
Maintainers
0
Weekly downloads
 
Created
Source

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>

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.

Type: Element

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

currentUrl

Type: string, like location.href

Same as before.

License

MIT © Federico Brigante

Keywords

FAQs

Package last updated on 08 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc