{"id":28755533,"url":"https://github.com/alessiofrittoli/abort-controller","last_synced_at":"2026-02-26T21:03:47.315Z","repository":{"id":291087835,"uuid":"976511133","full_name":"alessiofrittoli/abort-controller","owner":"alessiofrittoli","description":"Typed AbortController","archived":false,"fork":false,"pushed_at":"2025-05-02T10:32:37.000Z","size":137,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-06T01:23:36.545Z","etag":null,"topics":["abort-controller"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@alessiofrittoli/abort-controller","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alessiofrittoli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"license.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["alessiofrittoli"]}},"created_at":"2025-05-02T08:35:21.000Z","updated_at":"2025-05-02T10:34:04.000Z","dependencies_parsed_at":"2025-05-02T10:53:29.421Z","dependency_job_id":null,"html_url":"https://github.com/alessiofrittoli/abort-controller","commit_stats":null,"previous_names":["alessiofrittoli/abort-controller"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alessiofrittoli/abort-controller","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiofrittoli%2Fabort-controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiofrittoli%2Fabort-controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiofrittoli%2Fabort-controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiofrittoli%2Fabort-controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alessiofrittoli","download_url":"https://codeload.github.com/alessiofrittoli/abort-controller/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiofrittoli%2Fabort-controller/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260275179,"owners_count":22984650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abort-controller"],"created_at":"2025-06-17T02:06:00.402Z","updated_at":"2026-02-26T21:03:41.857Z","avatar_url":"https://github.com/alessiofrittoli.png","language":"TypeScript","funding_links":["https://github.com/sponsors/alessiofrittoli"],"categories":[],"sub_categories":[],"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\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026color=%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\u003cdetails\u003e\n\n\u003csummary style=\"cursor:pointer\"\u003eParameters\u003c/summary\u003e\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\u003cTCode\u003e` | - | Custom `AbortError` options. |\n\n\u003c/details\u003e\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 =\u003e {\n  console.log( 'Aborted at', event.timeStamp )\n  console.log( signal.reason ) // `AbortSignal.reason` is now type of `AbortError`\n} )\n\nbutton.addEventListener( 'click', () =\u003e {\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', () =\u003e {\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', () =\u003e {\n  controller.abort( 'User clicked button 1.', { code: CustomAbortErrorCode.REASON_1 } )\n} )\n\nbutton2.addEventListener( 'click', () =\u003e {\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\u003ctable style='display:flex;gap:20px;'\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\n        \u003cimg alt=\"avatar\" src='https://avatars.githubusercontent.com/u/35973186' style='width:60px;border-radius:50%;object-fit:contain;'\u003e\n      \u003c/td\u003e\n      \u003ctd\u003e\n        \u003ctable style='display:flex;gap:2px;flex-direction:column;'\u003e\n          \u003ctbody\u003e\n              \u003ctr\u003e\n                \u003ctd\u003e\n                  \u003ca href='https://github.com/alessiofrittoli' target='_blank' rel='noopener'\u003eAlessio Frittoli\u003c/a\u003e\n                \u003c/td\u003e\n              \u003c/tr\u003e\n              \u003ctr\u003e\n                \u003ctd\u003e\n                  \u003csmall\u003e\n                    \u003ca href='https://alessiofrittoli.it' target='_blank' rel='noopener'\u003ehttps://alessiofrittoli.it\u003c/a\u003e |\n                    \u003ca href='mailto:info@alessiofrittoli.it' target='_blank' rel='noopener'\u003einfo@alessiofrittoli.it\u003c/a\u003e\n                  \u003c/small\u003e\n                \u003c/td\u003e\n              \u003c/tr\u003e\n          \u003c/tbody\u003e\n        \u003c/table\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falessiofrittoli%2Fabort-controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falessiofrittoli%2Fabort-controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falessiofrittoli%2Fabort-controller/lists"}