vibinex / chrome-extension

This chrome extension adds actionable overlays based on the company's data (code, deployments and success metrics)
10 stars 6 forks source link

A more robust method for URL parsing #84

Open avikalpg opened 10 months ago

avikalpg commented 10 months ago
          @avikalpg A more robust method would involve using a URL parsing library to abstract away the direct manipulation of URL strings. Libraries like `URL` built into modern JavaScript or third-party libraries like `urijs` can parse URLs and provide an API to access different parts of the URL.

For example, using the URL interface in JavaScript:

const url = new URL(tabUrl);
const pathname = url.pathname;
const searchParams = new URLSearchParams(url.search);

// Now you can check pathname segments and search parameters without directly splitting strings
if (pathname.startsWith('/orgs/') && searchParams.get('tab') === 'repositories') {
  // It's an organization's repositories page
}

This approach is less likely to break if GitHub changes its URL scheme because it doesn't rely on the URL having a specific number of segments or the order of query parameters. It also makes the code easier to read and understand.

Remember to check browser compatibility for the URL and URLSearchParams APIs if the script is intended to run in a wide range of browsers, or use a polyfill or third-party library if necessary.

_Originally posted by @coderabbitai[bot] in https://github.com/Alokit-Innovations/chrome-extension/pull/81#discussion_r1398057854_