@wiajs/req 1.7.7

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