# @fightingdreamer/iter-count

> Count number of items in iterator.

Latest version **0.1.3** (published 2023-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fightingdreamer/iter-count
pnpm add @fightingdreamer/iter-count
yarn add @fightingdreamer/iter-count
bun add @fightingdreamer/iter-count
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2023-12-12 |
| First published | 2023-12-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Patryk Stępień |
| Maintainers | fightingdreamer |
| Keywords | iter |

## Links

- npm: https://www.npmjs.com/package/@fightingdreamer/iter-count
- Homepage: https://github.com/fightingdreamer/npm-iter-count
- npm.io page: https://npm.io/package/@fightingdreamer/iter-count

## Recent versions

- 0.1.3 (latest) — 2023-12-12
- 0.1.2 — 2023-12-11
- 0.1.1 — 2023-12-11
- 0.1.0 — 2023-12-06

## README

# iter-count

## Description

Count items in `Iterable`.

Second implementation will count unique items and group them (similar to `uniq -c`).

## Install

```bash
bun add @fightingdreamer/iter-count
```

## Usage

```js
import {count} from '@fightingdreamer/iter-count'

const value = ['a', 'a', 'b'][Symbol.iterator]()
const result = count(value)
const expect = 3
console.assert(result == expect)
```

```js
import {countUnique} from '@fightingdreamer/iter-count'

const value = ['a', 'a', 'b'][Symbol.iterator]()
const result = countUnique(value)
const expect = new Map([['a', 2], ['b', 1]])
for (const [key, value] of expect.entries()) {
  console.assert(result.get(key) == value)
}
```

## Usage (node / commonjs)

```js
const {count} = require('@fightingdreamer/iter-count')

const value = ['a', 'a', 'b'][Symbol.iterator]()
const result = count(value)
const expect = 3
assert(result == expect)
```

```js
const {countUnique} = require('@fightingdreamer/iter-count')

const value = ['a', 'a', 'b'][Symbol.iterator]()
const result = countUnique(value)
const expect = new Map([['a', 2], ['b', 1]])
for (const [key, value] of expect.entries()) {
  assert(result.get(key) == value)
}
```

## Functions

```js
function count<T>(iterator: Iterable<T>): number
```

Will count items in 'iterator'.

```js
function countUnique<T>(iterator: Iterable<T>): Map<T, number>
```

Will count items in 'iterator' and group them into Map.

---
_Source: https://npm.io/package/@fightingdreamer/iter-count · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
