@lcap/axios-fixed 1.13.2

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 (87) hide show
  1. package/.husky/commit-msg +4 -0
  2. package/CHANGELOG.md +1359 -0
  3. package/LICENSE +7 -0
  4. package/MIGRATION_GUIDE.md +3 -0
  5. package/README.md +1784 -0
  6. package/dist/axios.js +4471 -0
  7. package/dist/axios.js.map +1 -0
  8. package/dist/axios.min.js +3 -0
  9. package/dist/axios.min.js.map +1 -0
  10. package/dist/browser/axios.cjs +3909 -0
  11. package/dist/browser/axios.cjs.map +1 -0
  12. package/dist/esm/axios.js +3932 -0
  13. package/dist/esm/axios.js.map +1 -0
  14. package/dist/esm/axios.min.js +3 -0
  15. package/dist/esm/axios.min.js.map +1 -0
  16. package/dist/node/axios.cjs +5242 -0
  17. package/dist/node/axios.cjs.map +1 -0
  18. package/index.d.cts +572 -0
  19. package/index.d.ts +585 -0
  20. package/index.js +43 -0
  21. package/lib/adapters/README.md +37 -0
  22. package/lib/adapters/adapters.js +126 -0
  23. package/lib/adapters/fetch.js +288 -0
  24. package/lib/adapters/http.js +895 -0
  25. package/lib/adapters/xhr.js +200 -0
  26. package/lib/axios.js +89 -0
  27. package/lib/cancel/CancelToken.js +135 -0
  28. package/lib/cancel/CanceledError.js +25 -0
  29. package/lib/cancel/isCancel.js +5 -0
  30. package/lib/core/Axios.js +240 -0
  31. package/lib/core/AxiosError.js +110 -0
  32. package/lib/core/AxiosHeaders.js +314 -0
  33. package/lib/core/InterceptorManager.js +71 -0
  34. package/lib/core/README.md +8 -0
  35. package/lib/core/buildFullPath.js +22 -0
  36. package/lib/core/dispatchRequest.js +81 -0
  37. package/lib/core/mergeConfig.js +106 -0
  38. package/lib/core/settle.js +27 -0
  39. package/lib/core/transformData.js +28 -0
  40. package/lib/defaults/index.js +161 -0
  41. package/lib/defaults/transitional.js +7 -0
  42. package/lib/env/README.md +3 -0
  43. package/lib/env/classes/FormData.js +2 -0
  44. package/lib/env/data.js +1 -0
  45. package/lib/helpers/AxiosTransformStream.js +143 -0
  46. package/lib/helpers/AxiosURLSearchParams.js +58 -0
  47. package/lib/helpers/HttpStatusCode.js +77 -0
  48. package/lib/helpers/README.md +7 -0
  49. package/lib/helpers/ZlibHeaderTransformStream.js +28 -0
  50. package/lib/helpers/bind.js +14 -0
  51. package/lib/helpers/buildURL.js +67 -0
  52. package/lib/helpers/callbackify.js +16 -0
  53. package/lib/helpers/combineURLs.js +15 -0
  54. package/lib/helpers/composeSignals.js +48 -0
  55. package/lib/helpers/cookies.js +53 -0
  56. package/lib/helpers/deprecatedMethod.js +26 -0
  57. package/lib/helpers/estimateDataURLDecodedBytes.js +73 -0
  58. package/lib/helpers/formDataToJSON.js +95 -0
  59. package/lib/helpers/formDataToStream.js +112 -0
  60. package/lib/helpers/fromDataURI.js +53 -0
  61. package/lib/helpers/isAbsoluteURL.js +15 -0
  62. package/lib/helpers/isAxiosError.js +14 -0
  63. package/lib/helpers/isURLSameOrigin.js +14 -0
  64. package/lib/helpers/null.js +2 -0
  65. package/lib/helpers/parseHeaders.js +55 -0
  66. package/lib/helpers/parseProtocol.js +6 -0
  67. package/lib/helpers/progressEventReducer.js +44 -0
  68. package/lib/helpers/readBlob.js +15 -0
  69. package/lib/helpers/resolveConfig.js +61 -0
  70. package/lib/helpers/speedometer.js +55 -0
  71. package/lib/helpers/spread.js +28 -0
  72. package/lib/helpers/throttle.js +44 -0
  73. package/lib/helpers/toFormData.js +223 -0
  74. package/lib/helpers/toURLEncodedForm.js +19 -0
  75. package/lib/helpers/trackStream.js +87 -0
  76. package/lib/helpers/validator.js +99 -0
  77. package/lib/platform/browser/classes/Blob.js +3 -0
  78. package/lib/platform/browser/classes/FormData.js +3 -0
  79. package/lib/platform/browser/classes/URLSearchParams.js +4 -0
  80. package/lib/platform/browser/index.js +13 -0
  81. package/lib/platform/common/utils.js +51 -0
  82. package/lib/platform/index.js +7 -0
  83. package/lib/platform/node/classes/FormData.js +3 -0
  84. package/lib/platform/node/classes/URLSearchParams.js +4 -0
  85. package/lib/platform/node/index.js +38 -0
  86. package/lib/utils.js +782 -0
  87. package/package.json +237 -0
package/lib/utils.js ADDED
@@ -0,0 +1,782 @@
1
+ 'use strict';
2
+
3
+ import bind from './helpers/bind.js';
4
+
5
+ // utils is a library of generic helper functions non-specific to axios
6
+
7
+ const {toString} = Object.prototype;
8
+ const {getPrototypeOf} = Object;
9
+ const {iterator, toStringTag} = Symbol;
10
+
11
+ const kindOf = (cache => thing => {
12
+ const str = toString.call(thing);
13
+ return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
14
+ })(Object.create(null));
15
+
16
+ const kindOfTest = (type) => {
17
+ type = type.toLowerCase();
18
+ return (thing) => kindOf(thing) === type
19
+ }
20
+
21
+ const typeOfTest = type => thing => typeof thing === type;
22
+
23
+ /**
24
+ * Determine if a value is an Array
25
+ *
26
+ * @param {Object} val The value to test
27
+ *
28
+ * @returns {boolean} True if value is an Array, otherwise false
29
+ */
30
+ const {isArray} = Array;
31
+
32
+ /**
33
+ * Determine if a value is undefined
34
+ *
35
+ * @param {*} val The value to test
36
+ *
37
+ * @returns {boolean} True if the value is undefined, otherwise false
38
+ */
39
+ const isUndefined = typeOfTest('undefined');
40
+
41
+ /**
42
+ * Determine if a value is a Buffer
43
+ *
44
+ * @param {*} val The value to test
45
+ *
46
+ * @returns {boolean} True if value is a Buffer, otherwise false
47
+ */
48
+ function isBuffer(val) {
49
+ return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
50
+ && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
51
+ }
52
+
53
+ /**
54
+ * Determine if a value is an ArrayBuffer
55
+ *
56
+ * @param {*} val The value to test
57
+ *
58
+ * @returns {boolean} True if value is an ArrayBuffer, otherwise false
59
+ */
60
+ const isArrayBuffer = kindOfTest('ArrayBuffer');
61
+
62
+
63
+ /**
64
+ * Determine if a value is a view on an ArrayBuffer
65
+ *
66
+ * @param {*} val The value to test
67
+ *
68
+ * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
69
+ */
70
+ function isArrayBufferView(val) {
71
+ let result;
72
+ if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
73
+ result = ArrayBuffer.isView(val);
74
+ } else {
75
+ result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
76
+ }
77
+ return result;
78
+ }
79
+
80
+ /**
81
+ * Determine if a value is a String
82
+ *
83
+ * @param {*} val The value to test
84
+ *
85
+ * @returns {boolean} True if value is a String, otherwise false
86
+ */
87
+ const isString = typeOfTest('string');
88
+
89
+ /**
90
+ * Determine if a value is a Function
91
+ *
92
+ * @param {*} val The value to test
93
+ * @returns {boolean} True if value is a Function, otherwise false
94
+ */
95
+ const isFunction = typeOfTest('function');
96
+
97
+ /**
98
+ * Determine if a value is a Number
99
+ *
100
+ * @param {*} val The value to test
101
+ *
102
+ * @returns {boolean} True if value is a Number, otherwise false
103
+ */
104
+ const isNumber = typeOfTest('number');
105
+
106
+ /**
107
+ * Determine if a value is an Object
108
+ *
109
+ * @param {*} thing The value to test
110
+ *
111
+ * @returns {boolean} True if value is an Object, otherwise false
112
+ */
113
+ const isObject = (thing) => thing !== null && typeof thing === 'object';
114
+
115
+ /**
116
+ * Determine if a value is a Boolean
117
+ *
118
+ * @param {*} thing The value to test
119
+ * @returns {boolean} True if value is a Boolean, otherwise false
120
+ */
121
+ const isBoolean = thing => thing === true || thing === false;
122
+
123
+ /**
124
+ * Determine if a value is a plain Object
125
+ *
126
+ * @param {*} val The value to test
127
+ *
128
+ * @returns {boolean} True if value is a plain Object, otherwise false
129
+ */
130
+ const isPlainObject = (val) => {
131
+ if (kindOf(val) !== 'object') {
132
+ return false;
133
+ }
134
+
135
+ const prototype = getPrototypeOf(val);
136
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
137
+ }
138
+
139
+ /**
140
+ * Determine if a value is an empty object (safely handles Buffers)
141
+ *
142
+ * @param {*} val The value to test
143
+ *
144
+ * @returns {boolean} True if value is an empty object, otherwise false
145
+ */
146
+ const isEmptyObject = (val) => {
147
+ // Early return for non-objects or Buffers to prevent RangeError
148
+ if (!isObject(val) || isBuffer(val)) {
149
+ return false;
150
+ }
151
+
152
+ try {
153
+ return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
154
+ } catch (e) {
155
+ // Fallback for any other objects that might cause RangeError with Object.keys()
156
+ return false;
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Determine if a value is a Date
162
+ *
163
+ * @param {*} val The value to test
164
+ *
165
+ * @returns {boolean} True if value is a Date, otherwise false
166
+ */
167
+ const isDate = kindOfTest('Date');
168
+
169
+ /**
170
+ * Determine if a value is a File
171
+ *
172
+ * @param {*} val The value to test
173
+ *
174
+ * @returns {boolean} True if value is a File, otherwise false
175
+ */
176
+ const isFile = kindOfTest('File');
177
+
178
+ /**
179
+ * Determine if a value is a Blob
180
+ *
181
+ * @param {*} val The value to test
182
+ *
183
+ * @returns {boolean} True if value is a Blob, otherwise false
184
+ */
185
+ const isBlob = kindOfTest('Blob');
186
+
187
+ /**
188
+ * Determine if a value is a FileList
189
+ *
190
+ * @param {*} val The value to test
191
+ *
192
+ * @returns {boolean} True if value is a File, otherwise false
193
+ */
194
+ const isFileList = kindOfTest('FileList');
195
+
196
+ /**
197
+ * Determine if a value is a Stream
198
+ *
199
+ * @param {*} val The value to test
200
+ *
201
+ * @returns {boolean} True if value is a Stream, otherwise false
202
+ */
203
+ const isStream = (val) => isObject(val) && isFunction(val.pipe);
204
+
205
+ /**
206
+ * Determine if a value is a FormData
207
+ *
208
+ * @param {*} thing The value to test
209
+ *
210
+ * @returns {boolean} True if value is an FormData, otherwise false
211
+ */
212
+ const isFormData = (thing) => {
213
+ let kind;
214
+ return thing && (
215
+ (typeof FormData === 'function' && thing instanceof FormData) || (
216
+ isFunction(thing.append) && (
217
+ (kind = kindOf(thing)) === 'formdata' ||
218
+ // detect form-data instance
219
+ (kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
220
+ )
221
+ )
222
+ )
223
+ }
224
+
225
+ /**
226
+ * Determine if a value is a URLSearchParams object
227
+ *
228
+ * @param {*} val The value to test
229
+ *
230
+ * @returns {boolean} True if value is a URLSearchParams object, otherwise false
231
+ */
232
+ const isURLSearchParams = kindOfTest('URLSearchParams');
233
+
234
+ const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
235
+
236
+ /**
237
+ * Trim excess whitespace off the beginning and end of a string
238
+ *
239
+ * @param {String} str The String to trim
240
+ *
241
+ * @returns {String} The String freed of excess whitespace
242
+ */
243
+ const trim = (str) => str.trim ?
244
+ str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
245
+
246
+ /**
247
+ * Iterate over an Array or an Object invoking a function for each item.
248
+ *
249
+ * If `obj` is an Array callback will be called passing
250
+ * the value, index, and complete array for each item.
251
+ *
252
+ * If 'obj' is an Object callback will be called passing
253
+ * the value, key, and complete object for each property.
254
+ *
255
+ * @param {Object|Array} obj The object to iterate
256
+ * @param {Function} fn The callback to invoke for each item
257
+ *
258
+ * @param {Boolean} [allOwnKeys = false]
259
+ * @returns {any}
260
+ */
261
+ function forEach(obj, fn, {allOwnKeys = false} = {}) {
262
+ // Don't bother if no value provided
263
+ if (obj === null || typeof obj === 'undefined') {
264
+ return;
265
+ }
266
+
267
+ let i;
268
+ let l;
269
+
270
+ // Force an array if not already something iterable
271
+ if (typeof obj !== 'object') {
272
+ /*eslint no-param-reassign:0*/
273
+ obj = [obj];
274
+ }
275
+
276
+ if (isArray(obj)) {
277
+ // Iterate over array values
278
+ for (i = 0, l = obj.length; i < l; i++) {
279
+ fn.call(null, obj[i], i, obj);
280
+ }
281
+ } else {
282
+ // Buffer check
283
+ if (isBuffer(obj)) {
284
+ return;
285
+ }
286
+
287
+ // Iterate over object keys
288
+ const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
289
+ const len = keys.length;
290
+ let key;
291
+
292
+ for (i = 0; i < len; i++) {
293
+ key = keys[i];
294
+ fn.call(null, obj[key], key, obj);
295
+ }
296
+ }
297
+ }
298
+
299
+ function findKey(obj, key) {
300
+ if (isBuffer(obj)){
301
+ return null;
302
+ }
303
+
304
+ key = key.toLowerCase();
305
+ const keys = Object.keys(obj);
306
+ let i = keys.length;
307
+ let _key;
308
+ while (i-- > 0) {
309
+ _key = keys[i];
310
+ if (key === _key.toLowerCase()) {
311
+ return _key;
312
+ }
313
+ }
314
+ return null;
315
+ }
316
+
317
+ const _global = (() => {
318
+ /*eslint no-undef:0*/
319
+ if (typeof globalThis !== "undefined") return globalThis;
320
+ return typeof self !== "undefined" ? self : (typeof window !== 'undefined' ? window : global)
321
+ })();
322
+
323
+ const isContextDefined = (context) => !isUndefined(context) && context !== _global;
324
+
325
+ /**
326
+ * Accepts varargs expecting each argument to be an object, then
327
+ * immutably merges the properties of each object and returns result.
328
+ *
329
+ * When multiple objects contain the same key the later object in
330
+ * the arguments list will take precedence.
331
+ *
332
+ * Example:
333
+ *
334
+ * ```js
335
+ * var result = merge({foo: 123}, {foo: 456});
336
+ * console.log(result.foo); // outputs 456
337
+ * ```
338
+ *
339
+ * @param {Object} obj1 Object to merge
340
+ *
341
+ * @returns {Object} Result of all merge properties
342
+ */
343
+ function merge(/* obj1, obj2, obj3, ... */) {
344
+ const {caseless, skipUndefined} = isContextDefined(this) && this || {};
345
+ const result = {};
346
+ const assignValue = (val, key) => {
347
+ const targetKey = caseless && findKey(result, key) || key;
348
+ if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
349
+ result[targetKey] = merge(result[targetKey], val);
350
+ } else if (isPlainObject(val)) {
351
+ result[targetKey] = merge({}, val);
352
+ } else if (isArray(val)) {
353
+ result[targetKey] = val.slice();
354
+ } else if (!skipUndefined || !isUndefined(val)) {
355
+ result[targetKey] = val;
356
+ }
357
+ }
358
+
359
+ for (let i = 0, l = arguments.length; i < l; i++) {
360
+ arguments[i] && forEach(arguments[i], assignValue);
361
+ }
362
+ return result;
363
+ }
364
+
365
+ /**
366
+ * Extends object a by mutably adding to it the properties of object b.
367
+ *
368
+ * @param {Object} a The object to be extended
369
+ * @param {Object} b The object to copy properties from
370
+ * @param {Object} thisArg The object to bind function to
371
+ *
372
+ * @param {Boolean} [allOwnKeys]
373
+ * @returns {Object} The resulting value of object a
374
+ */
375
+ const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
376
+ forEach(b, (val, key) => {
377
+ if (thisArg && isFunction(val)) {
378
+ a[key] = bind(val, thisArg);
379
+ } else {
380
+ a[key] = val;
381
+ }
382
+ }, {allOwnKeys});
383
+ return a;
384
+ }
385
+
386
+ /**
387
+ * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
388
+ *
389
+ * @param {string} content with BOM
390
+ *
391
+ * @returns {string} content value without BOM
392
+ */
393
+ const stripBOM = (content) => {
394
+ if (content.charCodeAt(0) === 0xFEFF) {
395
+ content = content.slice(1);
396
+ }
397
+ return content;
398
+ }
399
+
400
+ /**
401
+ * Inherit the prototype methods from one constructor into another
402
+ * @param {function} constructor
403
+ * @param {function} superConstructor
404
+ * @param {object} [props]
405
+ * @param {object} [descriptors]
406
+ *
407
+ * @returns {void}
408
+ */
409
+ const inherits = (constructor, superConstructor, props, descriptors) => {
410
+ constructor.prototype = Object.create(superConstructor.prototype, descriptors);
411
+ constructor.prototype.constructor = constructor;
412
+ Object.defineProperty(constructor, 'super', {
413
+ value: superConstructor.prototype
414
+ });
415
+ props && Object.assign(constructor.prototype, props);
416
+ }
417
+
418
+ /**
419
+ * Resolve object with deep prototype chain to a flat object
420
+ * @param {Object} sourceObj source object
421
+ * @param {Object} [destObj]
422
+ * @param {Function|Boolean} [filter]
423
+ * @param {Function} [propFilter]
424
+ *
425
+ * @returns {Object}
426
+ */
427
+ const toFlatObject = (sourceObj, destObj, filter, propFilter) => {
428
+ let props;
429
+ let i;
430
+ let prop;
431
+ const merged = {};
432
+
433
+ destObj = destObj || {};
434
+ // eslint-disable-next-line no-eq-null,eqeqeq
435
+ if (sourceObj == null) return destObj;
436
+
437
+ do {
438
+ props = Object.getOwnPropertyNames(sourceObj);
439
+ i = props.length;
440
+ while (i-- > 0) {
441
+ prop = props[i];
442
+ if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
443
+ destObj[prop] = sourceObj[prop];
444
+ merged[prop] = true;
445
+ }
446
+ }
447
+ sourceObj = filter !== false && getPrototypeOf(sourceObj);
448
+ } while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
449
+
450
+ return destObj;
451
+ }
452
+
453
+ /**
454
+ * Determines whether a string ends with the characters of a specified string
455
+ *
456
+ * @param {String} str
457
+ * @param {String} searchString
458
+ * @param {Number} [position= 0]
459
+ *
460
+ * @returns {boolean}
461
+ */
462
+ const endsWith = (str, searchString, position) => {
463
+ str = String(str);
464
+ if (position === undefined || position > str.length) {
465
+ position = str.length;
466
+ }
467
+ position -= searchString.length;
468
+ const lastIndex = str.indexOf(searchString, position);
469
+ return lastIndex !== -1 && lastIndex === position;
470
+ }
471
+
472
+
473
+ /**
474
+ * Returns new array from array like object or null if failed
475
+ *
476
+ * @param {*} [thing]
477
+ *
478
+ * @returns {?Array}
479
+ */
480
+ const toArray = (thing) => {
481
+ if (!thing) return null;
482
+ if (isArray(thing)) return thing;
483
+ let i = thing.length;
484
+ if (!isNumber(i)) return null;
485
+ const arr = new Array(i);
486
+ while (i-- > 0) {
487
+ arr[i] = thing[i];
488
+ }
489
+ return arr;
490
+ }
491
+
492
+ /**
493
+ * Checking if the Uint8Array exists and if it does, it returns a function that checks if the
494
+ * thing passed in is an instance of Uint8Array
495
+ *
496
+ * @param {TypedArray}
497
+ *
498
+ * @returns {Array}
499
+ */
500
+ // eslint-disable-next-line func-names
501
+ const isTypedArray = (TypedArray => {
502
+ // eslint-disable-next-line func-names
503
+ return thing => {
504
+ return TypedArray && thing instanceof TypedArray;
505
+ };
506
+ })(typeof Uint8Array !== 'undefined' && getPrototypeOf(Uint8Array));
507
+
508
+ /**
509
+ * For each entry in the object, call the function with the key and value.
510
+ *
511
+ * @param {Object<any, any>} obj - The object to iterate over.
512
+ * @param {Function} fn - The function to call for each entry.
513
+ *
514
+ * @returns {void}
515
+ */
516
+ const forEachEntry = (obj, fn) => {
517
+ const generator = obj && obj[iterator];
518
+
519
+ const _iterator = generator.call(obj);
520
+
521
+ let result;
522
+
523
+ while ((result = _iterator.next()) && !result.done) {
524
+ const pair = result.value;
525
+ fn.call(obj, pair[0], pair[1]);
526
+ }
527
+ }
528
+
529
+ /**
530
+ * It takes a regular expression and a string, and returns an array of all the matches
531
+ *
532
+ * @param {string} regExp - The regular expression to match against.
533
+ * @param {string} str - The string to search.
534
+ *
535
+ * @returns {Array<boolean>}
536
+ */
537
+ const matchAll = (regExp, str) => {
538
+ let matches;
539
+ const arr = [];
540
+
541
+ while ((matches = regExp.exec(str)) !== null) {
542
+ arr.push(matches);
543
+ }
544
+
545
+ return arr;
546
+ }
547
+
548
+ /* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */
549
+ const isHTMLForm = kindOfTest('HTMLFormElement');
550
+
551
+ const toCamelCase = str => {
552
+ return str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,
553
+ function replacer(m, p1, p2) {
554
+ return p1.toUpperCase() + p2;
555
+ }
556
+ );
557
+ };
558
+
559
+ /* Creating a function that will check if an object has a property. */
560
+ const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
561
+
562
+ /**
563
+ * Determine if a value is a RegExp object
564
+ *
565
+ * @param {*} val The value to test
566
+ *
567
+ * @returns {boolean} True if value is a RegExp object, otherwise false
568
+ */
569
+ const isRegExp = kindOfTest('RegExp');
570
+
571
+ const reduceDescriptors = (obj, reducer) => {
572
+ const descriptors = Object.getOwnPropertyDescriptors(obj);
573
+ const reducedDescriptors = {};
574
+
575
+ forEach(descriptors, (descriptor, name) => {
576
+ let ret;
577
+ if ((ret = reducer(descriptor, name, obj)) !== false) {
578
+ reducedDescriptors[name] = ret || descriptor;
579
+ }
580
+ });
581
+
582
+ Object.defineProperties(obj, reducedDescriptors);
583
+ }
584
+
585
+ /**
586
+ * Makes all methods read-only
587
+ * @param {Object} obj
588
+ */
589
+
590
+ const freezeMethods = (obj) => {
591
+ reduceDescriptors(obj, (descriptor, name) => {
592
+ // skip restricted props in strict mode
593
+ if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
594
+ return false;
595
+ }
596
+
597
+ const value = obj[name];
598
+
599
+ if (!isFunction(value)) return;
600
+
601
+ descriptor.enumerable = false;
602
+
603
+ if ('writable' in descriptor) {
604
+ descriptor.writable = false;
605
+ return;
606
+ }
607
+
608
+ if (!descriptor.set) {
609
+ descriptor.set = () => {
610
+ throw Error('Can not rewrite read-only method \'' + name + '\'');
611
+ };
612
+ }
613
+ });
614
+ }
615
+
616
+ const toObjectSet = (arrayOrString, delimiter) => {
617
+ const obj = {};
618
+
619
+ const define = (arr) => {
620
+ arr.forEach(value => {
621
+ obj[value] = true;
622
+ });
623
+ }
624
+
625
+ isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
626
+
627
+ return obj;
628
+ }
629
+
630
+ const noop = () => {}
631
+
632
+ const toFiniteNumber = (value, defaultValue) => {
633
+ return value != null && Number.isFinite(value = +value) ? value : defaultValue;
634
+ }
635
+
636
+
637
+
638
+ /**
639
+ * If the thing is a FormData object, return true, otherwise return false.
640
+ *
641
+ * @param {unknown} thing - The thing to check.
642
+ *
643
+ * @returns {boolean}
644
+ */
645
+ function isSpecCompliantForm(thing) {
646
+ return !!(thing && isFunction(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
647
+ }
648
+
649
+ const toJSONObject = (obj) => {
650
+ const stack = new Array(10);
651
+
652
+ const visit = (source, i) => {
653
+
654
+ if (isObject(source)) {
655
+ if (stack.indexOf(source) >= 0) {
656
+ return;
657
+ }
658
+
659
+ //Buffer check
660
+ if (isBuffer(source)) {
661
+ return source;
662
+ }
663
+
664
+ if(!('toJSON' in source)) {
665
+ stack[i] = source;
666
+ const target = isArray(source) ? [] : {};
667
+
668
+ forEach(source, (value, key) => {
669
+ const reducedValue = visit(value, i + 1);
670
+ !isUndefined(reducedValue) && (target[key] = reducedValue);
671
+ });
672
+
673
+ stack[i] = undefined;
674
+
675
+ return target;
676
+ }
677
+ }
678
+
679
+ return source;
680
+ }
681
+
682
+ return visit(obj, 0);
683
+ }
684
+
685
+ const isAsyncFn = kindOfTest('AsyncFunction');
686
+
687
+ const isThenable = (thing) =>
688
+ thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
689
+
690
+ // original code
691
+ // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
692
+
693
+ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
694
+ if (setImmediateSupported) {
695
+ return setImmediate;
696
+ }
697
+
698
+ return postMessageSupported ? ((token, callbacks) => {
699
+ _global.addEventListener("message", ({source, data}) => {
700
+ if (source === _global && data === token) {
701
+ callbacks.length && callbacks.shift()();
702
+ }
703
+ }, false);
704
+
705
+ return (cb) => {
706
+ callbacks.push(cb);
707
+ _global.postMessage(token, "*");
708
+ }
709
+ })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
710
+ })(
711
+ typeof setImmediate === 'function',
712
+ isFunction(_global.postMessage)
713
+ );
714
+
715
+ const asap = typeof queueMicrotask !== 'undefined' ?
716
+ queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
717
+
718
+ // *********************
719
+
720
+
721
+ const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
722
+
723
+
724
+ export default {
725
+ isArray,
726
+ isArrayBuffer,
727
+ isBuffer,
728
+ isFormData,
729
+ isArrayBufferView,
730
+ isString,
731
+ isNumber,
732
+ isBoolean,
733
+ isObject,
734
+ isPlainObject,
735
+ isEmptyObject,
736
+ isReadableStream,
737
+ isRequest,
738
+ isResponse,
739
+ isHeaders,
740
+ isUndefined,
741
+ isDate,
742
+ isFile,
743
+ isBlob,
744
+ isRegExp,
745
+ isFunction,
746
+ isStream,
747
+ isURLSearchParams,
748
+ isTypedArray,
749
+ isFileList,
750
+ forEach,
751
+ merge,
752
+ extend,
753
+ trim,
754
+ stripBOM,
755
+ inherits,
756
+ toFlatObject,
757
+ kindOf,
758
+ kindOfTest,
759
+ endsWith,
760
+ toArray,
761
+ forEachEntry,
762
+ matchAll,
763
+ isHTMLForm,
764
+ hasOwnProperty,
765
+ hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
766
+ reduceDescriptors,
767
+ freezeMethods,
768
+ toObjectSet,
769
+ toCamelCase,
770
+ noop,
771
+ toFiniteNumber,
772
+ findKey,
773
+ global: _global,
774
+ isContextDefined,
775
+ isSpecCompliantForm,
776
+ toJSONObject,
777
+ isAsyncFn,
778
+ isThenable,
779
+ setImmediate: _setImmediate,
780
+ asap,
781
+ isIterable
782
+ };