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

github-url-detection

Package Overview
Dependencies
Maintainers
0
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-url-detection

Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.

  • 10.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
409
increased by36.33%
Maintainers
0
Weekly downloads
 
Created
Source

github-url-detection

Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.

Battle-tested by and extracted from the Refined GitHub extension.

  • Try the live demo
  • See the code and expected URLs for every detection

Install

npm install github-url-detection
// This package is pure ESM
import * as pageDetect from 'github-url-detection';

Usage

const href = 'https://github.com/refined-github/github-url-detection/issues/1';
if (pageDetect.isIssue(new URL(href))) { // Pass the URL as an `URL` object
	alert('The passed URL is of an issue!')
}

if (pageDetect.isRepo()) { // Uses `window.location.href` by default
	alert('You’re looking at a repo!')
}

if (pageDetect.isIssueOrPRList()) {
	alert('You’re looking at a issues and PRs list!')
}

API

Most detections are URL-based while others need access to the current document. You can determine which ones are URL-based by looking at their signature: URL-based functions have a url parameter.

URL-based detections

By default, URL-based detections use the location global if you don't pass a url argument.

if (pageDetect.isIssueOrPRList()) {
	alert('You’re looking at a issues or PRs list!')
}
if (pageDetect.isIssueOrPRList(new URL('https://github.com/refined-github/github-url-detection/pulls'))) {
	alert('You’re looking at a issues or PRs list!')
}

Notice that the url parameter is not a plain string but it has to be a proper URL or location object.

Document-based detections

By default, document-based detections use the document global, which means they can only be used if you have the whole page, you can't just test any random URL string.

if (pageDetect.isOrganizationProfile()) {
	alert('You’re on an organization profile, like https://github.com/babel')
}

License

MIT © Federico Brigante

Keywords

FAQs

Package last updated on 10 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