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.1 to 0.1.2

84

index.js

@@ -102,3 +102,21 @@ 'use strict';

* ```js
* var question = enquirer.question('name', 'What is your name?');
* 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'
* });
* ```

@@ -157,2 +175,11 @@ * @emits `question`

* });
*
* // errors
* enquirer.ask('first')
* .then(function(answers) {
* console.log(answers)
* })
* .catch(function(err) {
* console.log(err)
* });
* ```

@@ -208,30 +235,36 @@ * @emits `ask` With the array of `questions` to be asked

return new Promise(function(resolve, reject) {
try {
var question = self.question(name).clone();
var PromptType = self.prompts[question.type];
try {
var question = self.question(name).clone();
var PromptType = self.prompts[question.type];
if (typeof PromptType !== 'function') {
throw new Error(`prompt type "${question.type}" is not registered`);
}
if (typeof PromptType !== 'function') {
throw new Error(`prompt type "${question.type}" is not registered`);
}
var prompt = new PromptType(question, answers, self.ui);
self.emit('prompt', question.default, 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);
return val;
});
return prompt.run(answers)
.then(function(val) {
question.answer = val[name];
self.emit('answer', val[name], name, question, answers);
return val;
})
resolve(promise);
} catch (err) {
self.close();
reject(err);
}
});
} catch (err) {
self.close();
throw err;
}
};
/**
* Create a new `Separator` to use in a choices array.
* @api public
*/
Enquirer.prototype.separator = function(options) {
return new utils.Separator(options);
};
/**
* Visit `method` over the properties in the given object, or map

@@ -251,2 +284,9 @@ * visit over the object-elements in an array.

/**
* Create a new `Separator` to use in a choices array.
* @api public
*/
Enquirer.Separator = utils.Separator;
/**
* Decorate `Emitter` methods onto the Enquirer prototype

@@ -253,0 +293,0 @@ */

@@ -11,2 +11,3 @@ 'use strict';

require('choices-separator', 'Separator');
require('clone-deep', 'clone');

@@ -13,0 +14,0 @@ require('collection-visit', 'visit');

{
"name": "enquirer",
"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",
"description": "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.",
"version": "0.1.2",
"homepage": "https://github.com/enquirer/enquirer",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/enquirer",
"repository": "enquirer/enquirer",
"bugs": {
"url": "https://github.com/jonschlinkert/enquirer/issues"
"url": "https://github.com/enquirer/enquirer/issues"
},

@@ -26,2 +26,3 @@ "license": "MIT",

"dependencies": {
"choices-separator": "^0.1.0",
"clone-deep": "^0.2.4",

@@ -28,0 +29,0 @@ "collection-visit": "^0.2.3",

@@ -1,4 +0,4 @@

# 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)
# 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/enquirer/enquirer.svg?style=flat)](https://travis-ci.org/enquirer/enquirer)
Intuitive, plugin-based prompt system for node.js. Much faster alternative to Inquirer, with all the same prompt types and more.
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.

@@ -8,4 +8,2 @@ ## Table of Contents

- [Install](#install)
- [What is this?](#what-is-this)
- [Why another prompt modules?](#why-another-prompt-modules)
- [Usage](#usage)

@@ -17,2 +15,4 @@ - [API](#api)

* [Publishing plugins](#publishing-plugins)
- [TODO](#todo)
- [Why another prompt module?](#why-another-prompt-module)
- [About](#about)

@@ -36,20 +36,2 @@ * [Related projects](#related-projects)

## 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

@@ -108,3 +90,3 @@

### [.question](index.js#L112)
### [.question](index.js#L130)

@@ -127,6 +109,24 @@ Create question `name` with the given `message` and `options`. Uses [enquirer-question](https://github.com/enquirer/enquirer-question), visit that library for additional details.

```js
var question = enquirer.question('name', 'What is your name?');
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'
});
```
### [.ask](index.js#L162)
### [.ask](index.js#L189)

@@ -151,5 +151,14 @@ Initialize a prompt session for one or more questions.

});
// errors
enquirer.ask('first')
.then(function(answers) {
console.log(answers)
})
.catch(function(err) {
console.log(err)
});
```
### [.prompt](index.js#L196)
### [.prompt](index.js#L223)

@@ -177,2 +186,10 @@ Initialize a prompt session for a single question. Used by the [ask](#ask) method.

### [.separator](index.js#L262)
Create a new `Separator` to use in a choices array.
### [.Separator](index.js#L285)
Create a new `Separator` to use in a choices array.
## Prompt types

@@ -184,3 +201,3 @@

The following types are all available as plugins:
The following types are all available as plugins (note that all of these modules are finished, I'm pushing them up one-by-one, and will check them off as I go):

@@ -215,2 +232,39 @@ * [ ] `checkbox` ([enquirer-prompt-checkbox][])

## TODO
* [x] support promises
* [ ] support callbacks
* [ ] support es6 generators
* [ ] support async `filter`, `when` etc
## 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](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](https://github.com/SBoudrias/Inquirer.js#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](https://github.com/SBoudrias/Inquirer.js#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

@@ -259,6 +313,6 @@

Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/enquirer/blob/master/LICENSE).
Released under the [MIT license](https://github.com/enquirer/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._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.30, on August 29, 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