mirror of
https://github.com/danbulant/discord.js
synced 2026-05-27 05:52:05 +00:00
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:
parent
5955498aca
commit
257371da28
1 changed files with 3 additions and 2 deletions
|
|
@ -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}`}`;
|
||||
|
|
|
|||
Loading…
Reference in a new issue