Gathering detailed insights and metrics for get-iterator
Gathering detailed insights and metrics for get-iterator
Gathering detailed insights and metrics for get-iterator
Gathering detailed insights and metrics for get-iterator
es-get-iterator
Get an iterator for any JS language value. Works robustly across all environments, all versions.
locate-path
Get the first path that exists on disk of multiple paths
p-locate
Get the first fulfilled promise that satisfies the provided testing function
@types/es-get-iterator
TypeScript definitions for es-get-iterator
Get the default iterator or async iterator for an Iterable.
npm install get-iterator
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2 Stars
33 Commits
3 Forks
1 Watchers
2 Branches
4 Contributors
Updated on Dec 14, 2022
Latest Version
2.0.1
Package Id
get-iterator@2.0.1
Unpacked Size
11.32 kB
Size
3.34 kB
File Count
8
NPM Version
7.24.2
Node Version
18.17.0
Published on
Aug 14, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Get the default iterator or async iterator for an iterable or async iterable
Reduce 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.
1npm install get-iterator
1import { getIterator } from 'get-iterator' 2const input = [1, 2, 3] 3const it = getIterator(input) 4console.log(it.next()) // { done: false, value: 1 } 5console.log(it.next()) // { done: false, value: 2 } 6console.log(it.next()) // { done: false, value: 3 } 7console.log(it.next()) // { done: true, value: undefined }
Regular iterator from iterable:
1import { getIterator } from 'get-iterator' 2 3const input = [1, 2, 3] 4const iterable = { 5 [Symbol.iterator] () { 6 let i = 0 7 return { 8 next () { 9 const value = input[i++] 10 return { done: !value, value } 11 } 12 } 13 } 14} 15 16const it = getIterator(input) 17console.log(it.next()) // { done: false, value: 1 } 18console.log(it.next()) // { done: false, value: 2 } 19console.log(it.next()) // { done: false, value: 3 } 20console.log(it.next()) // { done: true, value: undefined }
Async iterator from iterable:
1import { getIterator } from 'get-iterator' 2 3const input = [1, 2, 3] 4const iterable = { 5 [Symbol.asyncIterator] () { 6 let i = 0 7 return { 8 async next () { 9 const value = await new Promise((resolve, reject) => { 10 setTimeout(() => resolve(input[i++]), 10) 11 }) 12 return { done: !value, value } 13 } 14 } 15 } 16} 17 18const it = getIterator(iterable) 19console.log(await it.next()) // { done: false, value: 1 } 20console.log(await it.next()) // { done: false, value: 2 } 21console.log(await it.next()) // { done: false, value: 3 } 22console.log(await it.next()) // { done: true, value: undefined }
Already an iterator (probably):
1import { getIterator } from 'get-iterator' 2 3const input = [1, 2, 3] 4let i = 0 5const iterator = { 6 next () { 7 const value = input[i++] 8 return { done: !value, value } 9 } 10} 11 12const it = getIterator(iterator) 13console.log(it.next()) // { done: false, value: 1 } 14console.log(it.next()) // { done: false, value: 2 } 15console.log(it.next()) // { done: false, value: 3 } 16console.log(it.next()) // { done: true, value: undefined }
1import { getIterator } from 'get-iterator'
getIterator(obj)
Get 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.
This function will throw if obj
is not an iterable or iterator.
Name | Type | Description |
---|---|---|
obj | Iterable |Iterator | The object to extract the iterator from (may be an iterator already). |
Type | Description |
---|---|
Iterator | The result of calling obj[Symbol.iterator]() or obj[Symbol.asyncIterator]() or simply the passed obj if it is already an iterator. |
Feel free to dive in! Open an issue or submit PRs.
MIT © Alan Shaw
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 15/30 approved changesets -- score normalized to 5
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More