Skip to content

Commit

Permalink
Encode query string (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmu332233 authored Dec 4, 2022
1 parent 7466e28 commit ba842f5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ type QueryParameters = { [key: string]: any };
export const objectToQueryString = (queryParameters: QueryParameters) => {
return queryParameters
? Object.entries(queryParameters).reduce((queryString, [key, value]) => {
const encodedValue = encodeURIComponent(value);
const symbol = queryString.length === 0 ? '?' : '&';
queryString += value ? `${symbol}${key}=${value}` : '';
queryString += encodedValue ? `${symbol}${key}=${encodedValue}` : '';
return queryString;
}, '')
: '';
Expand Down

1 comment on commit ba842f5

@vercel
Copy link

@vercel vercel bot commented on ba842f5 Dec 4, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.