@fatcherjs/middleware-aborter 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -1,10 +1,8 @@
1
- import { warn } from 'fatcher';
2
-
3
1
  function aborter(options = {}) {
4
2
  const { timeout = 0, onAbort = null } = options;
5
3
  let _timeout = timeout;
6
4
  if (isNaN(timeout) || ~~timeout <= 0) {
7
- warn("<Aborter> Timeout is not a valid number.");
5
+ console.warn("[fatcher-middleware-aborter] Timeout is not a valid number.");
8
6
  _timeout = 0;
9
7
  }
10
8
  return {
@@ -2,13 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var fatcher = require('fatcher');
6
-
7
5
  function aborter(options = {}) {
8
6
  const { timeout = 0, onAbort = null } = options;
9
7
  let _timeout = timeout;
10
8
  if (isNaN(timeout) || ~~timeout <= 0) {
11
- fatcher.warn("<Aborter> Timeout is not a valid number.");
9
+ console.warn("[fatcher-middleware-aborter] Timeout is not a valid number.");
12
10
  _timeout = 0;
13
11
  }
14
12
  return {
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e.FatcherMiddlewareAborter={}))})(this,function(e){"use strict";function t(a={}){const{timeout:o=0,onAbort:r=null}=a;let n=o;return(isNaN(o)||~~o<=0)&&(console.warn("[fatcher-middleware-aborter] Timeout is not a valid number."),n=0),{name:"fatcher-middleware-aborter",async use(c,u){const i=new AbortController,s=u({signal:i.signal});if(!n)return s;const l=setTimeout(()=>{i.abort(),r?.()},n),d=await s;return clearTimeout(l),d}}}e.aborter=t,Object.defineProperty(e,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,21 +1,25 @@
1
1
  {
2
2
  "name": "@fatcherjs/middleware-aborter",
3
- "version": "1.0.0",
4
- "main": "dist/index.js",
5
- "module": "dist/index.esm.js",
6
- "browser": "dist/index.min.js",
7
- "typings": "dist/index.d.ts",
8
- "repository": "https://github.com/fatcherjs/middlewares/tree/master/packages/aborter",
3
+ "version": "1.2.0",
4
+ "main": "dist/aborter.js",
5
+ "module": "dist/aborter.esm.js",
6
+ "browser": "dist/aborter.min.js",
7
+ "typings": "dist/aborter.d.ts",
9
8
  "license": "MIT",
10
9
  "files": [
11
10
  "dist"
12
11
  ],
12
+ "homepage": "https://github.com/fatcherjs/fatcher/tree/master/packages/aborter",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/fatcherjs/fatcher.git"
16
+ },
13
17
  "peerDependencies": {
14
18
  "fatcher": "^1.0.0"
15
19
  },
16
20
  "scripts": {
17
21
  "dev": "rimraf dist && rollup -c rollup.config.ts -w",
18
- "build": "rimraf dist && rollup -c rollup.config.ts"
19
- },
20
- "readme": "# @fatcherjs/middleware-aborter\n\nA middleware for aborting fatcher request.\n\n## Install\n\n### NPM\n\n```bash\n>$ npm install @fatcherjs/middleware-aborter\n```\n\n### CDN\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/@fatcherjs/middleware-aborter/dist/index.min.js\"></script>\n```\n\n## Usage\n\n```ts\nimport { aborter } from '@fatcherjs/middleware-aborter';\nimport { fatcher, isAbortError } from 'fatcher';\n\nfatcher({\n url: '/bar/foo',\n middlewares: [\n aborter({\n timeout: 10 * 1000, // 10s\n onAbort: () => {\n console.log('Request is Aborted.');\n },\n }),\n ],\n})\n .then(res => {\n // Request success in 10s\n console.log(res);\n })\n .catch(err => {\n if (isAbortError(err)) {\n //Run error when request aborted.\n console.error(err);\n }\n\n // Other errors.\n });\n```\n\n## Options\n\n### timeout\n\n- Type: `number`\n- DefaultValue: `0`\n- Description:\n\nIf `timeout > 0`, will abort this request later.\n\nAborted request will throw a DOMException which can use `isAbortError` to confirm.\n\n### onAbort\n\n- Type: `(() => void) | null`\n- DefaultValue: `null`\n- Description:\n\nA callback when aborting this request.\n\n## License\n\n[MIT](../../LICENSE)\n"
22
+ "build": "rimraf dist && rollup -c rollup.config.ts",
23
+ "deploy": "pnpm run build && pnpm publish --no-git-check"
24
+ }
21
25
  }
package/dist/index.min.js DELETED
@@ -1 +0,0 @@
1
- (function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("fatcher")):typeof define=="function"&&define.amd?define(["exports","fatcher"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e.FatcherMiddlewareAborter={},e.Fatcher))})(this,function(e,t){"use strict";function u(a={}){const{timeout:r=0,onAbort:o=null}=a;let n=r;return(isNaN(r)||~~r<=0)&&(t.warn("<Aborter> Timeout is not a valid number."),n=0),{name:"fatcher-middleware-aborter",async use(l,c){const i=new AbortController,s=c({signal:i.signal});if(!n)return s;const f=setTimeout(()=>{i.abort(),o?.()},n),d=await s;return clearTimeout(f),d}}}e.aborter=u,Object.defineProperty(e,"__esModule",{value:!0})});