Travis build: 1516
This commit is contained in:
@ -10,19 +10,17 @@ Determine the `symbol` to be either `?` or `&` based on the `index` and concaten
|
||||
Return the `queryString` or an empty string when the `queryParameters` are falsy.
|
||||
|
||||
```js
|
||||
|
||||
const objectToQueryString = queryParameters => {
|
||||
return queryParameters
|
||||
? Object.entries(queryParameters).reduce((queryString, [key, val], index) => {
|
||||
const symbol = index === 0 ? '?' : '&';
|
||||
queryString += (typeof val === 'string') ? `${symbol}${key}=${val}` : '';
|
||||
return queryString;
|
||||
}, '')
|
||||
const symbol = index === 0 ? '?' : '&';
|
||||
queryString += typeof val === 'string' ? `${symbol}${key}=${val}` : '';
|
||||
return queryString;
|
||||
}, '')
|
||||
: '';
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
objectToQueryString({page: '1', size: '2kg', key: undefined}); // '?page=1&size=2kg'
|
||||
objectToQueryString({ page: '1', size: '2kg', key: undefined }); // '?page=1&size=2kg'
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user