
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
prompt-base
Advanced tools
Base prompt module used for creating custom prompt types for Enquirer.
Install with npm:
$ npm install --save prompt-base
See the examples folder for more detailed usage examples.
var Prompt = require('prompt-base');
var prompt = new Prompt({
name: 'color',
message: 'What is your favorite color?'
});
prompt.run()
.then(function(answer) {
console.log(answer);
})
Create a new Prompt with the given question
object, answers
and optional instance of readline-ui.
Params
question
{Object}: Plain object or instance of prompt-question.answers
{Object}: Optionally pass an answers object from a prompt manager (like enquirer).ui
{Object}: Optionally pass an instance of readline-ui. If not passed, an instance is created for you.Example
var prompt = new Prompt({
name: 'color',
message: 'What is your favorite color?'
});
prompt.ask(function(answer) {
console.log(answer);
//=> 'blue'
});
Initialize a prompt and resolve answers. If question.when
returns false,
the prompt will be skipped.
Params
answers
{Object}returns
{Promise}Default ask
method. This mayb eb overridden in custom prompts.
Render the current prompt input. This can be replaced by custom prompts.
Example
prompt.ui.on('keypress', prompt.render.bind(prompt));
Move the cursor in the specific direction
when the
given event
is emitted.
Params
direction
{String}event
{Object}Default keypress
event handler. This may be overridden in custom prompts.
Params
event
{Object}When the answer is submitted (user presses enter
key), re-render
and pass answer to callback. This may be replaced by custom prompts.
Params
input
{Object}Default tab
event handler. This may be overridden in custom prompts.
Params
event
{Object}Default error
event handler. This may be overridden in custom prompts.
Params
event
{Object}Returns a formatted prompt message.
returns
{String}Getter for getting the choices array from the question.
returns
{Object}: Choices objectGetter that returns question.message
after passing it to format.
returns
{String}: A formatted prompt message.Getter that returns the prefix to use before question.message
. The default value is a green ?
.
returns
{String}: The formatted prefix.Example
prompt.prefix = '!';
Create a new Separator
object. See choices-separator for more details.
Params
separator
{String}: Optionally pass a string to use as the separator.returns
{Object}: Returns a separator object.Example
new Prompt.Separator('---');
Instantiate
The main purpose of this library is to be inherited by other libraries to create custom prompt types. However, the main export is a function that can be instantiated to run basic "input" prompts, if you want to see how everything works, run examples, tests, etc.
var Prompt = require('prompt-base');
var prompt = new Prompt({
name: 'first',
message: 'What is your name?'
});
// callback
prompt.ask(function(answer) {
console.log(answer);
//=> 'Jon'
});
// promise
prompt.run()
.then(function(answers) {
console.log(answers);
//=> {first: 'Jon'}
});
Inherit
var Prompt = require('prompt-base');
function CustomPrompt(/*question, answers, rl*/) {
Prompt.apply(this, arguments);
}
util.inherits(CustomPrompt, Prompt);
The following custom prompts were created using this library:
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
Commits | Contributor |
---|---|
52 | jonschlinkert |
6 | doowb |
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running 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:
$ npm install && npm test
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on May 05, 2017.
FAQs
Base prompt module used for creating custom prompts.
The npm package prompt-base receives a total of 29,848 weekly downloads. As such, prompt-base popularity was classified as popular.
We found that prompt-base demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.