prompt-question
Advanced tools
Comparing version 2.0.1 to 2.1.0
24
index.js
@@ -5,2 +5,4 @@ 'use strict'; | ||
var Choices = require('prompt-choices'); | ||
var define = require('define-property'); | ||
var clone = require('clone-deep'); | ||
var koalas = require('koalas'); | ||
@@ -15,3 +17,3 @@ var utils = require('./lib/utils'); | ||
* console.log(question); | ||
* // Question { | ||
* // { | ||
* // type: 'input', | ||
@@ -38,4 +40,4 @@ * // name: 'color', | ||
this.type = 'input'; | ||
this.options = {}; | ||
this.type = 'input'; | ||
@@ -51,4 +53,4 @@ if (Array.isArray(message)) { | ||
utils.define(this, 'Choices', Choices); | ||
utils.define(this, 'isQuestion', true); | ||
define(this, 'Choices', Choices); | ||
define(this, 'isQuestion', true); | ||
utils.assign(this, { | ||
@@ -59,2 +61,6 @@ name: name, | ||
}); | ||
if (!utils.isString(this.name)) { | ||
throw new TypeError('expected name to be a non-empty string'); | ||
} | ||
} | ||
@@ -73,4 +79,3 @@ | ||
Question.prototype.clone = function() { | ||
var cache = utils.clone(this.cache); | ||
return new this.constructor(cache); | ||
return new this.constructor(clone(this.cache)); | ||
}; | ||
@@ -138,3 +143,6 @@ | ||
Question.prototype.getAnswer = function(val) { | ||
if (this.choices && this.choices.length) { | ||
if (this._choices && !this.choices.checked.length && this.default != null) { | ||
this.choices.check(this.default); | ||
} | ||
if (this._choices && this.choices.length) { | ||
return this.choices.checked; | ||
@@ -221,3 +229,3 @@ } | ||
Question.isQuestion = function(question) { | ||
return utils.isObject(question) && question.isQuestion; | ||
return utils.isObject(question) && question.isQuestion === true; | ||
}; | ||
@@ -224,0 +232,0 @@ |
'use strict'; | ||
var utils = require('lazy-cache')(require); | ||
var fn = require; | ||
require = utils; | ||
var define = require('define-property'); | ||
var extend = require('extend-shallow'); | ||
var typeOf = require('kind-of'); | ||
var utils = module.exports; | ||
/** | ||
* Lazily required module dependencies | ||
* Extend the given `obj` with `options`. Assigned values | ||
* are also on "question.cache" so that we can easily use | ||
* those when question.clone() is called | ||
*/ | ||
require('clone-deep', 'clone'); | ||
require('define-property', 'define'); | ||
require('extend-shallow', 'extend'); | ||
require('kind-of', 'typeOf'); | ||
require = fn; | ||
utils.assign = function(question, options) { | ||
var keys = Object.keys(options); | ||
var cache = {options: {}}; | ||
/** | ||
* Extend the given `obj` with `options` | ||
*/ | ||
for (var i = 0; i < keys.length; i++) { | ||
var key = keys[i]; | ||
var val = options[key]; | ||
utils.assign = function(obj, options) { | ||
var cache = {}; | ||
for (var key in options) { | ||
var val = options[key]; | ||
if (utils.isObject(val)) { | ||
utils.extend(cache, val); | ||
} else if (typeof val !== 'undefined') { | ||
extend(cache, val); | ||
} else if (val != null) { | ||
cache[key] = val; | ||
} | ||
} | ||
cache.message = cache.message || cache.name; | ||
utils.extend(obj, cache); | ||
utils.define(obj, 'cache', cache); | ||
if (cache.radio === true) { | ||
cache.options.radio = true; | ||
delete cache.radio; | ||
} | ||
if (!cache.message) { | ||
cache.message = cache.name; | ||
} | ||
define(question, 'cache', cache); | ||
var opts = question.options; | ||
extend(question, cache); | ||
question.options = extend({}, opts, cache.options); | ||
}; | ||
@@ -41,6 +50,14 @@ | ||
utils.isObject = function(val) { | ||
return utils.typeOf(val) === 'object'; | ||
return typeOf(val) === 'object'; | ||
}; | ||
/** | ||
* Return true if `str` is a non-empty string | ||
*/ | ||
utils.isString = function(str) { | ||
return str && typeof str === 'string'; | ||
}; | ||
/** | ||
* Expose `utils` modules | ||
@@ -47,0 +64,0 @@ */ |
{ | ||
"name": "prompt-question", | ||
"description": "Question object, used by Enquirer and prompt plugins.", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"homepage": "https://github.com/enquirer/prompt-question", | ||
@@ -30,3 +30,2 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"koalas": "^1.0.2", | ||
"lazy-cache": "^2.0.2", | ||
"prompt-choices": "^2.0.0" | ||
@@ -89,4 +88,2 @@ }, | ||
"reflinks": [ | ||
"verb", | ||
"verb-generate-readme", | ||
"base-prompt", | ||
@@ -93,0 +90,0 @@ "prompt-choices" |
@@ -87,2 +87,2 @@ # prompt-question [![NPM version](https://img.shields.io/npm/v/prompt-question.svg?style=flat)](https://www.npmjs.com/package/prompt-question) [![NPM monthly downloads](https://img.shields.io/npm/dm/prompt-question.svg?style=flat)](https://npmjs.org/package/prompt-question) [![NPM total downloads](https://img.shields.io/npm/dt/prompt-question.svg?style=flat)](https://npmjs.org/package/prompt-question) [![Linux Build Status](https://img.shields.io/travis/enquirer/prompt-question.svg?style=flat&label=Travis)](https://travis-ci.org/enquirer/prompt-question) | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 12, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 17, 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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
14166
7
274
1
- Removedlazy-cache@^2.0.2