# readline-promise

> Readline using promises

Latest version **1.0.5** (published 2020-12-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install readline-promise
pnpm add readline-promise
yarn add readline-promise
bun add readline-promise
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2020-12-15 |
| First published | 2016-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Branden Horiuchi |
| Maintainers | vbranden |
| Keywords | readline, promise |

## Links

- npm: https://www.npmjs.com/package/readline-promise
- Repository: https://github.com/bhoriuchi/readline-promise
- Issues: https://github.com/bhoriuchi/readline-promise/issues
- npm.io page: https://npm.io/package/readline-promise

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2020-12-15
- 1.0.4 — 2019-03-08
- 1.0.3 — 2018-02-09
- 1.0.2 — 2018-01-12
- 1.0.1 — 2018-01-11
- 0.0.1 — 2016-02-23

## README

# readline-promise

A drop in replacement for readline with additional promise based methods like `map`, `reduce`, and `forEach`. Uses a custom [AsyncIterator](https://github.com/tc39/proposal-async-iteration) implementation.

Note: If you were using `var readline = require('readline')`, change this to `var readline = require('readline-promise').default`.

## Example
```js
import readline from 'readline-promise';
import fs from 'fs';

const rlp = readline.createInterface({
  terminal: false,
  input: fs.createReadStream('data.txt')
});

rlp.forEach((line, index) => {
  console.log({ line, index });
});
```

## Example
```js
import readline from 'readline-promise';

const rlp = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: true
});

let bar = null;

rlp.questionAsync('Foo?').then(answer => {
  bar = answer;
});
```

## Extended API

`readline-promise` adds the following methods

### `readline.createInterface(options) → rlp`

Creates a new line reader Interface (`rlp`)

* `options` &lt;Object&gt; see [interface options](https://nodejs.org/api/readline.html#readline_readline_createinterface_options) for details

### `rlp.forEach(iteratee) → Promise<undefined>`

Iterates through each line calling an `iteratee` function with the value. See [Array.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) documentation for details

* `iteratee` &lt;Function&gt;
  * `line` &lt;*&gt; - line value
  * `index` &lt;Number&gt; - the line index starting from 0
  * `lines` &lt;Array&lt;*&gt;&gt; - all current line values as an array

### `rlp.each(iteratee) → Promise<undefined>`

Alias for `rlp.forEach`

### `rlp.map(iteratee) → Promise<Array<*>>`

Performs a map operation using the iteratee function. See [Array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) documentation for details

* `iteratee` &lt;Function&gt;
  * `line` &lt;*&gt; - line value
  * `index` &lt;Number&gt; - the line index starting from 0
  * `lines` &lt;Array&lt;*&gt;&gt; - all current line values as an array

### `rlp.reduce(iteratee [, accumulator]) → Promise<*>`

Performs a reduce operation using the iteratee and optional accumulator/initial value. See [Array.reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) documentation for details

* `iteratee` &lt;Function&gt;
  * `accumulator` &lt;*&gt; - accumulator value
  * `line` &lt;*&gt; - line value
  * `index` &lt;Number&gt;- the line index starting from 0
  * `lines` &lt;Array&lt;*&gt;&gt; - all current line values as an array
* `[accumulator]` &lt;*&gt; - Optional initial value

### `rlp.questionAsync(query) → Promise<*>`

Performs a question that returns a Promise that resolves to the answer value

* `query` &lt;String&gt; - prompt text

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