-
Notifications
You must be signed in to change notification settings - Fork 29
Fix: parameters in requests #8
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
Conversation
epallerols
left a comment
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.
only doubt is that if buildUrlWithParams('http://mandarina.com', { a: 0, b: 3 }) should return "http://mandarina.com?b=3" or "http://mandarina.com?a=0&b=3"
Whit the current implementation returns just b. I am not sure if it is desired
| })) | ||
| } | ||
|
|
||
| export const buildUrlWithParams = (url, params = {}) => { |
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.
Another approach could be to filter out the falsy values first:
export const buildUrlWithParams = (url, params = {}) => {
const queryParams = Object.keys(params)
.filter((k) => params[k])
.map(k => `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`)
.join('&')
return queryParams ? `${url}?${queryParams}` : url
}
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.
This is because filter and map will iterate over the values twice, and reduce will do it only once, said that your solution looks more readable and since the parameters won't be more than 10 elements, I will implement your suggestion, thanks :)
|
🎉 This PR is included in version 1.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR fixes:
forms.list,responses.listare fixedpageSizeis now camelcase, deprecatedpage_size