You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

4 years ago
  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. /**
  8. * Create an instance of Axios
  9. *
  10. * @param {Object} defaultConfig The default config for the instance
  11. * @return {Axios} A new instance of Axios
  12. */
  13. function createInstance(defaultConfig) {
  14. var context = new Axios(defaultConfig);
  15. var instance = bind(Axios.prototype.request, context);
  16. // Copy axios.prototype to instance
  17. utils.extend(instance, Axios.prototype, context);
  18. // Copy context to instance
  19. utils.extend(instance, context);
  20. return instance;
  21. }
  22. // Create the default instance to be exported
  23. var axios = createInstance(defaults);
  24. // Expose Axios class to allow class inheritance
  25. axios.Axios = Axios;
  26. // Factory for creating new instances
  27. axios.create = function create(instanceConfig) {
  28. return createInstance(mergeConfig(axios.defaults, instanceConfig));
  29. };
  30. // Expose Cancel & CancelToken
  31. axios.Cancel = require('./cancel/Cancel');
  32. axios.CancelToken = require('./cancel/CancelToken');
  33. axios.isCancel = require('./cancel/isCancel');
  34. // Expose all/spread
  35. axios.all = function all(promises) {
  36. return Promise.all(promises);
  37. };
  38. axios.spread = require('./helpers/spread');
  39. // Expose isAxiosError
  40. axios.isAxiosError = require('./helpers/isAxiosError');
  41. module.exports = axios;
  42. // Allow use of default import syntax in TypeScript
  43. module.exports.default = axios;