@whatwg-node/node-fetch 0.7.9 → 0.7.10-alpha-20250220111507-a3545bc54346479a467fb28e29d6484542def7a0

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/Headers.js CHANGED
@@ -12,14 +12,14 @@ class PonyfillHeaders {
12
12
  _map;
13
13
  objectNormalizedKeysOfHeadersInit = [];
14
14
  objectOriginalKeysOfHeadersInit = [];
15
- _setCookies = [];
15
+ _setCookies;
16
16
  constructor(headersInit) {
17
17
  this.headersInit = headersInit;
18
18
  }
19
19
  // perf: we don't need to build `this.map` for Requests, as we can access the headers directly
20
20
  _get(key) {
21
21
  const normalized = key.toLowerCase();
22
- if (normalized === 'set-cookie') {
22
+ if (normalized === 'set-cookie' && this._setCookies?.length) {
23
23
  return this._setCookies.join(', ');
24
24
  }
25
25
  // If the map is built, reuse it
@@ -65,6 +65,7 @@ class PonyfillHeaders {
65
65
  this.headersInit.forEach(([key, value]) => {
66
66
  const normalizedKey = key.toLowerCase();
67
67
  if (normalizedKey === 'set-cookie') {
68
+ this._setCookies ||= [];
68
69
  this._setCookies.push(value);
69
70
  return;
70
71
  }
@@ -75,6 +76,7 @@ class PonyfillHeaders {
75
76
  this._map = new Map();
76
77
  this.headersInit.forEach((value, key) => {
77
78
  if (key === 'set-cookie') {
79
+ this._setCookies ||= [];
78
80
  this._setCookies.push(value);
79
81
  return;
80
82
  }
@@ -88,6 +90,7 @@ class PonyfillHeaders {
88
90
  if (initValue != null) {
89
91
  const normalizedKey = initKey.toLowerCase();
90
92
  if (normalizedKey === 'set-cookie') {
93
+ this._setCookies ||= [];
91
94
  this._setCookies.push(initValue);
92
95
  continue;
93
96
  }
@@ -105,6 +108,7 @@ class PonyfillHeaders {
105
108
  append(name, value) {
106
109
  const key = name.toLowerCase();
107
110
  if (key === 'set-cookie') {
111
+ this._setCookies ||= [];
108
112
  this._setCookies.push(value);
109
113
  return;
110
114
  }
@@ -117,11 +121,11 @@ class PonyfillHeaders {
117
121
  if (value == null) {
118
122
  return null;
119
123
  }
120
- return value;
124
+ return value.toString();
121
125
  }
122
126
  has(name) {
123
127
  if (name === 'set-cookie') {
124
- return this._setCookies.length > 0;
128
+ return !!this._setCookies?.length;
125
129
  }
126
130
  return !!this._get(name); // we might need to check if header exists and not just check if it's not nullable
127
131
  }
@@ -142,7 +146,7 @@ class PonyfillHeaders {
142
146
  this.getMap().delete(key);
143
147
  }
144
148
  forEach(callback) {
145
- this._setCookies.forEach(setCookie => {
149
+ this._setCookies?.forEach(setCookie => {
146
150
  callback(setCookie, 'set-cookie', this);
147
151
  });
148
152
  if (!this._map) {
@@ -170,7 +174,7 @@ class PonyfillHeaders {
170
174
  });
171
175
  }
172
176
  *_keys() {
173
- if (this._setCookies.length) {
177
+ if (this._setCookies?.length) {
174
178
  yield 'set-cookie';
175
179
  }
176
180
  if (!this._map) {
@@ -193,7 +197,9 @@ class PonyfillHeaders {
193
197
  return new IteratorObject_js_1.PonyfillIteratorObject(this._keys(), 'HeadersIterator');
194
198
  }
195
199
  *_values() {
196
- yield* this._setCookies;
200
+ if (this._setCookies?.length) {
201
+ yield* this._setCookies;
202
+ }
197
203
  if (!this._map) {
198
204
  if (this.headersInit) {
199
205
  if (Array.isArray(this.headersInit)) {
@@ -214,7 +220,9 @@ class PonyfillHeaders {
214
220
  return new IteratorObject_js_1.PonyfillIteratorObject(this._values(), 'HeadersIterator');
215
221
  }
216
222
  *_entries() {
217
- yield* this._setCookies.map(cookie => ['set-cookie', cookie]);
223
+ if (this._setCookies?.length) {
224
+ yield* this._setCookies.map(cookie => ['set-cookie', cookie]);
225
+ }
218
226
  if (!this._map) {
219
227
  if (this.headersInit) {
220
228
  if (Array.isArray(this.headersInit)) {
@@ -235,7 +243,7 @@ class PonyfillHeaders {
235
243
  return new IteratorObject_js_1.PonyfillIteratorObject(this._entries(), 'HeadersIterator');
236
244
  }
237
245
  getSetCookie() {
238
- return this._setCookies;
246
+ return this._setCookies || [];
239
247
  }
240
248
  [Symbol.iterator]() {
241
249
  return this.entries();
@@ -244,7 +252,7 @@ class PonyfillHeaders {
244
252
  const record = {};
245
253
  this.forEach((value, key) => {
246
254
  if (key === 'set-cookie') {
247
- record['set-cookie'] = this._setCookies;
255
+ record['set-cookie'] = this._setCookies || [];
248
256
  }
249
257
  else {
250
258
  record[key] = value?.includes(',') ? value.split(',').map(el => el.trim()) : value;
package/esm/Headers.js CHANGED
@@ -8,14 +8,14 @@ export class PonyfillHeaders {
8
8
  _map;
9
9
  objectNormalizedKeysOfHeadersInit = [];
10
10
  objectOriginalKeysOfHeadersInit = [];
11
- _setCookies = [];
11
+ _setCookies;
12
12
  constructor(headersInit) {
13
13
  this.headersInit = headersInit;
14
14
  }
15
15
  // perf: we don't need to build `this.map` for Requests, as we can access the headers directly
16
16
  _get(key) {
17
17
  const normalized = key.toLowerCase();
18
- if (normalized === 'set-cookie') {
18
+ if (normalized === 'set-cookie' && this._setCookies?.length) {
19
19
  return this._setCookies.join(', ');
20
20
  }
21
21
  // If the map is built, reuse it
@@ -61,6 +61,7 @@ export class PonyfillHeaders {
61
61
  this.headersInit.forEach(([key, value]) => {
62
62
  const normalizedKey = key.toLowerCase();
63
63
  if (normalizedKey === 'set-cookie') {
64
+ this._setCookies ||= [];
64
65
  this._setCookies.push(value);
65
66
  return;
66
67
  }
@@ -71,6 +72,7 @@ export class PonyfillHeaders {
71
72
  this._map = new Map();
72
73
  this.headersInit.forEach((value, key) => {
73
74
  if (key === 'set-cookie') {
75
+ this._setCookies ||= [];
74
76
  this._setCookies.push(value);
75
77
  return;
76
78
  }
@@ -84,6 +86,7 @@ export class PonyfillHeaders {
84
86
  if (initValue != null) {
85
87
  const normalizedKey = initKey.toLowerCase();
86
88
  if (normalizedKey === 'set-cookie') {
89
+ this._setCookies ||= [];
87
90
  this._setCookies.push(initValue);
88
91
  continue;
89
92
  }
@@ -101,6 +104,7 @@ export class PonyfillHeaders {
101
104
  append(name, value) {
102
105
  const key = name.toLowerCase();
103
106
  if (key === 'set-cookie') {
107
+ this._setCookies ||= [];
104
108
  this._setCookies.push(value);
105
109
  return;
106
110
  }
@@ -113,11 +117,11 @@ export class PonyfillHeaders {
113
117
  if (value == null) {
114
118
  return null;
115
119
  }
116
- return value;
120
+ return value.toString();
117
121
  }
118
122
  has(name) {
119
123
  if (name === 'set-cookie') {
120
- return this._setCookies.length > 0;
124
+ return !!this._setCookies?.length;
121
125
  }
122
126
  return !!this._get(name); // we might need to check if header exists and not just check if it's not nullable
123
127
  }
@@ -138,7 +142,7 @@ export class PonyfillHeaders {
138
142
  this.getMap().delete(key);
139
143
  }
140
144
  forEach(callback) {
141
- this._setCookies.forEach(setCookie => {
145
+ this._setCookies?.forEach(setCookie => {
142
146
  callback(setCookie, 'set-cookie', this);
143
147
  });
144
148
  if (!this._map) {
@@ -166,7 +170,7 @@ export class PonyfillHeaders {
166
170
  });
167
171
  }
168
172
  *_keys() {
169
- if (this._setCookies.length) {
173
+ if (this._setCookies?.length) {
170
174
  yield 'set-cookie';
171
175
  }
172
176
  if (!this._map) {
@@ -189,7 +193,9 @@ export class PonyfillHeaders {
189
193
  return new PonyfillIteratorObject(this._keys(), 'HeadersIterator');
190
194
  }
191
195
  *_values() {
192
- yield* this._setCookies;
196
+ if (this._setCookies?.length) {
197
+ yield* this._setCookies;
198
+ }
193
199
  if (!this._map) {
194
200
  if (this.headersInit) {
195
201
  if (Array.isArray(this.headersInit)) {
@@ -210,7 +216,9 @@ export class PonyfillHeaders {
210
216
  return new PonyfillIteratorObject(this._values(), 'HeadersIterator');
211
217
  }
212
218
  *_entries() {
213
- yield* this._setCookies.map(cookie => ['set-cookie', cookie]);
219
+ if (this._setCookies?.length) {
220
+ yield* this._setCookies.map(cookie => ['set-cookie', cookie]);
221
+ }
214
222
  if (!this._map) {
215
223
  if (this.headersInit) {
216
224
  if (Array.isArray(this.headersInit)) {
@@ -231,7 +239,7 @@ export class PonyfillHeaders {
231
239
  return new PonyfillIteratorObject(this._entries(), 'HeadersIterator');
232
240
  }
233
241
  getSetCookie() {
234
- return this._setCookies;
242
+ return this._setCookies || [];
235
243
  }
236
244
  [Symbol.iterator]() {
237
245
  return this.entries();
@@ -240,7 +248,7 @@ export class PonyfillHeaders {
240
248
  const record = {};
241
249
  this.forEach((value, key) => {
242
250
  if (key === 'set-cookie') {
243
- record['set-cookie'] = this._setCookies;
251
+ record['set-cookie'] = this._setCookies || [];
244
252
  }
245
253
  else {
246
254
  record[key] = value?.includes(',') ? value.split(',').map(el => el.trim()) : value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.9",
3
+ "version": "0.7.10-alpha-20250220111507-a3545bc54346479a467fb28e29d6484542def7a0",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -5,7 +5,7 @@ export declare class PonyfillHeaders implements Headers {
5
5
  private _map;
6
6
  private objectNormalizedKeysOfHeadersInit;
7
7
  private objectOriginalKeysOfHeadersInit;
8
- private _setCookies;
8
+ private _setCookies?;
9
9
  constructor(headersInit?: PonyfillHeadersInit | undefined);
10
10
  private _get;
11
11
  private getMap;
@@ -5,7 +5,7 @@ export declare class PonyfillHeaders implements Headers {
5
5
  private _map;
6
6
  private objectNormalizedKeysOfHeadersInit;
7
7
  private objectOriginalKeysOfHeadersInit;
8
- private _setCookies;
8
+ private _setCookies?;
9
9
  constructor(headersInit?: PonyfillHeadersInit | undefined);
10
10
  private _get;
11
11
  private getMap;