refactor(APIRequest): utilize URLSearchParams (#3180)

* utilize URLSearchParams

* options.query can be undefined/null

* oops

* remembered what I intended
This commit is contained in:
bdistin
2019-04-05 04:32:19 -05:00
committed by SpaceEEC
parent c078682722
commit 5e9bd786d1
2 changed files with 15 additions and 7 deletions

View File

@@ -1,6 +1,5 @@
'use strict';
const querystring = require('querystring');
const FormData = require('form-data');
const https = require('https');
const { browser, UserAgent } = require('../util/Constants');
@@ -16,8 +15,13 @@ class APIRequest {
this.route = options.route;
this.options = options;
const queryString = (querystring.stringify(options.query).match(/[^=&?]+=[^=&?]+/g) || []).join('&');
this.path = `${path}${queryString ? `?${queryString}` : ''}`;
let queryString = '';
if (options.query) {
// Filter out undefined query options
const query = Object.entries(options.query).filter(([, value]) => typeof value !== 'undefined');
queryString = new URLSearchParams(query).toString();
}
this.path = `${path}${queryString && `?${queryString}`}`;
}
make() {