# @wilnersson/console-input-collector

> Helps you collect user input in your console apps.

Latest version **1.0.3** (published 2022-10-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @wilnersson/console-input-collector
pnpm add @wilnersson/console-input-collector
yarn add @wilnersson/console-input-collector
bun add @wilnersson/console-input-collector
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-10-08 |
| First published | 2022-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 33.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Henrik Wilnersson |
| Maintainers | wilnersson |

## Links

- npm: https://www.npmjs.com/package/@wilnersson/console-input-collector
- Repository: https://github.com/wilnersson/console-input-collector
- Homepage: https://github.com/wilnersson/console-input-collector#readme
- Issues: https://github.com/wilnersson/console-input-collector/issues
- npm.io page: https://npm.io/package/@wilnersson/console-input-collector

## Recent versions

- 1.0.3 (latest) — 2022-10-08
- 1.0.2 — 2022-10-07
- 1.0.1 — 2022-10-07
- 1.0.0 — 2022-10-07

## README

# Input Collector
Collect user input in your terminal input quickly and easily.

Instead of building your own functions for listening to the input stream, just request a type of input and supply the question. Input Collector handles collecting and validating the answers for you. Choose from five types of input collection:

* Strings
* Integers
* Passwords
* Single choice
* Multiple choice

## Example usage

Note that Input Collector is an ESM-only module, it can not be imported with `require()`.

```javascript
import collector from '@wilnersson/console-input-collector'

const userAge = await collector.requestIntegerInput('What year were you born?', 1900, 2030) // Answers outside supplied min and max range throws an exception.

console.log(userAge) // Logs user answer in terminal.
```

## Installation

```bash
npm install @wilnersson/console-input-collector
```

Alternatively if you simply clone the Github repository, copy all files in the `src` folder to a destination of your choice, and import the default export from the `index.js`-file.

## Error handling

Throws an Error with name `ValidationError` when user input is invalid. Recommended usage is looping until you get a valid response.

### Example
```javascript
try {
  const userAge = await collector.requestIntegerInput('What year were you born?', 1900, 2030) // <-- User supplies 'hello world'
} catch (e) {
  console.log(e.name) // -> ValidationError
}
```

## Known issues

[bug] Erasing password input breaks output line ([#1][i1])

[i1]: https://github.com/wilnersson/console-input-collector/issues/1

## Testing

Package has been tested and confirmed to be working on the following version of node: `16.8.0`

Run the built in unit tests with:

```bash
npm test
```

Of course this only works if you have cloned the repository and installed all dev-dependencies.

```bash
npm install
```

## Version

1.0.2

## Licence

[MIT](./LICENSE)

---
_Source: https://npm.io/package/@wilnersson/console-input-collector · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
