From eb9434a9b70c126f28de8d1658e21b01ed11bd23 Mon Sep 17 00:00:00 2001 From: Thomas Wang Date: Tue, 22 May 2018 18:24:04 -0700 Subject: [PATCH] add ponyfill --- assets/yetch-ponyfill.js | 206 +++++++++++++++++++++++++++++++++++++++ karma.conf.js | 2 +- 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 assets/yetch-ponyfill.js diff --git a/assets/yetch-ponyfill.js b/assets/yetch-ponyfill.js new file mode 100644 index 0000000..1a31638 --- /dev/null +++ b/assets/yetch-ponyfill.js @@ -0,0 +1,206 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else if(typeof exports === 'object') + exports["Yetch"] = factory(); + else + root["Yetch"] = factory(); +})(this, function() { +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] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = 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; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./node_modules/webpack/buildin/global.js": +/*!***********************************!*\ + !*** (webpack)/buildin/global.js ***! + \***********************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +eval("var g;\r\n\r\n// This works in non-strict mode\r\ng = (function() {\r\n\treturn this;\r\n})();\r\n\r\ntry {\r\n\t// This works if eval is allowed (see CSP)\r\n\tg = g || Function(\"return this\")() || (1, eval)(\"this\");\r\n} catch (e) {\r\n\t// This works if the window reference is available\r\n\tif (typeof window === \"object\") g = window;\r\n}\r\n\r\n// g can still be undefined, but nothing to do about it...\r\n// We return undefined, instead of nothing here, so it's\r\n// easier to handle this case. if(!global) { ...}\r\n\r\nmodule.exports = g;\r\n\n\n//# sourceURL=webpack://Yetch/(webpack)/buildin/global.js?"); + +/***/ }), + +/***/ "./src/index.js": +/*!**********************!*\ + !*** ./src/index.js ***! + \**********************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("exports.fetch = __webpack_require__(/*! ./internal/fetch */ \"./src/internal/fetch.js\").fetch\nexports.Headers = __webpack_require__(/*! ./internal/Headers */ \"./src/internal/Headers.js\").Headers\nexports.Request = __webpack_require__(/*! ./internal/Request */ \"./src/internal/Request.js\").Request\nexports.Response = __webpack_require__(/*! ./internal/Response */ \"./src/internal/Response.js\").Response\n\n\n//# sourceURL=webpack://Yetch/./src/index.js?"); + +/***/ }), + +/***/ "./src/internal/Body.js": +/*!******************************!*\ + !*** ./src/internal/Body.js ***! + \******************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("var support = __webpack_require__(/*! ./support */ \"./src/internal/support.js\").support\n\nvar viewClasses = [\n '[object Int8Array]',\n '[object Uint8Array]',\n '[object Uint8ClampedArray]',\n '[object Int16Array]',\n '[object Uint16Array]',\n '[object Int32Array]',\n '[object Uint32Array]',\n '[object Float32Array]',\n '[object Float64Array]'\n]\n\nvar isDataView = function (obj) {\n return obj && DataView.prototype.isPrototypeOf(obj)\n}\n\nvar isArrayBufferView = ArrayBuffer.isView || function (obj) {\n return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1\n}\n\nfunction consumed(body) {\n if (body.bodyUsed) {\n return Promise.reject(new TypeError('Already read'))\n }\n body.bodyUsed = true\n}\n\nfunction fileReaderReady(reader) {\n return new Promise(function (resolve, reject) {\n reader.onload = function () {\n resolve(reader.result)\n }\n reader.onerror = function () {\n reject(reader.error)\n }\n })\n}\n\nfunction readBlobAsArrayBuffer(blob) {\n var reader = new FileReader()\n var promise = fileReaderReady(reader)\n reader.readAsArrayBuffer(blob)\n return promise\n}\n\nfunction readBlobAsText(blob) {\n var reader = new FileReader()\n var promise = fileReaderReady(reader)\n reader.readAsText(blob)\n return promise\n}\n\nfunction readArrayBufferAsText(buf) {\n var view = new Uint8Array(buf)\n var chars = new Array(view.length)\n\n for (var i = 0; i < view.length; i++) {\n chars[i] = String.fromCharCode(view[i])\n }\n return chars.join('')\n}\n\nfunction bufferClone(buf) {\n if (buf.slice) {\n return buf.slice(0)\n } else {\n var view = new Uint8Array(buf.byteLength)\n view.set(new Uint8Array(buf))\n return view.buffer\n }\n}\n\nfunction decode(body) {\n var form = new FormData()\n body.trim().split('&').forEach(function (bytes) {\n if (bytes) {\n var split = bytes.split('=')\n var name = split.shift().replace(/\\+/g, ' ')\n var value = split.join('=').replace(/\\+/g, ' ')\n form.append(decodeURIComponent(name), decodeURIComponent(value))\n }\n })\n return form\n}\n\nfunction Body() {\n this.bodyUsed = false\n\n this._initBody = function (body) {\n this._bodyInit = body\n if (!body) {\n this._bodyText = ''\n } else if (typeof body === 'string') {\n this._bodyText = body\n } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {\n this._bodyBlob = body\n } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {\n this._bodyFormData = body\n } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {\n this._bodyText = body.toString()\n } else if (support.arrayBuffer && support.blob && isDataView(body)) {\n this._bodyArrayBuffer = bufferClone(body.buffer)\n // IE 10-11 can't handle a DataView body.\n this._bodyInit = new Blob([this._bodyArrayBuffer])\n } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {\n this._bodyArrayBuffer = bufferClone(body)\n } else {\n throw new Error('unsupported BodyInit type')\n }\n\n if (!this.headers.get('content-type')) {\n if (typeof body === 'string') {\n this.headers.set('content-type', 'text/plain;charset=UTF-8')\n } else if (this._bodyBlob && this._bodyBlob.type) {\n this.headers.set('content-type', this._bodyBlob.type)\n } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {\n this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8')\n }\n }\n }\n\n if (support.blob) {\n this.blob = function () {\n var rejected = consumed(this)\n if (rejected) {\n return rejected\n }\n\n if (this._bodyBlob) {\n return Promise.resolve(this._bodyBlob)\n } else if (this._bodyArrayBuffer) {\n return Promise.resolve(new Blob([this._bodyArrayBuffer]))\n } else if (this._bodyFormData) {\n throw new Error('could not read FormData body as blob')\n } else {\n return Promise.resolve(new Blob([this._bodyText]))\n }\n }\n\n this.arrayBuffer = function () {\n if (this._bodyArrayBuffer) {\n return consumed(this) || Promise.resolve(this._bodyArrayBuffer)\n } else {\n return this.blob().then(readBlobAsArrayBuffer)\n }\n }\n }\n\n this.text = function () {\n var rejected = consumed(this)\n if (rejected) {\n return rejected\n }\n\n if (this._bodyBlob) {\n return readBlobAsText(this._bodyBlob)\n } else if (this._bodyArrayBuffer) {\n return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))\n } else if (this._bodyFormData) {\n throw new Error('could not read FormData body as text')\n } else {\n return Promise.resolve(this._bodyText)\n }\n }\n\n if (support.formData) {\n this.formData = function () {\n return this.text().then(decode)\n }\n }\n\n this.json = function () {\n return this.text().then(JSON.parse)\n }\n\n return this\n}\n\nexports.Body = Body\n\n\n//# sourceURL=webpack://Yetch/./src/internal/Body.js?"); + +/***/ }), + +/***/ "./src/internal/DOMException.js": +/*!**************************************!*\ + !*** ./src/internal/DOMException.js ***! + \**************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("var root = __webpack_require__(/*! ./root */ \"./src/internal/root.js\").root\n\nvar DOMException = root.DOMException\ntry {\n new DOMException()\n} catch (err) {\n DOMException = function DOMException(message, name) {\n this.message = message\n this.name = name\n var error = Error(message)\n this.stack = error.stack\n }\n DOMException.prototype = Object.create(Error.prototype)\n DOMException.prototype.constructor = DOMException\n}\n\nexports.DOMException = DOMException\n\n\n//# sourceURL=webpack://Yetch/./src/internal/DOMException.js?"); + +/***/ }), + +/***/ "./src/internal/Headers.js": +/*!*********************************!*\ + !*** ./src/internal/Headers.js ***! + \*********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("var support = __webpack_require__(/*! ./support */ \"./src/internal/support.js\").support\n\nfunction normalizeName(name) {\n if (typeof name !== 'string') {\n name = String(name)\n }\n if (/[^a-z0-9\\-#$%&'*+.\\^_`|~]/i.test(name)) {\n throw new TypeError('Invalid character in header field name')\n }\n return name.toLowerCase()\n}\n\nfunction normalizeValue(value) {\n if (typeof value !== 'string') {\n value = String(value)\n }\n return value\n}\n\n// Build a destructive iterator for the value list\nfunction iteratorFor(items) {\n var iterator = {\n next: function () {\n var value = items.shift()\n return { done: value === undefined, value: value }\n }\n }\n\n if (support.iterable) {\n iterator[Symbol.iterator] = function () {\n return iterator\n }\n }\n\n return iterator\n}\n\nfunction Headers(headers) {\n this.map = {}\n\n if (headers instanceof Headers) {\n headers.forEach(function (value, name) {\n this.append(name, value)\n }, this)\n } else if (Array.isArray(headers)) {\n headers.forEach(function (header) {\n this.append(header[0], header[1])\n }, this)\n } else if (headers) {\n Object.getOwnPropertyNames(headers).forEach(function (name) {\n this.append(name, headers[name])\n }, this)\n }\n}\n\nHeaders.prototype.append = function (name, value) {\n name = normalizeName(name)\n value = normalizeValue(value)\n var oldValue = this.map[name]\n this.map[name] = oldValue ? oldValue + ',' + value : value\n}\n\nHeaders.prototype['delete'] = function (name) {\n delete this.map[normalizeName(name)]\n}\n\nHeaders.prototype.get = function (name) {\n name = normalizeName(name)\n return this.has(name) ? this.map[name] : null\n}\n\nHeaders.prototype.has = function (name) {\n return this.map.hasOwnProperty(normalizeName(name))\n}\n\nHeaders.prototype.set = function (name, value) {\n this.map[normalizeName(name)] = normalizeValue(value)\n}\n\nHeaders.prototype.forEach = function (callback, thisArg) {\n for (var name in this.map) {\n if (this.map.hasOwnProperty(name)) {\n callback.call(thisArg, this.map[name], name, this)\n }\n }\n}\n\nHeaders.prototype.keys = function () {\n var items = []\n this.forEach(function (value, name) { items.push(name) })\n return iteratorFor(items)\n}\n\nHeaders.prototype.values = function () {\n var items = []\n this.forEach(function (value) { items.push(value) })\n return iteratorFor(items)\n}\n\nHeaders.prototype.entries = function () {\n var items = []\n this.forEach(function (value, name) { items.push([name, value]) })\n return iteratorFor(items)\n}\n\nif (support.iterable) {\n Headers.prototype[Symbol.iterator] = Headers.prototype.entries\n}\n\nexports.Headers = Headers\n\n//# sourceURL=webpack://Yetch/./src/internal/Headers.js?"); + +/***/ }), + +/***/ "./src/internal/Request.js": +/*!*********************************!*\ + !*** ./src/internal/Request.js ***! + \*********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("var Headers = __webpack_require__(/*! ./Headers */ \"./src/internal/Headers.js\").Headers\nvar Body = __webpack_require__(/*! ./Body */ \"./src/internal/Body.js\").Body\n\n// HTTP methods whose capitalization should be normalized\nvar methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']\n\nfunction normalizeMethod(method) {\n var upcased = method.toUpperCase()\n return (methods.indexOf(upcased) > -1) ? upcased : method\n}\n\nfunction Request(input, options) {\n options = options || {}\n var body = options.body\n\n if (input instanceof Request) {\n if (input.bodyUsed) {\n throw new TypeError('Already read')\n }\n this.url = input.url\n this.credentials = input.credentials\n if (!options.headers) {\n this.headers = new Headers(input.headers)\n }\n this.method = input.method\n this.mode = input.mode\n this.signal = input.signal\n if (!body && input._bodyInit != null) {\n body = input._bodyInit\n input.bodyUsed = true\n }\n } else {\n this.url = String(input)\n }\n\n this.credentials = options.credentials || this.credentials || 'omit'\n if (options.headers || !this.headers) {\n this.headers = new Headers(options.headers)\n }\n this.method = normalizeMethod(options.method || this.method || 'GET')\n this.mode = options.mode || this.mode || null\n this.signal = options.signal || this.signal\n this.referrer = null\n\n if ((this.method === 'GET' || this.method === 'HEAD') && body) {\n throw new TypeError('Body not allowed for GET or HEAD requests')\n }\n this._initBody(body)\n}\n\nRequest.prototype.clone = function () {\n return new Request(this, { body: this._bodyInit })\n}\n\nBody.call(Request.prototype)\n\nexports.Request = Request\n\n\n//# sourceURL=webpack://Yetch/./src/internal/Request.js?"); + +/***/ }), + +/***/ "./src/internal/Response.js": +/*!**********************************!*\ + !*** ./src/internal/Response.js ***! + \**********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("var Headers = __webpack_require__(/*! ./Headers */ \"./src/internal/Headers.js\").Headers\nvar Body = __webpack_require__(/*! ./Body */ \"./src/internal/Body.js\").Body\n\nfunction Response(bodyInit, options) {\n if (!options) {\n options = {}\n }\n\n this.type = 'default'\n this.status = options.status === undefined ? 200 : options.status\n this.ok = this.status >= 200 && this.status < 300\n this.statusText = 'statusText' in options ? options.statusText : 'OK'\n this.headers = new Headers(options.headers)\n this.url = options.url || ''\n this._initBody(bodyInit)\n}\n\nBody.call(Response.prototype)\n\nResponse.prototype.clone = function () {\n return new Response(this._bodyInit, {\n status: this.status,\n statusText: this.statusText,\n headers: new Headers(this.headers),\n url: this.url\n })\n}\n\nResponse.error = function () {\n var response = new Response(null, { status: 0, statusText: '' })\n response.type = 'error'\n return response\n}\n\nvar redirectStatuses = [301, 302, 303, 307, 308]\n\nResponse.redirect = function (url, status) {\n if (redirectStatuses.indexOf(status) === -1) {\n throw new RangeError('Invalid status code')\n }\n\n return new Response(null, { status: status, headers: { location: url } })\n}\n\nexports.Response = Response\n\n\n//# sourceURL=webpack://Yetch/./src/internal/Response.js?"); + +/***/ }), + +/***/ "./src/internal/fetch.js": +/*!*******************************!*\ + !*** ./src/internal/fetch.js ***! + \*******************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("var support = __webpack_require__(/*! ./support */ \"./src/internal/support.js\").support\nvar DOMException = __webpack_require__(/*! ./DOMException */ \"./src/internal/DOMException.js\").DOMException\nvar Headers = __webpack_require__(/*! ./Headers */ \"./src/internal/Headers.js\").Headers\nvar Request = __webpack_require__(/*! ./Request */ \"./src/internal/Request.js\").Request\nvar Response = __webpack_require__(/*! ./Response */ \"./src/internal/Response.js\").Response\n\nfunction parseHeaders(rawHeaders) {\n var headers = new Headers()\n // Replace instances of \\r\\n and \\n followed by at least one space or horizontal tab with a space\n // https://tools.ietf.org/html/rfc7230#section-3.2\n var preProcessedHeaders = rawHeaders.replace(/\\r?\\n[\\t ]+/g, ' ')\n preProcessedHeaders.split(/\\r?\\n/).forEach(function(line) {\n var parts = line.split(':')\n var key = parts.shift().trim()\n if (key) {\n var value = parts.join(':').trim()\n headers.append(key, value)\n }\n })\n return headers\n}\n\nfunction fetch(input, init) {\n return new Promise(function (resolve, reject) {\n var request = new Request(input, init)\n\n if (request.signal && request.signal.aborted) {\n return reject(new DOMException('Aborted', 'AbortError'))\n }\n\n var xhr = new XMLHttpRequest()\n\n function abortXhr() {\n xhr.abort()\n }\n\n xhr.onload = function () {\n var options = {\n status: xhr.status,\n statusText: xhr.statusText,\n headers: parseHeaders(xhr.getAllResponseHeaders() || '')\n }\n options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL')\n var body = 'response' in xhr ? xhr.response : xhr.responseText\n resolve(new Response(body, options))\n }\n\n xhr.onerror = function () {\n reject(new TypeError('Network request failed'))\n }\n\n xhr.ontimeout = function () {\n reject(new TypeError('Network request failed'))\n }\n\n xhr.onabort = function () {\n reject(new DOMException('Aborted', 'AbortError'))\n }\n\n xhr.open(request.method, request.url, true)\n\n if (request.credentials === 'include') {\n xhr.withCredentials = true\n } else if (request.credentials === 'omit') {\n xhr.withCredentials = false\n }\n\n if ('responseType' in xhr && support.blob) {\n xhr.responseType = 'blob'\n }\n\n request.headers.forEach(function (value, name) {\n xhr.setRequestHeader(name, value)\n })\n\n if (request.signal) {\n request.signal.addEventListener('abort', abortXhr)\n\n xhr.onreadystatechange = function () {\n // DONE (success or failure)\n if (xhr.readyState === 4) {\n request.signal.removeEventListener('abort', abortXhr)\n }\n }\n }\n\n xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit)\n })\n}\n\nfetch.polyfill = true\nexports.fetch = fetch\n\n//# sourceURL=webpack://Yetch/./src/internal/fetch.js?"); + +/***/ }), + +/***/ "./src/internal/root.js": +/*!******************************!*\ + !*** ./src/internal/root.js ***! + \******************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("/* WEBPACK VAR INJECTION */(function(global) {exports.root = typeof window === 'object' ?\n window : typeof self === 'object' ?\n self : typeof global === 'object' ?\n global : null;\n\n/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node_modules/webpack/buildin/global.js */ \"./node_modules/webpack/buildin/global.js\")))\n\n//# sourceURL=webpack://Yetch/./src/internal/root.js?"); + +/***/ }), + +/***/ "./src/internal/support.js": +/*!*********************************!*\ + !*** ./src/internal/support.js ***! + \*********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("var root = __webpack_require__(/*! ./root */ \"./src/internal/root.js\").root\n\nexports.support = {\n searchParams: 'URLSearchParams' in root,\n iterable: 'Symbol' in root && 'iterator' in Symbol,\n blob: 'FileReader' in root && 'Blob' in root && (function() {\n try {\n new Blob()\n return true\n } catch (e) {\n return false\n }\n })(),\n formData: 'FormData' in root,\n arrayBuffer: 'ArrayBuffer' in root\n}\n\n\n//# sourceURL=webpack://Yetch/./src/internal/support.js?"); + +/***/ }), + +/***/ 0: +/*!****************************!*\ + !*** multi ./src/index.js ***! + \****************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("module.exports = __webpack_require__(/*! ./src/index.js */\"./src/index.js\");\n\n\n//# sourceURL=webpack://Yetch/multi_./src/index.js?"); + +/***/ }) + +/******/ }); +}); \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js index f8bff7c..f37142f 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -21,7 +21,7 @@ module.exports = function(config) { 'bower_components/jquery/dist/jquery.js', 'node_modules/es6-promise/dist/es6-promise.auto.js', 'node_modules/abortcontroller-polyfill/dist/abortcontroller-polyfill-only.js', - 'node_modules/yetch/dist/yetch-ponyfill.js', + 'assets/yetch-ponyfill.js', 'pretender.js', 'test/**/*.js' ],