JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 20221
  • Score
    100M100P100Q138075F
  • License MIT

Multiple-choice/checkbox prompt. Can be used standalone or with a prompt system like [Enquirer].

Package Exports

  • prompt-checkbox

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (prompt-checkbox) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

prompt-checkbox NPM version NPM monthly downloads NPM total downloads

Multiple-choice/checkbox prompt. Can be used standalone or with a prompt system like Enquirer.

prompt-checkbox example

Install

Install with npm:

$ npm install --save prompt-checkbox

Usage

var Enquirer = require('enquirer');
var enquirer = new Enquirer();

enquirer.register('checkbox', require('prompt-checkbox'));

Example

var Question = require('prompt-question');
var Prompt = require('prompt-checkbox');
var question = new Question('colors', 'What are your favorite colors?', {
  type: 'checkbox',
  choices: [
    'red',
    'blue',
    'yellow'
  ]
});

var prompt = new Prompt(question);
prompt.run()
  .then(function(answers) {
    console.log(answers)
  })
  .catch(function(err) {
    console.log(err)
  })

Enquirer examples

Enquirer supports both the declarative inquirer-style question format and a functional format using the .question method:

Functional-style questions

Functional style questions.

var Enquirer = require('enquirer');
var enquirer = new Enquirer();

enquirer.register('checkbox', require('prompt-checkbox'));
enquirer.question('color', 'What is your favorite color?', {
  type: 'checkbox',
  default: 'blue',
  choices: ['red', 'yellow', 'blue']
});

enquirer.ask('color')
  .then(function(answers) {
    console.log(answers)
  });

Inquirer-style questions

Declarative questions format.

var Enquirer = require('enquirer');
var enquirer = new Enquirer();

enquirer.register('checkbox', require('prompt-checkbox'));

var questions = [
  {
    name: 'color',
    message: 'What is your favorite color?',
    type: 'checkbox',
    default: 'blue',
    choices: ['red', 'yellow', 'blue']
  }
];

enquirer.ask(questions)
  .then(function(answers) {
    console.log(answers)
  });

options

options.radio

Enable hybrid radio-checkbox support. Adds support for all and none radio options (you need to add the options yourself).

var Enquirer = require('enquirer');
var enquirer = new Enquirer();

enquirer.register('checkbox', require('prompt-checkbox'));
enquirer.question('fruits', 'What fruits do you like?', {
  type: 'checkbox',
  choices: ['all', 'none', enquirer.separator(), 'watermelon', 'strawberry', 'apple'],
  radio: true
});

enquirer.ask('fruits')
  .then(function(answers) {
    console.log(answers)
  });

Attribution

Based on the checkbox prompt in inquirer.

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.5.0, on April 12, 2017.