Skip to content

Commit

Permalink
Replace use of Headers with object (#174)
Browse files Browse the repository at this point in the history
* Turn of biome linter/complexity/useLiteralKeys linter rule

* Replace use of Headers with Object

* Update README

* Add Node 20 to CI matrix
  • Loading branch information
mattt authored Dec 19, 2023
1 parent 4324b48 commit 16c47e6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/previous-releases

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ such as injecting headers or adding log statements.

```js
replicate.fetch = (url, options) => {
const headers = new Headers(options && options.headers);
headers.append("X-Custom-Header", "some value");
const headers = options && options.headers ? { ...options.headers } : {};
headers["X-Custom-Header"] = "some value";

console.log("fetch", { url, ...options, headers });

Expand Down
7 changes: 4 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
"useMediaCaption": "off",
"noSvgWithoutTitle": "off"
},
"complexity": {
"useLiteralKeys": "off",
"useOptionalChain": "off"
},
"performance": {
"noAccumulatingSpread": "off"
},
"suspicious": {
"noArrayIndexKey": "off",
"noExplicitAny": "off"
},
"complexity": {
"useOptionalChain": "off"
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ class Replicate {
url.searchParams.append(key, value);
}

const headers = new Headers();
const headers = {};
if (auth) {
headers.append("Authorization", `Token ${auth}`);
headers["Authorization"] = `Token ${auth}`;
}
headers.append("Content-Type", "application/json");
headers.append("User-Agent", userAgent);
headers["Content-Type"] = "application/json";
headers["User-Agent"] = userAgent;
if (options.headers) {
for (const [key, value] of options.headers.entries()) {
headers.append(key, value);
for (const [key, value] of Object.entries(options.headers)) {
headers[key] = value;
}
}

Expand Down

0 comments on commit 16c47e6

Please sign in to comment.