{"name":"abortable-iterator","version":"5.1.0","description":"Make any iterator or iterable abortable via an AbortSignal","author":{"name":"Alan Shaw"},"license":"Apache-2.0 OR MIT","homepage":"https://github.com/alanshaw/abortable-iterator#readme","repository":{"type":"git","url":"git+https://github.com/alanshaw/abortable-iterator.git"},"bugs":{"url":"https://github.com/alanshaw/abortable-iterator/issues"},"publishConfig":{"access":"public","provenance":true},"keywords":["AbortController","AbortSignal","abort","abortable","async","cancel","iterator","signal","stop"],"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js"},"./duplex":{"types":"./dist/src/duplex.d.ts","import":"./dist/src/duplex.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"project":true,"sourceType":"module"}},"release":{"branches":["master"],"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"breaking":true,"release":"major"},{"revert":true,"release":"patch"},{"type":"feat","release":"minor"},{"type":"fix","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","release":"patch"},{"type":"deps","release":"patch"},{"scope":"no-release","release":false}]}],["@semantic-release/release-notes-generator",{"preset":"conventionalcommits","presetConfig":{"types":[{"type":"feat","section":"Features"},{"type":"fix","section":"Bug Fixes"},{"type":"chore","section":"Trivial Changes"},{"type":"docs","section":"Documentation"},{"type":"deps","section":"Dependencies"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github","@semantic-release/git"]},"scripts":{"clean":"aegir clean","lint":"aegir lint","dep-check":"aegir dep-check","build":"aegir build","test":"aegir test","test:chrome":"npm run test -- -t browser --cov","test:chrome-webworker":"npm run test -- -t webworker","test:firefox":"npm run test -- -t browser -- --browser firefox","test:firefox-webworker":"npm run test -- -t webworker -- --browser firefox","test:node":"npm run test -- -t node --cov","test:electron-main":"npm run test -- -t electron-main","release":"aegir release","docs":"aegir docs"},"dependencies":{"get-iterator":"^2.0.0","it-stream-types":"^2.0.1"},"devDependencies":{"aegir":"^44.1.0","delay":"^6.0.0","it-drain":"^3.0.1","it-pipe":"^3.0.1"},"_id":"abortable-iterator@5.1.0","gitHead":"ad5f6c5079ef2a48f0750ac50f91acf5743b77df","_nodeVersion":"20.16.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-a3nRG0GOGw3IPFA2hdhrZU+QuD3mA6i+5f4YM/Obe+D5lYccxScI32rAIHAW5ttFV7+beiof09gHav4qUEZDwg==","shasum":"2bdd7e3a1b3fe2e6893f1b60502b0e6a3028a792","tarball":"http://registry-npm.ywwl.com/abortable-iterator/download/abortable-iterator-5.1.0.tgz","fileCount":15,"unpackedSize":35020,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/abortable-iterator@5.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF6j9Oyksm190aIlJ0i9fzCCdc8HFbGs6bHa+lONdIAGAiB4FIGJwTxiy5ZhupMScX3nday6alTM33MhPCa9gCH2mA=="}],"size":8588,"noattachment":false,"key":"/abortable-iterator/-/abortable-iterator-5.1.0.tgz"},"_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/abortable-iterator_5.1.0_1723033386748_0.8296566697604926"},"_hasShrinkwrap":false,"readme":"# abortable-iterator\n\n[![codecov](https://img.shields.io/codecov/c/github/alanshaw/abortable-iterator.svg?style=flat-square)](https://codecov.io/gh/alanshaw/abortable-iterator)\n[![CI](https://img.shields.io/github/actions/workflow/status/alanshaw/abortable-iterator/js-test-and-release.yml?branch=master\\&style=flat-square)](https://github.com/alanshaw/abortable-iterator/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)\n\n> Make any iterator or iterable abortable via an AbortSignal\n\n# About\n\n<!--\n\n!IMPORTANT!\n\nEverything in this README between \"# About\" and \"# Install\" is automatically\ngenerated and will be overwritten the next time the doc generator is run.\n\nTo make changes to this section, please update the @packageDocumentation section\nof src/index.js or src/index.ts\n\nTo experiment with formatting, please run \"npm run docs\" from the root of this\nrepo and examine the changes made.\n\n-->\n\n## Example\n\n```js\nimport { abortableSource } from 'abortable-iterator'\n\nasync function main () {\n  // An example function that creates an async iterator that yields an increasing\n  // number every x milliseconds and NEVER ENDS!\n  const asyncCounter = async function * (start, delay) {\n    let i = start\n    while (true) {\n      yield new Promise(resolve => setTimeout(() => resolve(i++), delay))\n    }\n  }\n\n  // Create a counter that'll yield numbers from 0 upwards every second\n  const everySecond = asyncCounter(0, 1000)\n\n  // Make everySecond abortable!\n  const controller = new AbortController()\n  const abortableEverySecond = abortableSource(everySecond, controller.signal)\n\n  // Abort after 5 seconds\n  setTimeout(() => controller.abort(), 5000)\n\n  try {\n    // Start the iteration, which will throw after 5 seconds when it is aborted\n    for await (const n of abortableEverySecond) {\n      console.log(n)\n    }\n  } catch (err) {\n    if (err.code === 'ERR_ABORTED') {\n      // Expected - all ok :D\n    } else {\n      throw err\n    }\n  }\n}\n\nmain()\n```\n\n# Install\n\n```console\n$ npm i abortable-iterator\n```\n\n## Browser `<script>` tag\n\nLoading this module through a script tag will make its exports available as `AbortableIterator` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/abortable-iterator/dist/index.min.js\"></script>\n```\n\n## API\n\n```js\nimport {\n  abortableSource,\n  abortableSink,\n  abortableTransform,\n  abortableDuplex\n} from 'abortable-iterator'\n```\n\n- [`abortableSource(source, signal, [options])`](#abortablesource-signal-options)\n- [`abortableSink(sink, signal, [options])`](#abortablesinksink-signal-options)\n- [`abortableTransform(transform, signal, [options])`](#abortabletransformtransform-signal-options)\n- [`abortableDuplex(duplex, signal, [options])`](#abortableduplexduplex-signal-options)\n\n### `abortableSource(source, signal, [options])`\n\n**(alias for `abortable.source(source, signal, [options])`)**\n\nMake any iterator or iterable abortable via an `AbortSignal`.\n\n#### Parameters\n\n| Name                  | Type                                                                                                                                                                                                                                                 | Description                                                                                                                                                              |\n| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| source                | [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol)\\|[`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol) | The iterator or iterable object to make abortable                                                                                                                        |\n| signal                | [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)                                                                                                                                                                        | Signal obtained from `AbortController.signal` which is used to abort the iterator.                                                                                       |\n| options               | `Object`                                                                                                                                                                                                                                             | (optional) options                                                                                                                                                       |\n| options.onAbort       | `Function`                                                                                                                                                                                                                                           | An (async) function called when the iterator is being aborted, before the abort error is thrown. Default `null`                                                          |\n| options.abortMessage  | `String`                                                                                                                                                                                                                                             | The message that the error will have if the iterator is aborted. Default \"The operation was aborted\"                                                                     |\n| options.abortCode     | `String`\\|`Number`                                                                                                                                                                                                                                   | The value assigned to the `code` property of the error that is thrown if the iterator is aborted. Default \"ABORT\\_ERR\"                                                   |\n| options.returnOnAbort | `Boolean`                                                                                                                                                                                                                                            | Instead of throwing the abort error, just return from iterating over the source stream.                                                                                  |\n| options.onReturnError | `Function`                                                                                                                                                                                                                                           | When a generator is aborted, we call `.return` on it - if this function errors the error value will be passed to the `.onReturnError` callback if passed. Default `null` |\n\n#### Returns\n\n| Type                                                                                                                      | Description                                                                                                     |\n| ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |\n| [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol) | An iterator that wraps the passed `source` parameter that makes it abortable via the passed `signal` parameter. |\n\nThe returned iterator will `throw` an `AbortError` when it is aborted that has a `type` with the value `aborted` and `code` property with the value `ABORT_ERR` by default.\n\n### `abortableSink(sink, signal, [options])`\n\nThe same as [`abortable.source`](#abortablesource-signal-options) except this makes the passed [`sink`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#sink-it) abortable. Returns a new sink that wraps the passed `sink` and makes it abortable via the passed `signal` parameter.\n\n### `abortableTransform(transform, signal, [options])`\n\nThe same as [`abortable.source`](#abortablesource-signal-options) except this makes the passed [`transform`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#transform-it) abortable. Returns a new transform that wraps the passed `transform` and makes it abortable via the passed `signal` parameter.\n\n### `abortableDuplex(duplex, signal, [options])`\n\nThe same as [`abortable.source`](#abortablesource-signal-options) except this makes the passed [`duplex`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it) abortable. Returns a new duplex that wraps the passed `duplex` and makes it abortable via the passed `signal` parameter.\n\nNote that this will abort *both* sides of the duplex. Use `duplex.sink = abortable.sink(duplex.sink)` or `duplex.source = abortable.source(duplex.source)` to abort just the sink or the source.\n\n## Related\n\n- [`it-pipe`](https://www.npmjs.com/package/it-pipe) Utility to \"pipe\" async iterables together\n\n# API Docs\n\n- <https://alanshaw.github.io/abortable-iterator>\n\n# License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](https://github.com/alanshaw/abortable-iterator/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](https://github.com/alanshaw/abortable-iterator/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n# Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","publish_time":1723033386896,"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"alanshaw","email":"alan138@gmail.com"}],"_cnpm_publish_time":1723033386896,"dist-tags":{"latest":"5.1.0"}}