Comparing version 1.0.0 to 1.0.1
40
index.js
@@ -11,5 +11,5 @@ 'use strict'; | ||
var isObject = require('isobject'); | ||
var UI = require('readline-ui'); | ||
var get = require('get-value'); | ||
var set = require('set-value'); | ||
var UI = require('readline-ui'); | ||
@@ -29,11 +29,11 @@ /** | ||
debug('initializing from <%s>', __filename); | ||
if (!(this instanceof Enquirer)) { | ||
return new Enquirer(options); | ||
var proto = Object.create(Enquirer.prototype); | ||
Enquirer.apply(proto, arguments); | ||
return proto; | ||
} | ||
this.session = false; | ||
this.options = options || {}; | ||
this.questions = this.options.question || {}; | ||
this.answers = this.options.answers || {}; | ||
this.questions = {}; | ||
this.prompts = {}; | ||
@@ -159,2 +159,14 @@ this.queue = []; | ||
/** | ||
* Set a question on `enquirer.questions`. Same as [#question](#question) | ||
* but returns the enquirer instance instead of the question object. | ||
* | ||
* @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 enquirer instance | ||
* @api public | ||
*/ | ||
Enquirer.prototype.set = function() { | ||
@@ -165,2 +177,10 @@ this.question.apply(this, arguments); | ||
/** | ||
* Get a registered question from `enquirer.questions`. | ||
* | ||
* @param {String} `name` The name of the question to get. | ||
* @return {Object|undefined} Returns the question object or undefined. | ||
* @api public | ||
*/ | ||
Enquirer.prototype.get = function(name) { | ||
@@ -170,2 +190,10 @@ return get(this.questions, name); | ||
/** | ||
* Returns true if a question is registered on `enquirer.questions`. | ||
* | ||
* @param {String} `name` The name of the question to check for. | ||
* @return {Boolean} | ||
* @api public | ||
*/ | ||
Enquirer.prototype.has = function(name) { | ||
@@ -271,2 +299,4 @@ return this.questions.hasOwnProperty(name); | ||
var question = this.question(name).clone(); | ||
question.options = extend({}, this.options, question.options); | ||
var PromptType = this.prompts[question.type]; | ||
@@ -273,0 +303,0 @@ name = question.name; |
{ | ||
"name": "enquirer", | ||
"description": "Intuitive plugin-based prompt system for node.js.", | ||
"version": "1.0.0", | ||
"homepage": "https://enquirer.io", | ||
"description": "Intuitive, plugin-based prompt system for node.js.", | ||
"version": "1.0.1", | ||
"homepage": "http://enquirer.io", | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
@@ -36,9 +36,8 @@ "contributors": [ | ||
"promise-reduce": "^2.1.0", | ||
"prompt-base": "^1.0.2", | ||
"prompt-question": "^3.0.1", | ||
"readline-ui": "^2.2.1", | ||
"prompt-base": "^2.1.2", | ||
"prompt-question": "^3.0.3", | ||
"readline-ui": "^2.2.2", | ||
"set-value": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"capture-stream": "^0.1.2", | ||
"gulp": "^3.9.1", | ||
@@ -50,3 +49,3 @@ "gulp-eslint": "^3.0.1", | ||
"gulp-unused": "^0.2.1", | ||
"mocha": "^3.4.1", | ||
"mocha": "^3.4.2", | ||
"strip-color": "^0.1.0" | ||
@@ -120,3 +119,2 @@ }, | ||
"reflinks": [ | ||
"chalk", | ||
"enquirer", | ||
@@ -123,0 +121,0 @@ "enquirer-prompts", |
# enquirer [![NPM version](https://img.shields.io/npm/v/enquirer.svg?style=flat)](https://www.npmjs.com/package/enquirer) [![NPM monthly downloads](https://img.shields.io/npm/dm/enquirer.svg?style=flat)](https://npmjs.org/package/enquirer) [![NPM total downloads](https://img.shields.io/npm/dt/enquirer.svg?style=flat)](https://npmjs.org/package/enquirer) [![Linux Build Status](https://img.shields.io/travis/enquirer/enquirer.svg?style=flat&label=Travis)](https://travis-ci.org/enquirer/enquirer) | ||
> Intuitive plugin-based prompt system for node.js. | ||
> Intuitive, plugin-based prompt system for node.js. | ||
@@ -109,4 +109,38 @@ ## Table of Contents | ||
### [.ask](index.js#L220) | ||
### [.set](index.js#L169) | ||
Set a question on `enquirer.questions`. Same as [#question](#question) | ||
but returns the enquirer instance instead of the question object. | ||
**Params** | ||
* `name` **{String|Object}**: Name or options object | ||
* `message` **{String|Object}**: Message or options object | ||
* `options` **{Object}** | ||
* `returns` **{Object}**: Returns the enquirer instance | ||
**Events** | ||
* `emits`: `question` | ||
### [.get](index.js#L182) | ||
Get a registered question from `enquirer.questions`. | ||
**Params** | ||
* `name` **{String}**: The name of the question to get. | ||
* `returns` **{Object|undefined}**: Returns the question object or undefined. | ||
### [.has](index.js#L194) | ||
Returns true if a question is registered on `enquirer.questions`. | ||
**Params** | ||
* `name` **{String}**: The name of the question to check for. | ||
* `returns` **{Boolean}** | ||
### [.ask](index.js#L248) | ||
Initialize a prompt session for one or more questions. | ||
@@ -144,3 +178,3 @@ | ||
### [.prompt](index.js#L254) | ||
### [.prompt](index.js#L282) | ||
@@ -171,7 +205,7 @@ Initialize a prompt session for a single question. Used by the [ask](#ask) method. | ||
### [.separator](index.js#L303) | ||
### [.separator](index.js#L333) | ||
Create a new `Separator` to use in a choices array. | ||
### [.Separator](index.js#L326) | ||
### [.Separator](index.js#L356) | ||
@@ -228,22 +262,2 @@ Create a new `Separator` to use in a choices array. | ||
**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** 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 | ||
@@ -279,2 +293,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 22, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 28, 2017._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
319
289
23898
+ Addedprompt-actions@2.0.2(transitive)
+ Addedprompt-base@2.2.0(transitive)
- Removedprompt-actions@1.1.1(transitive)
- Removedprompt-base@1.0.5(transitive)
Updatedprompt-base@^2.1.2
Updatedprompt-question@^3.0.3
Updatedreadline-ui@^2.2.2