Skip to content

Commit 0bb478f

Browse files
committed
perf: improve stringify performance
1 parent bc7e1a1 commit 0bb478f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

lib/stringify.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ function getAsPrimitive(value) {
2828
function stringify(input) {
2929
let result = "";
3030

31+
if (input === null || typeof input !== 'object') {
32+
return result;
33+
}
34+
3135
const keys = Object.keys(input);
3236
const keyLength = keys.length;
3337

3438
for (let i = 0; i < keyLength; i++) {
3539
const key = keys[i];
3640
const value = input[key];
37-
const encodedKey = encodeString(key);
41+
const encodedKey = encodeString(key) + "=";
3842

3943
if (i) {
4044
result += "&";
@@ -47,10 +51,10 @@ function stringify(input) {
4751
result += "&";
4852
}
4953

50-
result += encodedKey + "=" + getAsPrimitive(value[j]);
54+
result += encodedKey + getAsPrimitive(value[j]);
5155
}
5256
} else {
53-
result += encodedKey + "=" + getAsPrimitive(value);
57+
result += encodedKey + getAsPrimitive(value);
5458
}
5559
}
5660

0 commit comments

Comments
 (0)