0.4.0 • Published 3 years ago

yesno v0.4.0

Weekly downloads
36,981
License
BSD
Repository
github
Last release
3 years ago

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);
    }
});
aewebwampp5-new-sketchlightspeed-devtoolsrhinotsyarn-upgrade-match@proppos/faspay-clisl-static-html@fortification/coremovebotplex-tags@mvd/frodo-clireadhub_cliexpress-react-generator-typescript@everything-registry/sub-chunk-32025minds-editorconfig-installersyncodemayosymlynxswagger-client-builderwikp-ttswhere-to-eat-lunchteamboxspotify-playlist-scrapertest1dwebthe-pstic80-typescriptvideo-ascii@dino-dev/cli@devbab/plex-tagsjs-rotatelibjoomla-to-markdownipfs-cohostjad-react-clijungledrumkindle-cleantime-interactivetorichattidymodulestrnc@anthonyjdella/customized-resume-cli@archethicjs/aeweb-cli@animoca/ethereum-migrations-core@animoca/ethereum-migrations-core_library@annadamm/scribblehub-to-epub@anchor-protocol/airdropcli@anchor-protocol/anchorcli@atproto/lex-cli@arianee/arn-admin-client@architect/env@chugsplash/core@chugsplash/plugins@dhub/cli@dig-platform/dighub-cli@danshfaim/puppyzerobyw-dlusdocker@iameli/lex-cli@hujw77/core@hujw77/plugins@fxhash/cli@git-lazy/subtree@lugia/cli-package@lugia/console-utils@mtyk/workflow@neutron-org/get-artifacts@namestys/polywrap@mcshovel/gsdk-deploy@mirror-protocol/mirrorcli@modusjs/cli@hyperspace/cli@dvrylc/sentinel@kabelsalat/cli@pixi-build-tools/fiddle@proppos/fastpay-climulti-db-drivermqp-servermyui5librarymobomyreuselibrarymyui5librarychenpadplusnpm-synchronizeobjimgrploys3-plussails-generate-archivereactuateproject-templifyserverless-package-commonserverless-package-externalserverless-package-libnode-confirmneanderthalpkgpurgepodspec-versionpolywrapresume-cliresume-cli-devqrcode-cmdreact-quick-classskald-compile
0.4.0

3 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.1

12 years ago