Skip to content

Commit 16c47e6

Browse files
authored
Replace use of Headers with object (#174)
* Turn of biome linter/complexity/useLiteralKeys linter rule * Replace use of Headers with Object * Update README * Add Node 20 to CI matrix
1 parent 4324b48 commit 16c47e6

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212

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

1818
steps:
1919
- uses: actions/checkout@v3

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ such as injecting headers or adding log statements.
132132

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

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

biome.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
"useMediaCaption": "off",
1818
"noSvgWithoutTitle": "off"
1919
},
20+
"complexity": {
21+
"useLiteralKeys": "off",
22+
"useOptionalChain": "off"
23+
},
2024
"performance": {
2125
"noAccumulatingSpread": "off"
2226
},
2327
"suspicious": {
2428
"noArrayIndexKey": "off",
2529
"noExplicitAny": "off"
26-
},
27-
"complexity": {
28-
"useOptionalChain": "off"
2930
}
3031
}
3132
}

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ class Replicate {
191191
url.searchParams.append(key, value);
192192
}
193193

194-
const headers = new Headers();
194+
const headers = {};
195195
if (auth) {
196-
headers.append("Authorization", `Token ${auth}`);
196+
headers["Authorization"] = `Token ${auth}`;
197197
}
198-
headers.append("Content-Type", "application/json");
199-
headers.append("User-Agent", userAgent);
198+
headers["Content-Type"] = "application/json";
199+
headers["User-Agent"] = userAgent;
200200
if (options.headers) {
201-
for (const [key, value] of options.headers.entries()) {
202-
headers.append(key, value);
201+
for (const [key, value] of Object.entries(options.headers)) {
202+
headers[key] = value;
203203
}
204204
}
205205

0 commit comments

Comments
 (0)