prompt
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@colors/colors | 1.5.0 | 10.89 kB | MIT | prod | |
async | 3.2.3 | 151.16 kB | MIT | prod | |
read | 1.0.7 | 2.61 kB | ISC | prod | |
revalidator | 0.1.8 | 14.11 kB | Apache 2.0 | prod | 1 1 |
winston | 2.4.7 | 40.46 kB | MIT | prod | 1 1 |
The "prompt" package is a beautifully crafted, user-friendly command-line prompt for node.js. Its primary function is to solicit user input from the command line. It's equipped with robust features like input validation, default values, and password hiding, ensuring a secure and hassle-free user interaction.
The usage of "prompt" is straightforward primarily because of its core methods prompt.get()
and prompt.addProperties()
. Here's an example of its usage:
var prompt = require('prompt');
prompt.start();
prompt.get(['username', 'email'], function (err, result) {
console.log('Command-line input received:');
console.log(' username: ' + result.username);
console.log(' email: ' + result.email);
});
The above code initiates the prompt process, queries the user for their 'username' and 'email', then logs this information to the console.
For commanding complex property validation, use the "schema" object. For instance:
var schema = {
properties: {
name: {
pattern: /^[a-zA-Z\s\-]+$/,
message: 'Name must be only letters, spaces, or dashes',
required: true
},
password: {
hidden: true
}
}
};
prompt.start();
prompt.get(schema, function (err, result) {
console.log('Command-line input received:');
console.log(' name: ' + result.name);
console.log(' password: ' + result.password);
});
This example similarly initiates the prompt, asks the user for their 'name' and 'password' (which remains unseen), then logs the user inputs. The 'name' input is limited to letters, spaces, or dashes only. If the user enters anything else, the prompt property message will alert them, and reprompt the query.
The comprehensive documentation for "prompt" can be found inside the GitHub repository - git@github.com:flatiron/prompt.git
. This includes numerous examples, detailed properties for validation and prompting, customization instructions, and more. It serves as a great resource for developers aiming to optimally utilize the "prompt" package.