Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

autofetch

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autofetch - npm Package Compare versions

Comparing version 3.2.0 to 4.0.0

2

dist/index.browser.js

@@ -1,2 +0,2 @@

!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var o in r)("object"==typeof exports?exports:t)[o]=r[o]}}(this,function(){return function(t){function e(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return t[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";r(2);var o=self.fetch.bind(self),n=r(3),i=n.fetchDecorator;t.exports={fetch:i(o)}},function(t,e){!function(t){"use strict";function e(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function r(t){return"string"!=typeof t&&(t=String(t)),t}function o(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return m.iterable&&(e[Symbol.iterator]=function(){return e}),e}function n(t){this.map={},t instanceof n?t.forEach(function(t,e){this.append(e,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function i(t){return t.bodyUsed?Promise.reject(new TypeError("Already read")):void(t.bodyUsed=!0)}function a(t){return new Promise(function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}})}function s(t){var e=new FileReader,r=a(e);return e.readAsArrayBuffer(t),r}function f(t){var e=new FileReader,r=a(e);return e.readAsText(t),r}function u(t){for(var e=new Uint8Array(t),r=new Array(e.length),o=0;o<e.length;o++)r[o]=String.fromCharCode(e[o]);return r.join("")}function c(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function l(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,t)if("string"==typeof t)this._bodyText=t;else if(m.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(m.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(m.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(m.arrayBuffer&&m.blob&&w(t))this._bodyArrayBuffer=c(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!m.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t)&&!g(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=c(t)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):m.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},m.blob&&(this.blob=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?i(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(s)}),this.text=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return f(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(u(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},m.formData&&(this.formData=function(){return this.text().then(y)}),this.json=function(){return this.text().then(JSON.parse)},this}function p(t){var e=t.toUpperCase();return j.indexOf(e)>-1?e:t}function d(t,e){e=e||{};var r=e.body;if(t instanceof d){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new n(t.headers)),this.method=t.method,this.mode=t.mode,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new n(e.headers)),this.method=p(e.method||this.method||"GET"),this.mode=e.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function y(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var r=t.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(n))}}),e}function h(t){var e=new n;return t.split(/\r?\n/).forEach(function(t){var r=t.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();e.append(o,n)}}),e}function b(t,e){e||(e={}),this.type="default",this.status="status"in e?e.status:200,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new n(e.headers),this.url=e.url||"",this._initBody(t)}if(!t.fetch||(((t||{}).navigator||{}).userAgent||"").match(/Safari/)){var m={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(m.arrayBuffer)var v=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],w=function(t){return t&&DataView.prototype.isPrototypeOf(t)},g=ArrayBuffer.isView||function(t){return t&&v.indexOf(Object.prototype.toString.call(t))>-1};n.prototype.append=function(t,o){t=e(t),o=r(o);var n=this.map[t];this.map[t]=n?n+","+o:o},n.prototype.delete=function(t){delete this.map[e(t)]},n.prototype.get=function(t){return t=e(t),this.has(t)?this.map[t]:null},n.prototype.has=function(t){return this.map.hasOwnProperty(e(t))},n.prototype.set=function(t,o){this.map[e(t)]=r(o)},n.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},n.prototype.keys=function(){var t=[];return this.forEach(function(e,r){t.push(r)}),o(t)},n.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),o(t)},n.prototype.entries=function(){var t=[];return this.forEach(function(e,r){t.push([r,e])}),o(t)},m.iterable&&(n.prototype[Symbol.iterator]=n.prototype.entries);var j=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];d.prototype.clone=function(){return new d(this,{body:this._bodyInit})},l.call(d.prototype),l.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new n(this.headers),url:this.url})},b.error=function(){var t=new b(null,{status:0,statusText:""});return t.type="error",t};var A=[301,302,303,307,308];b.redirect=function(t,e){if(A.indexOf(e)===-1)throw new RangeError("Invalid status code");return new b(null,{status:e,headers:{location:t}})},t.Headers=n,t.Request=d,t.Response=b,t.fetch=function(t,e){return new Promise(function(r,o){var n=new d(t,e),i=new XMLHttpRequest;i.onload=function(){var t={status:i.status,statusText:i.statusText,headers:h(i.getAllResponseHeaders()||"")};t.url="responseURL"in i?i.responseURL:t.headers.get("X-Request-URL");var e="response"in i?i.response:i.responseText;r(new b(e,t))},i.onerror=function(){o(new TypeError("Network request failed"))},i.ontimeout=function(){o(new TypeError("Network request failed"))},i.open(n.method,n.url,!0),"include"===n.credentials&&(i.withCredentials=!0),"responseType"in i&&m.blob&&(i.responseType="blob"),n.headers.forEach(function(t,e){i.setRequestHeader(e,t)}),i.send("undefined"==typeof n._bodyInit?null:n._bodyInit)})},t.fetch.polyfill=!0}}("undefined"!=typeof self?self:this)},function(t,e,r){"use strict";function o(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=r(4),a=r(9),s=r(10),f=function(t){return t},u={},c="",l={},p={},d=function(t){return t},y=function(t){return t instanceof Headers?function(){return Array.from(t.keys()).reduce(function(e,r){return e[r]=t.get(r),e},{})}():t},h=new RegExp(/(:([a-zA-Z0-9-_]{1,}))/g),b=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t.replace(h,function(t,r,o){return e[o]||t})},m=function(t,e,r){var o=e.ssl,n=(e.method,e.query);return t=b(t,e.params),"function"==typeof r?r(t,e):("string"==typeof r&&(t=t.replace(/^\/\//,r)),/^\/\//.test(t)&&(t=(o?"https":"http")+":"+t),n&&(t+=""+(t.match(/\?/)?"&":"?")+i.stringify(n)),t)},v=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{method:"GET"};e.method=(e.method||"GET").toUpperCase();var r="GET"===e.method||"HEAD"===e.method;e.json=e.json!==!1||e.json,r&&!e.query&&e.data&&(e.query=e.data),r||e.body||!e.data||(e.body=e.data),r&&e.body&&(("object"===n(e.body)&&Object.keys(e.body).length>0||e.body.length>0)&&console.warn("[Autofetch]: Request with GET/HEAD method cannot have body, ingored."),delete e.body),e.params=Object.assign({},l,e.params),e.query=Object.assign({},p,e.query);var o=new Headers(Object.assign({},y(u),y(e.headers)));if(!("function"==typeof FormData&&e.body instanceof FormData)&&(r?"":o.set("Content-Type",o.get("Content-Type")||a(e.body,e.json)),"object"===n(e.body)))switch(o.get("Content-Type")){case s.form:e.body=i.stringify(e.body);break;default:e.body=JSON.stringify(e.body)}return e.headers=o,[m(t,e,c),e]},w=function(t){var e=function(){return t.call.apply(t,[void 0].concat(o(v.apply(void 0,arguments)))).then(d).then(f)};return e.callback=function(t){"function"==typeof t&&(f=t),delete e.callback},e.baseHost=function(t){c=t,delete e.baseHost},e.headers=function(t){if("object"!==("undefined"==typeof t?"undefined":n(t))&&"function"!=typeof t)throw new Error("global headers must be object or function");u=t,delete e.headers},e.params=function(t){l=t,delete e.params},e.query=function(t){p=t,delete e.query},e};t.exports={fetchDecorator:w}},function(t,e,r){"use strict";var o=r(5),n=r(8),i=r(7);t.exports={formats:i,parse:n,stringify:o}},function(t,e,r){"use strict";var o=r(6),n=r(7),i={brackets:function(t){return t+"[]"},indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},a=Date.prototype.toISOString,s={delimiter:"&",encode:!0,encoder:o.encode,encodeValuesOnly:!1,serializeDate:function(t){return a.call(t)},skipNulls:!1,strictNullHandling:!1},f=function t(e,r,n,i,a,s,f,u,c,l,p,d){var y=e;if("function"==typeof f)y=f(r,y);else if(y instanceof Date)y=l(y);else if(null===y){if(i)return s&&!d?s(r):r;y=""}if("string"==typeof y||"number"==typeof y||"boolean"==typeof y||o.isBuffer(y)){if(s){var h=d?r:s(r);return[p(h)+"="+p(s(y))]}return[p(r)+"="+p(String(y))]}var b=[];if("undefined"==typeof y)return b;var m;if(Array.isArray(f))m=f;else{var v=Object.keys(y);m=u?v.sort(u):v}for(var w=0;w<m.length;++w){var g=m[w];a&&null===y[g]||(b=Array.isArray(y)?b.concat(t(y[g],n(r,g),n,i,a,s,f,u,c,l,p,d)):b.concat(t(y[g],r+(c?"."+g:"["+g+"]"),n,i,a,s,f,u,c,l,p,d)))}return b};t.exports=function(t,e){var r=t,o=e||{};if(null!==o.encoder&&void 0!==o.encoder&&"function"!=typeof o.encoder)throw new TypeError("Encoder has to be a function.");var a="undefined"==typeof o.delimiter?s.delimiter:o.delimiter,u="boolean"==typeof o.strictNullHandling?o.strictNullHandling:s.strictNullHandling,c="boolean"==typeof o.skipNulls?o.skipNulls:s.skipNulls,l="boolean"==typeof o.encode?o.encode:s.encode,p="function"==typeof o.encoder?o.encoder:s.encoder,d="function"==typeof o.sort?o.sort:null,y="undefined"!=typeof o.allowDots&&o.allowDots,h="function"==typeof o.serializeDate?o.serializeDate:s.serializeDate,b="boolean"==typeof o.encodeValuesOnly?o.encodeValuesOnly:s.encodeValuesOnly;if("undefined"==typeof o.format)o.format=n.default;else if(!Object.prototype.hasOwnProperty.call(n.formatters,o.format))throw new TypeError("Unknown format option provided.");var m,v,w=n.formatters[o.format];"function"==typeof o.filter?(v=o.filter,r=v("",r)):Array.isArray(o.filter)&&(v=o.filter,m=v);var g=[];if("object"!=typeof r||null===r)return"";var j;j=o.arrayFormat in i?o.arrayFormat:"indices"in o?o.indices?"indices":"repeat":"indices";var A=i[j];m||(m=Object.keys(r)),d&&m.sort(d);for(var O=0;O<m.length;++O){var x=m[O];c&&null===r[x]||(g=g.concat(f(r[x],x,A,u,c,l?p:null,v,d,y,h,w,b)))}return g.join(a)}},function(t,e){"use strict";var r=Object.prototype.hasOwnProperty,o=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}();e.arrayToObject=function(t,e){for(var r=e&&e.plainObjects?Object.create(null):{},o=0;o<t.length;++o)"undefined"!=typeof t[o]&&(r[o]=t[o]);return r},e.merge=function(t,o,n){if(!o)return t;if("object"!=typeof o){if(Array.isArray(t))t.push(o);else{if("object"!=typeof t)return[t,o];(n.plainObjects||n.allowPrototypes||!r.call(Object.prototype,o))&&(t[o]=!0)}return t}if("object"!=typeof t)return[t].concat(o);var i=t;return Array.isArray(t)&&!Array.isArray(o)&&(i=e.arrayToObject(t,n)),Array.isArray(t)&&Array.isArray(o)?(o.forEach(function(o,i){r.call(t,i)?t[i]&&"object"==typeof t[i]?t[i]=e.merge(t[i],o,n):t.push(o):t[i]=o}),t):Object.keys(o).reduce(function(t,r){var i=o[r];return Object.prototype.hasOwnProperty.call(t,r)?t[r]=e.merge(t[r],i,n):t[r]=i,t},i)},e.decode=function(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(e){return t}},e.encode=function(t){if(0===t.length)return t;for(var e="string"==typeof t?t:String(t),r="",n=0;n<e.length;++n){var i=e.charCodeAt(n);45===i||46===i||95===i||126===i||i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122?r+=e.charAt(n):i<128?r+=o[i]:i<2048?r+=o[192|i>>6]+o[128|63&i]:i<55296||i>=57344?r+=o[224|i>>12]+o[128|i>>6&63]+o[128|63&i]:(n+=1,i=65536+((1023&i)<<10|1023&e.charCodeAt(n)),r+=o[240|i>>18]+o[128|i>>12&63]+o[128|i>>6&63]+o[128|63&i])}return r},e.compact=function(t,r){if("object"!=typeof t||null===t)return t;var o=r||[],n=o.indexOf(t);if(n!==-1)return o[n];if(o.push(t),Array.isArray(t)){for(var i=[],a=0;a<t.length;++a)t[a]&&"object"==typeof t[a]?i.push(e.compact(t[a],o)):"undefined"!=typeof t[a]&&i.push(t[a]);return i}var s=Object.keys(t);return s.forEach(function(r){t[r]=e.compact(t[r],o)}),t},e.isRegExp=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},e.isBuffer=function(t){return null!==t&&"undefined"!=typeof t&&!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))}},function(t,e){"use strict";var r=String.prototype.replace,o=/%20/g;t.exports={default:"RFC3986",formatters:{RFC1738:function(t){return r.call(t,o,"+")},RFC3986:function(t){return t}},RFC1738:"RFC1738",RFC3986:"RFC3986"}},function(t,e,r){"use strict";var o=r(6),n=Object.prototype.hasOwnProperty,i={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:o.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},a=function(t,e){for(var r={},o=t.split(e.delimiter,e.parameterLimit===1/0?void 0:e.parameterLimit),i=0;i<o.length;++i){var a,s,f=o[i],u=f.indexOf("]=")===-1?f.indexOf("="):f.indexOf("]=")+1;u===-1?(a=e.decoder(f),s=e.strictNullHandling?null:""):(a=e.decoder(f.slice(0,u)),s=e.decoder(f.slice(u+1))),n.call(r,a)?r[a]=[].concat(r[a]).concat(s):r[a]=s}return r},s=function(t,e,r){if(!t.length)return e;var o,n=t.shift();if("[]"===n)o=[],o=o.concat(s(t,e,r));else{o=r.plainObjects?Object.create(null):{};var i="["===n.charAt(0)&&"]"===n.charAt(n.length-1)?n.slice(1,-1):n,a=parseInt(i,10);!isNaN(a)&&n!==i&&String(a)===i&&a>=0&&r.parseArrays&&a<=r.arrayLimit?(o=[],o[a]=s(t,e,r)):o[i]=s(t,e,r)}return o},f=function(t,e,r){if(t){var o=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,f=i.exec(o),u=f?o.slice(0,f.index):o,c=[];if(u){if(!r.plainObjects&&n.call(Object.prototype,u)&&!r.allowPrototypes)return;c.push(u)}for(var l=0;null!==(f=a.exec(o))&&l<r.depth;){if(l+=1,!r.plainObjects&&n.call(Object.prototype,f[1].slice(1,-1))&&!r.allowPrototypes)return;c.push(f[1])}return f&&c.push("["+o.slice(f.index)+"]"),s(c,e,r)}};t.exports=function(t,e){var r=e||{};if(null!==r.decoder&&void 0!==r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(r.delimiter="string"==typeof r.delimiter||o.isRegExp(r.delimiter)?r.delimiter:i.delimiter,r.depth="number"==typeof r.depth?r.depth:i.depth,r.arrayLimit="number"==typeof r.arrayLimit?r.arrayLimit:i.arrayLimit,r.parseArrays=r.parseArrays!==!1,r.decoder="function"==typeof r.decoder?r.decoder:i.decoder,r.allowDots="boolean"==typeof r.allowDots?r.allowDots:i.allowDots,r.plainObjects="boolean"==typeof r.plainObjects?r.plainObjects:i.plainObjects,r.allowPrototypes="boolean"==typeof r.allowPrototypes?r.allowPrototypes:i.allowPrototypes,r.parameterLimit="number"==typeof r.parameterLimit?r.parameterLimit:i.parameterLimit,r.strictNullHandling="boolean"==typeof r.strictNullHandling?r.strictNullHandling:i.strictNullHandling,""===t||null===t||"undefined"==typeof t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?a(t,r):t,s=r.plainObjects?Object.create(null):{},u=Object.keys(n),c=0;c<u.length;++c){var l=u[c],p=f(l,n[l],r);s=o.merge(s,p,r)}return o.compact(s)}},function(t,e,r){"use strict";var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n=r(10),i=function(t,e){if("string"==typeof t)try{if(JSON.parse(t))return n.json}catch(t){return n.text}return"object"===("undefined"==typeof t?"undefined":o(t))?e!==!1?n.json:n.form:n.text};t.exports=i},function(t,e){"use strict";t.exports={formData:"multipart/form-data",form:"application/x-www-form-urlencoded",json:"application/json",text:"text/plain"}}])});
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var o in r)("object"==typeof exports?exports:t)[o]=r[o]}}(this,function(){return function(t){function e(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return t[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";r(2);var o=self.fetch.bind(self),n=r(3),i=n.fetchDecorator;t.exports={fetch:i(o)}},function(t,e){!function(t){"use strict";function e(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function r(t){return"string"!=typeof t&&(t=String(t)),t}function o(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return m.iterable&&(e[Symbol.iterator]=function(){return e}),e}function n(t){this.map={},t instanceof n?t.forEach(function(t,e){this.append(e,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function i(t){return t.bodyUsed?Promise.reject(new TypeError("Already read")):void(t.bodyUsed=!0)}function a(t){return new Promise(function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}})}function s(t){var e=new FileReader,r=a(e);return e.readAsArrayBuffer(t),r}function f(t){var e=new FileReader,r=a(e);return e.readAsText(t),r}function u(t){for(var e=new Uint8Array(t),r=new Array(e.length),o=0;o<e.length;o++)r[o]=String.fromCharCode(e[o]);return r.join("")}function c(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function l(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,t)if("string"==typeof t)this._bodyText=t;else if(m.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(m.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(m.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(m.arrayBuffer&&m.blob&&g(t))this._bodyArrayBuffer=c(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!m.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t)&&!w(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=c(t)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):m.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},m.blob&&(this.blob=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?i(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(s)}),this.text=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return f(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(u(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},m.formData&&(this.formData=function(){return this.text().then(y)}),this.json=function(){return this.text().then(JSON.parse)},this}function p(t){var e=t.toUpperCase();return j.indexOf(e)>-1?e:t}function d(t,e){e=e||{};var r=e.body;if(t instanceof d){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new n(t.headers)),this.method=t.method,this.mode=t.mode,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new n(e.headers)),this.method=p(e.method||this.method||"GET"),this.mode=e.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function y(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var r=t.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(n))}}),e}function h(t){var e=new n;return t.split(/\r?\n/).forEach(function(t){var r=t.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();e.append(o,n)}}),e}function b(t,e){e||(e={}),this.type="default",this.status="status"in e?e.status:200,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new n(e.headers),this.url=e.url||"",this._initBody(t)}if(!t.fetch||(((t||{}).navigator||{}).userAgent||"").match(/Safari/)){var m={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(m.arrayBuffer)var v=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],g=function(t){return t&&DataView.prototype.isPrototypeOf(t)},w=ArrayBuffer.isView||function(t){return t&&v.indexOf(Object.prototype.toString.call(t))>-1};n.prototype.append=function(t,o){t=e(t),o=r(o);var n=this.map[t];this.map[t]=n?n+","+o:o},n.prototype.delete=function(t){delete this.map[e(t)]},n.prototype.get=function(t){return t=e(t),this.has(t)?this.map[t]:null},n.prototype.has=function(t){return this.map.hasOwnProperty(e(t))},n.prototype.set=function(t,o){this.map[e(t)]=r(o)},n.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},n.prototype.keys=function(){var t=[];return this.forEach(function(e,r){t.push(r)}),o(t)},n.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),o(t)},n.prototype.entries=function(){var t=[];return this.forEach(function(e,r){t.push([r,e])}),o(t)},m.iterable&&(n.prototype[Symbol.iterator]=n.prototype.entries);var j=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];d.prototype.clone=function(){return new d(this,{body:this._bodyInit})},l.call(d.prototype),l.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new n(this.headers),url:this.url})},b.error=function(){var t=new b(null,{status:0,statusText:""});return t.type="error",t};var A=[301,302,303,307,308];b.redirect=function(t,e){if(A.indexOf(e)===-1)throw new RangeError("Invalid status code");return new b(null,{status:e,headers:{location:t}})},t.Headers=n,t.Request=d,t.Response=b,t.fetch=function(t,e){return new Promise(function(r,o){var n=new d(t,e),i=new XMLHttpRequest;i.onload=function(){var t={status:i.status,statusText:i.statusText,headers:h(i.getAllResponseHeaders()||"")};t.url="responseURL"in i?i.responseURL:t.headers.get("X-Request-URL");var e="response"in i?i.response:i.responseText;r(new b(e,t))},i.onerror=function(){o(new TypeError("Network request failed"))},i.ontimeout=function(){o(new TypeError("Network request failed"))},i.open(n.method,n.url,!0),"include"===n.credentials&&(i.withCredentials=!0),"responseType"in i&&m.blob&&(i.responseType="blob"),n.headers.forEach(function(t,e){i.setRequestHeader(e,t)}),i.send("undefined"==typeof n._bodyInit?null:n._bodyInit)})},t.fetch.polyfill=!0}}("undefined"!=typeof self?self:this)},function(t,e,r){"use strict";function o(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=r(4),a=r(9),s=r(10),f=function(t){return t},u={},c="",l={},p={},d=!1,y=function(t){return t},h=function(t){return t instanceof Headers?function(){return Array.from(t.keys()).reduce(function(e,r){return e[r]=t.get(r),e},{})}():t},b=new RegExp(/(:([a-zA-Z0-9-_]{1,}))/g),m=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t.replace(b,function(t,r,o){return e[o]||t})},v=function(t,e,r){var o=e.ssl,n=(e.method,e.query);return t=m(t,e.params),"function"==typeof r?r(t,e):("string"==typeof r&&(t=t.replace(/^\/\//,r)),/^\/\//.test(t)&&(t=(o?"https":"http")+":"+t),n&&(t+=""+(t.match(/\?/)?"&":"?")+i.stringify(n)),t)},g=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{method:"GET"};e.method=(e.method||"GET").toUpperCase();var r=e.debug!==!1&&(e.debug||d),o="GET"===e.method||"HEAD"===e.method;e.json=e.json!==!1||e.json,o&&!e.query&&e.data&&(e.query=e.data),o||e.body||!e.data||(e.body=e.data),o&&e.body&&(("object"===n(e.body)&&Object.keys(e.body).length>0||e.body.length>0)&&console.warn("[Autofetch]: Request with GET/HEAD method cannot have body, ingored."),delete e.body),e.params=Object.assign({},l,e.params),e.query=Object.assign({},p,e.query);var f=new Headers(Object.assign({},h(u),h(e.headers)));if(!("function"==typeof FormData&&e.body instanceof FormData)&&(o?"":f.set("Content-Type",f.get("Content-Type")||a(e.body,e.json)),"object"===n(e.body)))switch(f.get("Content-Type")){case s.form:e.body=i.stringify(e.body);break;default:e.body=JSON.stringify(e.body)}e.headers=f;v(t,e,c);return r&&console.log("[autofetch]["+e.method.toUpperCase()+"] "+t+" => "+t+" "+(e.body?JSON.stringify(e.body):"")),[v(t,e,c),e]},w=function(t){var e=function(){return t.call.apply(t,[void 0].concat(o(g.apply(void 0,arguments)))).then(y).then(f)};return e.callback=function(t){"function"==typeof t&&(f=t),delete e.callback},e.baseHost=function(t){c=t,delete e.baseHost},e.headers=function(t){if("object"!==("undefined"==typeof t?"undefined":n(t))&&"function"!=typeof t)throw new Error("global headers must be object or function");u=t,delete e.headers},e.params=function(t){l=t,delete e.params},e.query=function(t){p=t,delete e.query},e.debug=function(t){d=t,delete e.debug},e};t.exports={fetchDecorator:w}},function(t,e,r){"use strict";var o=r(5),n=r(8),i=r(7);t.exports={formats:i,parse:n,stringify:o}},function(t,e,r){"use strict";var o=r(6),n=r(7),i={brackets:function(t){return t+"[]"},indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},a=Date.prototype.toISOString,s={delimiter:"&",encode:!0,encoder:o.encode,encodeValuesOnly:!1,serializeDate:function(t){return a.call(t)},skipNulls:!1,strictNullHandling:!1},f=function t(e,r,n,i,a,s,f,u,c,l,p,d){var y=e;if("function"==typeof f)y=f(r,y);else if(y instanceof Date)y=l(y);else if(null===y){if(i)return s&&!d?s(r):r;y=""}if("string"==typeof y||"number"==typeof y||"boolean"==typeof y||o.isBuffer(y)){if(s){var h=d?r:s(r);return[p(h)+"="+p(s(y))]}return[p(r)+"="+p(String(y))]}var b=[];if("undefined"==typeof y)return b;var m;if(Array.isArray(f))m=f;else{var v=Object.keys(y);m=u?v.sort(u):v}for(var g=0;g<m.length;++g){var w=m[g];a&&null===y[w]||(b=Array.isArray(y)?b.concat(t(y[w],n(r,w),n,i,a,s,f,u,c,l,p,d)):b.concat(t(y[w],r+(c?"."+w:"["+w+"]"),n,i,a,s,f,u,c,l,p,d)))}return b};t.exports=function(t,e){var r=t,o=e||{};if(null!==o.encoder&&void 0!==o.encoder&&"function"!=typeof o.encoder)throw new TypeError("Encoder has to be a function.");var a="undefined"==typeof o.delimiter?s.delimiter:o.delimiter,u="boolean"==typeof o.strictNullHandling?o.strictNullHandling:s.strictNullHandling,c="boolean"==typeof o.skipNulls?o.skipNulls:s.skipNulls,l="boolean"==typeof o.encode?o.encode:s.encode,p="function"==typeof o.encoder?o.encoder:s.encoder,d="function"==typeof o.sort?o.sort:null,y="undefined"!=typeof o.allowDots&&o.allowDots,h="function"==typeof o.serializeDate?o.serializeDate:s.serializeDate,b="boolean"==typeof o.encodeValuesOnly?o.encodeValuesOnly:s.encodeValuesOnly;if("undefined"==typeof o.format)o.format=n.default;else if(!Object.prototype.hasOwnProperty.call(n.formatters,o.format))throw new TypeError("Unknown format option provided.");var m,v,g=n.formatters[o.format];"function"==typeof o.filter?(v=o.filter,r=v("",r)):Array.isArray(o.filter)&&(v=o.filter,m=v);var w=[];if("object"!=typeof r||null===r)return"";var j;j=o.arrayFormat in i?o.arrayFormat:"indices"in o?o.indices?"indices":"repeat":"indices";var A=i[j];m||(m=Object.keys(r)),d&&m.sort(d);for(var O=0;O<m.length;++O){var x=m[O];c&&null===r[x]||(w=w.concat(f(r[x],x,A,u,c,l?p:null,v,d,y,h,g,b)))}return w.join(a)}},function(t,e){"use strict";var r=Object.prototype.hasOwnProperty,o=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}();e.arrayToObject=function(t,e){for(var r=e&&e.plainObjects?Object.create(null):{},o=0;o<t.length;++o)"undefined"!=typeof t[o]&&(r[o]=t[o]);return r},e.merge=function(t,o,n){if(!o)return t;if("object"!=typeof o){if(Array.isArray(t))t.push(o);else{if("object"!=typeof t)return[t,o];(n.plainObjects||n.allowPrototypes||!r.call(Object.prototype,o))&&(t[o]=!0)}return t}if("object"!=typeof t)return[t].concat(o);var i=t;return Array.isArray(t)&&!Array.isArray(o)&&(i=e.arrayToObject(t,n)),Array.isArray(t)&&Array.isArray(o)?(o.forEach(function(o,i){r.call(t,i)?t[i]&&"object"==typeof t[i]?t[i]=e.merge(t[i],o,n):t.push(o):t[i]=o}),t):Object.keys(o).reduce(function(t,r){var i=o[r];return Object.prototype.hasOwnProperty.call(t,r)?t[r]=e.merge(t[r],i,n):t[r]=i,t},i)},e.decode=function(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(e){return t}},e.encode=function(t){if(0===t.length)return t;for(var e="string"==typeof t?t:String(t),r="",n=0;n<e.length;++n){var i=e.charCodeAt(n);45===i||46===i||95===i||126===i||i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122?r+=e.charAt(n):i<128?r+=o[i]:i<2048?r+=o[192|i>>6]+o[128|63&i]:i<55296||i>=57344?r+=o[224|i>>12]+o[128|i>>6&63]+o[128|63&i]:(n+=1,i=65536+((1023&i)<<10|1023&e.charCodeAt(n)),r+=o[240|i>>18]+o[128|i>>12&63]+o[128|i>>6&63]+o[128|63&i])}return r},e.compact=function(t,r){if("object"!=typeof t||null===t)return t;var o=r||[],n=o.indexOf(t);if(n!==-1)return o[n];if(o.push(t),Array.isArray(t)){for(var i=[],a=0;a<t.length;++a)t[a]&&"object"==typeof t[a]?i.push(e.compact(t[a],o)):"undefined"!=typeof t[a]&&i.push(t[a]);return i}var s=Object.keys(t);return s.forEach(function(r){t[r]=e.compact(t[r],o)}),t},e.isRegExp=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},e.isBuffer=function(t){return null!==t&&"undefined"!=typeof t&&!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))}},function(t,e){"use strict";var r=String.prototype.replace,o=/%20/g;t.exports={default:"RFC3986",formatters:{RFC1738:function(t){return r.call(t,o,"+")},RFC3986:function(t){return t}},RFC1738:"RFC1738",RFC3986:"RFC3986"}},function(t,e,r){"use strict";var o=r(6),n=Object.prototype.hasOwnProperty,i={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:o.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},a=function(t,e){for(var r={},o=t.split(e.delimiter,e.parameterLimit===1/0?void 0:e.parameterLimit),i=0;i<o.length;++i){var a,s,f=o[i],u=f.indexOf("]=")===-1?f.indexOf("="):f.indexOf("]=")+1;u===-1?(a=e.decoder(f),s=e.strictNullHandling?null:""):(a=e.decoder(f.slice(0,u)),s=e.decoder(f.slice(u+1))),n.call(r,a)?r[a]=[].concat(r[a]).concat(s):r[a]=s}return r},s=function(t,e,r){if(!t.length)return e;var o,n=t.shift();if("[]"===n)o=[],o=o.concat(s(t,e,r));else{o=r.plainObjects?Object.create(null):{};var i="["===n.charAt(0)&&"]"===n.charAt(n.length-1)?n.slice(1,-1):n,a=parseInt(i,10);!isNaN(a)&&n!==i&&String(a)===i&&a>=0&&r.parseArrays&&a<=r.arrayLimit?(o=[],o[a]=s(t,e,r)):o[i]=s(t,e,r)}return o},f=function(t,e,r){if(t){var o=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,f=i.exec(o),u=f?o.slice(0,f.index):o,c=[];if(u){if(!r.plainObjects&&n.call(Object.prototype,u)&&!r.allowPrototypes)return;c.push(u)}for(var l=0;null!==(f=a.exec(o))&&l<r.depth;){if(l+=1,!r.plainObjects&&n.call(Object.prototype,f[1].slice(1,-1))&&!r.allowPrototypes)return;c.push(f[1])}return f&&c.push("["+o.slice(f.index)+"]"),s(c,e,r)}};t.exports=function(t,e){var r=e||{};if(null!==r.decoder&&void 0!==r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(r.delimiter="string"==typeof r.delimiter||o.isRegExp(r.delimiter)?r.delimiter:i.delimiter,r.depth="number"==typeof r.depth?r.depth:i.depth,r.arrayLimit="number"==typeof r.arrayLimit?r.arrayLimit:i.arrayLimit,r.parseArrays=r.parseArrays!==!1,r.decoder="function"==typeof r.decoder?r.decoder:i.decoder,r.allowDots="boolean"==typeof r.allowDots?r.allowDots:i.allowDots,r.plainObjects="boolean"==typeof r.plainObjects?r.plainObjects:i.plainObjects,r.allowPrototypes="boolean"==typeof r.allowPrototypes?r.allowPrototypes:i.allowPrototypes,r.parameterLimit="number"==typeof r.parameterLimit?r.parameterLimit:i.parameterLimit,r.strictNullHandling="boolean"==typeof r.strictNullHandling?r.strictNullHandling:i.strictNullHandling,""===t||null===t||"undefined"==typeof t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?a(t,r):t,s=r.plainObjects?Object.create(null):{},u=Object.keys(n),c=0;c<u.length;++c){var l=u[c],p=f(l,n[l],r);s=o.merge(s,p,r)}return o.compact(s)}},function(t,e,r){"use strict";var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n=r(10),i=function(t,e){if("string"==typeof t)try{if(JSON.parse(t))return n.json}catch(t){return n.text}return"object"===("undefined"==typeof t?"undefined":o(t))?e!==!1?n.json:n.form:n.text};t.exports=i},function(t,e){"use strict";t.exports={formData:"multipart/form-data",form:"application/x-www-form-urlencoded",json:"application/json",text:"text/plain"}}])});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguYnJvd3Nlci5qcyIsInNvdXJjZXMiOlsid2VicGFjazovLy9pbmRleC5icm93c2VyLmpzIl0sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIifQ==

@@ -10,2 +10,3 @@ const qs = require('qs');

let globalQuery = {};
let globalDebug = false;

@@ -56,2 +57,4 @@ const responseMiddleware = (response) => {

const debug = options.debug === false ? false : options.debug || globalDebug;
const isGet = options.method === 'GET' || options.method === 'HEAD';

@@ -98,2 +101,8 @@

const realUrl = parseUrl(url, options, baseHost);
if (debug) {
console.log(`[autofetch][${options.method.toUpperCase()}] ${url} => ${url} ${options.body ? JSON.stringify(options.body) : ''}`);
}
return [

@@ -144,2 +153,8 @@ parseUrl(url, options, baseHost),

fetchRequest.debug = (debug) => {
globalDebug = debug;
delete fetchRequest.debug;
};
return fetchRequest;

@@ -146,0 +161,0 @@ };

{
"name": "autofetch",
"version": "3.2.0",
"version": "4.0.0",
"description": "fetch for node",

@@ -9,4 +9,4 @@ "main": "src/index.node.js",

"build": "webpack --config=scripts/webpack.config.js",
"prepublish": "npm run build",
"publish": "rm -rf dist/",
"prepublishOnly": "npm run build",
"publishOnly": "rm -rf dist/",
"test": "echo \"Error: no test specified\" && exit 1"

@@ -50,6 +50,5 @@ },

"dependencies": {
"isomorphic-fetch": "^2.2.1",
"node-fetch": "^1.6.3",
"node-fetch": "2",
"qs": "^6.3.0"
}
}
"use strict";
const realFetch = require('isomorphic-fetch/fetch-npm-node.js');
const realFetch = require('node-fetch');

@@ -12,1 +12,8 @@ const { fetchDecorator } = require('./../libs/utils');

module.exports = fetch;
if(!global.fetch){
global.fetch = realFetch;
global.Response = realFetch.Response;
global.Request = realFetch.Request;
global.Headers = realFetch.Headers;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc