summaryrefslogtreecommitdiff
path: root/node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js
diff options
context:
space:
mode:
authorakiyamn2023-09-24 23:22:21 +1000
committerakiyamn2023-09-24 23:22:21 +1000
commit4e87195739f2a5d9a05451b48773c8afdc680765 (patch)
tree9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js
downloadprice-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz
price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js')
-rw-r--r--node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js b/node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js
new file mode 100644
index 0000000..05210b9
--- /dev/null
+++ b/node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js
@@ -0,0 +1,52 @@
+export var hasFetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
+
+var _blobConstructor;
+export function blobConstructor() {
+ if (typeof _blobConstructor !== 'undefined') {
+ return _blobConstructor;
+ }
+ try {
+ new global.Blob([new ArrayBuffer(1)])
+ _blobConstructor = true
+ } catch (e) {
+ _blobConstructor = false
+ }
+ return _blobConstructor
+}
+var xhr;
+
+function checkTypeSupport(type) {
+ if (!xhr) {
+ xhr = new global.XMLHttpRequest()
+ // If location.host is empty, e.g. if this page/worker was loaded
+ // from a Blob, then use example.com to avoid an error
+ xhr.open('GET', global.location.host ? '/' : 'https://example.com')
+ }
+ try {
+ xhr.responseType = type
+ return xhr.responseType === type
+ } catch (e) {
+ return false
+ }
+
+}
+
+// For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'.
+// Safari 7.1 appears to have fixed this bug.
+var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined'
+var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice)
+
+export var arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer')
+ // These next two tests unavoidably show warnings in Chrome. Since fetch will always
+ // be used if it's available, just return false for these to avoid the warnings.
+export var msstream = !hasFetch && haveSlice && checkTypeSupport('ms-stream')
+export var mozchunkedarraybuffer = !hasFetch && haveArrayBuffer &&
+ checkTypeSupport('moz-chunked-arraybuffer')
+export var overrideMimeType = isFunction(xhr.overrideMimeType)
+export var vbArray = isFunction(global.VBArray)
+
+function isFunction(value) {
+ return typeof value === 'function'
+}
+
+xhr = null // Help gc