{"_id":"@alessiofrittoli/abort-controller","name":"@alessiofrittoli/abort-controller","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@alessiofrittoli/abort-controller","version":"0.1.0","description":"Typed AbortController","author":{"name":"Alessio Frittoli","email":"info@alessiofrittoli.it","url":"https://alessiofrittoli.it"},"license":"MIT","funding":[{"type":"github","url":"https://github.com/sponsors/alessiofrittoli"}],"keywords":["abort-controller"],"homepage":"https://github.com/alessiofrittoli/abort-controller#readme","bugs":{"url":"https://github.com/alessiofrittoli/abort-controller/issues","email":"info@alessiofrittoli.it"},"repository":{"type":"git","url":"git+https://github.com/alessiofrittoli/abort-controller.git"},"main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","sideEffects":false,"scripts":{"//1a":"*********************************************************************","//1b":"******************** DEV - BUILD - LINT - RELEASE *******************","//1c":"*********************************************************************","dev":"NODE_ENV=development tsup --watch","build:prod":"NODE_ENV=production tsup","build":"pnpm lint && pnpm test:ci && pnpm build:prod","lint":"eslint","release":"node scripts/publish.js --verbose --npm","//2a":"*********************************************************************","//2b":"***************************** UNIT TESTS ****************************","//2c":"*********************************************************************","test":"jest --verbose","test:watch":"jest --watchAll --verbose","test:ci":"jest --ci --verbose","//3a":"*********************************************************************","//3b":"************************ UNIT TESTS COVERAGE ************************","//3c":"*********************************************************************","test:coverage":"pnpm test:watch --coverage","test:coverage:ci":"pnpm test:ci --coverage","test:serve-coverage":"http-server ./coverage/lcov-report --gzip true -p 0 -o --silent","test:coverage:serve":"concurrently --prefix none --kill-others \"pnpm test:coverage\" \"pnpm test:serve-coverage\""},"pnpm":{"onlyBuiltDependencies":["esbuild"]},"devDependencies":{"@alessiofrittoli/node-scripts":"^2.5.0","@eslint/js":"^9.25.1","@jest/globals":"^29.7.0","@types/jest":"^29.5.14","@types/node":"^22.15.3","concurrently":"^9.1.2","dotenv":"^16.5.0","eslint":"^9.25.1","globals":"^16.0.0","http-server":"^14.1.1","jest":"^29.7.0","jest-environment-jsdom":"^29.7.0","ts-jest":"^29.3.2","ts-node":"^10.9.2","tsup":"^8.4.0","typescript":"^5.8.3","typescript-eslint":"^8.31.1"},"dependencies":{"@alessiofrittoli/exception":"^3.2.0"},"_id":"@alessiofrittoli/abort-controller@0.1.0","gitHead":"d5f193a9bc60fe6effa87db412a0f975f6513a6d","_nodeVersion":"22.12.0","_npmVersion":"11.0.0","dist":{"integrity":"sha512-bVx5XvRT33AOqFI7yvelOEsIVrs6myMzQYQujCjAX5DDRYOA0P9YuR/dVSZmxDLOs5ZKzD4z/6+zKJt1imvtEw==","shasum":"dc12f7a1ae322c542fbdbec59789248a86f3d0b6","tarball":"https://registry.npmjs.org/@alessiofrittoli/abort-controller/-/abort-controller-0.1.0.tgz","fileCount":7,"unpackedSize":15603,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCGg+MqFfP5XcBAAtyL/yEzYdszuw1pLDQESpHgYr5TFgIgahZ6RUEQdKFnOnLcXnagAGngdA2k5cYs14aj7EjPZbA="}]},"_npmUser":{"name":"alessiofrittoli","email":"info@alessiofrittoli.it"},"directories":{},"maintainers":[{"name":"alessiofrittoli","email":"info@alessiofrittoli.it"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/abort-controller_0.1.0_1746181975869_0.6237583849023682"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-02T10:32:55.787Z","0.1.0":"2025-05-02T10:32:56.044Z","modified":"2025-05-02T10:32:56.277Z"},"maintainers":[{"name":"alessiofrittoli","email":"info@alessiofrittoli.it"}],"description":"Typed AbortController","homepage":"https://github.com/alessiofrittoli/abort-controller#readme","keywords":["abort-controller"],"repository":{"type":"git","url":"git+https://github.com/alessiofrittoli/abort-controller.git"},"author":{"name":"Alessio Frittoli","email":"info@alessiofrittoli.it","url":"https://alessiofrittoli.it"},"bugs":{"url":"https://github.com/alessiofrittoli/abort-controller/issues","email":"info@alessiofrittoli.it"},"license":"MIT","readme":"# AbortController 🛑\n\n[![NPM Latest Version][version-badge]][npm-url] [![Coverage Status][coverage-badge]][coverage-url] [![Socket Status][socket-badge]][socket-url] [![NPM Monthly Downloads][downloads-badge]][npm-url] [![Dependencies][deps-badge]][deps-url]\n\n[![GitHub Sponsor][sponsor-badge]][sponsor-url]\n\n[version-badge]: https://img.shields.io/npm/v/%40alessiofrittoli%2Fabort-controller\n[npm-url]: https://npmjs.org/package/%40alessiofrittoli%2Fabort-controller\n[coverage-badge]: https://coveralls.io/repos/github/alessiofrittoli/abort-controller/badge.svg\n[coverage-url]: https://coveralls.io/github/alessiofrittoli/abort-controller\n[socket-badge]: https://socket.dev/api/badge/npm/package/@alessiofrittoli/abort-controller\n[socket-url]: https://socket.dev/npm/package/@alessiofrittoli/abort-controller/overview\n[downloads-badge]: https://img.shields.io/npm/dm/%40alessiofrittoli%2Fabort-controller.svg\n[deps-badge]: https://img.shields.io/librariesio/release/npm/%40alessiofrittoli%2Fabort-controller\n[deps-url]: https://libraries.io/npm/%40alessiofrittoli%2Fabort-controller\n\n[sponsor-badge]: https://img.shields.io/static/v1?label=Fund%20this%20package&message=%E2%9D%A4&logo=GitHub&color=%23DB61A2\n[sponsor-url]: https://github.com/sponsors/alessiofrittoli\n\n## Typed AbortController\n\n### Table of Contents\n\n- [Getting started](#getting-started)\n- [API Reference](#api-reference)\n  - [Type Parameters](#type-parameters)\n  - [Methods](#methods)\n  - [Examples](#examples)\n- [Development](#development)\n  - [Install depenendencies](#install-depenendencies)\n  - [Build the source code](#build-the-source-code)\n  - [ESLint](#eslint)\n  - [Jest](#jest)\n- [Contributing](#contributing)\n- [Security](#security)\n- [Credits](#made-with-)\n\n---\n\n### Getting started\n\nRun the following command to start using `abort-controller` in your projects:\n\n```bash\nnpm i @alessiofrittoli/abort-controller\n```\n\nor using `pnpm`\n\n```bash\npnpm i @alessiofrittoli/abort-controller\n```\n\n---\n\n### API Reference\n\nThe `AbortController` Class extends the [Native Web API AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) Class, but provides a typed `.abort()` method and `.signal.reason` using the [`AbortError`](https://npmjs.com/package/@alessiofrittoli/exception#aborterror-class) provided by [`@alessiofrittoli/exception`](https://npmjs.com/package/@alessiofrittoli/exception) package.\n\n#### Type Parameters\n\n| Parameter | Default | Description |\n|-----------|---------|-------------|\n| `TCode`   | `ErrorCode` | A custom type assigned to the `AbortError.code`. Default: [`ErrorCode`](https://www.npmjs.com/package/@alessiofrittoli/exception#errorcode-enum). |\n\n---\n\n#### Methods\n\n##### `AbortController.abort()`\n\nInvoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.\n\n<details>\n\n<summary style=\"cursor:pointer\">Parameters</summary>\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `reason`  | `string` | 'The operation was aborted.' | The abort reason. This will be set to `AbortError.message`. |\n| `option`  | `AbortErrorOptions<TCode>` | - | Custom `AbortError` options. |\n\n</details>\n\n---\n\n#### Examples\n\n##### Listening to abort events\n\n```ts\nimport { AbortController } from '@alessiofrittoli/abort-controller'\n\nconst controller  = new AbortController()\nconst { signal }  = controller\n\nsignal.addEventListener( 'abort', event => {\n  console.log( 'Aborted at', event.timeStamp )\n  console.log( signal.reason ) // `AbortSignal.reason` is now type of `AbortError`\n} )\n\nbutton.addEventListener( 'click', () => {\n  controller.abort( 'User aborted the request.' )\n} )\n```\n\n---\n\n##### Using custom AbortError codes\n\n```ts\nimport { AbortController } from '@alessiofrittoli/abort-controller'\n\nenum CustomAbortErrorCode\n{\n  REASON_1 = 'ERR:ABORTREASON1',\n  REASON_2 = 'ERR:ABORTREASON2',\n}\n\nconst controller  = new AbortController()\nconst { signal }  = controller\n\nsignal.addEventListener( 'abort', () => {\n  switch ( signal.reason.code ) {\n    case CustomAbortErrorCode.REASON_1:\n      console.log( 'User aborted the request due to button 1 click.' )\n      break\n    \n    case CustomAbortErrorCode.REASON_2:\n      console.log( 'User aborted the request due to button 2 click.' )\n      break\n  \n    default:\n      console.log( 'User aborted the request due to unknown reason.' )\n      break\n  }\n} )\n  \nbutton.addEventListener( 'click', () => {\n  controller.abort( 'User clicked button 1.', { code: CustomAbortErrorCode.REASON_1 } )\n} )\n\nbutton2.addEventListener( 'click', () => {\n  controller.abort( 'User clicked button 2.', { code: CustomAbortErrorCode.REASON_2 } )\n} )\n```\n\n---\n\n### Development\n\n#### Install depenendencies\n\n```bash\nnpm install\n```\n\nor using `pnpm`\n\n```bash\npnpm i\n```\n\n#### Build the source code\n\nRun the following command to test and build code for distribution.\n\n```bash\npnpm build\n```\n\n#### [ESLint](https://www.npmjs.com/package/eslint)\n\nwarnings / errors check.\n\n```bash\npnpm lint\n```\n\n#### [Jest](https://npmjs.com/package/jest)\n\nRun all the defined test suites by running the following:\n\n```bash\n# Run tests and watch file changes.\npnpm test:watch\n\n# Run tests in a CI environment.\npnpm test:ci\n```\n\n- See [`package.json`](./package.json) file scripts for more info.\n\nRun tests with coverage.\n\nAn HTTP server is then started to serve coverage files from `./coverage` folder.\n\n⚠️ You may see a blank page the first time you run this command. Simply refresh the browser to see the updates.\n\n```bash\ntest:coverage:serve\n```\n\n---\n\n### Contributing\n\nContributions are truly welcome!\n\nPlease refer to the [Contributing Doc](./CONTRIBUTING.md) for more information on how to start contributing to this project.\n\nHelp keep this project up to date with [GitHub Sponsor][sponsor-url].\n\n[![GitHub Sponsor][sponsor-badge]][sponsor-url]\n\n---\n\n### Security\n\nIf you believe you have found a security vulnerability, we encourage you to **_responsibly disclose this and NOT open a public issue_**. We will investigate all legitimate reports. Email `security@alessiofrittoli.it` to disclose any security vulnerabilities.\n\n### Made with ☕\n\n<table style='display:flex;gap:20px;'>\n  <tbody>\n    <tr>\n      <td>\n        <img alt=\"avatar\" src='https://avatars.githubusercontent.com/u/35973186' style='width:60px;border-radius:50%;object-fit:contain;'>\n      </td>\n      <td>\n        <table style='display:flex;gap:2px;flex-direction:column;'>\n          <tbody>\n              <tr>\n                <td>\n                  <a href='https://github.com/alessiofrittoli' target='_blank' rel='noopener'>Alessio Frittoli</a>\n                </td>\n              </tr>\n              <tr>\n                <td>\n                  <small>\n                    <a href='https://alessiofrittoli.it' target='_blank' rel='noopener'>https://alessiofrittoli.it</a> |\n                    <a href='mailto:info@alessiofrittoli.it' target='_blank' rel='noopener'>info@alessiofrittoli.it</a>\n                  </small>\n                </td>\n              </tr>\n          </tbody>\n        </table>\n      </td>\n    </tr>\n  </tbody>\n</table>\n","readmeFilename":"README.md","_rev":"1-c0e20f798dda16f77374d70270d1bc6b"}