Travis build: 1511

This commit is contained in:
30secondsofcode
2019-10-16 06:39:13 +00:00
parent 4b6bce7ac8
commit ca2c1a51c0
14 changed files with 207 additions and 117 deletions

View File

@ -10,17 +10,19 @@ 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) => {
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'
```