Comparing version
/** | ||
* @packageDocumentation | ||
* | ||
* The final batch may be smaller than the max. | ||
* | ||
* @example | ||
* | ||
* ```javascript | ||
* import batch from 'it-batch' | ||
* import all from 'it-all' | ||
* | ||
* // This can also be an iterator, generator, etc | ||
* const values = [0, 1, 2, 3, 4] | ||
* const batchSize = 2 | ||
* | ||
* const result = all(batch(values, batchSize)) | ||
* | ||
* console.info(result) // [0, 1], [2, 3], [4] | ||
* ``` | ||
* | ||
* Async sources must be awaited: | ||
* | ||
* ```javascript | ||
* import batch from 'it-batch' | ||
* import all from 'it-all' | ||
* | ||
* const values = async function * () { | ||
* yield * [0, 1, 2, 3, 4] | ||
* } | ||
* | ||
* const batchSize = 2 | ||
* const result = await all(batch(values(), batchSize)) | ||
* | ||
* console.info(result) // [0, 1], [2, 3], [4] | ||
* ``` | ||
*/ | ||
/** | ||
* Takes an (async) iterable that emits things and returns an async iterable that | ||
@@ -3,0 +39,0 @@ * emits those things in fixed-sized batches |
@@ -0,1 +1,37 @@ | ||
/** | ||
* @packageDocumentation | ||
* | ||
* The final batch may be smaller than the max. | ||
* | ||
* @example | ||
* | ||
* ```javascript | ||
* import batch from 'it-batch' | ||
* import all from 'it-all' | ||
* | ||
* // This can also be an iterator, generator, etc | ||
* const values = [0, 1, 2, 3, 4] | ||
* const batchSize = 2 | ||
* | ||
* const result = all(batch(values, batchSize)) | ||
* | ||
* console.info(result) // [0, 1], [2, 3], [4] | ||
* ``` | ||
* | ||
* Async sources must be awaited: | ||
* | ||
* ```javascript | ||
* import batch from 'it-batch' | ||
* import all from 'it-all' | ||
* | ||
* const values = async function * () { | ||
* yield * [0, 1, 2, 3, 4] | ||
* } | ||
* | ||
* const batchSize = 2 | ||
* const result = await all(batch(values(), batchSize)) | ||
* | ||
* console.info(result) // [0, 1], [2, 3], [4] | ||
* ``` | ||
*/ | ||
function isAsyncIterable(thing) { | ||
@@ -2,0 +38,0 @@ return thing[Symbol.asyncIterator] != null; |
{ | ||
"name": "it-batch", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "Takes an async iterator that emits things and emits them as fixed size batches", | ||
@@ -32,2 +32,3 @@ "author": "Alex Potsides <alex@achingbrain.net>", | ||
"parserOptions": { | ||
"project": true, | ||
"sourceType": "module" | ||
@@ -135,5 +136,5 @@ } | ||
"devDependencies": { | ||
"aegir": "^40.0.11", | ||
"aegir": "^41.1.9", | ||
"it-all": "^3.0.0" | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
# it-batch <!-- omit in toc --> | ||
[](https://codecov.io/gh/achingbrain/it) | ||
@@ -8,27 +6,7 @@ [](https://github.com/achingbrain/it/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) | ||
## Table of contents <!-- omit in toc --> | ||
# About | ||
- [Install](#install) | ||
- [Browser `<script>` tag](#browser-script-tag) | ||
- [Usage](#usage) | ||
- [License](#license) | ||
- [Contribution](#contribution) | ||
## Install | ||
```console | ||
$ npm i it-batch | ||
``` | ||
### Browser `<script>` tag | ||
Loading this module through a script tag will make it's exports available as `ItBatch` in the global namespace. | ||
```html | ||
<script src="https://unpkg.com/it-batch/dist/index.min.js"></script> | ||
``` | ||
The final batch may be smaller than the max. | ||
## Usage | ||
## Example | ||
@@ -57,4 +35,4 @@ ```javascript | ||
} | ||
const batchSize = 2 | ||
const result = await all(batch(values(), batchSize)) | ||
@@ -65,4 +43,18 @@ | ||
## License | ||
# Install | ||
```console | ||
$ npm i it-batch | ||
``` | ||
## Browser `<script>` tag | ||
Loading this module through a script tag will make it's exports available as `ItBatch` in the global namespace. | ||
```html | ||
<script src="https://unpkg.com/it-batch/dist/index.min.js"></script> | ||
``` | ||
# License | ||
Licensed under either of | ||
@@ -73,4 +65,4 @@ | ||
## Contribution | ||
# Contribution | ||
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. |
@@ -0,1 +1,38 @@ | ||
/** | ||
* @packageDocumentation | ||
* | ||
* The final batch may be smaller than the max. | ||
* | ||
* @example | ||
* | ||
* ```javascript | ||
* import batch from 'it-batch' | ||
* import all from 'it-all' | ||
* | ||
* // This can also be an iterator, generator, etc | ||
* const values = [0, 1, 2, 3, 4] | ||
* const batchSize = 2 | ||
* | ||
* const result = all(batch(values, batchSize)) | ||
* | ||
* console.info(result) // [0, 1], [2, 3], [4] | ||
* ``` | ||
* | ||
* Async sources must be awaited: | ||
* | ||
* ```javascript | ||
* import batch from 'it-batch' | ||
* import all from 'it-all' | ||
* | ||
* const values = async function * () { | ||
* yield * [0, 1, 2, 3, 4] | ||
* } | ||
* | ||
* const batchSize = 2 | ||
* const result = await all(batch(values(), batchSize)) | ||
* | ||
* console.info(result) // [0, 1], [2, 3], [4] | ||
* ``` | ||
*/ | ||
function isAsyncIterable <T> (thing: any): thing is AsyncIterable<T> { | ||
@@ -2,0 +39,0 @@ return thing[Symbol.asyncIterator] != null |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14632
16.68%225
92.31%65
-10.96%