Skip to content

Commit

Permalink
Merge branch 'master' into releas-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Aug 17, 2020
2 parents 3c127ce + f9aa349 commit b2398ff
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/blob-to-it/package.json
@@ -1,6 +1,6 @@
{
"name": "blob-to-it",
"version": "0.0.1",
"version": "0.0.2",
"description": "Turns a blob into an async iterator",
"main": "index.js",
"repository": "github:achingbrain/it",
Expand All @@ -19,7 +19,7 @@
"author": "Alex Potsides <alex@achingbrain.net>",
"license": "ISC",
"dependencies": {
"browser-readablestream-to-it": "^0.0.1"
"browser-readablestream-to-it": "^0.0.2"
},
"devDependencies": {
"chai": "^4.2.0",
Expand Down
21 changes: 13 additions & 8 deletions packages/browser-readablestream-to-it/README.md
Expand Up @@ -28,15 +28,20 @@ const stream = new ReadableStream({
}
})

// An optional object which may have the following keys:
const options = {
// Unless `true` stream will be cancelled when consumed partially (e.g. break
// in for await loop). Default to `false`.
preventCancel: false
}

const arr = await all(toIt(stream, options))
const arr = await all(toIt(stream))

console.info(arr) // 0, 1, 2, 3, 4
```

### preventCancel

By default a readable stream will have [.cancel](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/cancel) called on it once it has ended or
reading has stopped prematurely.

To prevent this behaviour, pass `preventCancel: true` as an option:

```javascript
const arr = await all(toIt(stream, { preventCancel: true }))

console.info(arr) // 0, 1, 2, 3, 4
```
2 changes: 1 addition & 1 deletion packages/browser-readablestream-to-it/package.json
@@ -1,6 +1,6 @@
{
"name": "browser-readablestream-to-it",
"version": "0.0.1",
"version": "0.0.2",
"description": "Turns a browser readble stream into an async iterator",
"main": "index.js",
"repository": "github:achingbrain/it",
Expand Down
26 changes: 26 additions & 0 deletions packages/it-length/README.md
@@ -0,0 +1,26 @@
# it-length

[![Build status](https://travis-ci.org/achingbrain/it.svg?branch=master)](https://travis-ci.org/achingbrain/it?branch=master) [![Coverage Status](https://coveralls.io/repos/github/achingbrain/it/badge.svg?branch=master)](https://coveralls.io/github/achingbrain/it?branch=master) [![Dependencies Status](https://david-dm.org/achingbrain/it/status.svg?path=packages/it-last)](https://david-dm.org/achingbrain/it?path=packages/it-last)

> Counts the items in an async iterable
N.b. will consume the iterable

## Install

```sh
$ npm install --save it-length
```

## Usage

```javascript
const length = require('it-length')

// This can also be an iterator, async iterator, generator, etc
const values = [0, 1, 2, 3, 4]

const res = await length(values)

console.info(res) // 5
```
13 changes: 13 additions & 0 deletions packages/it-length/index.js
@@ -0,0 +1,13 @@
'use strict'

const length = async (iterator) => {
let count = 0

for await (const _ of iterator) { // eslint-disable-line no-unused-vars
count++
}

return count
}

module.exports = length
22 changes: 22 additions & 0 deletions packages/it-length/package.json
@@ -0,0 +1,22 @@
{
"name": "it-length",
"version": "0.0.2",
"description": "Counts the number of items in an async iterable",
"main": "index.js",
"repository": "github:achingbrain/it",
"homepage": "https://github.com/achingbrain/it#readme",
"bugs": "https://github.com/achingbrain/it/issues",
"scripts": {
"test": "ava",
"lint": "standard",
"coverage": "nyc --reporter html --reporter lcov ava",
"clean": "rm -rf .nyc_output coverage"
},
"author": "Alex Potsides <alex@achingbrain.net>",
"license": "ISC",
"devDependencies": {
"ava": "^2.4.0",
"nyc": "^14.0.0",
"standard": "^14.3.1"
}
}
10 changes: 10 additions & 0 deletions packages/it-length/test.js
@@ -0,0 +1,10 @@
import length from './'
import test from 'ava'

test('Should count the items in an async iterator', async (t) => {
const values = [0, 1, 2, 3, 4]

const res = await length(values)

t.is(res, 5)
})

0 comments on commit b2398ff

Please sign in to comment.