{"id":13630633,"url":"https://github.com/enquirer/prompt-checkbox","last_synced_at":"2025-08-03T06:13:37.539Z","repository":{"id":49253372,"uuid":"66805241","full_name":"enquirer/prompt-checkbox","owner":"enquirer","description":"This repository has been archived, use Enquirer instead.","archived":false,"fork":false,"pushed_at":"2023-01-11T09:37:08.000Z","size":1528,"stargazers_count":22,"open_issues_count":5,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-23T09:32:03.274Z","etag":null,"topics":["check","checkbox","choices","enquirer","generate","generator","inquirer","multiple-choice","prompt","question","radio","readline","scaffolder","select","terminal","yeoman"],"latest_commit_sha":null,"homepage":"https://github.com/enquirer/enquirer","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/enquirer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-29T02:41:17.000Z","updated_at":"2023-12-02T21:52:46.000Z","dependencies_parsed_at":"2023-02-09T02:25:11.915Z","dependency_job_id":null,"html_url":"https://github.com/enquirer/prompt-checkbox","commit_stats":null,"previous_names":["enquirer/enquirer-prompt-checkbox"],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enquirer%2Fprompt-checkbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enquirer%2Fprompt-checkbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enquirer%2Fprompt-checkbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enquirer%2Fprompt-checkbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enquirer","download_url":"https://codeload.github.com/enquirer/prompt-checkbox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217130,"owners_count":21066633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["check","checkbox","choices","enquirer","generate","generator","inquirer","multiple-choice","prompt","question","radio","readline","scaffolder","select","terminal","yeoman"],"created_at":"2024-08-01T22:01:51.417Z","updated_at":"2025-04-10T12:33:12.039Z","avatar_url":"https://github.com/enquirer.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# prompt-checkbox [![NPM version](https://img.shields.io/npm/v/prompt-checkbox.svg?style=flat)](https://www.npmjs.com/package/prompt-checkbox) [![NPM monthly downloads](https://img.shields.io/npm/dm/prompt-checkbox.svg?style=flat)](https://npmjs.org/package/prompt-checkbox) [![NPM total downloads](https://img.shields.io/npm/dt/prompt-checkbox.svg?style=flat)](https://npmjs.org/package/prompt-checkbox) [![Linux Build Status](https://img.shields.io/travis/enquirer/prompt-checkbox.svg?style=flat\u0026label=Travis)](https://travis-ci.org/enquirer/prompt-checkbox)\n\n\u003e Multiple-choice/checkbox prompt. Can be used standalone or with a prompt system like [Enquirer](http://enquirer.io).\n\n![prompt-checkbox example](https://raw.githubusercontent.com/enquirer/prompt-checkbox/master/docs/example.gif)\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save prompt-checkbox\n```\n\n## Usage\n\n```js\nvar Prompt = require('prompt-checkbox');\nvar prompt = new Prompt({\n  name: 'colors',\n  message: 'What are your favorite colors?',\n  choices: [\n    'red',\n    'blue',\n    'yellow'\n  ]\n});\n\n// promises\nprompt.run()\n  .then(function(answers) {\n    console.log(answers)\n  })\n  .catch(function(err) {\n    console.log(err)\n  })\n\n// async\nprompt.ask(function(answers) {\n  console.log(answers)\n});\n```\n\n## Special features\n\nFeatures you won't find with other prompts!\n\n### Choices function\n\nDefine choices as a function. This allows you to dynamically generate the choices when the question is asked.\n\n```js\nvar prompt = new Prompt({\n  name: 'colors',\n  message: 'What are your favorite colors?',\n  choices: function() {\n    // dynamically build choices \n    return ['red', 'blue', 'green'];\n  }\n});\n```\n\n### Choice groups\n\n![Choices groups](https://raw.githubusercontent.com/enquirer/prompt-checkbox/master/docs/choice-groups.gif)\n\n**Easy to configure!**\n\nJust pass an object of arrays on `choices`, and each key in the object will be used as the group \"toggle\":\n\n```js\nvar Prompt = require('prompt-checkbox');\nvar prompt = new Prompt({\n  name: 'install',\n  message: 'Which packages do you want to install?',\n  choices: {\n    dependencies: ['generate', 'micromatch'],\n    devDependencies: ['mocha', 'kind-of']\n  }\n});\n```\n\n### Radio choices\n\nAdds `all` and `none` choices, which select or deselect all choices, respectively. Named \"radio choices\" since it acts like a hybrid between checkboxes and radio buttons.\n\n\u003cbr\u003e\n\n![radio choices](https://raw.githubusercontent.com/enquirer/prompt-checkbox/master/docs/radio-choices.gif)\n\n**Code example**\n\n```js\nvar Prompt = require('prompt-checkbox');\nvar prompt = new Prompt({\n  name: 'install',\n  message: 'Which packages do you want to install?',\n  radio: true,\n  choices: ['foo', 'bar', 'baz']\n});\n```\n\n### Radio groups\n\nUse \"radio\" choices with choice groups.\n\n\u003cbr\u003e\n\n![radio groups](https://raw.githubusercontent.com/enquirer/prompt-checkbox/master/docs/radio-groups.gif)\n\n```js\nvar Prompt = require('prompt-checkbox');\nvar prompt = new Prompt({\n  name: 'install',\n  message: 'Which packages do you want to install?',\n  radio: true,\n  choices: {\n    dependencies: ['generate', 'micromatch'],\n    devDependencies: ['mocha', 'kind-of']\n  }\n});\n```\n\n## options\n\nThe following options are either specific to prompt-checkbox, or have behavior that differs in some way from the built-in options from [prompt-base](https://github.com/enquirer/prompt-base). _(Any other options from [prompt-base](https://github.com/enquirer/prompt-base) may be used as well.)_\n\n### options.default\n\n**Type**: `string|number|array`\n\n**Default**: `undefined`\n\nSpecify the \"default\" choices to check when the prompt is initialized. Default can be a choice name (string), index (number), or an array of choice names or indices.\n\n**Examples**\n\nSpecify default as a string (choice name):\n\n```js\nvar prompt = new Prompt({\n  name: 'colors',\n  message: 'Best flavor?',\n  default: 'chocolate',\n  choices: ['chocolate'] // \u003c= hmm, I wonder what they'll choose?\n});\n```\n\nSpecify an array of defaults (choice names or indices):\n\n```js\nvar prompt = new Prompt({\n  name: 'colors',\n  message: 'Favorite colors?',\n  default: [1, 'blue'],\n  choices: ['red', 'blue', 'yellow']\n});\n```\n\n### options.radio\n\n**Type**: `boolean`\n\n**Default**: `undefined`\n\nEnable hybrid radio-checkbox support, which adds `all` and `none` radio options for toggling all options on and off.\n\n```js\nvar Prompt = require('prompt-checkbox');\nvar prompt = new Prompt({\n  name: 'colors',\n  message: 'What are your favorite colors?',\n  radio: true,\n  choices: [\n    'red',\n    'blue',\n    'yellow'\n  ]\n});\n```\n\n### options.transform\n\n**Type**: `function`\n\n**Default**: `undefined`\n\nModify answer values before they're returned.\n\n**Example**\n\nUse `options.transform` and the `prompt.choices.get()` method to convert answers (checked choices) to an array of objects (versus of an array of strings).\n\n```js\nvar Prompt = require('prompt-checkbox');\nvar prompt = new Prompt({\n  name: 'colors',\n  message: 'What are your favorite colors?',\n  choices: ['red', 'blue', 'yellow'],\n  transform: function(answer) {\n    // - \"this\" is the prompt instance\n    // - \"this.choices.get()\" returns the choice object for each choice\n    return answer ? answer.map(this.choices.get.bind(this.choices)) : [];\n  }\n});\n```\n\n## Keypresses\n\nIn addition to the keypresses that are supported by [prompt-base](https://github.com/enquirer/prompt-base), the following keypress offer different behavior that is specific to checklists:\n\n* \u003ckbd\u003edown\u003c/kbd\u003e - move the pointer (cursor) down one row for each keypress\n* \u003ckbd\u003eup\u003c/kbd\u003e - move the pointer (cursor) up one row for each keypress\n* \u003ckbd\u003ei\u003c/kbd\u003e - toggle all choices to the opposite of their current state.\n* \u003ckbd\u003ea\u003c/kbd\u003e - enable or disable all choices\n* \u003ckbd\u003espace\u003c/kbd\u003e - toggle a choice\n* \u003ckbd\u003enumber\u003c/kbd\u003e - toggle the choice at the given index (starting at 1)\n\n## Usage with [enquirer](http://enquirer.io)\n\nRegister the prompt with enquirer:\n\n```js\nvar Enquirer = require('enquirer');\nvar enquirer = new Enquirer();\n\nenquirer.register('checkbox', require('prompt-checkbox'));\n```\n\n### Enquirer examples\n\nFor formatting questions, [enquirer](http://enquirer.io) supports either:\n\n* declarative, inquirer-style question format\n* functional format using the `.question` method.\n\n**Inquirer-style questions**\n\nDeclarative questions format, similar to `inquirer`.\n\n```js\nvar questions = [\n  {\n    name: 'color',\n    message: 'What is your favorite color?',\n    type: 'checkbox',\n    default: 'blue',\n    choices: ['red', 'yellow', 'blue']\n  }\n];\n\nenquirer.prompt(questions)\n  .then(function(answers) {\n    console.log(answers)\n  });\n```\n\nOr:\n\n```js\nenquirer.prompt({\n    name: 'color',\n    message: 'What is your favorite color?',\n    type: 'checkbox',\n    default: 'blue',\n    choices: ['red', 'yellow', 'blue']\n  })\n  .then(function(answers) {\n    console.log(answers)\n  });\n```\n\n**Functional-style questions**\n\nUse the `.question` method to pre-register questions, so they can be called later. Also, the `message` may be passed as the second argument, or as a property on the question options.\n\n```js\nenquirer.question('letter', 'What are your favorite letters?', {\n  type: 'checkbox', //\u003c= specify the prompt type\n  choices: ['a', 'b', 'c']\n});\n\nenquirer.question('numbers', {\n  type: 'checkbox', //\u003c= specify the prompt type\n  message: 'What are your favorite numbers?',\n  choices: ['1', '2', '3']\n});\n\n// pass the name(s) or questions to ask\nenquirer.prompt(['letters', 'numbers'])\n  .then(function(answers) {\n    console.log(answers)\n  });\n```\n\n## About\n\n### Related projects\n\n* [enquirer](https://www.npmjs.com/package/enquirer): Intuitive, plugin-based prompt system for node.js. | [homepage](http://enquirer.io \"Intuitive, plugin-based prompt system for node.js.\")\n* [prompt-base](https://www.npmjs.com/package/prompt-base): Base prompt module used for creating custom prompts. | [homepage](https://github.com/enquirer/prompt-base \"Base prompt module used for creating custom prompts.\")\n* [prompt-choices](https://www.npmjs.com/package/prompt-choices): Create an array of multiple choice objects for use in prompts. | [homepage](https://github.com/enquirer/prompt-choices \"Create an array of multiple choice objects for use in prompts.\")\n* [prompt-question](https://www.npmjs.com/package/prompt-question): Question object, used by Enquirer and prompt plugins. | [homepage](https://github.com/enquirer/prompt-question \"Question object, used by Enquirer and prompt plugins.\")\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n### Running tests\n\nRunning 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:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n### Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 08, 2017._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenquirer%2Fprompt-checkbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenquirer%2Fprompt-checkbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenquirer%2Fprompt-checkbox/lists"}