Skip to content

Commit

Permalink
perf: optimize loops (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnritzdoge committed Apr 12, 2021
1 parent 26d84e2 commit 01b8012
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/lib/PetitioRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ export class PetitioRequest {
*/
public query(key: Record<string, any>): this
public query(key: string | Record<string, any>, value?: any): this {
if (typeof key === "object") for (const qy of Object.keys(key)) this.url.searchParams.append(qy, key[qy]);
else this.url.searchParams.append(key, value);
if (typeof key === "object") {
const keys = Object.keys(key);
// eslint-disable-next-line @typescript-eslint/prefer-for-of, no-plusplus
for (let ii = 0; ii < keys.length; ++ii) {
const val = keys[ii];
this.url.searchParams.append(val, key[val]);
}
} else this.url.searchParams.append(key, value);

return this;
}
Expand Down Expand Up @@ -201,9 +207,15 @@ export class PetitioRequest {
public header(header: Record<string, string>): this
public header(header: string | Record<string, string>, value?: string): this {
// eslint-disable-next-line max-len
if (typeof header === "object") for (const hN of Object.keys(header)) this.reqHeaders[hN.toLowerCase()] = header[hN];
if (typeof header === "object") {
const keys = Object.keys(header);

else this.reqHeaders[header.toLowerCase()] = value;
// eslint-disable-next-line @typescript-eslint/prefer-for-of, no-plusplus
for (let ii = 0; ii < keys.length; ++ii) {
const val = keys[ii];
this.reqHeaders[val.toLowerCase()] = header[val];
}
} else this.reqHeaders[header.toLowerCase()] = value;

return this;
}
Expand Down

0 comments on commit 01b8012

Please sign in to comment.