Socket
Socket
Sign inDemoInstall

enquirer

Package Overview
Dependencies
83
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

changes.md

129

index.js

@@ -7,11 +7,20 @@ 'use strict';

/**
* Create an instance of `Enquirer` with the given `options`.
*
* ```js
* var enquirer = new Enquirer();
* ```
* @param {Object} `options`
* @api public
*/
function Enquirer(options) {
debug('initializing from <%s>', __filename);
this.active = false;
this.options = options || {};
this.active = false;
this.questions = {};
this.prompts = {};
this.answers = {};
this.prompts = {};
this.queue = [];
this.init();
}

@@ -24,27 +33,48 @@

Enquirer.prototype.init = function() {
this.register('input', require('enquirer-prompt-input'));
this.UI = this.options.UI || require('readline-ui');
if (!this.prompts.hasOwnProperty('input')) {
this.register('input', require('enquirer-prompt-input'));
}
this.UI = this.options.UI || utils.UI;
this.ui = new this.UI(this.options);
this.finish = this.ui.finish.bind(this.ui);
this.close = this.ui.close.bind(this.ui);
this.rl = this.ui.rl;
this.ui.on('finished', function() {
this.ui.once('finish', function() {
this.active = false;
this.close = null;
this.queue = [];
this.emit('finish');
}.bind(this));
this.rl = this.ui.rl;
this.finish = this.ui.finish.bind(this.ui);
this.close = this.ui.close.bind(this.ui);
this.emit('init', this);
};
/**
* Invoke a plugin `fn`
* Lazily initialize Enquirer defaults
*/
Enquirer.prototype.lazyInit = function() {
if (this.initialized) return;
this.initialized = true;
this.init();
};
/**
* Register a new prompt `type` with the given `fn`.
*
* ```js
* enquirer.use(require('my-enquirer-plugin'));
* enquirer.register('confirm', require('enquirer-prompt-confirm'));
* ```
* @param {Function} `fn` Function that takes an instance of `Enquirer`
* @return {Object} Returns the instance for chaining.
* @param {String} `type` The name of the prompt type
* @param {Function} `fn` Prompt function that inherits from [enquirer-prompt][].
* @return {Object} Returns the Enquirer instance for chaining.
* @api public
*/
Enquirer.prototype.use = function(fn) {
fn.call(this, this);
Enquirer.prototype.register = function(type, PromptType) {
if (utils.isObject(type)) {
return this.visit('register', type);
}
this.prompts[type] = PromptType;
return this;

@@ -54,18 +84,14 @@ };

/**
* Register a new prompt type.
* Invoke a plugin `fn`
*
* ```js
* enquirer.register('confirm', require('enquirer-confirm'));
* enquirer.use(require('some-enquirer-plugin'));
* ```
* @param {String} `name`
* @param {Function} `fn`
* @return {Object} Returns the Enquirer instance for chaining.
* @param {Function} `fn` Function that takes an instance of `Enquirer`
* @return {Object} Returns the instance for chaining.
* @api public
*/
Enquirer.prototype.register = function(name, fn) {
if (utils.isObject(name)) {
return this.visit('register', name);
}
this.prompts[name] = fn.bind(this);
Enquirer.prototype.use = function(fn) {
fn.call(this, this);
return this;

@@ -76,7 +102,12 @@ };

* Create question `name` with the given `message` and `options`.
* Uses [enquirer-question][], visit that library for additional details.
*
* ```js
* var question = enquirer.question('name', 'What is your name?');
* ```
* @emits `question`
* @param {String|Object} `name` Name or options object
* @param {String|Object} `message` Message or options object
* @param {Object} `options`
* @return {Object} Returns the question object
* @return {Object} Returns the created question object
* @api public

@@ -90,4 +121,6 @@ */

var question = new utils.Question(name, message, options);
var opts = utils.extend({}, this.options, options);
var question = new utils.Question(name, message, opts);
this.questions[question.name] = question;
this.emit('question', question);
return question;

@@ -101,3 +134,2 @@ };

* @return {Array} Returns an array of question names
* @api public
*/

@@ -115,7 +147,20 @@

}
return (this.queue = Object.keys(this.questions));
this.queue = Object.keys(this.questions);
return this.queue;
};
/**
* Initialize a prompt session for one or more questions
* Initialize a prompt session for one or more questions.
*
* ```js
* enquirer.question('first', 'First name?');
* enquirer.question('last', 'Last name?');
*
* enquirer.ask('first')
* .then(function(answers) {
* console.log(answers)
* });
* ```
* @emits `ask` With the array of `questions` to be asked
* @return {Array|Object} `questions` One or more question objects or names of registered questions.
* @api public

@@ -125,5 +170,8 @@ */

Enquirer.prototype.ask = function(questions) {
this.lazyInit();
var queue = this.enqueue(questions);
var prompt = this.prompt.bind(this);
var finish = this.finish.bind(this);
// disable `finish` to prevent successive calls
this.finish = utils.identity;

@@ -133,2 +181,4 @@ function ask(acc, question) {

}
this.emit('ask', queue);
return Promise.resolve(queue)

@@ -140,4 +190,13 @@ .then(utils.reduce(ask, this.answers))

/**
* Initialize a prompt session for a single question.
* Initialize a prompt session for a single question. Used by the [ask](#ask) method.
*
* ```js
* enquirer.question('first', 'First name?');
* enquirer.prompt('first')
* .then(function(answers) {
* console.log(answers)
* });
* ```
* @emits `prompt` with the `default` value, `key`, `question` object, and `answers` object
* @emits `answer` with the `answer` value, `key`, `question` object, and `answers` object
* @param {String} `name`

@@ -152,2 +211,3 @@ * @api public

this.lazyInit();
this.queue = this.queue || [name];

@@ -166,7 +226,8 @@ var answers = this.answers;

var prompt = new PromptType(question, answers, self.rl);
self.emit('prompt', question, answers, prompt);
var prompt = new PromptType(question, answers, self.ui);
self.emit('prompt', question.default, question, answers, prompt);
var promise = prompt.run(answers)
.then(function(val) {
question.answer = val[name];
self.emit('answer', val[name], name, question, answers);

@@ -188,7 +249,5 @@ return val;

*
* @name .visit
* @param {String} `method` The name of the `base` method to call.
* @param {Object|Array} `val` The object or array to iterate over.
* @return {Object} Returns the instance for chaining.
* @api public
*/

@@ -195,0 +254,0 @@

{
"name": "enquirer",
"description": "Plugin-based prompt system for node.js",
"version": "0.1.0",
"description": "Intuitive, plugin-based prompt system for node.js. Much faster alternative to Inquirer, with all the same prompt types and more.",
"version": "0.1.1",
"homepage": "https://github.com/jonschlinkert/enquirer",

@@ -13,2 +13,4 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"files": [
"index.js",
"lib",
"LICENSE",

@@ -25,4 +27,2 @@ "README.md"

"dependencies": {
"ansi-cyan": "^0.1.1",
"ansi-red": "^0.1.1",
"clone-deep": "^0.2.4",

@@ -32,5 +32,9 @@ "collection-visit": "^0.2.3",

"debug": "^2.2.0",
"kind-of": "^3.0.4",
"enquirer-prompt-input": "^0.1.0",
"enquirer-question": "^0.1.1",
"extend-shallow": "^2.0.1",
"isobject": "^2.1.0",
"lazy-cache": "^2.0.1",
"promise-reduce": "^2.1.0"
"promise-reduce": "^2.1.0",
"readline-ui": "^0.1.0"
},

@@ -40,2 +44,3 @@ "devDependencies": {

"gulp-eslint": "^3.0.1",
"gulp-format-md": "^0.1.10",
"gulp-istanbul": "^1.1.0",

@@ -47,4 +52,68 @@ "gulp-mocha": "^3.0.1",

"keywords": [
"enquirer"
]
"answer",
"answers",
"ask",
"checkbox",
"choice",
"cli",
"command",
"enquirer",
"input",
"inquire",
"inquirer",
"interact",
"list",
"menu",
"password",
"prompt",
"prompts",
"question",
"readline",
"stdin",
"stdout",
"terminal",
"tty",
"ui"
],
"verb": {
"toc": true,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"lint": {
"reflinks": true
},
"related": {
"list": [
"enquirer-question",
"enquirer-prompt",
"prompt-choices",
"readline-utils"
]
},
"reflinks": [
"assemble",
"enquirer-prompt",
"enquirer-question",
"generate",
"inquirer",
"update",
"verb",
"verb-generate-readme",
"enquirer-prompt-checkbox",
"enquirer-prompt-confirm",
"enquirer-prompt-editor",
"enquirer-prompt-expand",
"enquirer-prompt-input",
"enquirer-prompt-list",
"enquirer-prompt-password",
"enquirer-prompt-radio",
"enquirer-prompt-rawlist",
"enquirer-prompts"
]
}
}

@@ -1,7 +0,30 @@

# enquirer [![NPM version](https://badge.fury.io/js/enquirer.svg)](https://npmjs.org/package/enquirer) [![Build Status](https://travis-ci.org/jonschlinkert/enquirer.svg?branch=master)](https://travis-ci.org/jonschlinkert/enquirer)
# enquirer [![NPM version](https://img.shields.io/npm/v/enquirer.svg?style=flat)](https://www.npmjs.com/package/enquirer) [![NPM downloads](https://img.shields.io/npm/dm/enquirer.svg?style=flat)](https://npmjs.org/package/enquirer) [![Build Status](https://img.shields.io/travis/jonschlinkert/enquirer.svg?style=flat)](https://travis-ci.org/jonschlinkert/enquirer)
> Plugin based prompt system for node.js
Intuitive, plugin-based prompt system for node.js. Much faster alternative to Inquirer, with all the same prompt types and more.
## Installation
## Table of Contents
- [Install](#install)
- [What is this?](#what-is-this)
- [Why another prompt modules?](#why-another-prompt-modules)
- [Usage](#usage)
- [API](#api)
- [Prompt types](#prompt-types)
* [Publishing prompt types](#publishing-prompt-types)
- [Plugins](#plugins)
* [Publishing plugins](#publishing-plugins)
- [About](#about)
* [Related projects](#related-projects)
* [Contributing](#contributing)
* [Building docs](#building-docs)
* [Running tests](#running-tests)
* [Author](#author)
* [License](#license)
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
## Install
Install with [npm](https://www.npmjs.com/):
```sh

@@ -11,2 +34,20 @@ $ npm install --save enquirer

## What is this?
This is a faster, lighter, plugin-based alternative to [inquirer](https://github.com/sboudrias/Inquirer.js), with support for all of the same prompt types and features.
## Why another prompt modules?
We use prompts extensively in [generate](https://github.com/generate/generate), [verb](https://github.com/verbose/verb), [update](https://github.com/update/update) and [assemble](https://github.com/assemble/assemble), and other libries we maintain, and we wanted to improve the user experience and reduce dependencies associated with other libraries we tried, like Inquirer.
**Initial load time**
Enquirer takes **~11ms** to load. This is about the same amount of time that it takes [chalk](https://github.com/chalk/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 this cuts into that threshold significantly, leaving less room for everything else.
## Usage

@@ -16,7 +57,200 @@

var enquirer = require('enquirer');
enquirer();
```
## License
## API
MIT © [Jon Schlinkert](https://github.com/jonschlinkert)
### [Enquirer](index.js#L17)
Create an instance of `Enquirer` with the given `options`.
**Params**
* `options` **{Object}**
**Example**
```js
var enquirer = new Enquirer();
```
### [.register](index.js#L73)
Register a new prompt `type` with the given `fn`.
**Params**
* `type` **{String}**: The name of the prompt type
* `fn` **{Function}**: Prompt function that inherits from [enquirer-prompt](https://github.com/enquirer/enquirer-prompt).
* `returns` **{Object}**: Returns the Enquirer instance for chaining.
**Example**
```js
enquirer.register('confirm', require('enquirer-prompt-confirm'));
```
### [.use](index.js#L92)
Invoke a plugin `fn`
**Params**
* `fn` **{Function}**: Function that takes an instance of `Enquirer`
* `returns` **{Object}**: Returns the instance for chaining.
**Example**
```js
enquirer.use(require('some-enquirer-plugin'));
```
### [.question](index.js#L112)
Create question `name` with the given `message` and `options`. Uses [enquirer-question](https://github.com/enquirer/enquirer-question), visit that library for additional details.
**Params**
* `name` **{String|Object}**: Name or options object
* `message` **{String|Object}**: Message or options object
* `options` **{Object}**
* `returns` **{Object}**: Returns the created question object
**Events**
* `emits`: `question`
**Example**
```js
var question = enquirer.question('name', 'What is your name?');
```
### [.ask](index.js#L162)
Initialize a prompt session for one or more questions.
* `returns` **{Array|Object}** `questions`: One or more question objects or names of registered questions.
**Events**
* `emits`: `ask` With the array of `questions` to be asked
**Example**
```js
enquirer.question('first', 'First name?');
enquirer.question('last', 'Last name?');
enquirer.ask('first')
.then(function(answers) {
console.log(answers)
});
```
### [.prompt](index.js#L196)
Initialize a prompt session for a single question. Used by the [ask](#ask) method.
**Params**
* `name` **{String}**
**Events**
* `emits`: `prompt` with the `default` value, `key`, `question` object, and `answers` object
* `emits`: `answer` with the `answer` value, `key`, `question` object, and `answers` object
**Example**
```js
enquirer.question('first', 'First name?');
enquirer.prompt('first')
.then(function(answers) {
console.log(answers)
});
```
## Prompt types
**What is a prompt "type"?**
Prompt types determine the type of question, or prompt, to initiate. Currently, the only prompt type included in enquirer is `input`.
The following types are all available as plugins:
* [ ] `checkbox` ([enquirer-prompt-checkbox][])
* [ ] `confirm` ([enquirer-prompt-confirm][])
* [ ] `editor` ([enquirer-prompt-editor][])
* [ ] `expand` ([enquirer-prompt-expand][])
* [x] `input` ([enquirer-prompt-input](https://github.com/jonschlinkert/enquirer-prompt-input)) (included in enquirer by default)
* [ ] `list` ([enquirer-prompt-list][])
* [ ] `password` ([enquirer-prompt-password][])
* [ ] `radio` ([enquirer-prompt-radio][])
* [ ] `rawlist` ([enquirer-prompt-rawlist][])
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 `enquirer-prompt-*`.
TBC
## Plugins
TODO
### Publishing plugins
Plugin modules are named using the convention `enquirer-*`.
TBC
## About
### Related projects
* [enquirer-prompt](https://www.npmjs.com/package/enquirer-prompt): Base prompt module used for creating custom prompt types for Enquirer. | [homepage](https://github.com/enquirer/enquirer-prompt "Base prompt module used for creating custom prompt types for Enquirer.")
* [enquirer-question](https://www.npmjs.com/package/enquirer-question): Question object, used by Enquirer and prompt plugins. | [homepage](https://github.com/enquirer/enquirer-question "Question object, used by Enquirer and prompt plugins.")
* [prompt-choices](https://www.npmjs.com/package/prompt-choices): Create an array of multiple choice objects for use in prompts. | [homepage](https://github.com/enquirer/prompt-choices "Create an array of multiple choice objects for use in prompts.")
* [readline-utils](https://www.npmjs.com/package/readline-utils): Readline utils, for moving the cursor, clearing lines, creating a readline interface, and more. | [homepage](https://github.com/enquirer/readline-utils "Readline utils, for moving the cursor, clearing lines, creating a readline interface, and more.")
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Please read the [contributing guide](.github/contributing.md) for avice on opening issues, pull requests, and coding standards.
### Building docs
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
```sh
$ npm install -g verb verb-generate-readme && verb
```
### Running tests
Install dev dependencies:
```sh
$ npm install -d && npm test
```
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
### License
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/enquirer/blob/master/LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.30, on August 28, 2016._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc