@whatwg-node/node-fetch 0.4.4-alpha-20230613143059-7231b86 → 0.4.4-alpha-20230613143421-6ca77f9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/Response.js CHANGED
@@ -61,25 +61,24 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
61
61
  }
62
62
  static json(data, init) {
63
63
  let bodyInit = JSON.stringify(data);
64
- if (init != null) {
65
- if (init.headers != null) {
66
- init.headers = new Headers_js_1.PonyfillHeaders(init.headers);
67
- if (!init.headers.has('content-type')) {
68
- init.headers.set('content-type', JSON_CONTENT_TYPE);
69
- }
70
- if (!init.headers.has('content-length')) {
71
- bodyInit = Buffer.from(bodyInit);
72
- init.headers.set('content-length', bodyInit.byteLength.toString());
73
- }
64
+ const resInit = init || {};
65
+ if (resInit.headers != null) {
66
+ resInit.headers = new Headers_js_1.PonyfillHeaders(resInit.headers);
67
+ if (!resInit.headers.has('content-type')) {
68
+ resInit.headers.set('content-type', JSON_CONTENT_TYPE);
74
69
  }
75
- else {
70
+ if (!resInit.headers.has('content-length')) {
76
71
  bodyInit = Buffer.from(bodyInit);
77
- init.headers = [
78
- ['content-type', JSON_CONTENT_TYPE],
79
- ['content-length', bodyInit.byteLength.toString()],
80
- ];
72
+ resInit.headers.set('content-length', bodyInit.byteLength.toString());
81
73
  }
82
74
  }
75
+ else {
76
+ bodyInit = Buffer.from(bodyInit);
77
+ resInit.headers = [
78
+ ['content-type', JSON_CONTENT_TYPE],
79
+ ['content-length', bodyInit.byteLength.toString()],
80
+ ];
81
+ }
83
82
  return new PonyfillResponse(bodyInit, init);
84
83
  }
85
84
  }
package/esm/Response.js CHANGED
@@ -58,25 +58,24 @@ export class PonyfillResponse extends PonyfillBody {
58
58
  }
59
59
  static json(data, init) {
60
60
  let bodyInit = JSON.stringify(data);
61
- if (init != null) {
62
- if (init.headers != null) {
63
- init.headers = new PonyfillHeaders(init.headers);
64
- if (!init.headers.has('content-type')) {
65
- init.headers.set('content-type', JSON_CONTENT_TYPE);
66
- }
67
- if (!init.headers.has('content-length')) {
68
- bodyInit = Buffer.from(bodyInit);
69
- init.headers.set('content-length', bodyInit.byteLength.toString());
70
- }
61
+ const resInit = init || {};
62
+ if (resInit.headers != null) {
63
+ resInit.headers = new PonyfillHeaders(resInit.headers);
64
+ if (!resInit.headers.has('content-type')) {
65
+ resInit.headers.set('content-type', JSON_CONTENT_TYPE);
71
66
  }
72
- else {
67
+ if (!resInit.headers.has('content-length')) {
73
68
  bodyInit = Buffer.from(bodyInit);
74
- init.headers = [
75
- ['content-type', JSON_CONTENT_TYPE],
76
- ['content-length', bodyInit.byteLength.toString()],
77
- ];
69
+ resInit.headers.set('content-length', bodyInit.byteLength.toString());
78
70
  }
79
71
  }
72
+ else {
73
+ bodyInit = Buffer.from(bodyInit);
74
+ resInit.headers = [
75
+ ['content-type', JSON_CONTENT_TYPE],
76
+ ['content-length', bodyInit.byteLength.toString()],
77
+ ];
78
+ }
80
79
  return new PonyfillResponse(bodyInit, init);
81
80
  }
82
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.4.4-alpha-20230613143059-7231b86",
3
+ "version": "0.4.4-alpha-20230613143421-6ca77f9",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -18,5 +18,5 @@ export declare class PonyfillResponse<TJSON = any> extends PonyfillBody<TJSON> i
18
18
  clone(): PonyfillResponse<any>;
19
19
  static error(): PonyfillResponse<any>;
20
20
  static redirect(url: string, status?: number): PonyfillResponse<any>;
21
- static json<T = any>(data: T, init?: RequestInit): PonyfillResponse<T>;
21
+ static json<T = any>(data: T, init?: ResponsePonyfilInit): PonyfillResponse<T>;
22
22
  }
@@ -18,5 +18,5 @@ export declare class PonyfillResponse<TJSON = any> extends PonyfillBody<TJSON> i
18
18
  clone(): PonyfillResponse<any>;
19
19
  static error(): PonyfillResponse<any>;
20
20
  static redirect(url: string, status?: number): PonyfillResponse<any>;
21
- static json<T = any>(data: T, init?: RequestInit): PonyfillResponse<T>;
21
+ static json<T = any>(data: T, init?: ResponsePonyfilInit): PonyfillResponse<T>;
22
22
  }