Skip to content

Commit 28450a6

Browse files
Fixed support for Node 8 and 9
1 parent 481eb43 commit 28450a6

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

index.mjs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import axios from "axios";
44
import createHmac from "create-hmac";
55
import OAuth from "oauth-1.0a";
6+
import Url from "url-parse";
67

78
/**
89
* WooCommerce REST API wrapper
@@ -61,25 +62,24 @@ export default class WooCommerceRestApi {
6162
/**
6263
* Parse params object.
6364
*
64-
* @param {String} params
65-
* @param {URLSearchParams} searchParams
65+
* @param {Object} params
66+
* @param {Object} query
6667
*/
67-
_parseParamsObject(params, searchParams) {
68+
_parseParamsObject(params, query) {
6869
for (const key in params) {
6970
const value = params[key];
7071

7172
if (typeof value === "object") {
72-
// parseParamsObject(value, searchParams);
7373
for (const prop in value) {
74-
searchParams.set(
75-
key.toString() + "[" + prop.toString() + "]",
76-
value[prop]
77-
);
74+
const itemKey = key.toString() + "[" + prop.toString() + "]";
75+
query[itemKey] = value[prop];
7876
}
7977
} else {
80-
searchParams.set(key, value);
78+
query[key] = value;
8179
}
8280
}
81+
82+
return query;
8383
}
8484

8585
/**
@@ -96,17 +96,17 @@ export default class WooCommerceRestApi {
9696
return url;
9797
}
9898

99-
const query = new URL(url).searchParams;
99+
const query = new Url(url, null, true).query;
100100
const values = [];
101101

102102
let queryString = "";
103103

104104
// Include params object into URL.searchParams.
105105
this._parseParamsObject(params, query);
106106

107-
query.forEach((value, key) => {
107+
for (const key in query) {
108108
values.push(key);
109-
});
109+
}
110110
values.sort();
111111

112112
for (const i in values) {
@@ -118,7 +118,7 @@ export default class WooCommerceRestApi {
118118
.replace(/%5B/g, "[")
119119
.replace(/%5D/g, "]");
120120
queryString += "=";
121-
queryString += encodeURIComponent(query.get(values[i]));
121+
queryString += encodeURIComponent(query[values[i]]);
122122
}
123123

124124
return url.split("?")[0] + "?" + queryString;
@@ -141,7 +141,7 @@ export default class WooCommerceRestApi {
141141

142142
// Include port.
143143
if (this.port !== "") {
144-
const hostname = new URL(url).hostname;
144+
const hostname = new Url(url).hostname;
145145

146146
url = url.replace(hostname, hostname + ":" + this.port);
147147
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"axios": "^0.19.0",
2929
"create-hmac": "^1.1.7",
3030
"oauth-1.0a": "^2.2.6",
31-
"url-polyfill": "^1.1.7"
31+
"url-parse": "^1.4.7"
3232
},
3333
"devDependencies": {
3434
"@babel/cli": "7.5.5",

0 commit comments

Comments
 (0)