Package Exports
- enquirer
- enquirer/lib/utils
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (enquirer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
enquirer

Intuitive, plugin-based prompt system for node.js. Much faster and lighter alternative to Inquirer, with all the same prompt types and more, but without the bloat.
Table of Contents
(TOC generated by verb using markdown-toc)
Usage
Enquirer
Create an instance of Enquirer with the given options.
Example
var Enquirer = require('enquirer');
var enquirer = new Enquirer();Params
options{Object}
.register
Register a new prompt type with the given fn.
Example
enquirer.register('confirm', require('enquirer-prompt-confirm'));Params
type{String}: The name of the prompt typefn{Function}: Prompt function that inherits from prompt-base.returns{Object}: Returns the Enquirer instance for chaining.
.use
Invoke a plugin fn
Example
enquirer.use(require('some-enquirer-plugin'));Params
fn{Function}: Function that takes an instance ofEnquirerreturns{Object}: Returns the instance for chaining.
.question
Create question name with the given message and options. Uses enquirer-question, visit that library for additional details.
Example
enquirer.question('color', 'What is your favorite color?');
enquirer.question('color', 'What is your favorite color?', {
default: 'blue'
});
enquirer.question('color', {
message: 'What is your favorite color?',
default: 'blue'
});
enquirer.question({
name: 'color',
message: 'What is your favorite color?',
default: 'blue'
});
enquirer.question({
name: 'color',
type: 'input', // "input" is the default prompt type and doesn't need to be specified
message: 'What is your favorite color?',
default: 'blue'
});Params
name{String|Object}: Name or options objectmessage{String|Object}: Message or options objectoptions{Object}returns{Object}: Returns the created question object
Events
emits:question
.ask
Initialize a prompt session for one or more questions.
Example
var Enquirer = require('enquirer');
var enquirer = new Enquirer();
enquirer.question('first', 'First name?');
enquirer.question('last', 'Last name?');
enquirer.ask('first')
.then(function(answers) {
console.log(answers)
});
// errors
enquirer.ask('first')
.then(function(answers) {
console.log(answers)
})
.catch(function(err) {
console.log(err)
});returns{Array|Object}questions: One or more question objects or names of registered questions.
Events
emits:askWith the array ofquestionsto be asked
.prompt
Initialize a prompt session for a single question. Used by the ask method.
Example
var Enquirer = require('enquirer');
var enquirer = new Enquirer();
enquirer.question('first', 'First name?');
enquirer.prompt('first')
.then(function(answers) {
console.log(answers)
});Params
name{String}
Events
emits:promptwith thedefaultvalue,key,questionobject, andanswersobjectemits:answerwith theanswervalue,key,questionobject, andanswersobject
.separator
Create a new Separator to use in a choices array.
.Separator
Create a new Separator to use in a choices array.
Prompt types
What is a prompt "type"?
Prompt types determine the type of question - or prompt - to initiate. Currently, the only prompt type that ships with enquirer is input.
These following additional prompt types are available as plugins:
- prompt-autocompletion: Prompt that autocompletes as you type. Can be used standalone or with a prompt system… more | homepage
- prompt-checkbox: Multiple-choice/checkbox prompt. Can be used standalone or with a prompt system like [Enquirer]. | homepage
- prompt-confirm: Confirm (yes/no) prompt. Can be used standalone or with a prompt system like [Enquirer]. | homepage
- prompt-editor: Editor prompt. Opens your text editor and waits for you to save your input during… more | homepage
- prompt-expand: Expand prompt. Can be used as a standalone prompt, or with a prompt system like… more | homepage
- prompt-input: This package name is not currently in use, but was formerly occupied by a popular… more | homepage
- prompt-list: List-style prompt. Can be used as a standalone prompt, or with a prompt system like… more | homepage
- prompt-password: Password prompt. Can be used as a standalone prompt, or with a prompt system like… more | homepage
- prompt-question: Question object, used by Enquirer and prompt plugins. | homepage
- prompt-radio: Radio prompt. This prompt behaves like other radio-button interfaces, where only one choice is enabled… more | homepage
- prompt-rawlist: Rawlist prompt. Can be used as a standalone prompt, or with a prompt system like… more | homepage
Or you can use enquirer-prompts, if you want a bundle with all of the listed prompt types.
Publishing prompt types
Prompt modules are named using the convention prompt-*.
TBC
Plugins
TODO
Publishing plugins
Plugin modules are named using the convention enquirer-*.
TBC
Why another prompt module?
We use prompts extensively in our projects, and we wanted to improve the user experience and reduce dependencies associated with other libraries we tried, like Inquirer.
Our main goals were:
- reduce initial load time
- make prompt-types easier to add
- make code footprint smaller
Initial load time
Enquirer takes ~11ms to load. This is about the same amount of time that it takes chalk to load.
By comparison, Inquirer takes ~120ms just to load!!! This is about how long it takes babel, or other massive libraries that you would never include in production code.
Regardless of whether or not a prompt is every actually used, your own application will be 120ms slower from having Inquirer in its dependency tree. This is caused by its own massive dependency tree, code redundancy, monolithic and slow reactive interface (which makes little sense for this use case anyway), poor API design (Inquirer actually executes code, even if you never call the library!), and so on.
120ms might not seem like a lot, but there is a critical threshold where performance of an application begins to feel laggy, and having inquirer in your dependency tree cuts into that threshold significantly, leaving less room for everything else.
Make prompts easier to add
Inquirer uses a reactive interface for flow control. Aside from being overkill and not offering and real code advantages, to work with the code you need to be familiar with microsoft's RX first. This makes it a pain to add new prompt types (e.g. you probably won't).
Regarding the specific "merits" of RX alone, we think it's overkill, makes the application slow, bloated, hard to maintain, hard to contribute to, and difficult to extend. Events are sufficient.
Code footprint
By moving prompt types into separate libraries, we're able to keep the core library small and fast. Moreover, implementors and authors can create their own prompt types without having to require enquirer itself (unlike inquirer). This also makes the individual prompt libraries easier to maintain.
About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for avice on opening issues, pull requests, and coding standards.
Running tests
Install dev dependencies:
$ npm install -d && npm testAuthor
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb-generate-readme, v0.1.31, on October 17, 2016.