@gcmdev/faxios 0.1.0

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.
Files changed (144) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +1817 -0
  3. package/dist/index.d.ts +21 -0
  4. package/dist/index.js +25 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/adapters/fetch-helpers.d.ts +16 -0
  7. package/dist/lib/adapters/fetch-helpers.js +91 -0
  8. package/dist/lib/adapters/fetch-helpers.js.map +1 -0
  9. package/dist/lib/adapters/fetch.d.ts +3 -0
  10. package/dist/lib/adapters/fetch.js +417 -0
  11. package/dist/lib/adapters/fetch.js.map +1 -0
  12. package/dist/lib/cancel/CanceledError.d.ts +15 -0
  13. package/dist/lib/cancel/CanceledError.js +20 -0
  14. package/dist/lib/cancel/CanceledError.js.map +1 -0
  15. package/dist/lib/cancel/isCancel.d.ts +1 -0
  16. package/dist/lib/cancel/isCancel.js +5 -0
  17. package/dist/lib/cancel/isCancel.js.map +1 -0
  18. package/dist/lib/core/Faxios.d.ts +68 -0
  19. package/dist/lib/core/Faxios.js +269 -0
  20. package/dist/lib/core/Faxios.js.map +1 -0
  21. package/dist/lib/core/FaxiosError.d.ts +71 -0
  22. package/dist/lib/core/FaxiosError.js +192 -0
  23. package/dist/lib/core/FaxiosError.js.map +1 -0
  24. package/dist/lib/core/FaxiosHeaders.d.ts +45 -0
  25. package/dist/lib/core/FaxiosHeaders.js +299 -0
  26. package/dist/lib/core/FaxiosHeaders.js.map +1 -0
  27. package/dist/lib/core/InterceptorManager.d.ts +9 -0
  28. package/dist/lib/core/InterceptorManager.js +28 -0
  29. package/dist/lib/core/InterceptorManager.js.map +1 -0
  30. package/dist/lib/core/buildFullPath.d.ts +11 -0
  31. package/dist/lib/core/buildFullPath.js +41 -0
  32. package/dist/lib/core/buildFullPath.js.map +1 -0
  33. package/dist/lib/core/define.d.ts +28 -0
  34. package/dist/lib/core/define.js +35 -0
  35. package/dist/lib/core/define.js.map +1 -0
  36. package/dist/lib/core/dispatchRequest.d.ts +2 -0
  37. package/dist/lib/core/dispatchRequest.js +127 -0
  38. package/dist/lib/core/dispatchRequest.js.map +1 -0
  39. package/dist/lib/core/mergeConfig.d.ts +11 -0
  40. package/dist/lib/core/mergeConfig.js +152 -0
  41. package/dist/lib/core/mergeConfig.js.map +1 -0
  42. package/dist/lib/core/prepareRequest.d.ts +3 -0
  43. package/dist/lib/core/prepareRequest.js +112 -0
  44. package/dist/lib/core/prepareRequest.js.map +1 -0
  45. package/dist/lib/core/route.d.ts +14 -0
  46. package/dist/lib/core/route.js +24 -0
  47. package/dist/lib/core/route.js.map +1 -0
  48. package/dist/lib/core/settle.d.ts +2 -0
  49. package/dist/lib/core/settle.js +12 -0
  50. package/dist/lib/core/settle.js.map +1 -0
  51. package/dist/lib/core/transformData.d.ts +8 -0
  52. package/dist/lib/core/transformData.js +16 -0
  53. package/dist/lib/core/transformData.js.map +1 -0
  54. package/dist/lib/core/validateSchema.d.ts +6 -0
  55. package/dist/lib/core/validateSchema.js +32 -0
  56. package/dist/lib/core/validateSchema.js.map +1 -0
  57. package/dist/lib/defaults/index.d.ts +3 -0
  58. package/dist/lib/defaults/index.js +150 -0
  59. package/dist/lib/defaults/index.js.map +1 -0
  60. package/dist/lib/defaults/transitional.d.ts +9 -0
  61. package/dist/lib/defaults/transitional.js +10 -0
  62. package/dist/lib/defaults/transitional.js.map +1 -0
  63. package/dist/lib/env/data.d.ts +1 -0
  64. package/dist/lib/env/data.js +2 -0
  65. package/dist/lib/env/data.js.map +1 -0
  66. package/dist/lib/faxios.d.ts +99 -0
  67. package/dist/lib/faxios.js +68 -0
  68. package/dist/lib/faxios.js.map +1 -0
  69. package/dist/lib/helpers/FaxiosURLSearchParams.d.ts +7 -0
  70. package/dist/lib/helpers/FaxiosURLSearchParams.js +44 -0
  71. package/dist/lib/helpers/FaxiosURLSearchParams.js.map +1 -0
  72. package/dist/lib/helpers/HttpStatusCode.d.ts +72 -0
  73. package/dist/lib/helpers/HttpStatusCode.js +76 -0
  74. package/dist/lib/helpers/HttpStatusCode.js.map +1 -0
  75. package/dist/lib/helpers/buildURL.d.ts +19 -0
  76. package/dist/lib/helpers/buildURL.js +60 -0
  77. package/dist/lib/helpers/buildURL.js.map +1 -0
  78. package/dist/lib/helpers/combineURLs.d.ts +1 -0
  79. package/dist/lib/helpers/combineURLs.js +14 -0
  80. package/dist/lib/helpers/combineURLs.js.map +1 -0
  81. package/dist/lib/helpers/composeSignals.d.ts +8 -0
  82. package/dist/lib/helpers/composeSignals.js +48 -0
  83. package/dist/lib/helpers/composeSignals.js.map +1 -0
  84. package/dist/lib/helpers/cookies.d.ts +6 -0
  85. package/dist/lib/helpers/cookies.js +58 -0
  86. package/dist/lib/helpers/cookies.js.map +1 -0
  87. package/dist/lib/helpers/estimateDataURLDecodedBytes.d.ts +1 -0
  88. package/dist/lib/helpers/estimateDataURLDecodedBytes.js +91 -0
  89. package/dist/lib/helpers/estimateDataURLDecodedBytes.js.map +1 -0
  90. package/dist/lib/helpers/formDataToJSON.d.ts +9 -0
  91. package/dist/lib/helpers/formDataToJSON.js +98 -0
  92. package/dist/lib/helpers/formDataToJSON.js.map +1 -0
  93. package/dist/lib/helpers/isAbsoluteURL.d.ts +1 -0
  94. package/dist/lib/helpers/isAbsoluteURL.js +14 -0
  95. package/dist/lib/helpers/isAbsoluteURL.js.map +1 -0
  96. package/dist/lib/helpers/isFaxiosError.d.ts +8 -0
  97. package/dist/lib/helpers/isFaxiosError.js +13 -0
  98. package/dist/lib/helpers/isFaxiosError.js.map +1 -0
  99. package/dist/lib/helpers/isURLSameOrigin.d.ts +2 -0
  100. package/dist/lib/helpers/isURLSameOrigin.js +10 -0
  101. package/dist/lib/helpers/isURLSameOrigin.js.map +1 -0
  102. package/dist/lib/helpers/parseHeaders.d.ts +16 -0
  103. package/dist/lib/helpers/parseHeaders.js +70 -0
  104. package/dist/lib/helpers/parseHeaders.js.map +1 -0
  105. package/dist/lib/helpers/progressEventReducer.d.ts +5 -0
  106. package/dist/lib/helpers/progressEventReducer.js +45 -0
  107. package/dist/lib/helpers/progressEventReducer.js.map +1 -0
  108. package/dist/lib/helpers/sanitizeHeaderValue.d.ts +4 -0
  109. package/dist/lib/helpers/sanitizeHeaderValue.js +43 -0
  110. package/dist/lib/helpers/sanitizeHeaderValue.js.map +1 -0
  111. package/dist/lib/helpers/speedometer.d.ts +8 -0
  112. package/dist/lib/helpers/speedometer.js +42 -0
  113. package/dist/lib/helpers/speedometer.js.map +1 -0
  114. package/dist/lib/helpers/substitutePathParams.d.ts +2 -0
  115. package/dist/lib/helpers/substitutePathParams.js +14 -0
  116. package/dist/lib/helpers/substitutePathParams.js.map +1 -0
  117. package/dist/lib/helpers/throttle.d.ts +8 -0
  118. package/dist/lib/helpers/throttle.js +42 -0
  119. package/dist/lib/helpers/throttle.js.map +1 -0
  120. package/dist/lib/helpers/toFormData.d.ts +26 -0
  121. package/dist/lib/helpers/toFormData.js +233 -0
  122. package/dist/lib/helpers/toFormData.js.map +1 -0
  123. package/dist/lib/helpers/toURLEncodedForm.d.ts +2 -0
  124. package/dist/lib/helpers/toURLEncodedForm.js +8 -0
  125. package/dist/lib/helpers/toURLEncodedForm.js.map +1 -0
  126. package/dist/lib/helpers/trackStream.d.ts +1 -0
  127. package/dist/lib/helpers/trackStream.js +81 -0
  128. package/dist/lib/helpers/trackStream.js.map +1 -0
  129. package/dist/lib/helpers/validator.d.ts +16 -0
  130. package/dist/lib/helpers/validator.js +86 -0
  131. package/dist/lib/helpers/validator.js.map +1 -0
  132. package/dist/lib/platform.d.ts +22 -0
  133. package/dist/lib/platform.js +26 -0
  134. package/dist/lib/platform.js.map +1 -0
  135. package/dist/lib/types/standard-schema.d.ts +37 -0
  136. package/dist/lib/types/standard-schema.js +8 -0
  137. package/dist/lib/types/standard-schema.js.map +1 -0
  138. package/dist/lib/types.d.ts +219 -0
  139. package/dist/lib/types.js +5 -0
  140. package/dist/lib/types.js.map +1 -0
  141. package/dist/lib/utils.d.ts +143 -0
  142. package/dist/lib/utils.js +805 -0
  143. package/dist/lib/utils.js.map +1 -0
  144. package/package.json +110 -0
@@ -0,0 +1,805 @@
1
+ "use strict";
2
+ // utils is a library of generic helper functions non-specific to faxios
3
+ const { toString } = Object.prototype;
4
+ const { getPrototypeOf } = Object;
5
+ const { iterator, toStringTag } = Symbol;
6
+ const hasOwnProperty = (obj, prop) => Object.hasOwn(obj, prop);
7
+ /**
8
+ * Walk the prototype chain (excluding the shared Object.prototype) looking for
9
+ * an own `prop`. This distinguishes genuine own/inherited members — including
10
+ * class accessors and template prototypes — from members injected via
11
+ * Object.prototype pollution (e.g. `Object.prototype.username = '...'`), which
12
+ * live on Object.prototype itself and are therefore never matched.
13
+ *
14
+ * @param {*} thing The value whose chain to inspect
15
+ * @param {string|symbol} prop The property key to look for
16
+ *
17
+ * @returns {boolean} True when `prop` is owned below Object.prototype
18
+ */
19
+ const hasOwnInPrototypeChain = (thing, prop) => {
20
+ let obj = thing != null && typeof thing === "object" ? thing : null;
21
+ if (obj === null)
22
+ return false;
23
+ const seen = [];
24
+ while (obj != null && obj !== Object.prototype) {
25
+ if (seen.indexOf(obj) !== -1) {
26
+ return false;
27
+ }
28
+ seen.push(obj);
29
+ if (hasOwnProperty(obj, prop)) {
30
+ return true;
31
+ }
32
+ obj = getPrototypeOf(obj);
33
+ }
34
+ return false;
35
+ };
36
+ /**
37
+ * Read `obj[prop]` only when it is safe from Object.prototype pollution. Own
38
+ * properties and members inherited from a non-Object.prototype source (a class
39
+ * instance or template object) are honored; a value reachable only through a
40
+ * polluted Object.prototype is ignored and `undefined` is returned.
41
+ *
42
+ * @param {*} obj The source object
43
+ * @param {string|symbol} prop The property key to read
44
+ *
45
+ * @returns {*} The resolved value, or undefined when unsafe/absent
46
+ */
47
+ const getSafeProp = (obj, prop) => obj != null && hasOwnInPrototypeChain(obj, prop) ? obj[prop] : undefined;
48
+ const kindOf = (cache => (thing) => {
49
+ const str = toString.call(thing);
50
+ return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
51
+ })(Object.create(null));
52
+ const kindOfTest = (type) => {
53
+ type = type.toLowerCase();
54
+ return (thing) => kindOf(thing) === type;
55
+ };
56
+ const typeOfTest = (type) => (thing) => typeof thing === type;
57
+ /**
58
+ * Determine if a value is a non-null object
59
+ *
60
+ * @param {Object} val The value to test
61
+ *
62
+ * @returns {boolean} True if value is an Array, otherwise false
63
+ */
64
+ const { isArray } = Array;
65
+ /**
66
+ * Determine if a value is undefined
67
+ *
68
+ * @param {*} val The value to test
69
+ *
70
+ * @returns {boolean} True if the value is undefined, otherwise false
71
+ */
72
+ const isUndefined = typeOfTest("undefined");
73
+ /**
74
+ * Determine if a value is a Buffer
75
+ *
76
+ * @param {*} val The value to test
77
+ *
78
+ * @returns {boolean} True if value is a Buffer, otherwise false
79
+ */
80
+ function isBuffer(val) {
81
+ return (val !== null &&
82
+ !isUndefined(val) &&
83
+ !isUndefined(val.constructor) &&
84
+ isFunction(val.constructor["isBuffer"]) &&
85
+ val.constructor.isBuffer(val));
86
+ }
87
+ /**
88
+ * Determine if a value is an ArrayBuffer
89
+ *
90
+ * @param {*} val The value to test
91
+ *
92
+ * @returns {boolean} True if value is an ArrayBuffer, otherwise false
93
+ */
94
+ const isArrayBuffer = kindOfTest("ArrayBuffer");
95
+ /**
96
+ * Determine if a value is a view on an ArrayBuffer
97
+ *
98
+ * @param {*} val The value to test
99
+ *
100
+ * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
101
+ */
102
+ function isArrayBufferView(val) {
103
+ let result;
104
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
105
+ if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView) {
106
+ result = ArrayBuffer.isView(val);
107
+ }
108
+ else {
109
+ result = val && val.buffer && isArrayBuffer(val.buffer);
110
+ }
111
+ return !!result;
112
+ }
113
+ /**
114
+ * Determine if a value is a String
115
+ *
116
+ * @param {*} val The value to test
117
+ *
118
+ * @returns {boolean} True if value is a String, otherwise false
119
+ */
120
+ const isString = typeOfTest("string");
121
+ /**
122
+ * Determine if a value is a Function
123
+ *
124
+ * @param {*} val The value to test
125
+ * @returns {boolean} True if value is a Function, otherwise false
126
+ */
127
+ const isFunction = typeOfTest("function");
128
+ /**
129
+ * Determine if a value is a Number
130
+ *
131
+ * @param {*} val The value to test
132
+ *
133
+ * @returns {boolean} True if value is a Number, otherwise false
134
+ */
135
+ const isNumber = typeOfTest("number");
136
+ /**
137
+ * Determine if a value is an Object
138
+ *
139
+ * @param {*} thing The value to test
140
+ *
141
+ * @returns {boolean} True if value is an Object, otherwise false
142
+ */
143
+ const isObject = (thing) => thing !== null && typeof thing === "object";
144
+ /**
145
+ * Determine if a value is a Boolean
146
+ *
147
+ * @param {*} thing The value to test
148
+ * @returns {boolean} True if value is a Boolean, otherwise false
149
+ */
150
+ const isBoolean = (thing) => thing === true || thing === false;
151
+ /**
152
+ * Determine if a value is a plain Object
153
+ *
154
+ * @param {*} val The value to test
155
+ *
156
+ * @returns {boolean} True if value is a plain Object, otherwise false
157
+ */
158
+ const isPlainObject = (val) => {
159
+ if (!isObject(val)) {
160
+ return false;
161
+ }
162
+ const prototype = getPrototypeOf(val);
163
+ return ((prototype === null ||
164
+ prototype === Object.prototype ||
165
+ getPrototypeOf(prototype) === null) &&
166
+ // Treat any genuine (non-Object.prototype-polluted) Symbol.toStringTag or
167
+ // Symbol.iterator as evidence the value is a tagged/iterable type rather
168
+ // than a plain object, while ignoring keys injected onto Object.prototype.
169
+ !hasOwnInPrototypeChain(val, toStringTag) &&
170
+ !hasOwnInPrototypeChain(val, iterator));
171
+ };
172
+ /**
173
+ * Determine if a value is an empty object (safely handles Buffers)
174
+ *
175
+ * @param {*} val The value to test
176
+ *
177
+ * @returns {boolean} True if value is an empty object, otherwise false
178
+ */
179
+ const isEmptyObject = (val) => {
180
+ // Early return for non-objects or Buffers to prevent RangeError
181
+ if (!isObject(val) || isBuffer(val)) {
182
+ return false;
183
+ }
184
+ try {
185
+ return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
186
+ }
187
+ catch {
188
+ // Fallback for any other objects that might cause RangeError with Object.keys()
189
+ return false;
190
+ }
191
+ };
192
+ /**
193
+ * Determine if a value is a Date
194
+ *
195
+ * @param {*} val The value to test
196
+ *
197
+ * @returns {boolean} True if value is a Date, otherwise false
198
+ */
199
+ const isDate = kindOfTest("Date");
200
+ /**
201
+ * Determine if a value is a File
202
+ *
203
+ * @param {*} val The value to test
204
+ *
205
+ * @returns {boolean} True if value is a File, otherwise false
206
+ */
207
+ const isFile = kindOfTest("File");
208
+ /**
209
+ * Determine if a value is a React Native Blob
210
+ * React Native "blob": an object with a `uri` attribute. Optionally, it can
211
+ * also have a `name` and `type` attribute to specify filename and content type
212
+ *
213
+ * @see https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/Libraries/Network/FormData.js#L68-L71
214
+ *
215
+ * @param {*} value The value to test
216
+ *
217
+ * @returns {boolean} True if value is a React Native Blob, otherwise false
218
+ */
219
+ const isReactNativeBlob = (value) => !!(value && typeof value.uri !== "undefined");
220
+ /**
221
+ * Determine if environment is React Native
222
+ * ReactNative `FormData` has a non-standard `getParts()` method
223
+ *
224
+ * @param {*} formData The formData to test
225
+ *
226
+ * @returns {boolean} True if environment is React Native, otherwise false
227
+ */
228
+ const isReactNative = (formData) => formData && typeof formData.getParts !== "undefined";
229
+ /**
230
+ * Determine if a value is a Blob
231
+ *
232
+ * @param {*} val The value to test
233
+ *
234
+ * @returns {boolean} True if value is a Blob, otherwise false
235
+ */
236
+ const isBlob = kindOfTest("Blob");
237
+ /**
238
+ * Determine if a value is a FileList
239
+ *
240
+ * @param {*} val The value to test
241
+ *
242
+ * @returns {boolean} True if value is a FileList, otherwise false
243
+ */
244
+ const isFileList = kindOfTest("FileList");
245
+ /**
246
+ * Determine if a value is a Stream
247
+ *
248
+ * @param {*} val The value to test
249
+ *
250
+ * @returns {boolean} True if value is a Stream, otherwise false
251
+ */
252
+ const isStream = (val) => isObject(val) && isFunction(val.pipe);
253
+ /**
254
+ * Determine if a value is a FormData
255
+ *
256
+ * @param {*} thing The value to test
257
+ *
258
+ * @returns {boolean} True if value is an FormData, otherwise false
259
+ */
260
+ const G = globalThis;
261
+ const FormDataCtor = typeof G["FormData"] !== "undefined" ? G["FormData"] : undefined;
262
+ const isFormData = (thing) => {
263
+ if (!thing)
264
+ return false;
265
+ if (FormDataCtor && thing instanceof FormDataCtor)
266
+ return true;
267
+ // Reject plain objects inheriting directly from Object.prototype so prototype-pollution gadgets can't spoof FormData.
268
+ const proto = getPrototypeOf(thing);
269
+ if (!proto || proto === Object.prototype)
270
+ return false;
271
+ if (!isFunction(thing.append))
272
+ return false;
273
+ const kind = kindOf(thing);
274
+ return (kind === "formdata" ||
275
+ // detect form-data instance
276
+ (kind === "object" && isFunction(thing.toString) && thing.toString() === "[object FormData]"));
277
+ };
278
+ /**
279
+ * Determine if a value is a URLSearchParams object
280
+ *
281
+ * @param {*} val The value to test
282
+ *
283
+ * @returns {boolean} True if value is a URLSearchParams object, otherwise false
284
+ */
285
+ const isURLSearchParams = kindOfTest("URLSearchParams");
286
+ const [isReadableStream, isRequest, isResponse, isHeaders] = [
287
+ "ReadableStream",
288
+ "Request",
289
+ "Response",
290
+ "Headers",
291
+ ].map(kindOfTest);
292
+ /**
293
+ * Iterate over an Array or an Object invoking a function for each item.
294
+ *
295
+ * If `obj` is an Array callback will be called passing
296
+ * the value, index, and complete array for each item.
297
+ *
298
+ * If 'obj' is an Object callback will be called passing
299
+ * the value, key, and complete object for each property.
300
+ *
301
+ * @param {Object|Array<unknown>} obj The object to iterate
302
+ * @param {Function} fn The callback to invoke for each item
303
+ *
304
+ * @param {Object} [options]
305
+ * @param {Boolean} [options.allOwnKeys = false]
306
+ * @returns {any}
307
+ */
308
+ function forEach(obj, fn, { allOwnKeys = false } = {}) {
309
+ // Don't bother if no value provided
310
+ if (obj === null || typeof obj === "undefined") {
311
+ return;
312
+ }
313
+ let i;
314
+ let l;
315
+ // Force an array if not already something iterable
316
+ if (typeof obj !== "object") {
317
+ /*eslint no-param-reassign:0*/
318
+ obj = [obj];
319
+ }
320
+ if (isArray(obj)) {
321
+ // Iterate over array values
322
+ for (i = 0, l = obj.length; i < l; i++) {
323
+ fn.call(null, obj[i], i, obj);
324
+ }
325
+ }
326
+ else {
327
+ // Buffer check
328
+ if (isBuffer(obj)) {
329
+ return;
330
+ }
331
+ // Iterate over object keys
332
+ const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
333
+ const len = keys.length;
334
+ let key;
335
+ for (i = 0; i < len; i++) {
336
+ key = keys[i];
337
+ fn.call(null, obj[key], key, obj);
338
+ }
339
+ }
340
+ }
341
+ /**
342
+ * Finds a key in an object, case-insensitive, returning the actual key name.
343
+ * Returns null if the object is a Buffer or if no match is found.
344
+ *
345
+ * @param {Object} obj - The object to search.
346
+ * @param {string} key - The key to find (case-insensitive).
347
+ * @returns {?string} The actual key name if found, otherwise null.
348
+ */
349
+ function findKey(obj, key) {
350
+ if (isBuffer(obj)) {
351
+ return null;
352
+ }
353
+ key = key.toLowerCase();
354
+ const keys = Object.keys(obj);
355
+ let i = keys.length;
356
+ let _key;
357
+ while (i-- > 0) {
358
+ _key = keys[i];
359
+ if (key === _key.toLowerCase()) {
360
+ return _key;
361
+ }
362
+ }
363
+ return null;
364
+ }
365
+ const _global = globalThis;
366
+ const isContextDefined = (context) => !isUndefined(context) && context !== _global;
367
+ /**
368
+ * Accepts varargs expecting each argument to be an object, then
369
+ * immutably merges the properties of each object and returns result.
370
+ *
371
+ * When multiple objects contain the same key the later object in
372
+ * the arguments list will take precedence.
373
+ *
374
+ * Example:
375
+ *
376
+ * ```js
377
+ * const result = merge({foo: 123}, {foo: 456});
378
+ * console.log(result.foo); // outputs 456
379
+ * ```
380
+ *
381
+ * @param {Object} obj1 Object to merge
382
+ *
383
+ * @returns {Object} Result of all merge properties
384
+ */
385
+ function merge(...objs) {
386
+ const ctx = (isContextDefined(this) && this);
387
+ const caseless = ctx && ctx.caseless;
388
+ const skipUndefined = ctx && ctx.skipUndefined;
389
+ const result = {};
390
+ const assignValue = (val, key) => {
391
+ const keyStr = key;
392
+ // Skip dangerous property names to prevent prototype pollution
393
+ if (keyStr === "__proto__" || keyStr === "constructor" || keyStr === "prototype") {
394
+ return;
395
+ }
396
+ // findKey lowercases the key, so caseless lookup only applies to strings —
397
+ // symbol keys are identity-matched.
398
+ const targetKey = (caseless && typeof keyStr === "string" ? (findKey(result, keyStr) ?? (keyStr)) : (keyStr));
399
+ // Read via own-prop only — a bare `result[targetKey]` walks the prototype
400
+ // chain, so a polluted Object.prototype value could surface here and get
401
+ // copied into the merged result.
402
+ const existing = hasOwnProperty(result, targetKey) ? result[targetKey] : undefined;
403
+ if (isPlainObject(existing) && isPlainObject(val)) {
404
+ result[targetKey] = merge(existing, val);
405
+ }
406
+ else if (isPlainObject(val)) {
407
+ result[targetKey] = merge({}, val);
408
+ }
409
+ else if (isArray(val)) {
410
+ result[targetKey] = val.slice();
411
+ }
412
+ else if (!skipUndefined || !isUndefined(val)) {
413
+ result[targetKey] = val;
414
+ }
415
+ };
416
+ for (let i = 0, l = objs.length; i < l; i++) {
417
+ const source = objs[i];
418
+ if (!source || isBuffer(source)) {
419
+ continue;
420
+ }
421
+ forEach(source, assignValue);
422
+ if (typeof source !== "object" || isArray(source)) {
423
+ continue;
424
+ }
425
+ const symbols = Object.getOwnPropertySymbols(source);
426
+ for (let j = 0; j < symbols.length; j++) {
427
+ const symbol = symbols[j];
428
+ if (propertyIsEnumerable.call(source, symbol)) {
429
+ assignValue(source[symbol], symbol);
430
+ }
431
+ }
432
+ }
433
+ return result;
434
+ }
435
+ /**
436
+ * Extends object a by mutably adding to it the properties of object b.
437
+ *
438
+ * @param {Object} a The object to be extended
439
+ * @param {Object} b The object to copy properties from
440
+ * @param {Object} thisArg The object to bind function to
441
+ *
442
+ * @param {Object} [options]
443
+ * @param {Boolean} [options.allOwnKeys]
444
+ * @returns {Object} The resulting value of object a
445
+ */
446
+ const extend = (a, b, thisArg, { allOwnKeys } = {}) => {
447
+ forEach(b, (val, key) => {
448
+ if (thisArg && isFunction(val)) {
449
+ Object.defineProperty(a, key, Object.assign(Object.create(null), {
450
+ value: val.bind(thisArg),
451
+ writable: true,
452
+ enumerable: true,
453
+ configurable: true,
454
+ }));
455
+ }
456
+ else {
457
+ Object.defineProperty(a, key, Object.assign(Object.create(null), {
458
+ value: val,
459
+ writable: true,
460
+ enumerable: true,
461
+ configurable: true,
462
+ }));
463
+ }
464
+ }, { allOwnKeys });
465
+ return a;
466
+ };
467
+ /**
468
+ * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
469
+ *
470
+ * @param {string} content with BOM
471
+ *
472
+ * @returns {string} content value without BOM
473
+ */
474
+ const stripBOM = (content) => {
475
+ if (content.charCodeAt(0) === 0xfeff) {
476
+ content = content.slice(1);
477
+ }
478
+ return content;
479
+ };
480
+ /**
481
+ * Resolve object with deep prototype chain to a flat object
482
+ * @param {Object} sourceObj source object
483
+ * @param {Object} [destObj]
484
+ * @param {Function|Boolean} [filter]
485
+ * @param {Function} [propFilter]
486
+ *
487
+ * @returns {Object}
488
+ */
489
+ const toFlatObject = (sourceObj, destObj, filter, propFilter) => {
490
+ let props;
491
+ let i;
492
+ let prop;
493
+ const merged = {};
494
+ const dest = destObj ?? {};
495
+ if (sourceObj == null)
496
+ return dest;
497
+ let src = sourceObj;
498
+ do {
499
+ props = Object.getOwnPropertyNames(src);
500
+ i = props.length;
501
+ while (i-- > 0) {
502
+ prop = props[i];
503
+ if ((!propFilter || propFilter(prop, src, dest)) && !merged[prop]) {
504
+ dest[prop] = src[prop];
505
+ merged[prop] = true;
506
+ }
507
+ }
508
+ src = filter !== false && getPrototypeOf(src);
509
+ } while (src && (!filter || filter(src, dest)) && src !== Object.prototype);
510
+ return dest;
511
+ };
512
+ const toArray = (thing) => {
513
+ if (!thing)
514
+ return null;
515
+ if (isArray(thing))
516
+ return thing;
517
+ if (!isNumber(thing.length))
518
+ return null;
519
+ return Array.from(thing);
520
+ };
521
+ /**
522
+ * Checking if the Uint8Array exists and if it does, it returns a function that checks if the
523
+ * thing passed in is an instance of Uint8Array
524
+ *
525
+ * @param {TypedArray}
526
+ *
527
+ * @returns {Array}
528
+ */
529
+ const isTypedArray = ((TypedArray) => (thing) => TypedArray && thing instanceof TypedArray)(typeof Uint8Array !== "undefined" && getPrototypeOf(Uint8Array));
530
+ const forEachEntry = (obj, fn) => {
531
+ for (const [key, value] of obj) {
532
+ fn.call(obj, key, value);
533
+ }
534
+ };
535
+ /**
536
+ * It takes a regular expression and a string, and returns an array of all the matches
537
+ *
538
+ * @param {string} regExp - The regular expression to match against.
539
+ * @param {string} str - The string to search.
540
+ *
541
+ * @returns {Array<boolean>}
542
+ */
543
+ const matchAll = (regExp, str) => {
544
+ let matches;
545
+ const arr = [];
546
+ while ((matches = regExp.exec(str)) !== null) {
547
+ arr.push(matches);
548
+ }
549
+ return arr;
550
+ };
551
+ /* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */
552
+ const isHTMLForm = kindOfTest("HTMLFormElement");
553
+ const toCamelCase = (str) => str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function replacer(_m, p1, p2) {
554
+ return p1.toUpperCase() + p2;
555
+ });
556
+ const { propertyIsEnumerable } = Object.prototype;
557
+ /**
558
+ * Determine if a value is a RegExp object
559
+ *
560
+ * @param {*} val The value to test
561
+ *
562
+ * @returns {boolean} True if value is a RegExp object, otherwise false
563
+ */
564
+ const isRegExp = kindOfTest("RegExp");
565
+ const reduceDescriptors = (obj, reducer) => {
566
+ const descriptors = Object.getOwnPropertyDescriptors(obj);
567
+ const reducedDescriptors = {};
568
+ forEach(descriptors, (descriptor, name) => {
569
+ let ret;
570
+ if ((ret = reducer(descriptor, name, obj)) !== false) {
571
+ reducedDescriptors[name] = ret ?? descriptor;
572
+ }
573
+ });
574
+ Object.defineProperties(obj, reducedDescriptors);
575
+ };
576
+ /**
577
+ * Makes all methods read-only
578
+ * @param {Object} obj
579
+ */
580
+ const freezeMethods = (obj) => {
581
+ // eslint-disable-next-line sonarjs/function-return-type
582
+ reduceDescriptors(obj, (descriptor, name) => {
583
+ // skip restricted props in strict mode
584
+ if (isFunction(obj) && ["arguments", "caller", "callee"].includes(name)) {
585
+ return false;
586
+ }
587
+ const value = obj[name];
588
+ if (!isFunction(value))
589
+ return false;
590
+ descriptor.enumerable = false;
591
+ if ("writable" in descriptor) {
592
+ descriptor.writable = false;
593
+ return descriptor;
594
+ }
595
+ if (!descriptor.set) {
596
+ descriptor.set = () => {
597
+ throw Error("Can not rewrite read-only method '" + name + "'");
598
+ };
599
+ }
600
+ return descriptor;
601
+ });
602
+ };
603
+ /**
604
+ * Converts an array or a delimited string into an object set with values as keys and true as values.
605
+ * Useful for fast membership checks.
606
+ *
607
+ * @param {Array|string} arrayOrString - The array or string to convert.
608
+ * @param {string} delimiter - The delimiter to use if input is a string.
609
+ * @returns {Object} An object with keys from the array or string, values set to true.
610
+ */
611
+ const toObjectSet = (arrayOrString, delimiter) => {
612
+ const obj = {};
613
+ const define = (arr) => {
614
+ arr.forEach(value => {
615
+ obj[value] = true;
616
+ });
617
+ };
618
+ isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
619
+ return obj;
620
+ };
621
+ const noop = () => { };
622
+ const toFiniteNumber = (value, defaultValue) => {
623
+ const num = +value;
624
+ return value != null && Number.isFinite(num) ? num : defaultValue;
625
+ };
626
+ /**
627
+ * If the thing is a FormData object, return true, otherwise return false.
628
+ *
629
+ * @param {unknown} thing - The thing to check.
630
+ *
631
+ * @returns {boolean}
632
+ */
633
+ function isSpecCompliantForm(thing) {
634
+ return !!(thing &&
635
+ isFunction(thing.append) &&
636
+ thing[toStringTag] === "FormData" &&
637
+ thing[iterator]);
638
+ }
639
+ /**
640
+ * Recursively converts an object to a JSON-compatible object, handling circular references and Buffers.
641
+ *
642
+ * @param {Object} obj - The object to convert.
643
+ * @returns {Object} The JSON-compatible object.
644
+ */
645
+ const toJSONObject = (obj) => {
646
+ const visited = new WeakSet();
647
+ const visit = (source) => {
648
+ if (isObject(source)) {
649
+ if (visited.has(source)) {
650
+ return;
651
+ }
652
+ //Buffer check
653
+ if (isBuffer(source)) {
654
+ return source;
655
+ }
656
+ if (!("toJSON" in source)) {
657
+ // add-on descent / delete-on-ascent: preserves path semantics, so DAG nodes serialise at every occurrence (see #7230).
658
+ visited.add(source);
659
+ const target = isArray(source) ? [] : {};
660
+ forEach(source, (value, key) => {
661
+ const reducedValue = visit(value);
662
+ !isUndefined(reducedValue) && (target[key] = reducedValue);
663
+ });
664
+ visited.delete(source);
665
+ return target;
666
+ }
667
+ }
668
+ return source;
669
+ };
670
+ return visit(obj);
671
+ };
672
+ /**
673
+ * Determines if a value is an async function.
674
+ *
675
+ * @param {*} thing - The value to test.
676
+ * @returns {boolean} True if value is an async function, otherwise false.
677
+ */
678
+ const isAsyncFn = kindOfTest("AsyncFunction");
679
+ /**
680
+ * Determines if a value is thenable (has then and catch methods).
681
+ *
682
+ * @param {*} thing - The value to test.
683
+ * @returns {boolean} True if value is thenable, otherwise false.
684
+ */
685
+ const isThenable = (thing) => thing &&
686
+ (isObject(thing) || isFunction(thing)) &&
687
+ isFunction(thing.then) &&
688
+ isFunction(thing.catch);
689
+ // original code
690
+ // https://github.com/DigitalBrainJS/FaxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
691
+ /**
692
+ * Provides a cross-platform setImmediate implementation.
693
+ * Uses native setImmediate if available, otherwise falls back to postMessage or setTimeout.
694
+ *
695
+ * @param {boolean} setImmediateSupported - Whether setImmediate is supported.
696
+ * @param {boolean} postMessageSupported - Whether postMessage is supported.
697
+ * @returns {Function} A function to schedule a callback asynchronously.
698
+ */
699
+ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
700
+ if (setImmediateSupported) {
701
+ return _global["setImmediate"];
702
+ }
703
+ return postMessageSupported
704
+ ? ((token, callbacks) => {
705
+ const _addEventListener = _global.addEventListener;
706
+ _addEventListener("message", (evt) => {
707
+ if (evt["source"] === _global && evt["data"] === token) {
708
+ callbacks.length && callbacks.shift()();
709
+ }
710
+ }, false);
711
+ const _postMessage = _global.postMessage;
712
+ return (cb) => {
713
+ callbacks.push(cb);
714
+ _postMessage(token, "*");
715
+ };
716
+ // eslint-disable-next-line sonarjs/pseudo-random
717
+ })(`faxios@${Math.random()}`, [])
718
+ : (cb) => setTimeout(cb);
719
+ })(isFunction(_global["setImmediate"]), isFunction(_global["postMessage"]));
720
+ /**
721
+ * Schedules a microtask or asynchronous callback as soon as possible.
722
+ * Uses queueMicrotask if available, otherwise falls back to process.nextTick or _setImmediate.
723
+ *
724
+ * @type {Function}
725
+ */
726
+ const _process = _global["process"];
727
+ const asap = typeof queueMicrotask !== "undefined"
728
+ ? queueMicrotask.bind(globalThis)
729
+ : (_process && _process.nextTick) || _setImmediate;
730
+ // *********************
731
+ const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
732
+ /**
733
+ * Determine if a value is iterable via an iterator that is NOT sourced solely
734
+ * from a polluted Object.prototype. Use this instead of `isIterable` whenever
735
+ * the iterable comes from untrusted input (e.g. user-supplied header sources),
736
+ * so `Object.prototype[Symbol.iterator] = ...` cannot turn an ordinary object
737
+ * into an attacker-controlled entries iterator.
738
+ *
739
+ * @param {*} thing The value to test
740
+ *
741
+ * @returns {boolean} True if value has a non-polluted iterator
742
+ */
743
+ const isSafeIterable = (thing) => thing != null && hasOwnInPrototypeChain(thing, iterator) && isIterable(thing);
744
+ export default {
745
+ isArray,
746
+ isArrayBuffer,
747
+ isBuffer,
748
+ isFormData,
749
+ isArrayBufferView,
750
+ isString,
751
+ isNumber,
752
+ isBoolean,
753
+ isObject,
754
+ isPlainObject,
755
+ isEmptyObject,
756
+ isReadableStream,
757
+ isRequest,
758
+ isResponse,
759
+ isHeaders,
760
+ isUndefined,
761
+ isDate,
762
+ isFile,
763
+ isReactNativeBlob,
764
+ isReactNative,
765
+ isBlob,
766
+ isRegExp,
767
+ isFunction,
768
+ isStream,
769
+ isURLSearchParams,
770
+ isTypedArray,
771
+ isFileList,
772
+ forEach,
773
+ merge,
774
+ extend,
775
+ stripBOM,
776
+ toFlatObject,
777
+ kindOf,
778
+ kindOfTest,
779
+ toArray,
780
+ forEachEntry,
781
+ matchAll,
782
+ isHTMLForm,
783
+ hasOwnProperty,
784
+ hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
785
+ hasOwnInPrototypeChain,
786
+ getSafeProp,
787
+ reduceDescriptors,
788
+ freezeMethods,
789
+ toObjectSet,
790
+ toCamelCase,
791
+ noop,
792
+ toFiniteNumber,
793
+ findKey,
794
+ global: _global,
795
+ isContextDefined,
796
+ isSpecCompliantForm,
797
+ toJSONObject,
798
+ isAsyncFn,
799
+ isThenable,
800
+ setImmediate: _setImmediate,
801
+ asap,
802
+ isIterable,
803
+ isSafeIterable,
804
+ };
805
+ //# sourceMappingURL=utils.js.map