feat(REST): allow options.query as URLSearchParams (#4143)

* feat: support query as URLSearchParams

* style: remove unnecessary comment

* patch: use const

Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>

* feat: not reconstructing the search params

Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
This commit is contained in:
Carter
2020-06-04 05:34:29 -06:00
committed by GitHub
parent 5955498aca
commit 257371da28

View File

@@ -18,8 +18,9 @@ class APIRequest {
let queryString = '';
if (options.query) {
// Filter out undefined query options
const query = Object.entries(options.query).filter(([, value]) => value !== null && typeof value !== 'undefined');
const query = Object.entries(options.query)
.filter(([, value]) => ![null, 'null', 'undefined'].includes(value) && typeof value !== 'undefined')
.flatMap(([key, value]) => (Array.isArray(value) ? value.map(v => [key, v]) : [[key, value]]));
queryString = new URLSearchParams(query).toString();
}
this.path = `${path}${queryString && `?${queryString}`}`;