-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great tests! 👏
c4783cd
to
0b6552e
Compare
# [2.10.0](v2.9.0...v2.10.0) (2021-03-13) ### Features * add getQueryParam utility method to support pagination ([#128](#128)) ([d4f067a](d4f067a))
🎉 This PR is included in version 2.10.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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)