# yesno

> A simple library for asking boolean questions in cli programs

Latest version **0.4.0** (published 2022-06-19) · BSD license · 0 weekly downloads

## Install

```sh
npm install yesno
pnpm add yesno
yarn add yesno
bun add yesno
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2022-06-19 |
| First published | 2013-09-21 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Tim Channell |
| Maintainers | mreinstein, tcql |
| Keywords | cli, confirm, yesno, yes or no, prompt, question |

## Links

- npm: https://www.npmjs.com/package/yesno
- Repository: https://github.com/tcql/node-yesno
- Homepage: https://github.com/tcql/node-yesno#readme
- Issues: https://github.com/tcql/node-yesno/issues
- npm.io page: https://npm.io/package/yesno

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2022-06-19
- 0.3.1 — 2019-09-25
- 0.3.0 — 2019-07-26
- 0.2.1 — 2019-07-26
- 0.2.0 — 2018-11-30
- 0.1.0 — 2018-11-30
- 0.0.1 — 2013-09-21

## README

[![Build Status](https://travis-ci.org/tcql/node-yesno.svg?branch=master)](https://travis-ci.org/tcql/node-yesno)

A nodejs library for issuing and handling responses to yes/no questions 

Supports Node 8+.

### Installation

```bash
npm install yesno
```

### Usage

```javascript
import yesno from 'yesno';        // modern es modules approach

// *OR*

const yesno = require('yesno');   // commonjs approach
```

### Examples


##### basic

```javascript
const ok = await yesno({
    question: 'Are you sure you want to continue?'
});
````

yesno accepts `yes`, `y` , `no`, and `n` values by default.

All yesno responses are case insensitive.


##### Custom Yes/No values

```javascript
const ok = await yesno({
    question: 'Dude, Is this groovy or what?',
    yesValues: [ 'groovy' ],
    noValues: [ 'or what' ]
});

console.log(ok ? 'Tubular.' : 'Aw, why you gotta be like that?');
```

Now the question only responds to `groovy` as yes and `or what` as no.


##### No default value

Sometimes you may want to ensure the user didn't accidentally accept a default.
You can disable the default response by passing null as the defaultValue parameter.

```javascript
const ok = await yesno({
    question: 'Are you sure you want to 'rm-rf /' ?',
    defaultValue: null
});
```


##### Handling invalid responses

By default, if the user enters a value that isn't recognized as an acceptable response, it will
print out a message like: 

    Invalid response.
    Answer either yes : (yes, y)
    Or no : (no, n)

and re-ask the question. If you want to change this behavior, you can set the invalid handler before asking your question:

```javascript
const ok = await yesno({
    question: 'Ready to continue?',
    invalid: function ({ question, defaultValue, yesValues, noValues }) {
        process.stdout.write("\n Whoa. That was not a good answer. Well. No more tries for you.");
        process.exit(1);
    }
});
```

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