camelot-unchained
Version:
Camelot Unchained Client Library
38 lines (36 loc) • 1.06 kB
JavaScript
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
;
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
} else {
var error = new Error(response.statusText);
error.response = response;
throw error;
}
}
exports.checkStatus = checkStatus;
function parseJSON(response) {
return response.json();
}
exports.parseJSON = parseJSON;
function makeQueryString(url) {
var params = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
if (!params) return url;
var key = void 0;
var qs = [];
for (key in params) {
if (params.hasOwnProperty(key)) {
qs.push(key + "=" + encodeURIComponent(params[key]));
}
}
if (qs.length) {
url += "?" + qs.join("&");
}
return url;
}
exports.makeQueryString = makeQueryString;