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

Add getQueryParam utility method to support pagination #128

Merged
merged 1 commit into from
Mar 13, 2021

Conversation

mkistler
Copy link
Contributor

This PR adds a small utility method to extract the value of a query parameter from a URL string. This will be used in the pagination support for Node.

Checklist
  • npm test passes (tip: npm run lint-fix can correct most style issues)
  • tests are included
  • documentation is changed or added

@mkistler mkistler requested review from dpopp07 and padamstx March 12, 2021 02:45
Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

* @throws if urlStr is an invalid URL
*/
export function getQueryParam(urlStr: string, param: string): string {
const url = new URL(urlStr, 'https://foo.bar');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind adding a comment explaining that 'https://foo.bar' is there to support relative URLs? Maybe this is more common than I realize but I've never seen that pattern and I was a little confused. Upon looking it up it made perfect sense but a comment may be helpful for future people

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion! I will add a comment.

it('should return the first value when the query string has duplicate parameters', function() {
const nextUrl = '/api/v1/offerings?start=foo&start=bar&limit=10';
expect(getQueryParam(nextUrl, 'start')).toBe('foo');
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great tests! 👏

@mkistler mkistler force-pushed the mdk/pagination-methods branch from c4783cd to 0b6552e Compare March 13, 2021 01:00
@mkistler mkistler merged commit d4f067a into main Mar 13, 2021
@mkistler mkistler deleted the mdk/pagination-methods branch March 13, 2021 13:36
ibm-devx-automation pushed a commit that referenced this pull request Mar 13, 2021
# [2.10.0](v2.9.0...v2.10.0) (2021-03-13)

### Features

* add getQueryParam utility method to support pagination ([#128](#128)) ([d4f067a](d4f067a))
@ibm-devx-automation
Copy link

🎉 This PR is included in version 2.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

4 participants