Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A more robust method for URL parsing #84

Open
avikalpg opened this issue Nov 18, 2023 · 0 comments
Open

A more robust method for URL parsing #84

avikalpg opened this issue Nov 18, 2023 · 0 comments
Assignees

Comments

@avikalpg
Copy link
Member

          @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 #81 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant