{"_id":"get-iterator","_rev":"4576703","name":"get-iterator","description":"Get the default iterator or async iterator for an iterable or async iterable","dist-tags":{"latest":"2.0.1"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"alanshaw","email":""}],"time":{"modified":"2026-04-10T15:45:03.000Z","created":"2018-11-01T11:09:59.076Z","2.0.1":"2023-08-14T06:32:51.917Z","2.0.0":"2022-01-12T16:31:42.046Z","1.0.2":"2019-02-24T14:35:52.537Z","1.0.1":"2018-11-01T11:15:22.141Z","1.0.0":"2018-11-01T11:09:59.076Z"},"users":{},"author":{"name":"Alan Shaw"},"repository":{"type":"git","url":"git+https://github.com/alanshaw/get-iterator.git"},"versions":{"2.0.1":{"name":"get-iterator","version":"2.0.1","description":"Get the default iterator or async iterator for an iterable or async iterable","type":"module","types":"./dist/src/index.d.ts","exports":{".":{"import":"./dist/src/index.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"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":"chore","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","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":"Trivial Changes"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github","@semantic-release/git"]},"scripts":{"lint":"aegir lint","dep-check":"aegir dep-check dist/src/**/*.js dist/test/**/*.js","build":"tsc","pretest":"npm run build","test":"aegir test -f ./dist/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":"semantic-release"},"keywords":["iterator","iterable","get","getter","@@iterator","Symbol.iterator","Symbol.asyncIterator"],"author":{"name":"Alan Shaw"},"license":"MIT","devDependencies":{"aegir":"^36.1.3"},"dependencies":{},"repository":{"type":"git","url":"git+https://github.com/alanshaw/get-iterator.git"},"bugs":{"url":"https://github.com/alanshaw/get-iterator/issues"},"homepage":"https://github.com/alanshaw/get-iterator#readme","gitHead":"b5c09781aad34e9fa3f3aae5c7bd4358e6f87f2e","_id":"get-iterator@2.0.1","_nodeVersion":"18.17.0","_npmVersion":"7.24.2","dist":{"shasum":"a904829f61bace789e0d64bd1a504c511a015c3f","size":3425,"noattachment":false,"key":"/get-iterator/-/get-iterator-2.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/get-iterator/download/get-iterator-2.0.1.tgz"},"_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"alanshaw","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/get-iterator_2.0.1_1691994771732_0.28738239197600834"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-08-14T06:32:51.917Z","publish_time":1691994771917,"_source_registry_name":"default","_cnpm_publish_time":1691994771917},"2.0.0":{"name":"get-iterator","version":"2.0.0","description":"Get the default iterator or async iterator for an iterable or async iterable","type":"module","types":"./dist/src/index.d.ts","exports":{".":{"import":"./dist/src/index.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"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":"chore","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","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":"Trivial Changes"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github","@semantic-release/git"]},"scripts":{"lint":"aegir lint","dep-check":"aegir dep-check dist/src/**/*.js dist/test/**/*.js","build":"tsc","pretest":"npm run build","test":"aegir test -f ./dist/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":"semantic-release"},"keywords":["iterator","iterable","get","getter","@@iterator","Symbol.iterator","Symbol.asyncIterator"],"author":{"name":"Alan Shaw"},"license":"MIT","devDependencies":{"aegir":"^36.1.3"},"dependencies":{},"repository":{"type":"git","url":"git+https://github.com/alanshaw/get-iterator.git"},"bugs":{"url":"https://github.com/alanshaw/get-iterator/issues"},"homepage":"https://github.com/alanshaw/get-iterator#readme","gitHead":"860bce2bc0125f090f8ae7c4b0700553535ed0a6","_id":"get-iterator@2.0.0","_nodeVersion":"16.13.1","_npmVersion":"7.24.2","dist":{"shasum":"c9ac9f8002e5d8d6b4dc9dae07c30945022a58c1","size":3425,"noattachment":false,"key":"/get-iterator/-/get-iterator-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/get-iterator/download/get-iterator-2.0.0.tgz"},"_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"alanshaw","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/get-iterator_2.0.0_1642005101874_0.8999581680053554"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-01-12T16:33:22.845Z","publish_time":1642005102046,"_cnpm_publish_time":1642005102046},"1.0.2":{"name":"get-iterator","version":"1.0.2","description":"Get the default iterator or async iterator for an Iterable.","main":"index.js","scripts":{"test":"standard && nyc --reporter=lcov --reporter=text ava --verbose"},"keywords":["iterator","iterable","get","getter","@@iterator","Symbol.iterator","Symbol.asyncIterator"],"author":{"name":"Alan Shaw"},"license":"MIT","devDependencies":{"ava":"^1.0.0-rc.1","babel-eslint":"^10.0.1","nyc":"^13.1.0","standard":"^12.0.1"},"ava":{"babel":false,"compileEnhancements":false,"failWithoutAssertions":false},"standard":{"parser":"babel-eslint"},"dependencies":{},"repository":{"type":"git","url":"git+https://github.com/alanshaw/get-iterator.git"},"bugs":{"url":"https://github.com/alanshaw/get-iterator/issues"},"homepage":"https://github.com/alanshaw/get-iterator#readme","gitHead":"441076c10e2cd4b1b931a70b2db282a52cedeed3","_id":"get-iterator@1.0.2","_npmVersion":"6.5.0","_nodeVersion":"11.9.0","_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"dist":{"shasum":"cd747c02b4c084461fac14f48f6b45a80ed25c82","size":2464,"noattachment":false,"key":"/get-iterator/-/get-iterator-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/get-iterator/download/get-iterator-1.0.2.tgz"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"alanshaw","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/get-iterator_1.0.2_1551018952414_0.2872486061019197"},"_hasShrinkwrap":false,"publish_time":1551018952537,"_cnpm_publish_time":1551018952537,"_cnpmcore_publish_time":"2021-12-16T10:27:16.590Z"},"1.0.1":{"name":"get-iterator","version":"1.0.1","description":"Get the default iterator or async iterator for an Iterable.","main":"index.js","scripts":{"test":"standard && nyc --reporter=lcov --reporter=text ava --verbose"},"keywords":["iterator","iterable","get","getter","@@iterator","Symbol.iterator","Symbol.asyncIterator"],"author":{"name":"Alan Shaw"},"license":"MIT","devDependencies":{"ava":"^1.0.0-rc.1","babel-eslint":"^10.0.1","nyc":"^13.1.0","standard":"^12.0.1"},"ava":{"babel":false,"compileEnhancements":false,"failWithoutAssertions":false},"standard":{"parser":"babel-eslint"},"gitHead":"863f08876c7bbceac970402421eff67396f10054","_id":"get-iterator@1.0.1","_npmVersion":"6.4.1","_nodeVersion":"11.0.0","_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"alanshaw","email":""}],"dist":{"shasum":"8a284d9b4df9213269c56646dbedb5a90996595f","size":2413,"noattachment":false,"key":"/get-iterator/-/get-iterator-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/get-iterator/download/get-iterator-1.0.1.tgz"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/get-iterator_1.0.1_1541070921982_0.2448522117430627"},"_hasShrinkwrap":false,"publish_time":1541070922141,"_cnpm_publish_time":1541070922141,"_cnpmcore_publish_time":"2021-12-16T10:27:16.833Z"},"1.0.0":{"name":"get-iterator","version":"1.0.0","description":"Get the default iterator or async iterator for an Iterable.","main":"index.js","scripts":{"test":"standard && nyc --reporter=lcov --reporter=text ava --verbose"},"keywords":["iterator","iterable","get","getter","@@iterator","Symbol.iterator","Symbol.asyncIterator"],"author":{"name":"Alan Shaw"},"license":"MIT","devDependencies":{"ava":"^1.0.0-rc.1","babel-eslint":"^10.0.1","nyc":"^13.1.0","standard":"^12.0.1"},"ava":{"babel":false,"compileEnhancements":false,"failWithoutAssertions":false},"standard":{"parser":"babel-eslint"},"gitHead":"71a1a5c81d2175545db5537cce18dfdc7f062ec6","_id":"get-iterator@1.0.0","_npmVersion":"6.4.1","_nodeVersion":"11.0.0","_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"alanshaw","email":""}],"dist":{"shasum":"d4122381dceca6723aeb49c33d3c0cc7bc42ef51","size":2411,"noattachment":false,"key":"/get-iterator/-/get-iterator-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/get-iterator/download/get-iterator-1.0.0.tgz"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/get-iterator_1.0.0_1541070598914_0.6004742466791742"},"_hasShrinkwrap":false,"publish_time":1541070599076,"_cnpm_publish_time":1541070599076,"_cnpmcore_publish_time":"2021-12-16T10:27:17.045Z"}},"readme":"# get-iterator\n\n[![Build Status](https://github.com/alanshaw/get-iterator/actions/workflows/js-test-and-release.yml/badge.svg?branch=master)](https://github.com/alanshaw/get-iterator/actions/workflows/js-test-and-release.yml)\n[![Dependencies Status](https://status.david-dm.org/gh/alanshaw/get-iterator.svg)](https://david-dm.org/alanshaw/get-iterator)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n> Get the default iterator or async iterator for an iterable or async iterable\n\nReduce the boilerplate of extracting the iterator from an object when you don't know if the object is an (async) iterable or already an (async) iterator.\n\n## Install\n\n```sh\nnpm install get-iterator\n```\n\n## Usage\n\n```js\nimport { getIterator } from 'get-iterator'\nconst input = [1, 2, 3]\nconst it = getIterator(input)\nconsole.log(it.next()) // { done: false, value: 1 }\nconsole.log(it.next()) // { done: false, value: 2 }\nconsole.log(it.next()) // { done: false, value: 3 }\nconsole.log(it.next()) // { done: true, value: undefined }\n```\n\n### Examples\n\nRegular iterator from iterable:\n\n```js\nimport { getIterator } from 'get-iterator'\n\nconst input = [1, 2, 3]\nconst iterable = {\n  [Symbol.iterator] () {\n    let i = 0\n    return {\n      next () {\n        const value = input[i++]\n        return { done: !value, value }\n      }\n    }\n  }\n}\n\nconst it = getIterator(input)\nconsole.log(it.next()) // { done: false, value: 1 }\nconsole.log(it.next()) // { done: false, value: 2 }\nconsole.log(it.next()) // { done: false, value: 3 }\nconsole.log(it.next()) // { done: true, value: undefined }\n```\n\nAsync iterator from iterable:\n\n```js\nimport { getIterator } from 'get-iterator'\n\nconst input = [1, 2, 3]\nconst iterable = {\n  [Symbol.asyncIterator] () {\n    let i = 0\n    return {\n      async next () {\n        const value = await new Promise((resolve, reject) => {\n          setTimeout(() => resolve(input[i++]), 10)\n        })\n        return { done: !value, value }\n      }\n    }\n  }\n}\n\nconst it = getIterator(iterable)\nconsole.log(await it.next()) // { done: false, value: 1 }\nconsole.log(await it.next()) // { done: false, value: 2 }\nconsole.log(await it.next()) // { done: false, value: 3 }\nconsole.log(await it.next()) // { done: true, value: undefined }\n```\n\nAlready an iterator (probably):\n\n```js\nimport { getIterator } from 'get-iterator'\n\nconst input = [1, 2, 3]\nlet i = 0\nconst iterator = {\n  next () {\n    const value = input[i++]\n    return { done: !value, value }\n  }\n}\n\nconst it = getIterator(iterator)\nconsole.log(it.next()) // { done: false, value: 1 }\nconsole.log(it.next()) // { done: false, value: 2 }\nconsole.log(it.next()) // { done: false, value: 3 }\nconsole.log(it.next()) // { done: true, value: undefined }\n```\n\n## API\n\n```js\nimport { getIterator } from 'get-iterator'\n```\n\n### `getIterator(obj)`\n\nGet the default iterator or async iterator for an Iterable. If `obj` is already an iterator (i.e. has a `next` function) return it, since it's probably already an iterator.\n\nThis function will throw if `obj` is not an iterable or iterator.\n\n#### Parameters\n\n| Name | Type | Description |\n|------|------|-------------|\n| obj | [`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 object to extract the iterator from (may be an iterator already). |\n\n#### Returns\n\n| Type | Description |\n|------|-------------|\n| [`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol) | The result of calling `obj[Symbol.iterator]()` or `obj[Symbol.asyncIterator]()` or simply the passed `obj` if it is already an iterator. |\n\n## Contribute\n\nFeel free to dive in! [Open an issue](https://github.com/alanshaw/get-iterator/issues/new) or submit PRs.\n\n## License\n\n[MIT](https://github.com/alanshaw/get-iterator/blob/master/LICENSE) © Alan Shaw\n","_attachments":{},"homepage":"https://github.com/alanshaw/get-iterator#readme","bugs":{"url":"https://github.com/alanshaw/get-iterator/issues"},"license":"MIT"}