Socket
Socket
Sign inDemoInstall

yesno

Package Overview
Dependencies
0
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    yesno

A simple library for asking boolean questions in cli programs


Version published
Weekly downloads
138K
increased by2.97%
Maintainers
2
Install size
8.59 kB
Created
Weekly downloads
 

Readme

Source

Build Status

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

Supports Node 8+.

Installation

npm install yesno

Usage

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

// *OR*

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

Examples

basic
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
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.

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:

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);
    }
});

Keywords

FAQs

Last updated on 19 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc