Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Apr 18, 2019
0 parents commit 36b5fe1
Show file tree
Hide file tree
Showing 7 changed files with 6,878 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
node_modules
*.log
.DS_Store
.nyc_output
coverage
8 changes: 8 additions & 0 deletions .travis.yml
@@ -0,0 +1,8 @@
sudo: required
language: node_js

node_js:
- '8'
- '10'

script: npm run coveralls
29 changes: 29 additions & 0 deletions README.md
@@ -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
```
13 changes: 13 additions & 0 deletions index.js
@@ -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

0 comments on commit 36b5fe1

Please sign in to comment.