moxios.js 32.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("axios"));
	else if(typeof define === 'function' && define.amd)
		define(["axios"], factory);
	else if(typeof exports === 'object')
		exports["moxios"] = factory(require("axios"));
	else
		root["moxios"] = factory(root["axios"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;
/******/
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	
	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	
	var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
	
	var _axios = __webpack_require__(1);
	
	var _axios2 = _interopRequireDefault(_axios);
	
	var _buildURL = __webpack_require__(2);
	
	var _buildURL2 = _interopRequireDefault(_buildURL);
	
	var _isURLSameOrigin = __webpack_require__(5);
	
	var _isURLSameOrigin2 = _interopRequireDefault(_isURLSameOrigin);
	
	var _btoa = __webpack_require__(6);
	
	var _btoa2 = _interopRequireDefault(_btoa);
	
	var _cookies = __webpack_require__(7);
	
	var _cookies2 = _interopRequireDefault(_cookies);
	
	var _settle = __webpack_require__(8);
	
	var _settle2 = _interopRequireDefault(_settle);
	
	var _createError = __webpack_require__(9);
	
	var _createError2 = _interopRequireDefault(_createError);
	
	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
	
	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
	
	var TimeoutException = new Error('Timeout: Stub function not called.');
	var DEFAULT_WAIT_DELAY = 100;
	
	// The default adapter
	var defaultAdapter = void 0;
	
	/**
	 * The mock adapter that gets installed.
	 *
	 * @param {Function} resolve The function to call when Promise is resolved
	 * @param {Function} reject The function to call when Promise is rejected
	 * @param {Object} config The config object to be used for the request
	 */
	var mockAdapter = function mockAdapter(config) {
	  return new Promise(function (resolve, reject) {
	    var request = new Request(resolve, reject, config);
	    moxios.requests.track(request);
	
	    // Check for matching stub to auto respond with
	    for (var i = 0, l = moxios.stubs.count(); i < l; i++) {
	      var stub = moxios.stubs.at(i);
	      var correctURL = stub.url instanceof RegExp ? stub.url.test(request.url) : stub.url === request.url;
	      var correctMethod = true;
	
	      if (stub.method !== undefined) {
	        correctMethod = stub.method.toLowerCase() === request.config.method.toLowerCase();
	      }
	
	      if (correctURL && correctMethod) {
	        if (stub.timeout) {
	          throwTimeout(config);
	        }
	        request.respondWith(stub.response);
	        stub.resolve();
	        break;
	      }
	    }
	  });
	};
	
	/**
	 * create common object for timeout response
	 *
	 * @param {object} config The config object to be used for the request
	 */
	var createTimeout = function createTimeout(config) {
	  return (0, _createError2.default)('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED');
	};
	
	/**
	 * throw common error for timeout response
	 *
	 * @param {object} config The config object to be used for the request
	 */
	var throwTimeout = function throwTimeout(config) {
	  throw createTimeout(config);
	};
	
	var Tracker = function () {
	  function Tracker() {
	    _classCallCheck(this, Tracker);
	
	    this.__items = [];
	  }
	
	  /**
	   * Reset all the items being tracked
	   */
	
	
	  _createClass(Tracker, [{
	    key: 'reset',
	    value: function reset() {
	      this.__items.splice(0);
	    }
	
	    /**
	     * Add an item to be tracked
	     *
	     * @param {Object} item An item to be tracked
	     */
	
	  }, {
	    key: 'track',
	    value: function track(item) {
	      this.__items.push(item);
	    }
	
	    /**
	     * The count of items being tracked
	     *
	     * @return {Number}
	     */
	
	  }, {
	    key: 'count',
	    value: function count() {
	      return this.__items.length;
	    }
	
	    /**
	     * Get an item being tracked at a given index
	     *
	     * @param {Number} index The index for the item to retrieve
	     * @return {Object}
	     */
	
	  }, {
	    key: 'at',
	    value: function at(index) {
	      return this.__items[index];
	    }
	
	    /**
	     * Get the first item being tracked
	     *
	     * @return {Object}
	     */
	
	  }, {
	    key: 'first',
	    value: function first() {
	      return this.at(0);
	    }
	
	    /**
	     * Get the most recent (last) item being tracked
	     *
	     * @return {Object}
	     */
	
	  }, {
	    key: 'mostRecent',
	    value: function mostRecent() {
	      return this.at(this.count() - 1);
	    }
	
	    /**
	     * Dump the items being tracked to the console.
	     */
	
	  }, {
	    key: 'debug',
	    value: function debug() {
	      console.log();
	      this.__items.forEach(function (element) {
	        var output = void 0;
	
	        if (element.config) {
	          // request
	          output = element.config.method.toLowerCase() + ', ';
	          output += element.config.url;
	        } else {
	          // stub
	          output = element.method.toLowerCase() + ', ';
	          output += element.url + ', ';
	          output += element.response.status + ', ';
	
	          if (element.response.response) {
	            output += JSON.stringify(element.response.response);
	          } else {
	            output += '{}';
	          }
	        }
	        console.log(output);
	      });
	    }
	
	    /**
	     * Find and return element given the HTTP method and the URL.
	     */
	
	  }, {
	    key: 'get',
	    value: function get(method, url) {
	      function getElem(element, index, array) {
	        var matchedUrl = element.url instanceof RegExp ? element.url.test(element.url) : element.url === url;
	        var matchedMethod = void 0;
	
	        if (element.config) {
	          // request tracking
	          matchedMethod = method.toLowerCase() === element.config.method.toLowerCase();
	        } else {
	          // stub tracking
	          matchedMethod = method.toLowerCase() === element.method.toLowerCase();
	        }
	
	        if (matchedUrl && matchedMethod) {
	          return element;
	        }
	      }
	
	      return this.__items.find(getElem);
	    }
	
	    /**
	     * Stop an element from being tracked by removing it. Finds and returns the element,
	     * given the HTTP method and the URL.
	     */
	
	  }, {
	    key: 'remove',
	    value: function remove(method, url) {
	      var elem = this.get(method, url);
	      var index = this.__items.indexOf(elem);
	
	      return this.__items.splice(index, 1)[0];
	    }
	  }]);
	
	  return Tracker;
	}();
	
	var Request = function () {
	  /**
	   * Create a new Request object
	   *
	   * @param {Function} resolve The function to call when Promise is resolved
	   * @param {Function} reject The function to call when Promise is rejected
	   * @param {Object} config The config object to be used for the request
	   */
	
	  function Request(resolve, reject, config) {
	    _classCallCheck(this, Request);
	
	    this.resolve = resolve;
	    this.reject = reject;
	    this.config = config;
	
	    this.headers = config.headers;
	    this.url = (0, _buildURL2.default)(config.url, config.params, config.paramsSerializer);
	    this.timeout = config.timeout;
	    this.withCredentials = config.withCredentials || false;
	    this.responseType = config.responseType;
	
	    // Set auth header
	    if (config.auth) {
	      var username = config.auth.username || '';
	      var password = config.auth.password || '';
	      this.headers.Authorization = 'Basic ' + (0, _btoa2.default)(username + ':' + password);
	    }
	
	    // Set xsrf header
	    if (typeof document !== 'undefined' && typeof document.cookie !== 'undefined') {
	      var xsrfValue = config.withCredentials || (0, _isURLSameOrigin2.default)(config.url) ? _cookies2.default.read(config.xsrfCookieName) : undefined;
	
	      if (xsrfValue) {
	        this.headers[config.xsrfHeaderName] = xsrfValue;
	      }
	    }
	  }
	
	  /**
	   * Respond to this request with a timeout result
	   *
	   * @return {Promise} A Promise that rejects with a timeout result
	   */
	
	
	  _createClass(Request, [{
	    key: 'respondWithTimeout',
	    value: function respondWithTimeout() {
	      var response = new Response(this, createTimeout(this.config));
	      (0, _settle2.default)(this.resolve, this.reject, response);
	      return new Promise(function (resolve, reject) {
	        moxios.wait(function () {
	          reject(response);
	        });
	      });
	    }
	
	    /**
	     * Respond to this request with a specified result
	     *
	     * @param {Object} res The data representing the result of the request
	     * @return {Promise} A Promise that resolves once the response is ready
	     */
	
	  }, {
	    key: 'respondWith',
	    value: function respondWith(res) {
	      var response = new Response(this, res);
	      (0, _settle2.default)(this.resolve, this.reject, response);
	      return new Promise(function (resolve) {
	        moxios.wait(function () {
	          resolve(response);
	        });
	      });
	    }
	  }]);
	
	  return Request;
	}();
	
	var Response =
	/**
	 * Create a new Response object
	 *
	 * @param {Request} req The Request that this Response is associated with
	 * @param {Object} res The data representing the result of the request
	 */
	function Response(req, res) {
	  _classCallCheck(this, Response);
	
	  this.config = req.config;
	  this.data = res.responseText || res.response;
	  this.status = res.status;
	  this.statusText = res.statusText;
	
	  /* lowecase all headers keys to be consistent with Axios */
	  if ('headers' in res) {
	    var newHeaders = {};
	    for (var header in res.headers) {
	      newHeaders[header.toLowerCase()] = res.headers[header];
	    }
	    res.headers = newHeaders;
	  }
	  this.headers = res.headers;
	  this.request = req;
	  this.code = res.code;
	};
	
	var moxios = {
	  stubs: new Tracker(),
	  requests: new Tracker(),
	  delay: DEFAULT_WAIT_DELAY,
	  timeoutException: TimeoutException,
	
	  /**
	   * Install the mock adapter for axios
	   */
	  install: function install() {
	    var instance = arguments.length <= 0 || arguments[0] === undefined ? _axios2.default : arguments[0];
	
	    defaultAdapter = instance.defaults.adapter;
	    instance.defaults.adapter = mockAdapter;
	  },
	
	  /**
	   * Uninstall the mock adapter and reset state
	   */
	  uninstall: function uninstall() {
	    var instance = arguments.length <= 0 || arguments[0] === undefined ? _axios2.default : arguments[0];
	
	    instance.defaults.adapter = defaultAdapter;
	    this.stubs.reset();
	    this.requests.reset();
	  },
	
	  /**
	   * Stub a response to be used to respond to a request matching a method and a URL or RegExp
	   *
	   * @param {String} method An axios command
	   * @param {String|RegExp} urlOrRegExp A URL or RegExp to test against
	   * @param {Object} response The response to use when a match is made
	   */
	  stubRequest: function stubRequest(urlOrRegExp, response) {
	    this.stubs.track({ url: urlOrRegExp, response: response });
	  },
	
	  /**
	   * Stub a response to be used one or more times to respond to a request matching a
	   * method and a URL or RegExp.
	   *
	   * @param {String} method An axios command
	   * @param {String|RegExp} urlOrRegExp A URL or RegExp to test against
	   * @param {Object} response The response to use when a match is made
	   */
	  stubOnce: function stubOnce(method, urlOrRegExp, response) {
	    var _this = this;
	
	    return new Promise(function (resolve) {
	      _this.stubs.track({ url: urlOrRegExp, method: method, response: response, resolve: resolve });
	    });
	  },
	
	  /**
	   * Stub a timed response to a request matching a method and a URL or RegExp. If
	   * timer fires, reject with a TimeoutException for simple assertions. The goal is
	   * to show that a certain request was not made.
	   *
	   * @param {String} method An axios command
	   * @param {String|RegExp} urlOrRegExp A URL or RegExp to test against
	   * @param {Object} response The response to use when a match is made
	   */
	  stubFailure: function stubFailure(method, urlOrRegExp, response) {
	    var _this2 = this;
	
	    return new Promise(function (resolve, reject) {
	      _this2.stubs.track({ url: urlOrRegExp, method: method, response: response, resolve: resolve });
	      setTimeout(function () {
	        reject(TimeoutException);
	      }, 500);
	    });
	  },
	
	  /**
	   * Stub a timeout to be used to respond to a request matching a URL or RegExp
	   *
	   * @param {String|RegExp} urlOrRegExp A URL or RegExp to test against
	   */
	  stubTimeout: function stubTimeout(urlOrRegExp) {
	    this.stubs.track({ url: urlOrRegExp, timeout: true });
	  },
	
	  /**
	   * Run a single test with mock adapter installed.
	   * This will install the mock adapter, execute the function provided,
	   * then uninstall the mock adapter once complete.
	   *
	   * @param {Function} fn The function to be executed
	   */
	  withMock: function withMock(fn) {
	    this.install();
	    try {
	      fn();
	    } finally {
	      this.uninstall();
	    }
	  },
	
	  /**
	   * Wait for request to be made before proceding.
	   * This is naively using a `setTimeout`.
	   * May need to beef this up a bit in the future.
	   *
	   * @param {Function} fn The function to execute once waiting is over
	   * @param {Number} delay How much time in milliseconds to wait
	   */
	  wait: function wait(fn) {
	    var delay = arguments.length <= 1 || arguments[1] === undefined ? this.delay : arguments[1];
	
	    setTimeout(fn, delay);
	  }
	};
	
	exports.default = moxios;
	module.exports = exports['default'];

/***/ },
/* 1 */
/***/ function(module, exports) {

	module.exports = __WEBPACK_EXTERNAL_MODULE_1__;

/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	
	var utils = __webpack_require__(3);
	
	function encode(val) {
	  return encodeURIComponent(val).
	    replace(/%40/gi, '@').
	    replace(/%3A/gi, ':').
	    replace(/%24/g, '$').
	    replace(/%2C/gi, ',').
	    replace(/%20/g, '+').
	    replace(/%5B/gi, '[').
	    replace(/%5D/gi, ']');
	}
	
	/**
	 * Build a URL by appending params to the end
	 *
	 * @param {string} url The base of the url (e.g., http://www.google.com)
	 * @param {object} [params] The params to be appended
	 * @returns {string} The formatted url
	 */
	module.exports = function buildURL(url, params, paramsSerializer) {
	  /*eslint no-param-reassign:0*/
	  if (!params) {
	    return url;
	  }
	
	  var serializedParams;
	  if (paramsSerializer) {
	    serializedParams = paramsSerializer(params);
	  } else if (utils.isURLSearchParams(params)) {
	    serializedParams = params.toString();
	  } else {
	    var parts = [];
	
	    utils.forEach(params, function serialize(val, key) {
	      if (val === null || typeof val === 'undefined') {
	        return;
	      }
	
	      if (utils.isArray(val)) {
	        key = key + '[]';
	      }
	
	      if (!utils.isArray(val)) {
	        val = [val];
	      }
	
	      utils.forEach(val, function parseValue(v) {
	        if (utils.isDate(v)) {
	          v = v.toISOString();
	        } else if (utils.isObject(v)) {
	          v = JSON.stringify(v);
	        }
	        parts.push(encode(key) + '=' + encode(v));
	      });
	    });
	
	    serializedParams = parts.join('&');
	  }
	
	  if (serializedParams) {
	    url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
	  }
	
	  return url;
	};


/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	
	var bind = __webpack_require__(4);
	
	/*global toString:true*/
	
	// utils is a library of generic helper functions non-specific to axios
	
	var toString = Object.prototype.toString;
	
	/**
	 * Determine if a value is an Array
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is an Array, otherwise false
	 */
	function isArray(val) {
	  return toString.call(val) === '[object Array]';
	}
	
	/**
	 * Determine if a value is an ArrayBuffer
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is an ArrayBuffer, otherwise false
	 */
	function isArrayBuffer(val) {
	  return toString.call(val) === '[object ArrayBuffer]';
	}
	
	/**
	 * Determine if a value is a FormData
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is an FormData, otherwise false
	 */
	function isFormData(val) {
	  return (typeof FormData !== 'undefined') && (val instanceof FormData);
	}
	
	/**
	 * Determine if a value is a view on an ArrayBuffer
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
	 */
	function isArrayBufferView(val) {
	  var result;
	  if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
	    result = ArrayBuffer.isView(val);
	  } else {
	    result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
	  }
	  return result;
	}
	
	/**
	 * Determine if a value is a String
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is a String, otherwise false
	 */
	function isString(val) {
	  return typeof val === 'string';
	}
	
	/**
	 * Determine if a value is a Number
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is a Number, otherwise false
	 */
	function isNumber(val) {
	  return typeof val === 'number';
	}
	
	/**
	 * Determine if a value is undefined
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if the value is undefined, otherwise false
	 */
	function isUndefined(val) {
	  return typeof val === 'undefined';
	}
	
	/**
	 * Determine if a value is an Object
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is an Object, otherwise false
	 */
	function isObject(val) {
	  return val !== null && typeof val === 'object';
	}
	
	/**
	 * Determine if a value is a Date
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is a Date, otherwise false
	 */
	function isDate(val) {
	  return toString.call(val) === '[object Date]';
	}
	
	/**
	 * Determine if a value is a File
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is a File, otherwise false
	 */
	function isFile(val) {
	  return toString.call(val) === '[object File]';
	}
	
	/**
	 * Determine if a value is a Blob
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is a Blob, otherwise false
	 */
	function isBlob(val) {
	  return toString.call(val) === '[object Blob]';
	}
	
	/**
	 * Determine if a value is a Function
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is a Function, otherwise false
	 */
	function isFunction(val) {
	  return toString.call(val) === '[object Function]';
	}
	
	/**
	 * Determine if a value is a Stream
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is a Stream, otherwise false
	 */
	function isStream(val) {
	  return isObject(val) && isFunction(val.pipe);
	}
	
	/**
	 * Determine if a value is a URLSearchParams object
	 *
	 * @param {Object} val The value to test
	 * @returns {boolean} True if value is a URLSearchParams object, otherwise false
	 */
	function isURLSearchParams(val) {
	  return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
	}
	
	/**
	 * Trim excess whitespace off the beginning and end of a string
	 *
	 * @param {String} str The String to trim
	 * @returns {String} The String freed of excess whitespace
	 */
	function trim(str) {
	  return str.replace(/^\s*/, '').replace(/\s*$/, '');
	}
	
	/**
	 * Determine if we're running in a standard browser environment
	 *
	 * This allows axios to run in a web worker, and react-native.
	 * Both environments support XMLHttpRequest, but not fully standard globals.
	 *
	 * web workers:
	 *  typeof window -> undefined
	 *  typeof document -> undefined
	 *
	 * react-native:
	 *  typeof document.createElement -> undefined
	 */
	function isStandardBrowserEnv() {
	  return (
	    typeof window !== 'undefined' &&
	    typeof document !== 'undefined' &&
	    typeof document.createElement === 'function'
	  );
	}
	
	/**
	 * Iterate over an Array or an Object invoking a function for each item.
	 *
	 * If `obj` is an Array callback will be called passing
	 * the value, index, and complete array for each item.
	 *
	 * If 'obj' is an Object callback will be called passing
	 * the value, key, and complete object for each property.
	 *
	 * @param {Object|Array} obj The object to iterate
	 * @param {Function} fn The callback to invoke for each item
	 */
	function forEach(obj, fn) {
	  // Don't bother if no value provided
	  if (obj === null || typeof obj === 'undefined') {
	    return;
	  }
	
	  // Force an array if not already something iterable
	  if (typeof obj !== 'object' && !isArray(obj)) {
	    /*eslint no-param-reassign:0*/
	    obj = [obj];
	  }
	
	  if (isArray(obj)) {
	    // Iterate over array values
	    for (var i = 0, l = obj.length; i < l; i++) {
	      fn.call(null, obj[i], i, obj);
	    }
	  } else {
	    // Iterate over object keys
	    for (var key in obj) {
	      if (obj.hasOwnProperty(key)) {
	        fn.call(null, obj[key], key, obj);
	      }
	    }
	  }
	}
	
	/**
	 * Accepts varargs expecting each argument to be an object, then
	 * immutably merges the properties of each object and returns result.
	 *
	 * When multiple objects contain the same key the later object in
	 * the arguments list will take precedence.
	 *
	 * Example:
	 *
	 * ```js
	 * var result = merge({foo: 123}, {foo: 456});
	 * console.log(result.foo); // outputs 456
	 * ```
	 *
	 * @param {Object} obj1 Object to merge
	 * @returns {Object} Result of all merge properties
	 */
	function merge(/* obj1, obj2, obj3, ... */) {
	  var result = {};
	  function assignValue(val, key) {
	    if (typeof result[key] === 'object' && typeof val === 'object') {
	      result[key] = merge(result[key], val);
	    } else {
	      result[key] = val;
	    }
	  }
	
	  for (var i = 0, l = arguments.length; i < l; i++) {
	    forEach(arguments[i], assignValue);
	  }
	  return result;
	}
	
	/**
	 * Extends object a by mutably adding to it the properties of object b.
	 *
	 * @param {Object} a The object to be extended
	 * @param {Object} b The object to copy properties from
	 * @param {Object} thisArg The object to bind function to
	 * @return {Object} The resulting value of object a
	 */
	function extend(a, b, thisArg) {
	  forEach(b, function assignValue(val, key) {
	    if (thisArg && typeof val === 'function') {
	      a[key] = bind(val, thisArg);
	    } else {
	      a[key] = val;
	    }
	  });
	  return a;
	}
	
	module.exports = {
	  isArray: isArray,
	  isArrayBuffer: isArrayBuffer,
	  isFormData: isFormData,
	  isArrayBufferView: isArrayBufferView,
	  isString: isString,
	  isNumber: isNumber,
	  isObject: isObject,
	  isUndefined: isUndefined,
	  isDate: isDate,
	  isFile: isFile,
	  isBlob: isBlob,
	  isFunction: isFunction,
	  isStream: isStream,
	  isURLSearchParams: isURLSearchParams,
	  isStandardBrowserEnv: isStandardBrowserEnv,
	  forEach: forEach,
	  merge: merge,
	  extend: extend,
	  trim: trim
	};


/***/ },
/* 4 */
/***/ function(module, exports) {

	'use strict';
	
	module.exports = function bind(fn, thisArg) {
	  return function wrap() {
	    var args = new Array(arguments.length);
	    for (var i = 0; i < args.length; i++) {
	      args[i] = arguments[i];
	    }
	    return fn.apply(thisArg, args);
	  };
	};


/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	
	var utils = __webpack_require__(3);
	
	module.exports = (
	  utils.isStandardBrowserEnv() ?
	
	  // Standard browser envs have full support of the APIs needed to test
	  // whether the request URL is of the same origin as current location.
	  (function standardBrowserEnv() {
	    var msie = /(msie|trident)/i.test(navigator.userAgent);
	    var urlParsingNode = document.createElement('a');
	    var originURL;
	
	    /**
	    * Parse a URL to discover it's components
	    *
	    * @param {String} url The URL to be parsed
	    * @returns {Object}
	    */
	    function resolveURL(url) {
	      var href = url;
	
	      if (msie) {
	        // IE needs attribute set twice to normalize properties
	        urlParsingNode.setAttribute('href', href);
	        href = urlParsingNode.href;
	      }
	
	      urlParsingNode.setAttribute('href', href);
	
	      // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
	      return {
	        href: urlParsingNode.href,
	        protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
	        host: urlParsingNode.host,
	        search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
	        hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
	        hostname: urlParsingNode.hostname,
	        port: urlParsingNode.port,
	        pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
	                  urlParsingNode.pathname :
	                  '/' + urlParsingNode.pathname
	      };
	    }
	
	    originURL = resolveURL(window.location.href);
	
	    /**
	    * Determine if a URL shares the same origin as the current location
	    *
	    * @param {String} requestURL The URL to test
	    * @returns {boolean} True if URL shares the same origin, otherwise false
	    */
	    return function isURLSameOrigin(requestURL) {
	      var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
	      return (parsed.protocol === originURL.protocol &&
	            parsed.host === originURL.host);
	    };
	  })() :
	
	  // Non standard browser envs (web workers, react-native) lack needed support.
	  (function nonStandardBrowserEnv() {
	    return function isURLSameOrigin() {
	      return true;
	    };
	  })()
	);


/***/ },
/* 6 */
/***/ function(module, exports) {

	'use strict';
	
	// btoa polyfill for IE<10 courtesy https://github.com/davidchambers/Base64.js
	
	var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
	
	function E() {
	  this.message = 'String contains an invalid character';
	}
	E.prototype = new Error;
	E.prototype.code = 5;
	E.prototype.name = 'InvalidCharacterError';
	
	function btoa(input) {
	  var str = String(input);
	  var output = '';
	  for (
	    // initialize result and counter
	    var block, charCode, idx = 0, map = chars;
	    // if the next str index does not exist:
	    //   change the mapping table to "="
	    //   check if d has no fractional digits
	    str.charAt(idx | 0) || (map = '=', idx % 1);
	    // "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
	    output += map.charAt(63 & block >> 8 - idx % 1 * 8)
	  ) {
	    charCode = str.charCodeAt(idx += 3 / 4);
	    if (charCode > 0xFF) {
	      throw new E();
	    }
	    block = block << 8 | charCode;
	  }
	  return output;
	}
	
	module.exports = btoa;


/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	
	var utils = __webpack_require__(3);
	
	module.exports = (
	  utils.isStandardBrowserEnv() ?
	
	  // Standard browser envs support document.cookie
	  (function standardBrowserEnv() {
	    return {
	      write: function write(name, value, expires, path, domain, secure) {
	        var cookie = [];
	        cookie.push(name + '=' + encodeURIComponent(value));
	
	        if (utils.isNumber(expires)) {
	          cookie.push('expires=' + new Date(expires).toGMTString());
	        }
	
	        if (utils.isString(path)) {
	          cookie.push('path=' + path);
	        }
	
	        if (utils.isString(domain)) {
	          cookie.push('domain=' + domain);
	        }
	
	        if (secure === true) {
	          cookie.push('secure');
	        }
	
	        document.cookie = cookie.join('; ');
	      },
	
	      read: function read(name) {
	        var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
	        return (match ? decodeURIComponent(match[3]) : null);
	      },
	
	      remove: function remove(name) {
	        this.write(name, '', Date.now() - 86400000);
	      }
	    };
	  })() :
	
	  // Non standard browser env (web workers, react-native) lack needed support.
	  (function nonStandardBrowserEnv() {
	    return {
	      write: function write() {},
	      read: function read() { return null; },
	      remove: function remove() {}
	    };
	  })()
	);


/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	
	var createError = __webpack_require__(9);
	
	/**
	 * Resolve or reject a Promise based on response status.
	 *
	 * @param {Function} resolve A function that resolves the promise.
	 * @param {Function} reject A function that rejects the promise.
	 * @param {object} response The response.
	 */
	module.exports = function settle(resolve, reject, response) {
	  var validateStatus = response.config.validateStatus;
	  // Note: status is not exposed by XDomainRequest
	  if (!response.status || !validateStatus || validateStatus(response.status)) {
	    resolve(response);
	  } else {
	    reject(createError(
	      'Request failed with status code ' + response.status,
	      response.config,
	      null,
	      response
	    ));
	  }
	};


/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	
	var enhanceError = __webpack_require__(10);
	
	/**
	 * Create an Error with the specified message, config, error code, and response.
	 *
	 * @param {string} message The error message.
	 * @param {Object} config The config.
	 * @param {string} [code] The error code (for example, 'ECONNABORTED').
	 @ @param {Object} [response] The response.
	 * @returns {Error} The created error.
	 */
	module.exports = function createError(message, config, code, response) {
	  var error = new Error(message);
	  return enhanceError(error, config, code, response);
	};


/***/ },
/* 10 */
/***/ function(module, exports) {

	'use strict';
	
	/**
	 * Update an Error with the specified config, error code, and response.
	 *
	 * @param {Error} error The error to update.
	 * @param {Object} config The config.
	 * @param {string} [code] The error code (for example, 'ECONNABORTED').
	 @ @param {Object} [response] The response.
	 * @returns {Error} The error.
	 */
	module.exports = function enhanceError(error, config, code, response) {
	  error.config = config;
	  if (code) {
	    error.code = code;
	  }
	  error.response = response;
	  return error;
	};


/***/ }
/******/ ])
});
;
//# sourceMappingURL=moxios.js.map