(sub, path)
| 34 | } |
| 35 | |
| 36 | function _encode(sub, path) { |
| 37 | let encode = that.encode; |
| 38 | let type = that.type(sub); |
| 39 | if (type == "array") { |
| 40 | sub.forEach(function (e, i) { |
| 41 | if (!that.isObject(e)) i = ""; |
| 42 | _encode(e, path + `%5B${i}%5D`); |
| 43 | }); |
| 44 | |
| 45 | } else if (type == "object") { |
| 46 | for (let key in sub) { |
| 47 | if (path) { |
| 48 | _encode(sub[key], path + "%5B" + encode(key) + "%5D"); |
| 49 | } else { |
| 50 | _encode(sub[key], encode(key)); |
| 51 | } |
| 52 | } |
| 53 | } else { |
| 54 | if (!first) { |
| 55 | str += "&"; |
| 56 | } |
| 57 | first = false; |
| 58 | str += path + "=" + encode(sub); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | _encode(data, ""); |
| 63 | return str; |
no test coverage detected