axios 1.0.0-alpha.1 → 1.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.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

Files changed (70) hide show
  1. package/CHANGELOG.md +74 -1
  2. package/README.md +59 -48
  3. package/SECURITY.md +3 -2
  4. package/bin/ssl_hotfix.js +1 -1
  5. package/dist/axios.js +1564 -981
  6. package/dist/axios.js.map +1 -1
  7. package/dist/axios.min.js +1 -1
  8. package/dist/axios.min.js.map +1 -1
  9. package/dist/esm/axios.js +1472 -866
  10. package/dist/esm/axios.js.map +1 -1
  11. package/dist/esm/axios.min.js +1 -1
  12. package/dist/esm/axios.min.js.map +1 -1
  13. package/dist/node/axios.cjs +3761 -0
  14. package/dist/node/axios.cjs.map +1 -0
  15. package/gulpfile.js +88 -0
  16. package/index.d.ts +213 -67
  17. package/index.js +2 -1
  18. package/karma.conf.cjs +250 -0
  19. package/lib/adapters/http.js +256 -131
  20. package/lib/adapters/index.js +33 -0
  21. package/lib/adapters/xhr.js +79 -56
  22. package/lib/axios.js +41 -25
  23. package/lib/cancel/CancelToken.js +91 -88
  24. package/lib/cancel/CanceledError.js +5 -4
  25. package/lib/cancel/isCancel.js +2 -2
  26. package/lib/core/Axios.js +127 -100
  27. package/lib/core/AxiosError.js +10 -7
  28. package/lib/core/AxiosHeaders.js +274 -0
  29. package/lib/core/InterceptorManager.js +61 -53
  30. package/lib/core/buildFullPath.js +5 -4
  31. package/lib/core/dispatchRequest.js +21 -39
  32. package/lib/core/mergeConfig.js +8 -7
  33. package/lib/core/settle.js +6 -4
  34. package/lib/core/transformData.js +15 -10
  35. package/lib/defaults/index.js +46 -39
  36. package/lib/defaults/transitional.js +1 -1
  37. package/lib/env/classes/FormData.js +2 -2
  38. package/lib/env/data.js +1 -3
  39. package/lib/helpers/AxiosTransformStream.js +191 -0
  40. package/lib/helpers/AxiosURLSearchParams.js +23 -7
  41. package/lib/helpers/bind.js +2 -2
  42. package/lib/helpers/buildURL.js +16 -7
  43. package/lib/helpers/combineURLs.js +3 -2
  44. package/lib/helpers/cookies.js +43 -44
  45. package/lib/helpers/deprecatedMethod.js +4 -2
  46. package/lib/helpers/formDataToJSON.js +36 -15
  47. package/lib/helpers/fromDataURI.js +15 -13
  48. package/lib/helpers/isAbsoluteURL.js +3 -2
  49. package/lib/helpers/isAxiosError.js +4 -3
  50. package/lib/helpers/isURLSameOrigin.js +55 -56
  51. package/lib/helpers/null.js +1 -1
  52. package/lib/helpers/parseHeaders.js +24 -22
  53. package/lib/helpers/parseProtocol.js +3 -3
  54. package/lib/helpers/speedometer.js +55 -0
  55. package/lib/helpers/spread.js +3 -2
  56. package/lib/helpers/throttle.js +33 -0
  57. package/lib/helpers/toFormData.js +68 -18
  58. package/lib/helpers/toURLEncodedForm.js +5 -5
  59. package/lib/helpers/validator.js +20 -15
  60. package/lib/platform/browser/classes/FormData.js +1 -1
  61. package/lib/platform/browser/classes/URLSearchParams.js +2 -3
  62. package/lib/platform/browser/index.js +38 -6
  63. package/lib/platform/index.js +2 -2
  64. package/lib/platform/node/classes/FormData.js +2 -2
  65. package/lib/platform/node/classes/URLSearchParams.js +2 -3
  66. package/lib/platform/node/index.js +5 -4
  67. package/lib/utils.js +294 -192
  68. package/package.json +55 -22
  69. package/rollup.config.js +37 -7
  70. package/lib/helpers/normalizeHeaderName.js +0 -12
package/lib/utils.js CHANGED
@@ -1,76 +1,73 @@
1
1
  'use strict';
2
2
 
3
- var bind = require('./helpers/bind');
3
+ import bind from './helpers/bind.js';
4
4
 
5
5
  // utils is a library of generic helper functions non-specific to axios
6
6
 
7
- var toString = Object.prototype.toString;
7
+ const {toString} = Object.prototype;
8
+ const {getPrototypeOf} = Object;
8
9
 
9
- // eslint-disable-next-line func-names
10
- var kindOf = (function(cache) {
11
- // eslint-disable-next-line func-names
12
- return function(thing) {
13
- var str = toString.call(thing);
10
+ const kindOf = (cache => thing => {
11
+ const str = toString.call(thing);
14
12
  return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
15
- };
16
13
  })(Object.create(null));
17
14
 
18
- function kindOfTest(type) {
15
+ const kindOfTest = (type) => {
19
16
  type = type.toLowerCase();
20
- return function isKindOf(thing) {
21
- return kindOf(thing) === type;
22
- };
17
+ return (thing) => kindOf(thing) === type
23
18
  }
24
19
 
20
+ const typeOfTest = type => thing => typeof thing === type;
21
+
25
22
  /**
26
23
  * Determine if a value is an Array
27
24
  *
28
25
  * @param {Object} val The value to test
26
+ *
29
27
  * @returns {boolean} True if value is an Array, otherwise false
30
28
  */
31
- function isArray(val) {
32
- return Array.isArray(val);
33
- }
29
+ const {isArray} = Array;
34
30
 
35
31
  /**
36
32
  * Determine if a value is undefined
37
33
  *
38
- * @param {Object} val The value to test
34
+ * @param {*} val The value to test
35
+ *
39
36
  * @returns {boolean} True if the value is undefined, otherwise false
40
37
  */
41
- function isUndefined(val) {
42
- return typeof val === 'undefined';
43
- }
38
+ const isUndefined = typeOfTest('undefined');
44
39
 
45
40
  /**
46
41
  * Determine if a value is a Buffer
47
42
  *
48
- * @param {Object} val The value to test
43
+ * @param {*} val The value to test
44
+ *
49
45
  * @returns {boolean} True if value is a Buffer, otherwise false
50
46
  */
51
47
  function isBuffer(val) {
52
48
  return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
53
- && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
49
+ && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
54
50
  }
55
51
 
56
52
  /**
57
53
  * Determine if a value is an ArrayBuffer
58
54
  *
59
- * @function
60
- * @param {Object} val The value to test
55
+ * @param {*} val The value to test
56
+ *
61
57
  * @returns {boolean} True if value is an ArrayBuffer, otherwise false
62
58
  */
63
- var isArrayBuffer = kindOfTest('ArrayBuffer');
59
+ const isArrayBuffer = kindOfTest('ArrayBuffer');
64
60
 
65
61
 
66
62
  /**
67
63
  * Determine if a value is a view on an ArrayBuffer
68
64
  *
69
- * @param {Object} val The value to test
65
+ * @param {*} val The value to test
66
+ *
70
67
  * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
71
68
  */
72
69
  function isArrayBufferView(val) {
73
- var result;
70
+ let result;
74
71
  if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
75
72
  result = ArrayBuffer.isView(val);
76
73
  } else {
@@ -82,112 +79,116 @@ function isArrayBufferView(val) {
82
79
  /**
83
80
  * Determine if a value is a String
84
81
  *
85
- * @param {Object} val The value to test
82
+ * @param {*} val The value to test
83
+ *
86
84
  * @returns {boolean} True if value is a String, otherwise false
87
85
  */
88
- function isString(val) {
89
- return typeof val === 'string';
90
- }
86
+ const isString = typeOfTest('string');
87
+
88
+ /**
89
+ * Determine if a value is a Function
90
+ *
91
+ * @param {*} val The value to test
92
+ * @returns {boolean} True if value is a Function, otherwise false
93
+ */
94
+ const isFunction = typeOfTest('function');
91
95
 
92
96
  /**
93
97
  * Determine if a value is a Number
94
98
  *
95
- * @param {Object} val The value to test
99
+ * @param {*} val The value to test
100
+ *
96
101
  * @returns {boolean} True if value is a Number, otherwise false
97
102
  */
98
- function isNumber(val) {
99
- return typeof val === 'number';
100
- }
103
+ const isNumber = typeOfTest('number');
101
104
 
102
105
  /**
103
106
  * Determine if a value is an Object
104
107
  *
105
- * @param {Object} val The value to test
108
+ * @param {*} thing The value to test
109
+ *
106
110
  * @returns {boolean} True if value is an Object, otherwise false
107
111
  */
108
- function isObject(val) {
109
- return val !== null && typeof val === 'object';
110
- }
112
+ const isObject = (thing) => thing !== null && typeof thing === 'object';
113
+
114
+ /**
115
+ * Determine if a value is a Boolean
116
+ *
117
+ * @param {*} thing The value to test
118
+ * @returns {boolean} True if value is a Boolean, otherwise false
119
+ */
120
+ const isBoolean = thing => thing === true || thing === false;
111
121
 
112
122
  /**
113
123
  * Determine if a value is a plain Object
114
124
  *
115
- * @param {Object} val The value to test
116
- * @return {boolean} True if value is a plain Object, otherwise false
125
+ * @param {*} val The value to test
126
+ *
127
+ * @returns {boolean} True if value is a plain Object, otherwise false
117
128
  */
118
- function isPlainObject(val) {
129
+ const isPlainObject = (val) => {
119
130
  if (kindOf(val) !== 'object') {
120
131
  return false;
121
132
  }
122
133
 
123
- var prototype = Object.getPrototypeOf(val);
124
- return prototype === null || prototype === Object.prototype;
134
+ const prototype = getPrototypeOf(val);
135
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
125
136
  }
126
137
 
127
138
  /**
128
139
  * Determine if a value is a Date
129
140
  *
130
- * @function
131
- * @param {Object} val The value to test
141
+ * @param {*} val The value to test
142
+ *
132
143
  * @returns {boolean} True if value is a Date, otherwise false
133
144
  */
134
- var isDate = kindOfTest('Date');
145
+ const isDate = kindOfTest('Date');
135
146
 
136
147
  /**
137
148
  * Determine if a value is a File
138
149
  *
139
- * @function
140
- * @param {Object} val The value to test
150
+ * @param {*} val The value to test
151
+ *
141
152
  * @returns {boolean} True if value is a File, otherwise false
142
153
  */
143
- var isFile = kindOfTest('File');
154
+ const isFile = kindOfTest('File');
144
155
 
145
156
  /**
146
157
  * Determine if a value is a Blob
147
158
  *
148
- * @function
149
- * @param {Object} val The value to test
159
+ * @param {*} val The value to test
160
+ *
150
161
  * @returns {boolean} True if value is a Blob, otherwise false
151
162
  */
152
- var isBlob = kindOfTest('Blob');
163
+ const isBlob = kindOfTest('Blob');
153
164
 
154
165
  /**
155
166
  * Determine if a value is a FileList
156
167
  *
157
- * @function
158
- * @param {Object} val The value to test
159
- * @returns {boolean} True if value is a File, otherwise false
160
- */
161
- var isFileList = kindOfTest('FileList');
162
-
163
- /**
164
- * Determine if a value is a Function
168
+ * @param {*} val The value to test
165
169
  *
166
- * @param {Object} val The value to test
167
- * @returns {boolean} True if value is a Function, otherwise false
170
+ * @returns {boolean} True if value is a File, otherwise false
168
171
  */
169
- function isFunction(val) {
170
- return toString.call(val) === '[object Function]';
171
- }
172
+ const isFileList = kindOfTest('FileList');
172
173
 
173
174
  /**
174
175
  * Determine if a value is a Stream
175
176
  *
176
- * @param {Object} val The value to test
177
+ * @param {*} val The value to test
178
+ *
177
179
  * @returns {boolean} True if value is a Stream, otherwise false
178
180
  */
179
- function isStream(val) {
180
- return isObject(val) && isFunction(val.pipe);
181
- }
181
+ const isStream = (val) => isObject(val) && isFunction(val.pipe);
182
182
 
183
183
  /**
184
184
  * Determine if a value is a FormData
185
185
  *
186
- * @param {Object} thing The value to test
186
+ * @param {*} thing The value to test
187
+ *
187
188
  * @returns {boolean} True if value is an FormData, otherwise false
188
189
  */
189
- function isFormData(thing) {
190
- var pattern = '[object FormData]';
190
+ const isFormData = (thing) => {
191
+ const pattern = '[object FormData]';
191
192
  return thing && (
192
193
  (typeof FormData === 'function' && thing instanceof FormData) ||
193
194
  toString.call(thing) === pattern ||
@@ -197,49 +198,22 @@ function isFormData(thing) {
197
198
 
198
199
  /**
199
200
  * Determine if a value is a URLSearchParams object
200
- * @function
201
- * @param {Object} val The value to test
201
+ *
202
+ * @param {*} val The value to test
203
+ *
202
204
  * @returns {boolean} True if value is a URLSearchParams object, otherwise false
203
205
  */
204
- var isURLSearchParams = kindOfTest('URLSearchParams');
206
+ const isURLSearchParams = kindOfTest('URLSearchParams');
205
207
 
206
208
  /**
207
209
  * Trim excess whitespace off the beginning and end of a string
208
210
  *
209
211
  * @param {String} str The String to trim
210
- * @returns {String} The String freed of excess whitespace
211
- */
212
- function trim(str) {
213
- return str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
214
- }
215
-
216
- /**
217
- * Determine if we're running in a standard browser environment
218
- *
219
- * This allows axios to run in a web worker, and react-native.
220
- * Both environments support XMLHttpRequest, but not fully standard globals.
221
212
  *
222
- * web workers:
223
- * typeof window -> undefined
224
- * typeof document -> undefined
225
- *
226
- * react-native:
227
- * navigator.product -> 'ReactNative'
228
- * nativescript
229
- * navigator.product -> 'NativeScript' or 'NS'
213
+ * @returns {String} The String freed of excess whitespace
230
214
  */
231
- function isStandardBrowserEnv() {
232
- var product;
233
- if (typeof navigator !== 'undefined' && (
234
- (product = navigator.product) === 'ReactNative' ||
235
- product === 'NativeScript' ||
236
- product === 'NS')
237
- ) {
238
- return false;
239
- }
240
-
241
- return typeof window !== 'undefined' && typeof document !== 'undefined';
242
- }
215
+ const trim = (str) => str.trim ?
216
+ str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
243
217
 
244
218
  /**
245
219
  * Iterate over an Array or an Object invoking a function for each item.
@@ -252,13 +226,19 @@ function isStandardBrowserEnv() {
252
226
  *
253
227
  * @param {Object|Array} obj The object to iterate
254
228
  * @param {Function} fn The callback to invoke for each item
229
+ *
230
+ * @param {Boolean} [allOwnKeys = false]
231
+ * @returns {void}
255
232
  */
256
- function forEach(obj, fn) {
233
+ function forEach(obj, fn, {allOwnKeys = false} = {}) {
257
234
  // Don't bother if no value provided
258
235
  if (obj === null || typeof obj === 'undefined') {
259
236
  return;
260
237
  }
261
238
 
239
+ let i;
240
+ let l;
241
+
262
242
  // Force an array if not already something iterable
263
243
  if (typeof obj !== 'object') {
264
244
  /*eslint no-param-reassign:0*/
@@ -267,15 +247,18 @@ function forEach(obj, fn) {
267
247
 
268
248
  if (isArray(obj)) {
269
249
  // Iterate over array values
270
- for (var i = 0, l = obj.length; i < l; i++) {
250
+ for (i = 0, l = obj.length; i < l; i++) {
271
251
  fn.call(null, obj[i], i, obj);
272
252
  }
273
253
  } else {
274
254
  // Iterate over object keys
275
- for (var key in obj) {
276
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
277
- fn.call(null, obj[key], key, obj);
278
- }
255
+ const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
256
+ const len = keys.length;
257
+ let key;
258
+
259
+ for (i = 0; i < len; i++) {
260
+ key = keys[i];
261
+ fn.call(null, obj[key], key, obj);
279
262
  }
280
263
  }
281
264
  }
@@ -295,11 +278,12 @@ function forEach(obj, fn) {
295
278
  * ```
296
279
  *
297
280
  * @param {Object} obj1 Object to merge
281
+ *
298
282
  * @returns {Object} Result of all merge properties
299
283
  */
300
284
  function merge(/* obj1, obj2, obj3, ... */) {
301
- var result = {};
302
- function assignValue(val, key) {
285
+ const result = {};
286
+ const assignValue = (val, key) => {
303
287
  if (isPlainObject(result[key]) && isPlainObject(val)) {
304
288
  result[key] = merge(result[key], val);
305
289
  } else if (isPlainObject(val)) {
@@ -311,8 +295,8 @@ function merge(/* obj1, obj2, obj3, ... */) {
311
295
  }
312
296
  }
313
297
 
314
- for (var i = 0, l = arguments.length; i < l; i++) {
315
- forEach(arguments[i], assignValue);
298
+ for (let i = 0, l = arguments.length; i < l; i++) {
299
+ arguments[i] && forEach(arguments[i], assignValue);
316
300
  }
317
301
  return result;
318
302
  }
@@ -323,16 +307,18 @@ function merge(/* obj1, obj2, obj3, ... */) {
323
307
  * @param {Object} a The object to be extended
324
308
  * @param {Object} b The object to copy properties from
325
309
  * @param {Object} thisArg The object to bind function to
326
- * @return {Object} The resulting value of object a
310
+ *
311
+ * @param {Boolean} [allOwnKeys]
312
+ * @returns {Object} The resulting value of object a
327
313
  */
328
- function extend(a, b, thisArg) {
329
- forEach(b, function assignValue(val, key) {
330
- if (thisArg && typeof val === 'function') {
314
+ const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
315
+ forEach(b, (val, key) => {
316
+ if (thisArg && isFunction(val)) {
331
317
  a[key] = bind(val, thisArg);
332
318
  } else {
333
319
  a[key] = val;
334
320
  }
335
- });
321
+ }, {allOwnKeys});
336
322
  return a;
337
323
  }
338
324
 
@@ -340,9 +326,10 @@ function extend(a, b, thisArg) {
340
326
  * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
341
327
  *
342
328
  * @param {string} content with BOM
343
- * @return {string} content value without BOM
329
+ *
330
+ * @returns {string} content value without BOM
344
331
  */
345
- function stripBOM(content) {
332
+ const stripBOM = (content) => {
346
333
  if (content.charCodeAt(0) === 0xFEFF) {
347
334
  content = content.slice(1);
348
335
  }
@@ -355,11 +342,15 @@ function stripBOM(content) {
355
342
  * @param {function} superConstructor
356
343
  * @param {object} [props]
357
344
  * @param {object} [descriptors]
345
+ *
346
+ * @returns {void}
358
347
  */
359
-
360
- function inherits(constructor, superConstructor, props, descriptors) {
348
+ const inherits = (constructor, superConstructor, props, descriptors) => {
361
349
  constructor.prototype = Object.create(superConstructor.prototype, descriptors);
362
350
  constructor.prototype.constructor = constructor;
351
+ Object.defineProperty(constructor, 'super', {
352
+ value: superConstructor.prototype
353
+ });
363
354
  props && Object.assign(constructor.prototype, props);
364
355
  }
365
356
 
@@ -369,14 +360,14 @@ function inherits(constructor, superConstructor, props, descriptors) {
369
360
  * @param {Object} [destObj]
370
361
  * @param {Function|Boolean} [filter]
371
362
  * @param {Function} [propFilter]
363
+ *
372
364
  * @returns {Object}
373
365
  */
374
-
375
- function toFlatObject(sourceObj, destObj, filter, propFilter) {
376
- var props;
377
- var i;
378
- var prop;
379
- var merged = {};
366
+ const toFlatObject = (sourceObj, destObj, filter, propFilter) => {
367
+ let props;
368
+ let i;
369
+ let prop;
370
+ const merged = {};
380
371
 
381
372
  destObj = destObj || {};
382
373
  // eslint-disable-next-line no-eq-null,eqeqeq
@@ -392,71 +383,99 @@ function toFlatObject(sourceObj, destObj, filter, propFilter) {
392
383
  merged[prop] = true;
393
384
  }
394
385
  }
395
- sourceObj = filter !== false && Object.getPrototypeOf(sourceObj);
386
+ sourceObj = filter !== false && getPrototypeOf(sourceObj);
396
387
  } while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
397
388
 
398
389
  return destObj;
399
390
  }
400
391
 
401
- /*
402
- * determines whether a string ends with the characters of a specified string
392
+ /**
393
+ * Determines whether a string ends with the characters of a specified string
394
+ *
403
395
  * @param {String} str
404
396
  * @param {String} searchString
405
397
  * @param {Number} [position= 0]
398
+ *
406
399
  * @returns {boolean}
407
400
  */
408
- function endsWith(str, searchString, position) {
401
+ const endsWith = (str, searchString, position) => {
409
402
  str = String(str);
410
403
  if (position === undefined || position > str.length) {
411
404
  position = str.length;
412
405
  }
413
406
  position -= searchString.length;
414
- var lastIndex = str.indexOf(searchString, position);
407
+ const lastIndex = str.indexOf(searchString, position);
415
408
  return lastIndex !== -1 && lastIndex === position;
416
409
  }
417
410
 
418
411
 
419
412
  /**
420
413
  * Returns new array from array like object or null if failed
414
+ *
421
415
  * @param {*} [thing]
416
+ *
422
417
  * @returns {?Array}
423
418
  */
424
- function toArray(thing) {
419
+ const toArray = (thing) => {
425
420
  if (!thing) return null;
426
421
  if (isArray(thing)) return thing;
427
- var i = thing.length;
422
+ let i = thing.length;
428
423
  if (!isNumber(i)) return null;
429
- var arr = new Array(i);
424
+ const arr = new Array(i);
430
425
  while (i-- > 0) {
431
426
  arr[i] = thing[i];
432
427
  }
433
428
  return arr;
434
429
  }
435
430
 
431
+ /**
432
+ * Checking if the Uint8Array exists and if it does, it returns a function that checks if the
433
+ * thing passed in is an instance of Uint8Array
434
+ *
435
+ * @param {TypedArray}
436
+ *
437
+ * @returns {Array}
438
+ */
436
439
  // eslint-disable-next-line func-names
437
- var isTypedArray = (function(TypedArray) {
440
+ const isTypedArray = (TypedArray => {
438
441
  // eslint-disable-next-line func-names
439
- return function(thing) {
442
+ return thing => {
440
443
  return TypedArray && thing instanceof TypedArray;
441
444
  };
442
- })(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));
445
+ })(typeof Uint8Array !== 'undefined' && getPrototypeOf(Uint8Array));
443
446
 
444
- function forEachEntry(obj, fn) {
445
- var generator = obj && obj[Symbol.iterator];
447
+ /**
448
+ * For each entry in the object, call the function with the key and value.
449
+ *
450
+ * @param {Object<any, any>} obj - The object to iterate over.
451
+ * @param {Function} fn - The function to call for each entry.
452
+ *
453
+ * @returns {void}
454
+ */
455
+ const forEachEntry = (obj, fn) => {
456
+ const generator = obj && obj[Symbol.iterator];
446
457
 
447
- var iterator = generator.call(obj);
458
+ const iterator = generator.call(obj);
448
459
 
449
- var result;
460
+ let result;
450
461
 
451
462
  while ((result = iterator.next()) && !result.done) {
452
- var pair = result.value;
463
+ const pair = result.value;
453
464
  fn.call(obj, pair[0], pair[1]);
454
465
  }
455
466
  }
456
467
 
457
- function matchAll(regExp, str) {
458
- var matches;
459
- var arr = [];
468
+ /**
469
+ * It takes a regular expression and a string, and returns an array of all the matches
470
+ *
471
+ * @param {string} regExp - The regular expression to match against.
472
+ * @param {string} str - The string to search.
473
+ *
474
+ * @returns {Array<boolean>}
475
+ */
476
+ const matchAll = (regExp, str) => {
477
+ let matches;
478
+ const arr = [];
460
479
 
461
480
  while ((matches = regExp.exec(str)) !== null) {
462
481
  arr.push(matches);
@@ -465,47 +484,130 @@ function matchAll(regExp, str) {
465
484
  return arr;
466
485
  }
467
486
 
468
- var isHTMLForm = kindOfTest('HTMLFormElement');
487
+ /* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */
488
+ const isHTMLForm = kindOfTest('HTMLFormElement');
469
489
 
470
- var hasOwnProperty = (function resolver(_hasOwnProperty) {
471
- return function(obj, prop) {
472
- return _hasOwnProperty.call(obj, prop);
473
- };
474
- })(Object.prototype.hasOwnProperty);
475
-
476
- module.exports = {
477
- isArray: isArray,
478
- isArrayBuffer: isArrayBuffer,
479
- isBuffer: isBuffer,
480
- isFormData: isFormData,
481
- isArrayBufferView: isArrayBufferView,
482
- isString: isString,
483
- isNumber: isNumber,
484
- isObject: isObject,
485
- isPlainObject: isPlainObject,
486
- isUndefined: isUndefined,
487
- isDate: isDate,
488
- isFile: isFile,
489
- isBlob: isBlob,
490
- isFunction: isFunction,
491
- isStream: isStream,
492
- isURLSearchParams: isURLSearchParams,
493
- isStandardBrowserEnv: isStandardBrowserEnv,
494
- forEach: forEach,
495
- merge: merge,
496
- extend: extend,
497
- trim: trim,
498
- stripBOM: stripBOM,
499
- inherits: inherits,
500
- toFlatObject: toFlatObject,
501
- kindOf: kindOf,
502
- kindOfTest: kindOfTest,
503
- endsWith: endsWith,
504
- toArray: toArray,
505
- isTypedArray: isTypedArray,
506
- isFileList: isFileList,
507
- forEachEntry: forEachEntry,
508
- matchAll: matchAll,
509
- isHTMLForm: isHTMLForm,
510
- hasOwnProperty: hasOwnProperty
490
+ const toCamelCase = str => {
491
+ return str.toLowerCase().replace(/[_-\s]([a-z\d])(\w*)/g,
492
+ function replacer(m, p1, p2) {
493
+ return p1.toUpperCase() + p2;
494
+ }
495
+ );
496
+ };
497
+
498
+ /* Creating a function that will check if an object has a property. */
499
+ const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
500
+
501
+ /**
502
+ * Determine if a value is a RegExp object
503
+ *
504
+ * @param {*} val The value to test
505
+ *
506
+ * @returns {boolean} True if value is a RegExp object, otherwise false
507
+ */
508
+ const isRegExp = kindOfTest('RegExp');
509
+
510
+ const reduceDescriptors = (obj, reducer) => {
511
+ const descriptors = Object.getOwnPropertyDescriptors(obj);
512
+ const reducedDescriptors = {};
513
+
514
+ forEach(descriptors, (descriptor, name) => {
515
+ if (reducer(descriptor, name, obj) !== false) {
516
+ reducedDescriptors[name] = descriptor;
517
+ }
518
+ });
519
+
520
+ Object.defineProperties(obj, reducedDescriptors);
521
+ }
522
+
523
+ /**
524
+ * Makes all methods read-only
525
+ * @param {Object} obj
526
+ */
527
+
528
+ const freezeMethods = (obj) => {
529
+ reduceDescriptors(obj, (descriptor, name) => {
530
+ const value = obj[name];
531
+
532
+ if (!isFunction(value)) return;
533
+
534
+ descriptor.enumerable = false;
535
+
536
+ if ('writable' in descriptor) {
537
+ descriptor.writable = false;
538
+ return;
539
+ }
540
+
541
+ if (!descriptor.set) {
542
+ descriptor.set = () => {
543
+ throw Error('Can not read-only method \'' + name + '\'');
544
+ };
545
+ }
546
+ });
547
+ }
548
+
549
+ const toObjectSet = (arrayOrString, delimiter) => {
550
+ const obj = {};
551
+
552
+ const define = (arr) => {
553
+ arr.forEach(value => {
554
+ obj[value] = true;
555
+ });
556
+ }
557
+
558
+ isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
559
+
560
+ return obj;
561
+ }
562
+
563
+ const noop = () => {}
564
+
565
+ const toFiniteNumber = (value, defaultValue) => {
566
+ value = +value;
567
+ return Number.isFinite(value) ? value : defaultValue;
568
+ }
569
+
570
+ export default {
571
+ isArray,
572
+ isArrayBuffer,
573
+ isBuffer,
574
+ isFormData,
575
+ isArrayBufferView,
576
+ isString,
577
+ isNumber,
578
+ isBoolean,
579
+ isObject,
580
+ isPlainObject,
581
+ isUndefined,
582
+ isDate,
583
+ isFile,
584
+ isBlob,
585
+ isRegExp,
586
+ isFunction,
587
+ isStream,
588
+ isURLSearchParams,
589
+ isTypedArray,
590
+ isFileList,
591
+ forEach,
592
+ merge,
593
+ extend,
594
+ trim,
595
+ stripBOM,
596
+ inherits,
597
+ toFlatObject,
598
+ kindOf,
599
+ kindOfTest,
600
+ endsWith,
601
+ toArray,
602
+ forEachEntry,
603
+ matchAll,
604
+ isHTMLForm,
605
+ hasOwnProperty,
606
+ hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
607
+ reduceDescriptors,
608
+ freezeMethods,
609
+ toObjectSet,
610
+ toCamelCase,
611
+ noop,
612
+ toFiniteNumber
511
613
  };