Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@types/inquirer
Advanced tools
The @types/inquirer package provides TypeScript type definitions for Inquirer.js, a library for creating interactive command-line interfaces. These type definitions enable TypeScript developers to use Inquirer.js with type checking, ensuring that they are using the library's API correctly.
Prompt Types
Demonstrates how to use different types of prompts such as 'input' for text input and 'list' for selecting from a list of options.
import inquirer from 'inquirer';
async function askQuestion() {
const answers = await inquirer.prompt([
{
type: 'input',
name: 'name',
message: 'What's your name?',
},
{
type: 'list',
name: 'choice',
message: 'Pick a choice:',
choices: ['Choice A', 'Choice B'],
}
]);
console.log(answers);
}
askQuestion();
Validation
Shows how to validate user input to ensure it meets certain criteria, in this case, checking if the input is a number.
import inquirer from 'inquirer';
inquirer.prompt([
{
type: 'input',
name: 'age',
message: 'Enter your age:',
validate: function(value) {
var valid = !isNaN(parseFloat(value));
return valid || 'Please enter a number';
},
filter: Number,
}
]).then(answers => {
console.log(`Your age is ${answers.age}`);
});
Conditional Questions
Illustrates how to ask questions conditionally based on previous answers using the 'when' property.
import inquirer from 'inquirer';
inquirer.prompt([
{
type: 'confirm',
name: 'toBeAsked',
message: 'Do you want to answer more questions?',
},
{
type: 'input',
name: 'moreInfo',
message: 'Tell me more:',
when: function(answers) {
return answers.toBeAsked;
}
}
]).then(answers => {
console.log(answers);
});
Prompt is another package for creating interactive command-line prompts. Compared to Inquirer.js, it has a simpler API but lacks some of the advanced features such as conditional prompts and modular prompt types.
Enquirer is a modern, promise-based, performant library for creating command-line prompts. It offers a similar set of features to Inquirer.js but focuses on being lightweight and highly customizable.
Vorpal is a framework for building interactive CLI applications. While it includes a system for prompting, its scope is broader, including command parsing, extensions, and interactive command execution. It's more suited for building complex CLI tools compared to the focused prompting capabilities of Inquirer.js.
npm install --save @types/inquirer
This package contains type definitions for inquirer (https://github.com/SBoudrias/Inquirer.js).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/inquirer.
These definitions were written by Qubo, Parvez, Jouderian, Qibang, Jason Dreyzehner, Synarque, Justin Rockwood, Keith Kelly, Richard Lea, Jed Mao, and Manuel Thalmann.
FAQs
TypeScript definitions for inquirer
The npm package @types/inquirer receives a total of 2,100,823 weekly downloads. As such, @types/inquirer popularity was classified as popular.
We found that @types/inquirer demonstrated a healthy version release cadence and project activity because the last version was released less than 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.