Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into releas-lock
- Loading branch information
Showing
7 changed files
with
87 additions
and
11 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
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
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
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,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 | ||
``` |
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 length = async (iterator) => { | ||
let count = 0 | ||
|
||
for await (const _ of iterator) { // eslint-disable-line no-unused-vars | ||
count++ | ||
} | ||
|
||
return count | ||
} | ||
|
||
module.exports = length |
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,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" | ||
} | ||
} |
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,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) | ||
}) |