mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01: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:
@@ -18,8 +18,9 @@ class APIRequest {
|
|||||||
|
|
||||||
let queryString = '';
|
let queryString = '';
|
||||||
if (options.query) {
|
if (options.query) {
|
||||||
// Filter out undefined query options
|
const query = Object.entries(options.query)
|
||||||
const query = Object.entries(options.query).filter(([, value]) => value !== null && typeof value !== 'undefined');
|
.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();
|
queryString = new URLSearchParams(query).toString();
|
||||||
}
|
}
|
||||||
this.path = `${path}${queryString && `?${queryString}`}`;
|
this.path = `${path}${queryString && `?${queryString}`}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user