Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
inquirer-checkbox-plus-prompt
Advanced tools
Checkbox with autocomplete and other additions for Inquirer
The inquirer-checkbox-plus-prompt package is an extension for the Inquirer.js library that provides a checkbox prompt with autocompletion. It allows users to select multiple options from a list with the added functionality of filtering options through a search input.
Basic Checkbox Prompt with Autocomplete
This feature allows users to select multiple options from a list with the ability to filter the options by typing in a search input. The code demonstrates how to set up a basic checkbox prompt with autocomplete functionality.
const inquirer = require('inquirer');
const CheckboxPlusPrompt = require('inquirer-checkbox-plus-prompt');
inquirer.registerPrompt('checkbox-plus', CheckboxPlusPrompt);
inquirer.prompt([
{
type: 'checkbox-plus',
name: 'fruits',
message: 'Select your favorite fruits',
choices: ['Apple', 'Orange', 'Banana', 'Grapes', 'Pineapple'],
pageSize: 10,
source: (answersSoFar, input) => {
input = input || '';
return new Promise((resolve) => {
const choices = ['Apple', 'Orange', 'Banana', 'Grapes', 'Pineapple'];
const filteredChoices = choices.filter(choice => choice.toLowerCase().includes(input.toLowerCase()));
resolve(filteredChoices);
});
}
}
]).then(answers => console.log(answers));
Dynamic Choices Loading
This feature demonstrates how to load choices dynamically, simulating an asynchronous call to fetch data. The user can filter the list of countries by typing in the search input.
const inquirer = require('inquirer');
const CheckboxPlusPrompt = require('inquirer-checkbox-plus-prompt');
inquirer.registerPrompt('checkbox-plus', CheckboxPlusPrompt);
inquirer.prompt([
{
type: 'checkbox-plus',
name: 'countries',
message: 'Select countries you have visited',
pageSize: 10,
source: (answersSoFar, input) => {
input = input || '';
return new Promise((resolve) => {
// Simulate an asynchronous call to fetch data
setTimeout(() => {
const allCountries = ['USA', 'Canada', 'Mexico', 'Germany', 'France', 'Italy', 'Spain', 'China', 'Japan', 'Australia'];
const filteredCountries = allCountries.filter(country => country.toLowerCase().includes(input.toLowerCase()));
resolve(filteredCountries);
}, 1000);
});
}
}
]).then(answers => console.log(answers));
The inquirer-autocomplete-prompt package provides an autocomplete prompt for Inquirer.js. It allows users to search and select a single option from a list. Unlike inquirer-checkbox-plus-prompt, it does not support multiple selections.
A plugin for Inquirer, similar to the original checkbox with extra features.
The animated GIF is made by Terminalizer
npm install inquirer-checkbox-plus-prompt
You can name it with any name other than checkbox-plus
, just change the string 'checkbox-plus'
to anything else.
inquirer.registerPrompt('checkbox-plus', require('inquirer-checkbox-plus-prompt'));
inquirer.prompt({
type: 'checkbox-plus',
...
})
Takes type
, name
, message
, source
[, filter
, validate
, default
, pageSize
, highlight
, searchable
] properties.
The extra options that this plugin provides are:
choices
option in the original checkbox
prompt of Inquirer
.true
, the current selected choice gets highlighted. Default: false
.true
, allow the user to filter the list. The source
function gets called everytime the search query is changed. Default: false
.Check example.js for a more advanced example.
var inquirer = require('inquirer');
var fuzzy = require('fuzzy');
inquirer.registerPrompt('checkbox-plus', require('./index'));
var 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: function(answersSoFar, input) {
input = input || '';
return new Promise(function(resolve) {
var fuzzyResult = fuzzy.filter(input, colors);
var data = fuzzyResult.map(function(element) {
return element.original;
});
resolve(data);
});
}
}]).then(function(answers) {
console.log(answers.colors);
});
This project is under the MIT license.
FAQs
Checkbox with autocomplete and other additions for Inquirer
The npm package inquirer-checkbox-plus-prompt receives a total of 1,140,384 weekly downloads. As such, inquirer-checkbox-plus-prompt popularity was classified as popular.
We found that inquirer-checkbox-plus-prompt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.