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

use-abortable-fetch

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-abortable-fetch - npm Package Compare versions

Comparing version 2.6.3 to 2.6.4

39

package.json
{
"name": "use-abortable-fetch",
"version": "2.6.3",
"version": "2.6.4",
"main": "release/index.js",

@@ -15,29 +15,32 @@ "umd:main": "release/index.umd.js",

},
"repository": "git@github.com:mauricedb/use-abortable-fetch.git",
"repository": {
"type": "git",
"url": "git@github.com:mauricedb/use-abortable-fetch.git"
},
"author": "Maurice de Beijer <maurice.de.beijer@gmail.com>",
"license": "MIT",
"devDependencies": {
"@testing-library/react": "9.1.4",
"@types/content-type": "1.1.3",
"@types/jest": "^24.0.9",
"@types/jest": "24.0.18",
"@types/media-typer": "0.3.0",
"@types/react": "16.8.18",
"@types/react-dom": "16.8.4",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"@typescript-eslint/parser": "^1.4.2",
"eslint": "^5.15.1",
"eslint-config-prettier": "4.3.0",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^1.5.1",
"jest": "24.3.1",
"@types/react": "16.9.3",
"@types/react-dom": "16.9.0",
"@typescript-eslint/eslint-plugin": "2.3.1",
"@typescript-eslint/parser": "2.3.0",
"eslint": "6.4.0",
"eslint-config-prettier": "6.3.0",
"eslint-plugin-react": "7.14.3",
"eslint-plugin-react-hooks": "2.0.0",
"jest": "24.8.0",
"jest-fetch-mock": "2.1.2",
"microbundle": "0.11.0",
"parcel-bundler": "1.12.3",
"prettier": "1.17.1",
"react": "16.8.6",
"react-dom": "16.8.6",
"react-testing-library": "7.0.1",
"ts-jest": "24.0.2"
"prettier": "1.18.2",
"react": "16.9.0",
"react-dom": "16.9.0",
"ts-jest": "24.1.0"
},
"peerDependencies": {
"react": ">= 16.8.0"
"react": ">=16.8.0"
},

@@ -44,0 +47,0 @@ "dependencies": {

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

function n(n){return n&&"object"==typeof n&&"default"in n?n.default:n}var t=require("react"),e=n(require("media-typer")),r=n(require("content-type"));const o=function(){function n(){}return n.prototype.then=function(t,e){const r=new n,o=this.s;if(o){const n=1&o?t:e;if(n){try{u(r,1,n(this.v))}catch(n){u(r,2,n)}return r}return this}return this.o=function(n){try{const o=n.v;1&n.s?u(r,1,t?t(o):o):e?u(r,1,e(o)):u(r,2,o)}catch(n){u(r,2,n)}},r},n}();function u(n,t,e){if(!n.s){if(e instanceof o){if(!e.s)return void(e.o=u.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(u.bind(null,n,t),u.bind(null,n,2));n.s=t,n.v=e;const r=n.o;r&&r(n)}}const i={};!function(){function n(n){this._entry=n,this._pact=null,this._resolve=null,this._return=null,this._promise=null}function t(n){return{value:n,done:!0}}function e(n){return{value:n,done:!1}}n.prototype[Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator"))]=function(){return this},n.prototype._yield=function(n){return this._resolve(n&&n.then?n.then(e):e(n)),this._pact=new o},n.prototype.next=function(n){const e=this;return e._promise=new Promise(function(r){const l=e._pact;if(null===l){const n=e._entry;if(null===n)return r(e._promise);function s(n){e._resolve(n&&n.then?n.then(t):t(n)),e._pact=null,e._resolve=null}e._entry=null,e._resolve=r,n(e).then(s,function(n){if(n===i)s(e._return);else{const t=new o;e._resolve(t),e._pact=null,e._resolve=null,_resolve(t,2,n)}})}else e._pact=null,e._resolve=r,u(l,1,n)})},n.prototype.return=function(n){const e=this;return e._promise=new Promise(function(r){const o=e._pact;if(null===o)return null===e._entry?r(e._promise):(e._entry=null,r(n&&n.then?n.then(t):t(n)));e._return=n,e._resolve=r,e._pact=null,u(o,2,i)})},n.prototype.throw=function(n){const t=this;return t._promise=new Promise(function(e,r){const o=t._pact;if(null===o)return null===t._entry?e(t._promise):(t._entry=null,r(n));t._resolve=e,t._pact=null,u(o,2,n)})}}(),module.exports=function(n,o){var u=t.useState({data:null,loading:0,error:null,controller:null}),i=u[0],l=u[1],s=t.useRef(!1);return t.useLayoutEffect(function(){return s.current=!0,function(){s.current=!1}},[]),t.useEffect(function(){var t=new AbortController;return n&&function(n,t,o,u){void 0===t&&(t={});try{var i=Object.assign({},t,{signal:o.signal}),l=null;Promise.resolve(function(t,s){try{var c=(u(function(n){return{data:null,loading:n.loading+1,error:null,controller:o}}),Promise.resolve(fetch(n,i)).then(function(n){function t(){if(!l.ok){var n=new Error(l.statusText);throw n.status=l.status,n}}var o=(l=n).headers.get("content-type"),i=function(){if(o){function n(){u(function(n){return Object.assign({},n,{data:t,loading:n.loading-1})})}var t=null,i=function(n){if(n){var t=r.parse(n),o=e.parse(t.type);if("json"===o.subtype)return!0;if("json"===o.suffix)return!0;if(o.suffix&&/\bjson\b/i.test(o.suffix))return!0;if(o.subtype&&/\bjson\b/i.test(o.subtype))return!0}return!1}(o)?Promise.resolve(l.json()).then(function(n){t=n}):Promise.resolve(l.text()).then(function(n){t=n});return i&&i.then?i.then(n):n()}u(function(n){return Object.assign({},n,{loading:n.loading-1})})}();return i&&i.then?i.then(t):t()}))}catch(n){return s(n)}return c&&c.then?c.then(void 0,s):c}(0,function(n){var t="AbortError"!==n.name?n:null;u(function(n){return Object.assign({},n,{error:t,loading:l?n.loading:n.loading-1})})}))}catch(n){return Promise.reject(n)}}(n,o,t,function(n){s.current&&l(n)}),function(){return t.abort()}},[o,n]),{data:i.data,loading:!!i.loading,error:i.error,abort:function(){return i.controller&&i.controller.abort()}}};
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var r=require("react"),n=t(require("media-typer")),e=t(require("content-type"));"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator"))),module.exports=function(t,o){var u=r.useState({data:null,loading:0,error:null,controller:null}),i=u[0],a=u[1],l=r.useRef(!1);return r.useLayoutEffect(function(){return l.current=!0,function(){l.current=!1}},[]),r.useEffect(function(){var r=new AbortController;return t&&function(t,r,o,u){void 0===r&&(r={});try{var i=Object.assign({},r,{signal:o.signal}),a=null;Promise.resolve(function(r,l){try{var s=(u(function(t){return{data:null,loading:t.loading+1,error:null,controller:o}}),Promise.resolve(fetch(t,i)).then(function(t){function r(){if(!a.ok){var t=new Error(a.statusText);throw t.status=a.status,t}}var o=(a=t).headers.get("content-type"),i=function(){if(o){function t(){u(function(t){return Object.assign({},t,{data:r,loading:t.loading-1})})}var r=null,i=function(t){if(t){var r=e.parse(t),o=n.parse(r.type);if("json"===o.subtype)return!0;if("json"===o.suffix)return!0;if(o.suffix&&/\bjson\b/i.test(o.suffix))return!0;if(o.subtype&&/\bjson\b/i.test(o.subtype))return!0}return!1}(o)?Promise.resolve(a.json()).then(function(t){r=t}):Promise.resolve(a.text()).then(function(t){r=t});return i&&i.then?i.then(t):t()}u(function(t){return Object.assign({},t,{loading:t.loading-1})})}();return i&&i.then?i.then(r):r()}))}catch(t){return l(t)}return s&&s.then?s.then(void 0,l):s}(0,function(t){var r="AbortError"!==t.name?t:null;u(function(t){return Object.assign({},t,{error:r,loading:a?t.loading:t.loading-1})})}))}catch(t){return Promise.reject(t)}}(t,o,r,function(t){l.current&&a(t)}),function(){return r.abort()}},[o,t]),{data:i.data,loading:!!i.loading,error:i.error,abort:function(){return i.controller&&i.controller.abort()}}};
//# sourceMappingURL=index.js.map

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

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("media-typer"),require("content-type")):"function"==typeof define&&define.amd?define(["react","media-typer","content-type"],t):n.useAbortableFetch=t(n.react,n.mediaTyper,n.contentType)}(this,function(n,t,e){t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;const r=function(){function n(){}return n.prototype.then=function(t,e){const r=new n,u=this.s;if(u){const n=1&u?t:e;if(n){try{o(r,1,n(this.v))}catch(n){o(r,2,n)}return r}return this}return this.o=function(n){try{const u=n.v;1&n.s?o(r,1,t?t(u):u):e?o(r,1,e(u)):o(r,2,u)}catch(n){o(r,2,n)}},r},n}();function o(n,t,e){if(!n.s){if(e instanceof r){if(!e.s)return void(e.o=o.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(o.bind(null,n,t),o.bind(null,n,2));n.s=t,n.v=e;const u=n.o;u&&u(n)}}const u={};return function(){function n(n){this._entry=n,this._pact=null,this._resolve=null,this._return=null,this._promise=null}function t(n){return{value:n,done:!0}}function e(n){return{value:n,done:!1}}n.prototype[Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator"))]=function(){return this},n.prototype._yield=function(n){return this._resolve(n&&n.then?n.then(e):e(n)),this._pact=new r},n.prototype.next=function(n){const e=this;return e._promise=new Promise(function(i){const l=e._pact;if(null===l){const n=e._entry;if(null===n)return i(e._promise);function s(n){e._resolve(n&&n.then?n.then(t):t(n)),e._pact=null,e._resolve=null}e._entry=null,e._resolve=i,n(e).then(s,function(n){if(n===u)s(e._return);else{const t=new r;e._resolve(t),e._pact=null,e._resolve=null,_resolve(t,2,n)}})}else e._pact=null,e._resolve=i,o(l,1,n)})},n.prototype.return=function(n){const e=this;return e._promise=new Promise(function(r){const i=e._pact;if(null===i)return null===e._entry?r(e._promise):(e._entry=null,r(n&&n.then?n.then(t):t(n)));e._return=n,e._resolve=r,e._pact=null,o(i,2,u)})},n.prototype.throw=function(n){const t=this;return t._promise=new Promise(function(e,r){const u=t._pact;if(null===u)return null===t._entry?e(t._promise):(t._entry=null,r(n));t._resolve=e,t._pact=null,o(u,2,n)})}}(),function(r,o){var u=n.useState({data:null,loading:0,error:null,controller:null}),i=u[0],l=u[1],s=n.useRef(!1);return n.useLayoutEffect(function(){return s.current=!0,function(){s.current=!1}},[]),n.useEffect(function(){var n=new AbortController;return r&&function(n,r,o,u){void 0===r&&(r={});try{var i=Object.assign({},r,{signal:o.signal}),l=null;Promise.resolve(function(r,s){try{var c=(u(function(n){return{data:null,loading:n.loading+1,error:null,controller:o}}),Promise.resolve(fetch(n,i)).then(function(n){function r(){if(!l.ok){var n=new Error(l.statusText);throw n.status=l.status,n}}var o=(l=n).headers.get("content-type"),i=function(){if(o){function n(){u(function(n){return Object.assign({},n,{data:r,loading:n.loading-1})})}var r=null,i=function(n){if(n){var r=e.parse(n),o=t.parse(r.type);if("json"===o.subtype)return!0;if("json"===o.suffix)return!0;if(o.suffix&&/\bjson\b/i.test(o.suffix))return!0;if(o.subtype&&/\bjson\b/i.test(o.subtype))return!0}return!1}(o)?Promise.resolve(l.json()).then(function(n){r=n}):Promise.resolve(l.text()).then(function(n){r=n});return i&&i.then?i.then(n):n()}u(function(n){return Object.assign({},n,{loading:n.loading-1})})}();return i&&i.then?i.then(r):r()}))}catch(n){return s(n)}return c&&c.then?c.then(void 0,s):c}(0,function(n){var t="AbortError"!==n.name?n:null;u(function(n){return Object.assign({},n,{error:t,loading:l?n.loading:n.loading-1})})}))}catch(n){return Promise.reject(n)}}(r,o,n,function(n){s.current&&l(n)}),function(){return n.abort()}},[o,r]),{data:i.data,loading:!!i.loading,error:i.error,abort:function(){return i.controller&&i.controller.abort()}}}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react"),require("media-typer"),require("content-type")):"function"==typeof define&&define.amd?define(["react","media-typer","content-type"],e):t.useAbortableFetch=e(t.react,t.mediaTyper,t.contentType)}(this,function(t,e,n){return e=e&&e.hasOwnProperty("default")?e.default:e,n=n&&n.hasOwnProperty("default")?n.default:n,"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator"))),function(r,o){var u=t.useState({data:null,loading:0,error:null,controller:null}),i=u[0],a=u[1],l=t.useRef(!1);return t.useLayoutEffect(function(){return l.current=!0,function(){l.current=!1}},[]),t.useEffect(function(){var t=new AbortController;return r&&function(t,r,o,u){void 0===r&&(r={});try{var i=Object.assign({},r,{signal:o.signal}),a=null;Promise.resolve(function(r,l){try{var f=(u(function(t){return{data:null,loading:t.loading+1,error:null,controller:o}}),Promise.resolve(fetch(t,i)).then(function(t){function r(){if(!a.ok){var t=new Error(a.statusText);throw t.status=a.status,t}}var o=(a=t).headers.get("content-type"),i=function(){if(o){function t(){u(function(t){return Object.assign({},t,{data:r,loading:t.loading-1})})}var r=null,i=function(t){if(t){var r=n.parse(t),o=e.parse(r.type);if("json"===o.subtype)return!0;if("json"===o.suffix)return!0;if(o.suffix&&/\bjson\b/i.test(o.suffix))return!0;if(o.subtype&&/\bjson\b/i.test(o.subtype))return!0}return!1}(o)?Promise.resolve(a.json()).then(function(t){r=t}):Promise.resolve(a.text()).then(function(t){r=t});return i&&i.then?i.then(t):t()}u(function(t){return Object.assign({},t,{loading:t.loading-1})})}();return i&&i.then?i.then(r):r()}))}catch(t){return l(t)}return f&&f.then?f.then(void 0,l):f}(0,function(t){var e="AbortError"!==t.name?t:null;u(function(t){return Object.assign({},t,{error:e,loading:a?t.loading:t.loading-1})})}))}catch(t){return Promise.reject(t)}}(r,o,t,function(t){l.current&&a(t)}),function(){return t.abort()}},[o,r]),{data:i.data,loading:!!i.loading,error:i.error,abort:function(){return i.controller&&i.controller.abort()}}}});
//# sourceMappingURL=index.umd.js.map

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

export default function isJSON(contentTypeHeader: string | null): boolean;
export default function isJSON(contentTypeHeader: string | null | undefined): boolean;

@@ -16,8 +16,10 @@ import { Dispatch, SetStateAction } from 'react';

try {
setState((oldState: FetchState<T>) => ({
data: null,
loading: oldState.loading + 1,
error: null,
controller
}));
setState(
(oldState: FetchState<T>): FetchState<T> => ({
data: null,
loading: oldState.loading + 1,
error: null,
controller
})
);

@@ -35,12 +37,16 @@ rsp = await fetch(url, actualInit);

}
setState((oldState: FetchState<T>) => ({
...oldState,
data,
loading: oldState.loading - 1
}));
setState(
(oldState: FetchState<T>): FetchState<T> => ({
...oldState,
data,
loading: oldState.loading - 1
})
);
} else {
setState((oldState: FetchState<T>) => ({
...oldState,
loading: oldState.loading - 1
}));
setState(
(oldState: FetchState<T>): FetchState<T> => ({
...oldState,
loading: oldState.loading - 1
})
);
}

@@ -58,8 +64,10 @@

setState((oldState: FetchState<T>) => ({
...oldState,
error,
// Only decrease the loading counter if there is no repsonse
loading: rsp ? oldState.loading : oldState.loading - 1
}));
setState(
(oldState: FetchState<T>): FetchState<T> => ({
...oldState,
error,
// Only decrease the loading counter if there is no repsonse
loading: rsp ? oldState.loading : oldState.loading - 1
})
);
}

@@ -66,0 +74,0 @@ };

@@ -18,5 +18,5 @@ import { useState, useEffect, useLayoutEffect, useRef } from 'react';

const isMounted = useRef(false);
useLayoutEffect(() => {
useLayoutEffect((): (() => void) => {
isMounted.current = true;
return () => {
return (): void => {
isMounted.current = false;

@@ -26,6 +26,6 @@ };

useEffect(() => {
useEffect((): (() => void) => {
const controller = new AbortController();
if (url) {
fetchData<T>(url, init, controller, state => {
fetchData<T>(url, init, controller, (state): void => {
if (isMounted.current) {

@@ -37,3 +37,3 @@ setState(state);

return () => controller.abort();
return (): void => controller.abort();
}, [init, url]);

@@ -45,3 +45,3 @@

error: state.error,
abort: () => state.controller && state.controller.abort()
abort: (): null | void => state.controller && state.controller.abort()
};

@@ -48,0 +48,0 @@ };

@@ -21,3 +21,3 @@ import isJSON from './isJSON';

'model/gltf+json'
])('Content type "%s" should be JSON', (contentType: string) => {
])('Content type "%s" should be JSON', (contentType: string): void => {
expect(isJSON(contentType)).toBeTruthy();

@@ -34,4 +34,7 @@ });

'text/html'
])('Content type "%s" should not be JSON', (contentType: string) => {
expect(isJSON(contentType)).toBeFalsy();
});
])(
'Content type "%s" should not be JSON',
(contentType: string | null | undefined): void => {
expect(isJSON(contentType)).toBeFalsy();
}
);
import mediaTyper from 'media-typer';
import contentType from 'content-type';
export default function isJSON(contentTypeHeader: string | null): boolean {
export default function isJSON(
contentTypeHeader: string | null | undefined
): boolean {
if (contentTypeHeader) {

@@ -6,0 +8,0 @@ const ct = contentType.parse(contentTypeHeader);

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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