Skip to content

Commit 50d4cb5

Browse files
🚧 progress: First draft.
1 parent 50d2c39 commit 50d4cb5

File tree

7 files changed

+8844
-12
lines changed

7 files changed

+8844
-12
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
AsyncIterable to Array conversion for JavaScript.
55
See [docs](https://async-iterable-iterator.github.io/async-iterable-to-array/index.html).
66

7-
> :building_construction: Caveat emptor! This is work in progress. Code may be
8-
> working. Documentation may be present. Coherence may be. Maybe.
9-
107
> :warning: Depending on your environment, the code may require
118
> `regeneratorRuntime` to be defined, for instance by importing
129
> [regenerator-runtime/runtime](https://www.npmjs.com/package/regenerator-runtime).
1310
11+
```js
12+
import {asyncIterableToArray} from '@async-iterable-iterator/async-iterable-to-array';
13+
14+
let asyncIterable = ...;
15+
let array = await asyncIterableToArray(asyncIterable);
16+
```
17+
1418
[![License](https://img.shields.io/github/license/async-iterable-iterator/async-iterable-to-array.svg)](https://raw.githubusercontent.com/async-iterable-iterator/async-iterable-to-array/main/LICENSE)
1519
[![Version](https://img.shields.io/npm/v/@async-iterable-iterator/async-iterable-to-array.svg)](https://www.npmjs.org/package/@async-iterable-iterator/async-iterable-to-array)
1620
[![Tests](https://img.shields.io/github/workflow/status/async-iterable-iterator/async-iterable-to-array/ci:cover?event=push&label=tests)](https://github.com/async-iterable-iterator/async-iterable-to-array/actions/workflows/ci:cover.yml?query=branch:main)

doc/scripts/header.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ domReady(() => {
1717
header.insertBefore(projectname, header.firstChild);
1818

1919
const testlink = document.querySelector('header > a[data-ice="testLink"]');
20-
testlink.href = 'https://app.codecov.io/gh/async-iterable-iterator/async-iterable-to-array';
20+
testlink.href =
21+
'https://app.codecov.io/gh/async-iterable-iterator/async-iterable-to-array';
2122
testlink.target = '_BLANK';
2223

2324
const searchBox = document.querySelector('.search-box');

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
"release": "np --message ':hatching_chick: release: Bumping to v%s.'",
6464
"test": "ava"
6565
},
66-
"dependencies": {},
66+
"dependencies": {
67+
"@async-iterable-iterator/async-iterator-to-array": "^0.0.1"
68+
},
6769
"devDependencies": {
6870
"@babel/core": "7.16.5",
6971
"@babel/preset-env": "7.16.5",

src/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
const answer = 42;
2-
export default answer;
1+
import {asyncIteratorToArray} from '@async-iterable-iterator/async-iterator-to-array';
2+
3+
export const asyncIterableToArray = async (asyncIterable) => {
4+
const asyncIterator = asyncIterable[Symbol.asyncIterator]();
5+
return asyncIteratorToArray(asyncIterator);
6+
};

test/src/api.js

-5
This file was deleted.

test/src/asyncIterableToArray.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import test from 'ava';
2+
3+
import {asyncIterableToArray} from '../../src/index.js';
4+
5+
const asyncify = async function* (array) {
6+
// eslint-disable-next-line no-await-in-loop
7+
for (const x of array) yield await x;
8+
};
9+
10+
const macro = async (t, expected) => {
11+
const asyncIterable = asyncify(expected);
12+
const actual = await asyncIterableToArray(asyncIterable);
13+
t.deepEqual(actual, expected);
14+
};
15+
16+
macro.title = (title, expected) => title ?? JSON.stringify(expected);
17+
18+
test(macro, [1, 2, 3]);
19+
test(macro, [1, Math.random(), 3]);
20+
test(macro, [1, Math.random(), 3]);

yarn.lock

+8,806
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)