0.4.0 • Published 2 years ago

yesno v0.4.0

Weekly downloads
36,981
License
BSD
Repository
github
Last release
2 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-installerzerobyw-dl@fxhash/cliwhere-to-eat-lunchusdockertrncvideo-ascii@lugia/cli-package@lugia/console-utils@tdalabs/gsdk-deploytime-interactivetic80-typescripttidymodulestorichatskpm-builderthe-psteamboxsymlynxsyncodemayoskald-compiletest1dwebspotify-playlist-scraperswagger-client-builderwikp-ttsfastsitefig-teamsdsm-clidrobadi@git-lazy/subtreegprgot-swaggot-swag-delete@mcshovel/gsdk-deployflashbot-claim-alt-airdrop@namestys/polywrap@mirror-protocol/mirrorcli@mtyk/workflowgen-ng-lib-boilerplate@modusjs/cli@neutron-org/get-artifactsgistrgithub-to-awsgitswapimageinaryipfs-cohost@rockcarver/frodo-cli@dvrylc/sentinel@hyperspace/cliempress-hub@iameli/lex-cli@proppos/fastpay-clijad-react-cli@pixi-build-tools/fiddlehetzner-cdkjoomla-to-markdown@skpm/internal-utils@sphinx-labs/core@sphinx-labs/pluginsjungledrum@the-ksquare-group/resume-clikindle-clean@trivir/frodo-cli@the-/pskrollmyui5librarychenmyui5librarymobo@animoca/ethereum-migrations-core@animoca/ethereum-migrations-core_library@annadamm/scribblehub-to-epub@anthonyjdella/customized-resume-clibitweb-clineanderthalboostminer@arianee/arn-admin-clientmyreuselibraryjs-rotatelib@teambit/typescript@teambit/workspace-config-files@teambit/importer@teambit/remove@vroomlabs/gsdk-deploylokkolocalbackuplsi-soarnpm-synchronize
0.4.0

2 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.1

11 years ago