svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 1 | export default function objectPropsToUrlString(data) { |
| 2 | let str = ''; |
| 3 | Object.keys(data).map(key => { |
| 4 | if (typeof data[key] === 'object') { |
| 5 | let obj = data[key]; |
| 6 | let arr = []; |
| 7 | |
| 8 | Object.keys(obj).map(prop => { |
| 9 | if (obj[prop]) { |
| 10 | arr.push(encodeURIComponent(prop)); |
| 11 | } |
| 12 | }); |
| 13 | if (arr.length) { |
| 14 | str += `&${encodeURIComponent(key)}=${arr.join(',')}`; |
| 15 | } |
| 16 | } else if (data[key]) { |
| 17 | str += `&${encodeURIComponent(key)}=${encodeURIComponent( |
| 18 | data[key] |
| 19 | )}`; |
| 20 | } |
| 21 | }); |
| 22 | return str; |
| 23 | } |