d976fd7d213b537419368386aefd3555d3f1119685adb79235f3de4cd11757c26336d3b70623cb11ced31214c20ab04aa727488686abc6a769dfb3503dc28c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. var utils = require('./utils');
  3. var bind = require('./helpers/bind');
  4. var Axios = require('./core/Axios');
  5. var mergeConfig = require('./core/mergeConfig');
  6. var defaults = require('./defaults');
  7. var formDataToJSON = require('./helpers/formDataToJSON');
  8. /**
  9. * Create an instance of Axios
  10. *
  11. * @param {Object} defaultConfig The default config for the instance
  12. * @return {Axios} A new instance of Axios
  13. */
  14. function createInstance(defaultConfig) {
  15. var context = new Axios(defaultConfig);
  16. var instance = bind(Axios.prototype.request, context);
  17. // Copy axios.prototype to instance
  18. utils.extend(instance, Axios.prototype, context);
  19. // Copy context to instance
  20. utils.extend(instance, context);
  21. // Factory for creating new instances
  22. instance.create = function create(instanceConfig) {
  23. return createInstance(mergeConfig(defaultConfig, instanceConfig));
  24. };
  25. return instance;
  26. }
  27. // Create the default instance to be exported
  28. var axios = createInstance(defaults);
  29. // Expose Axios class to allow class inheritance
  30. axios.Axios = Axios;
  31. // Expose Cancel & CancelToken
  32. axios.CanceledError = require('./cancel/CanceledError');
  33. axios.CancelToken = require('./cancel/CancelToken');
  34. axios.isCancel = require('./cancel/isCancel');
  35. axios.VERSION = require('./env/data').version;
  36. axios.toFormData = require('./helpers/toFormData');
  37. // Expose AxiosError class
  38. axios.AxiosError = require('../lib/core/AxiosError');
  39. // alias for CanceledError for backward compatibility
  40. axios.Cancel = axios.CanceledError;
  41. // Expose all/spread
  42. axios.all = function all(promises) {
  43. return Promise.all(promises);
  44. };
  45. axios.spread = require('./helpers/spread');
  46. // Expose isAxiosError
  47. axios.isAxiosError = require('./helpers/isAxiosError');
  48. axios.formToJSON = function(thing) {
  49. return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
  50. };
  51. module.exports = axios;
  52. // Allow use of default import syntax in TypeScript
  53. module.exports.default = axios;