https://github.com/lamansky/add-counter
[Node.js] Adds a counter integer to iterated values.
https://github.com/lamansky/add-counter
Last synced: 3 months ago
JSON representation
[Node.js] Adds a counter integer to iterated values.
- Host: GitHub
- URL: https://github.com/lamansky/add-counter
- Owner: lamansky
- License: mit
- Created: 2018-02-05T16:06:55.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-05T16:08:24.000Z (over 8 years ago)
- Last Synced: 2025-03-08T14:18:40.095Z (over 1 year ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# add-counter
Adds a counter integer to iterated values.
## Installation
Requires [Node.js](https://nodejs.org/) 6.0.0 or above.
```bash
npm i add-counter
```
## API
The module exports a single function.
### Parameters
1. `iter` (iterable): The underlying iterable.
2. Optional: `i` (integer): The starting value of the counter. Normally this would be either `0` or `1`. Defaults to `0`.
### Return Value
A generator that, for each iterated value `x`, yields `[i++, x]`
## Example
```javascript
const addCounter = require('add-counter')
for (const [i, x] of addCounter(['a', 'b', 'c'])) {
// [0, 'a']
// [1, 'b']
// [2, 'c']
}
```