Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 36b5fe1
Showing
7 changed files
with
6,878 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
*.log | ||
.DS_Store | ||
.nyc_output | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sudo: required | ||
language: node_js | ||
|
||
node_js: | ||
- '8' | ||
- '10' | ||
|
||
script: npm run coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# async-iterator-to-array | ||
|
||
[![Build status](https://travis-ci.org/achingbrain/async-iterator-to-array.svg?branch=master)](https://travis-ci.org/achingbrain/async-iterator-to-array?branch=master) [![Coverage Status](https://coveralls.io/repos/github/achingbrain/async-iterator-to-array/badge.svg?branch=master)](https://coveralls.io/github/achingbrain/async-iterator-to-array?branch=master) [![Dependencies Status](https://david-dm.org/achingbrain/async-iterator-to-array/status.svg)](https://david-dm.org/achingbrain/async-iterator-to-array) | ||
|
||
> Collects all values from an async iterator and returns them as an array | ||
Mostly useful for tests. | ||
|
||
## Install | ||
|
||
```sh | ||
$ npm install --save async-iterator-to-array | ||
``` | ||
|
||
## Usage | ||
|
||
```javascript | ||
const toArray = require('async-iterator-to-array') | ||
|
||
async function * iterator (values) { | ||
for (let i = 0; i < values.length; i++) { | ||
yield values[i] | ||
} | ||
} | ||
|
||
const arr = await toArray(iterator([0, 1, 2, 3, 4])) | ||
|
||
console.info(arr) // 0, 1, 2, 3, 4 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
const toArray = async (iterator) => { | ||
const arr = [] | ||
|
||
for await (const entry of iterator) { | ||
arr.push(entry) | ||
} | ||
|
||
return arr | ||
} | ||
|
||
module.exports = toArray |
Oops, something went wrong.