🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

inquirer-ts-checkbox-plus-prompt

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inquirer-ts-checkbox-plus-prompt

Checkbox with autocomplete and other additions for Inquirer

1.0.0
Source
npm
Version published
Weekly downloads
2.6K
-11.64%
Maintainers
1
Weekly downloads
 
Created
Source

Inquirer TypeScript Checkbox Plus Prompt

A plugin for Inquirer, similar to the original checkbox with extra features. This project is TypeScript port from inquirer-checkbox-plus-prompt

npm npm

Demo

Installation

npm install -g inquirer-ts-checkbox-plus-prompt

Usage

You can name it with any name other than checkbox-plus, just change the string 'checkbox-plus' to anything else.

import { CheckboxPlusPrompt } from 'inquirer-ts-checkbox-plus-prompt';

inquirer.registerPrompt('checkbox-plus', CheckboxPlusPrompt);

inquirer.prompt({
  type: 'checkbox-plus',
  ...
})

Options

Takes type, name, message, source[, filter, validate, default, pageSize, highlight, searchable] properties.

The extra options that this plugin provides are:

  • source: (Function) a method that called to return a promise that should be resolved with a list of choices in a similar format as the choices option in the original checkbox prompt of Inquirer.
  • highlight: (Boolean) if true, the current selected choice gets highlighted. Default: false.
  • searchable: (Boolean) if true, allow the user to filter the list. The source function gets called everytime the search query is changed. Default: false.

Example

Check example.ts for a more advanced example.

import fuzzy from 'fuzzy';
import inquirer from 'inquirer';
import CheckboxPlusPrompt from '../lib/CheckboxPlusPrompt';

inquirer.registerPrompt('checkbox-plus', CheckboxPlusPrompt);

const colors = ['red', 'green', 'blue', 'yellow'];

inquirer
  .prompt([
    {
      type: 'checkbox-plus',
      name: 'colors',
      message: 'Enter colors',
      pageSize: 10,
      highlight: true,
      searchable: true,
      default: ['yellow', 'red'],
      source(answersSoFar, input) {
        input ||= '';

        return new Promise((resolve) => {
          const fuzzyResult = fuzzy.filter(input, colors);

          const data = fuzzyResult.map((element) => {
            return element.original;
          });

          resolve(data);
        });
      },
    },
  ])
  .then((answers) => {
    console.log(answers.colors);
  });

License

This project is under the MIT license.

Keywords

inquirer

FAQs

Package last updated on 27 Oct 2022

Did you know?

Socket

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