From 257371da288d5ac0d796de6802b951fa30245c0d Mon Sep 17 00:00:00 2001 From: Carter <45381083+Fyko@users.noreply.github.com> Date: Thu, 4 Jun 2020 05:34:29 -0600 Subject: [PATCH] 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> --- src/rest/APIRequest.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index 36ad0d72c..b466cd01e 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -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}`}`;