axios 0.5.0 → 0.5.4

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 (54) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/COOKBOOK.md +127 -0
  3. package/README.md +7 -2
  4. package/coverage/lcov-report/base.css +182 -0
  5. package/coverage/lcov-report/dist/axios.js.html +6075 -0
  6. package/coverage/lcov-report/dist/index.html +85 -0
  7. package/coverage/lcov-report/index.html +85 -0
  8. package/coverage/lcov-report/prettify.css +1 -0
  9. package/coverage/lcov-report/prettify.js +1 -0
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +156 -0
  12. package/coverage/lcov-report/webpack.tests.js.html +10236 -0
  13. package/coverage/lcov.info +2366 -0
  14. package/dist/axios.amd.js +118 -116
  15. package/dist/axios.amd.map +1 -1
  16. package/dist/axios.amd.min.js +3 -3
  17. package/dist/axios.amd.min.map +1 -1
  18. package/dist/axios.amd.standalone.js +118 -116
  19. package/dist/axios.amd.standalone.map +1 -1
  20. package/dist/axios.amd.standalone.min.js +2 -2
  21. package/dist/axios.amd.standalone.min.map +1 -1
  22. package/dist/axios.js +118 -116
  23. package/dist/axios.map +1 -1
  24. package/dist/axios.min.js +3 -3
  25. package/dist/axios.min.map +1 -1
  26. package/dist/axios.standalone.js +118 -116
  27. package/dist/axios.standalone.map +1 -1
  28. package/dist/axios.standalone.min.js +2 -2
  29. package/dist/axios.standalone.min.map +1 -1
  30. package/examples/README.md +9 -0
  31. package/examples/all/index.html +44 -0
  32. package/examples/amd/index.html +37 -0
  33. package/examples/get/index.html +33 -0
  34. package/examples/get/people.json +26 -0
  35. package/examples/post/index.html +45 -0
  36. package/examples/server.js +98 -0
  37. package/examples/transform-response/index.html +44 -0
  38. package/examples/upload/index.html +43 -0
  39. package/examples/upload/server.js +11 -0
  40. package/lib/adapters/http.js +10 -7
  41. package/lib/adapters/xhr.js +23 -17
  42. package/lib/axios.js +36 -26
  43. package/lib/core/InterceptorManager.js +2 -3
  44. package/lib/core/dispatchRequest.js +0 -2
  45. package/lib/defaults.js +6 -5
  46. package/lib/helpers/cookies.js +1 -1
  47. package/lib/helpers/parseHeaders.js +2 -2
  48. package/lib/helpers/spread.js +3 -1
  49. package/lib/helpers/transformData.js +1 -1
  50. package/lib/helpers/urlIsSameOrigin.js +8 -6
  51. package/lib/utils.js +10 -6
  52. package/package.json +20 -12
  53. package/webpack.config.js +5 -10
  54. package/webpack.tests.js +2 -0
package/dist/axios.amd.js CHANGED
@@ -50,6 +50,8 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
50
50
  /* 1 */
51
51
  /***/ function(module, exports, __webpack_require__) {
52
52
 
53
+ 'use strict';
54
+
53
55
  var defaults = __webpack_require__(2);
54
56
  var utils = __webpack_require__(3);
55
57
  var deprecatedMethod = __webpack_require__(4);
@@ -57,7 +59,14 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
57
59
  var InterceptorManager = __webpack_require__(6);
58
60
 
59
61
  // Polyfill ES6 Promise if needed
60
- __webpack_require__(9).polyfill();
62
+ (function () {
63
+ // webpack is being used to set es6-promise to the native Promise
64
+ // for the standalone build. It's necessary to make sure polyfill exists.
65
+ var P = __webpack_require__(9);
66
+ if (P && typeof P.polyfill === 'function') {
67
+ P.polyfill();
68
+ }
69
+ })();
61
70
 
62
71
  var axios = module.exports = function axios(config) {
63
72
  config = utils.merge({
@@ -125,32 +134,33 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
125
134
  };
126
135
 
127
136
  // Provide aliases for supported request methods
128
- createShortMethods('delete', 'get', 'head');
129
- createShortMethodsWithData('post', 'put', 'patch');
130
-
131
- function createShortMethods() {
132
- utils.forEach(arguments, function (method) {
133
- axios[method] = function (url, config) {
134
- return axios(utils.merge(config || {}, {
135
- method: method,
136
- url: url
137
- }));
138
- };
139
- });
140
- }
137
+ (function () {
138
+ function createShortMethods() {
139
+ utils.forEach(arguments, function (method) {
140
+ axios[method] = function (url, config) {
141
+ return axios(utils.merge(config || {}, {
142
+ method: method,
143
+ url: url
144
+ }));
145
+ };
146
+ });
147
+ }
141
148
 
142
- function createShortMethodsWithData() {
143
- utils.forEach(arguments, function (method) {
144
- axios[method] = function (url, data, config) {
145
- return axios(utils.merge(config || {}, {
146
- method: method,
147
- url: url,
148
- data: data
149
- }));
150
- };
151
- });
152
- }
149
+ function createShortMethodsWithData() {
150
+ utils.forEach(arguments, function (method) {
151
+ axios[method] = function (url, data, config) {
152
+ return axios(utils.merge(config || {}, {
153
+ method: method,
154
+ url: url,
155
+ data: data
156
+ }));
157
+ };
158
+ });
159
+ }
153
160
 
161
+ createShortMethods('delete', 'get', 'head');
162
+ createShortMethodsWithData('post', 'put', 'patch');
163
+ })();
154
164
 
155
165
 
156
166
  /***/ },
@@ -161,8 +171,6 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
161
171
 
162
172
  var utils = __webpack_require__(3);
163
173
 
164
- var JSON_START = /^\s*(\[|\{[^\{])/;
165
- var JSON_END = /[\}\]]\s*$/;
166
174
  var PROTECTION_PREFIX = /^\)\]\}',?\n/;
167
175
  var DEFAULT_CONTENT_TYPE = {
168
176
  'Content-Type': 'application/x-www-form-urlencoded'
@@ -170,6 +178,9 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
170
178
 
171
179
  module.exports = {
172
180
  transformRequest: [function (data, headers) {
181
+ if(utils.isFormData(data)) {
182
+ return data;
183
+ }
173
184
  if (utils.isArrayBuffer(data)) {
174
185
  return data;
175
186
  }
@@ -189,9 +200,9 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
189
200
  transformResponse: [function (data) {
190
201
  if (typeof data === 'string') {
191
202
  data = data.replace(PROTECTION_PREFIX, '');
192
- if (JSON_START.test(data) && JSON_END.test(data)) {
203
+ try {
193
204
  data = JSON.parse(data);
194
- }
205
+ } catch (e) {}
195
206
  }
196
207
  return data;
197
208
  }],
@@ -209,10 +220,15 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
209
220
  xsrfHeaderName: 'X-XSRF-TOKEN'
210
221
  };
211
222
 
223
+
212
224
  /***/ },
213
225
  /* 3 */
214
226
  /***/ function(module, exports, __webpack_require__) {
215
227
 
228
+ 'use strict';
229
+
230
+ /*global toString:true*/
231
+
216
232
  // utils is a library of generic helper functions non-specific to axios
217
233
 
218
234
  var toString = Object.prototype.toString;
@@ -360,16 +376,16 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
360
376
  }
361
377
 
362
378
  // Check if obj is array-like
363
- var isArray = obj.constructor === Array || typeof obj.callee === 'function';
379
+ var isArrayLike = isArray(obj) || (typeof obj === 'object' && !isNaN(obj.length));
364
380
 
365
381
  // Force an array if not already something iterable
366
- if (typeof obj !== 'object' && !isArray) {
382
+ if (typeof obj !== 'object' && !isArrayLike) {
367
383
  obj = [obj];
368
384
  }
369
385
 
370
386
  // Iterate over array values
371
- if (isArray) {
372
- for (var i=0, l=obj.length; i<l; i++) {
387
+ if (isArrayLike) {
388
+ for (var i = 0, l = obj.length; i < l; i++) {
373
389
  fn.call(null, obj[i], i, obj);
374
390
  }
375
391
  }
@@ -400,7 +416,7 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
400
416
  * @param {Object} obj1 Object to merge
401
417
  * @returns {Object} Result of all merge properties
402
418
  */
403
- function merge(obj1/*, obj2, obj3, ...*/) {
419
+ function merge(/*obj1, obj2, obj3, ...*/) {
404
420
  var result = {};
405
421
  forEach(arguments, function (obj) {
406
422
  forEach(obj, function (val, key) {
@@ -427,6 +443,7 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
427
443
  trim: trim
428
444
  };
429
445
 
446
+
430
447
  /***/ },
431
448
  /* 4 */
432
449
  /***/ function(module, exports, __webpack_require__) {
@@ -461,8 +478,6 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
461
478
 
462
479
  /* WEBPACK VAR INJECTION */(function(process) {'use strict';
463
480
 
464
- var Promise = __webpack_require__(9).Promise;
465
-
466
481
  /**
467
482
  * Dispatch a request to the server using whichever adapter
468
483
  * is supported by the current environment.
@@ -500,7 +515,7 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
500
515
 
501
516
  function InterceptorManager() {
502
517
  this.handlers = [];
503
- };
518
+ }
504
519
 
505
520
  /**
506
521
  * Add a new interceptor to the stack
@@ -541,18 +556,19 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
541
556
  utils.forEach(this.handlers, function (h) {
542
557
  if (h !== null) {
543
558
  fn(h);
544
- }
559
+ }
545
560
  });
546
561
  };
547
562
 
548
563
  module.exports = InterceptorManager;
549
-
550
564
 
551
565
 
552
566
  /***/ },
553
567
  /* 7 */
554
568
  /***/ function(module, exports, __webpack_require__) {
555
569
 
570
+ 'use strict';
571
+
556
572
  /**
557
573
  * Syntactic sugar for invoking a function and expanding an array for arguments.
558
574
  *
@@ -579,10 +595,15 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
579
595
  };
580
596
  };
581
597
 
598
+
582
599
  /***/ },
583
600
  /* 8 */
584
601
  /***/ function(module, exports, __webpack_require__) {
585
602
 
603
+ 'use strict';
604
+
605
+ /*global ActiveXObject:true*/
606
+
586
607
  var defaults = __webpack_require__(2);
587
608
  var utils = __webpack_require__(3);
588
609
  var buildUrl = __webpack_require__(11);
@@ -600,40 +621,42 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
600
621
  );
601
622
 
602
623
  // Merge headers
603
- var headers = utils.merge(
624
+ var requestHeaders = utils.merge(
604
625
  defaults.headers.common,
605
626
  defaults.headers[config.method] || {},
606
627
  config.headers || {}
607
628
  );
608
629
 
609
630
  if (utils.isFormData(data)) {
610
- delete headers['Content-Type']; // Let the browser set it
631
+ delete requestHeaders['Content-Type']; // Let the browser set it
611
632
  }
612
633
 
613
634
  // Create the request
614
- var request = new(XMLHttpRequest || ActiveXObject)('Microsoft.XMLHTTP');
635
+ var request = new (XMLHttpRequest || ActiveXObject)('Microsoft.XMLHTTP');
615
636
  request.open(config.method.toUpperCase(), buildUrl(config.url, config.params), true);
616
637
 
617
638
  // Listen for ready state
618
639
  request.onreadystatechange = function () {
619
640
  if (request && request.readyState === 4) {
620
641
  // Prepare the response
621
- var headers = parseHeaders(request.getAllResponseHeaders());
642
+ var responseHeaders = parseHeaders(request.getAllResponseHeaders());
643
+ var responseData = ['text', ''].indexOf(config.responseType || '') !== -1 ? request.responseText : request.response;
622
644
  var response = {
623
645
  data: transformData(
624
- request.responseText,
625
- headers,
646
+ responseData,
647
+ responseHeaders,
626
648
  config.transformResponse
627
649
  ),
628
650
  status: request.status,
629
- headers: headers,
651
+ statusText: request.statusText,
652
+ headers: responseHeaders,
630
653
  config: config
631
654
  };
632
655
 
633
656
  // Resolve or reject the Promise based on the status
634
- (request.status >= 200 && request.status < 300
635
- ? resolve
636
- : reject)(response);
657
+ (request.status >= 200 && request.status < 300 ?
658
+ resolve :
659
+ reject)(response);
637
660
 
638
661
  // Clean up request
639
662
  request = null;
@@ -641,18 +664,18 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
641
664
  };
642
665
 
643
666
  // Add xsrf header
644
- var xsrfValue = urlIsSameOrigin(config.url)
645
- ? cookies.read(config.xsrfCookieName || defaults.xsrfCookieName)
646
- : undefined;
667
+ var xsrfValue = urlIsSameOrigin(config.url) ?
668
+ cookies.read(config.xsrfCookieName || defaults.xsrfCookieName) :
669
+ undefined;
647
670
  if (xsrfValue) {
648
- headers[config.xsrfHeaderName || defaults.xsrfHeaderName] = xsrfValue;
671
+ requestHeaders[config.xsrfHeaderName || defaults.xsrfHeaderName] = xsrfValue;
649
672
  }
650
673
 
651
674
  // Add headers to the request
652
- utils.forEach(headers, function (val, key) {
675
+ utils.forEach(requestHeaders, function (val, key) {
653
676
  // Remove Content-Type if data is undefined
654
677
  if (!data && key.toLowerCase() === 'content-type') {
655
- delete headers[key];
678
+ delete requestHeaders[key];
656
679
  }
657
680
  // Otherwise add header to the request
658
681
  else {
@@ -684,6 +707,7 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
684
707
  request.send(data);
685
708
  };
686
709
 
710
+
687
711
  /***/ },
688
712
  /* 9 */
689
713
  /***/ function(module, exports, __webpack_require__) {
@@ -1657,69 +1681,40 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
1657
1681
  // shim for using process in browser
1658
1682
 
1659
1683
  var process = module.exports = {};
1684
+ var queue = [];
1685
+ var draining = false;
1660
1686
 
1661
- process.nextTick = (function () {
1662
- var canSetImmediate = typeof window !== 'undefined'
1663
- && window.setImmediate;
1664
- var canMutationObserver = typeof window !== 'undefined'
1665
- && window.MutationObserver;
1666
- var canPost = typeof window !== 'undefined'
1667
- && window.postMessage && window.addEventListener
1668
- ;
1669
-
1670
- if (canSetImmediate) {
1671
- return function (f) { return window.setImmediate(f) };
1687
+ function drainQueue() {
1688
+ if (draining) {
1689
+ return;
1672
1690
  }
1673
-
1674
- var queue = [];
1675
-
1676
- if (canMutationObserver) {
1677
- var hiddenDiv = document.createElement("div");
1678
- var observer = new MutationObserver(function () {
1679
- var queueList = queue.slice();
1680
- queue.length = 0;
1681
- queueList.forEach(function (fn) {
1682
- fn();
1683
- });
1684
- });
1685
-
1686
- observer.observe(hiddenDiv, { attributes: true });
1687
-
1688
- return function nextTick(fn) {
1689
- if (!queue.length) {
1690
- hiddenDiv.setAttribute('yes', 'no');
1691
- }
1692
- queue.push(fn);
1693
- };
1691
+ draining = true;
1692
+ var currentQueue;
1693
+ var len = queue.length;
1694
+ while(len) {
1695
+ currentQueue = queue;
1696
+ queue = [];
1697
+ var i = -1;
1698
+ while (++i < len) {
1699
+ currentQueue[i]();
1700
+ }
1701
+ len = queue.length;
1694
1702
  }
1695
-
1696
- if (canPost) {
1697
- window.addEventListener('message', function (ev) {
1698
- var source = ev.source;
1699
- if ((source === window || source === null) && ev.data === 'process-tick') {
1700
- ev.stopPropagation();
1701
- if (queue.length > 0) {
1702
- var fn = queue.shift();
1703
- fn();
1704
- }
1705
- }
1706
- }, true);
1707
-
1708
- return function nextTick(fn) {
1709
- queue.push(fn);
1710
- window.postMessage('process-tick', '*');
1711
- };
1703
+ draining = false;
1704
+ }
1705
+ process.nextTick = function (fun) {
1706
+ queue.push(fun);
1707
+ if (!draining) {
1708
+ setTimeout(drainQueue, 0);
1712
1709
  }
1713
-
1714
- return function nextTick(fn) {
1715
- setTimeout(fn, 0);
1716
- };
1717
- })();
1710
+ };
1718
1711
 
1719
1712
  process.title = 'browser';
1720
1713
  process.browser = true;
1721
1714
  process.env = {};
1722
1715
  process.argv = [];
1716
+ process.version = ''; // empty string to avoid regexp issues
1717
+ process.versions = {};
1723
1718
 
1724
1719
  function noop() {}
1725
1720
 
@@ -1740,6 +1735,7 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
1740
1735
  process.chdir = function (dir) {
1741
1736
  throw new Error('process.chdir is not supported');
1742
1737
  };
1738
+ process.umask = function() { return 0; };
1743
1739
 
1744
1740
 
1745
1741
  /***/ },
@@ -1842,6 +1838,7 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
1842
1838
  }
1843
1839
  };
1844
1840
 
1841
+
1845
1842
  /***/ },
1846
1843
  /* 13 */
1847
1844
  /***/ function(module, exports, __webpack_require__) {
@@ -1866,7 +1863,7 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
1866
1863
  module.exports = function parseHeaders(headers) {
1867
1864
  var parsed = {}, key, val, i;
1868
1865
 
1869
- if (!headers) return parsed;
1866
+ if (!headers) { return parsed; }
1870
1867
 
1871
1868
  utils.forEach(headers.split('\n'), function(line) {
1872
1869
  i = line.indexOf(':');
@@ -1881,6 +1878,7 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
1881
1878
  return parsed;
1882
1879
  };
1883
1880
 
1881
+
1884
1882
  /***/ },
1885
1883
  /* 14 */
1886
1884
  /***/ function(module, exports, __webpack_require__) {
@@ -1905,16 +1903,17 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
1905
1903
  return data;
1906
1904
  };
1907
1905
 
1906
+
1908
1907
  /***/ },
1909
1908
  /* 15 */
1910
1909
  /***/ function(module, exports, __webpack_require__) {
1911
1910
 
1912
1911
  'use strict';
1913
1912
 
1914
- var msie = /(msie|trident)/i.test(navigator.userAgent);
1915
1913
  var utils = __webpack_require__(3);
1914
+ var msie = /(msie|trident)/i.test(navigator.userAgent);
1916
1915
  var urlParsingNode = document.createElement('a');
1917
- var originUrl = urlResolve(window.location.href);
1916
+ var originUrl;
1918
1917
 
1919
1918
  /**
1920
1919
  * Parse a URL to discover it's components
@@ -1942,12 +1941,14 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
1942
1941
  hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
1943
1942
  hostname: urlParsingNode.hostname,
1944
1943
  port: urlParsingNode.port,
1945
- pathname: (urlParsingNode.pathname.charAt(0) === '/')
1946
- ? urlParsingNode.pathname
1947
- : '/' + urlParsingNode.pathname
1944
+ pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
1945
+ urlParsingNode.pathname :
1946
+ '/' + urlParsingNode.pathname
1948
1947
  };
1949
1948
  }
1950
1949
 
1950
+ originUrl = urlResolve(window.location.href);
1951
+
1951
1952
  /**
1952
1953
  * Determine if a URL shares the same origin as the current location
1953
1954
  *
@@ -1960,6 +1961,7 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
1960
1961
  parsed.host === originUrl.host);
1961
1962
  };
1962
1963
 
1964
+
1963
1965
  /***/ },
1964
1966
  /* 16 */
1965
1967
  /***/ function(module, exports, __webpack_require__) {
@@ -1984,5 +1986,5 @@ define("axios", [], function() { return /******/ (function(modules) { // webpack
1984
1986
 
1985
1987
 
1986
1988
  /***/ }
1987
- /******/ ])});
1989
+ /******/ ])});;
1988
1990
  //# sourceMappingURL=axios.amd.map