Comparing version 0.8.1 to 0.9.0
@@ -6,6 +6,4 @@ 'use strict'; | ||
}); | ||
exports.put = exports.post = exports.patch = exports.get = exports.error = exports.del = undefined; | ||
exports.put = exports.post = exports.patch = exports.get = exports.error = exports.del = exports.all = undefined; | ||
require('fetch-everywhere'); | ||
var _request = require('./utils/request'); | ||
@@ -43,3 +41,8 @@ | ||
function all(promises) { | ||
return Promise.all(promises); | ||
} | ||
var fitch = { | ||
all: all, | ||
del: del, | ||
@@ -54,2 +57,3 @@ error: error, | ||
exports.default = fitch; | ||
exports.all = all; | ||
exports.del = del; | ||
@@ -56,0 +60,0 @@ exports.error = error; |
@@ -62,8 +62,6 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
}); | ||
exports.put = exports.post = exports.patch = exports.get = exports.error = exports.del = undefined; | ||
exports.put = exports.post = exports.patch = exports.get = exports.error = exports.del = exports.all = undefined; | ||
__webpack_require__(1); | ||
var _request = __webpack_require__(1); | ||
var _request = __webpack_require__(3); | ||
var _request2 = _interopRequireDefault(_request); | ||
@@ -99,3 +97,8 @@ | ||
function all(promises) { | ||
return Promise.all(promises); | ||
} | ||
var fitch = { | ||
all: all, | ||
del: del, | ||
@@ -110,2 +113,3 @@ error: error, | ||
exports.default = fitch; | ||
exports.all = all; | ||
exports.del = del; | ||
@@ -122,2 +126,46 @@ exports.error = error; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
__webpack_require__(2); | ||
var _config = __webpack_require__(4); | ||
var _config2 = _interopRequireDefault(_config); | ||
var _params = __webpack_require__(5); | ||
var _params2 = _interopRequireDefault(_params); | ||
var _check = __webpack_require__(6); | ||
var _check2 = _interopRequireDefault(_check); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function request(method, url) { | ||
var req = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var paramsEncoded = ''; | ||
if (req.params) { | ||
paramsEncoded = (0, _params2.default)(req.params); | ||
} | ||
var configObj = (0, _config2.default)(method, req); | ||
var call = fetch(url + paramsEncoded, configObj); | ||
return req.raw ? call : call.then(function (resp) { | ||
return (0, _check2.default)(resp, req.dataType); | ||
}); | ||
} | ||
exports.default = request; | ||
/***/ }, | ||
/* 2 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
// the whatwg-fetch polyfill installs the fetch() function | ||
@@ -127,3 +175,3 @@ // on the global object (window or self) | ||
// Return that as the export for use in Webpack, Browserify etc. | ||
__webpack_require__(2); | ||
__webpack_require__(3); | ||
var globalObj = typeof self !== 'undefined' && self || this; | ||
@@ -134,3 +182,3 @@ module.exports = globalObj.fetch.bind(globalObj); | ||
/***/ }, | ||
/* 2 */ | ||
/* 3 */ | ||
/***/ function(module, exports) { | ||
@@ -318,2 +366,12 @@ | ||
function readArrayBufferAsText(buf) { | ||
var view = new Uint8Array(buf) | ||
var chars = new Array(view.length) | ||
for (var i = 0; i < view.length; i++) { | ||
chars[i] = String.fromCharCode(view[i]) | ||
} | ||
return chars.join('') | ||
} | ||
function bufferClone(buf) { | ||
@@ -382,2 +440,10 @@ if (buf.slice) { | ||
} | ||
this.arrayBuffer = function() { | ||
if (this._bodyArrayBuffer) { | ||
return consumed(this) || Promise.resolve(this._bodyArrayBuffer) | ||
} else { | ||
return this.blob().then(readBlobAsArrayBuffer) | ||
} | ||
} | ||
} | ||
@@ -394,5 +460,3 @@ | ||
} else if (this._bodyArrayBuffer) { | ||
var view = new Uint8Array(this._bodyArrayBuffer) | ||
var str = String.fromCharCode.apply(null, view) | ||
return Promise.resolve(str) | ||
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer)) | ||
} else if (this._bodyFormData) { | ||
@@ -405,12 +469,2 @@ throw new Error('could not read FormData body as text') | ||
if (support.arrayBuffer) { | ||
this.arrayBuffer = function() { | ||
if (this._bodyArrayBuffer) { | ||
return consumed(this) || Promise.resolve(this._bodyArrayBuffer) | ||
} else { | ||
return this.blob().then(readBlobAsArrayBuffer) | ||
} | ||
} | ||
} | ||
if (support.formData) { | ||
@@ -597,46 +651,2 @@ this.formData = function() { | ||
/***/ }, | ||
/* 3 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
__webpack_require__(1); | ||
var _config = __webpack_require__(4); | ||
var _config2 = _interopRequireDefault(_config); | ||
var _params = __webpack_require__(5); | ||
var _params2 = _interopRequireDefault(_params); | ||
var _check = __webpack_require__(6); | ||
var _check2 = _interopRequireDefault(_check); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function request(method, url) { | ||
var req = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var paramsEncoded = ''; | ||
if (req.params) { | ||
paramsEncoded = (0, _params2.default)(req.params); | ||
} | ||
var configObj = (0, _config2.default)(method, req); | ||
var call = fetch(url + paramsEncoded, configObj); | ||
return req.raw ? call : call.then(function (resp) { | ||
return (0, _check2.default)(resp, req.dataType); | ||
}); | ||
} | ||
exports.default = request; | ||
/***/ }, | ||
/* 4 */ | ||
@@ -718,3 +728,3 @@ /***/ function(module, exports) { | ||
/* 6 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ function(module, exports) { | ||
@@ -726,5 +736,2 @@ 'use strict'; | ||
}); | ||
__webpack_require__(1); | ||
function check(resp) { | ||
@@ -731,0 +738,0 @@ var dataType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'json'; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.fitch=e():t.fitch=e()}(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){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function n(t,e){return(0,h.default)("GET",t,e)}function i(t,e){return(0,h.default)("POST",t,e)}function s(t,e){return(0,h.default)("PUT",t,e)}function a(t,e){return(0,h.default)("PATCH",t,e)}function u(t,e){return(0,h.default)("DELETE",t,e)}function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";console.log("Error >",t)}Object.defineProperty(e,"__esModule",{value:!0}),e.put=e.post=e.patch=e.get=e.error=e.del=void 0,r(1);var d=r(5),h=o(d),c={del:u,error:f,get:n,patch:a,post:i,put:s};e.default=c,e.del=u,e.error=f,e.get=n,e.patch=a,e.post=i,e.put=s},function(t,e,r){r(6);var o="undefined"!=typeof self&&self||this;t.exports=o.fetch.bind(o)},function(t,e,r){"use strict";function o(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"json",r=["arrayBuffer","blob","formData","json","text"],o=r.indexOf(e);if(t.ok&&o!==-1)return t[e]();throw new Error(t.status+" - "+t.statusText+".")}Object.defineProperty(e,"__esModule",{value:!0}),r(1),e.default=o},function(t,e){"use strict";function r(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.body,o=e.cache,n=void 0===o?"default":o,i=e.credentials,s=e.headers,a=void 0===s?{"Content-Type":"application/json"}:s,u=e.integrity,f=e.mode,d=void 0===f?"cors":f,h=e.redirect,c=e.referrer,l=e.referrerPolicy,p=void 0;r&&(p=JSON.stringify(r));var y={body:p,cache:n,credentials:i,headers:a,method:t,mode:d,redirect:h,referrer:c};return u&&(y.integrity=u),l&&(y.referrerPolicy=l),y}Object.defineProperty(e,"__esModule",{value:!0}),e.default=r},function(t,e){"use strict";function r(t){var e=[];for(var r in t)({}).hasOwnProperty.call(t,r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(t[r]));return e.length?"?"+e.join("&"):""}Object.defineProperty(e,"__esModule",{value:!0}),e.default=r},function(t,e,r){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function n(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o="";r.params&&(o=(0,u.default)(r.params));var n=(0,s.default)(t,r),i=fetch(e+o,n);return r.raw?i:i.then(function(t){return(0,d.default)(t,r.dataType)})}Object.defineProperty(e,"__esModule",{value:!0}),r(1);var i=r(3),s=o(i),a=r(4),u=o(a),f=r(2),d=o(f);e.default=n},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 b.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):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 s(t){return new Promise(function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}})}function a(t){var e=new FileReader,r=s(e);return e.readAsArrayBuffer(t),r}function u(t){var e=new FileReader,r=s(e);return e.readAsText(t),r}function f(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function d(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,t)if("string"==typeof t)this._bodyText=t;else if(b.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(b.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(b.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(b.arrayBuffer&&b.blob&&v(t))this._bodyArrayBuffer=f(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!b.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t)&&!w(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=f(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):b.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},b.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.text=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return u(this._bodyBlob);if(this._bodyArrayBuffer){var e=new Uint8Array(this._bodyArrayBuffer),r=String.fromCharCode.apply(null,e);return Promise.resolve(r)}if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},b.arrayBuffer&&(this.arrayBuffer=function(){return this._bodyArrayBuffer?i(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(a)}),b.formData&&(this.formData=function(){return this.text().then(l)}),this.json=function(){return this.text().then(JSON.parse)},this}function h(t){var e=t.toUpperCase();return _.indexOf(e)>-1?e:t}function c(t,e){e=e||{};var r=e.body;if("string"==typeof t)this.url=t;else{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)}if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new n(e.headers)),this.method=h(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 l(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 p(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 y(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){var b={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(b.arrayBuffer)var m=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],v=function(t){return t&&DataView.prototype.isPrototypeOf(t)},w=ArrayBuffer.isView||function(t){return t&&m.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)},b.iterable&&(n.prototype[Symbol.iterator]=n.prototype.entries);var _=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];c.prototype.clone=function(){return new c(this,{body:this._bodyInit})},d.call(c.prototype),d.call(y.prototype),y.prototype.clone=function(){return new y(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new n(this.headers),url:this.url})},y.error=function(){var t=new y(null,{status:0,statusText:""});return t.type="error",t};var T=[301,302,303,307,308];y.redirect=function(t,e){if(T.indexOf(e)===-1)throw new RangeError("Invalid status code");return new y(null,{status:e,headers:{location:t}})},t.Headers=n,t.Request=c,t.Response=y,t.fetch=function(t,e){return new Promise(function(r,o){var n=new c(t,e),i=new XMLHttpRequest;i.onload=function(){var t={status:i.status,statusText:i.statusText,headers:p(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 y(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&&b.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){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.fitch=e():t.fitch=e()}(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){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function n(t,e){return(0,l.default)("GET",t,e)}function i(t,e){return(0,l.default)("POST",t,e)}function s(t,e){return(0,l.default)("PUT",t,e)}function a(t,e){return(0,l.default)("PATCH",t,e)}function u(t,e){return(0,l.default)("DELETE",t,e)}function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";console.log("Error >",t)}function d(t){return Promise.all(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.put=e.post=e.patch=e.get=e.error=e.del=e.all=void 0;var h=r(4),l=o(h),c={all:d,del:u,error:f,get:n,patch:a,post:i,put:s};e.default=c,e.all=d,e.del=u,e.error=f,e.get=n,e.patch=a,e.post=i,e.put=s},function(t,e){"use strict";function r(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"json",r=["arrayBuffer","blob","formData","json","text"],o=r.indexOf(e);if(t.ok&&o!==-1)return t[e]();throw new Error(t.status+" - "+t.statusText+".")}Object.defineProperty(e,"__esModule",{value:!0}),e.default=r},function(t,e){"use strict";function r(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.body,o=e.cache,n=void 0===o?"default":o,i=e.credentials,s=e.headers,a=void 0===s?{"Content-Type":"application/json"}:s,u=e.integrity,f=e.mode,d=void 0===f?"cors":f,h=e.redirect,l=e.referrer,c=e.referrerPolicy,p=void 0;r&&(p=JSON.stringify(r));var y={body:p,cache:n,credentials:i,headers:a,method:t,mode:d,redirect:h,referrer:l};return u&&(y.integrity=u),c&&(y.referrerPolicy=c),y}Object.defineProperty(e,"__esModule",{value:!0}),e.default=r},function(t,e){"use strict";function r(t){var e=[];for(var r in t)({}).hasOwnProperty.call(t,r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(t[r]));return e.length?"?"+e.join("&"):""}Object.defineProperty(e,"__esModule",{value:!0}),e.default=r},function(t,e,r){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function n(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o="";r.params&&(o=(0,u.default)(r.params));var n=(0,s.default)(t,r),i=fetch(e+o,n);return r.raw?i:i.then(function(t){return(0,d.default)(t,r.dataType)})}Object.defineProperty(e,"__esModule",{value:!0}),r(5);var i=r(2),s=o(i),a=r(3),u=o(a),f=r(1),d=o(f);e.default=n},function(t,e,r){r(6);var o="undefined"!=typeof self&&self||this;t.exports=o.fetch.bind(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):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 s(t){return new Promise(function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}})}function a(t){var e=new FileReader,r=s(e);return e.readAsArrayBuffer(t),r}function u(t){var e=new FileReader,r=s(e);return e.readAsText(t),r}function f(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 d(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function h(){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=d(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!m.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t)&&!_(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=d(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(a)}),this.text=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return u(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(f(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(p)}),this.json=function(){return this.text().then(JSON.parse)},this}function l(t){var e=t.toUpperCase();return T.indexOf(e)>-1?e:t}function c(t,e){e=e||{};var r=e.body;if("string"==typeof t)this.url=t;else{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)}if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new n(e.headers)),this.method=l(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 p(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 y(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){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)},_=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 T=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];c.prototype.clone=function(){return new c(this,{body:this._bodyInit})},h.call(c.prototype),h.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 P=[301,302,303,307,308];b.redirect=function(t,e){if(P.indexOf(e)===-1)throw new RangeError("Invalid status code");return new b(null,{status:e,headers:{location:t}})},t.Headers=n,t.Request=c,t.Response=b,t.fetch=function(t,e){return new Promise(function(r,o){var n=new c(t,e),i=new XMLHttpRequest;i.onload=function(){var t={status:i.status,statusText:i.statusText,headers:y(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)}])}); | ||
//# sourceMappingURL=index.umd.min.js.map |
@@ -6,5 +6,2 @@ 'use strict'; | ||
}); | ||
require('fetch-everywhere'); | ||
function check(resp) { | ||
@@ -11,0 +8,0 @@ var dataType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'json'; |
{ | ||
"name": "fitch", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"description": "A lightweight Promise based HTTP client, using Fetch API.", | ||
"keywords": [ | ||
"fitch", | ||
"fetch", | ||
"fitch" | ||
"http", | ||
"request", | ||
"promise" | ||
], | ||
@@ -20,7 +23,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"es6-promise": "^4.0.5", | ||
"fetch-everywhere": "^1.0.5" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.16.0", | ||
"ava": "^0.17.0", | ||
"babel-cli": "^6.18.0", | ||
@@ -38,3 +40,3 @@ "babel-eslint": "^7.1.0", | ||
"npm-run-all": "^3.1.1", | ||
"nyc": "^8.4.0", | ||
"nyc": "^9.0.1", | ||
"rimraf": "^2.5.4", | ||
@@ -54,12 +56,6 @@ "webpack": "^1.13.3" | ||
"lint": "eslint src", | ||
"start": "node ./api/index.js", | ||
"start": "node ./examples/api/index.js", | ||
"test": "ava ./tests/*", | ||
"watch:test": "npm test -- -w" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"es2015", | ||
"stage-2" | ||
] | ||
}, | ||
"ava": { | ||
@@ -66,0 +62,0 @@ "require": [ |
@@ -1,2 +0,3 @@ | ||
 | ||
 | ||
# Fitch.js | ||
@@ -14,2 +15,10 @@ A lightweight Promise based HTTP client, using Fetch API. | ||
## Features | ||
- Uses [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) | ||
- Works on both old and new browsers and on Node.js | ||
- Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API | ||
- Transform request and response data | ||
- Automatic transforms for JSON data | ||
## Get started | ||
@@ -41,3 +50,3 @@ | ||
```html | ||
<script src="node_modules/fitch/dist/index.umd.min.js"></script> | ||
<script src="https://unpkg.com/fitch/dist/index.umd.min.js"></script> | ||
``` | ||
@@ -107,2 +116,21 @@ | ||
## Concurrency | ||
### all | ||
Helper function for dealing with concurrent requests. | ||
```js | ||
const reqDogs = fitch.get('/dogs') | ||
const reqCats = fitch.get('/cats') | ||
function doSomething([ responseDogs, responseCats ]) { | ||
console.log('Dogs\t>>>', responseDogs) | ||
console.log('Cats\t>>>', responseCats) | ||
} | ||
fitch.all([ reqDogs, reqCats ]) | ||
.then(doSomething) | ||
``` | ||
## Browser Support | ||
@@ -126,1 +154,4 @@ | ||
You can verify your code with ESLint, using `npm run lint`. | ||
## Logo | ||
Copyright © [Bárbara Schoen](https://www.linkedin.com/in/b%C3%A1rbara-schoen-692269b6) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
159724
1
19
154
788
- Removedes6-promise@^4.0.5
- Removedes6-promise@4.2.8(transitive)