Comparing version 0.2.0 to 0.3.0
@@ -6,2 +6,3 @@ var QA = require('./'); | ||
{ title: "Username:", default: process.env.USER }, | ||
{ title: "E-Mail:", validate: { email: true } }, | ||
{ title: "{bold}Favorite foods:{reset}", list: 3 }, | ||
@@ -8,0 +9,0 @@ { key: "books", title: "{bold}Favorite books {grey}(Type as much as you want!){reset}{bold}:{reset}", list: true }, |
17
index.js
@@ -6,2 +6,3 @@ var read = require("read-cli-input"); | ||
var leftpad = require("left-pad"); | ||
var validate = require("validate-value"); | ||
@@ -57,3 +58,9 @@ module.exports = QA; | ||
if (question.default && !answer && (!answer.trim || !answer.trim())) { | ||
var err; | ||
if (question.validate && (err = validate(answer, question.validate))) { | ||
options.stdout.write(formatError(err)); | ||
return ask(question, options, callback); | ||
} | ||
if (question.default && isEmpty(answer)) { | ||
answer = question.default; | ||
@@ -124,1 +131,9 @@ } | ||
} | ||
function isEmpty (str) { | ||
return !str && (!str.trim || !str.trim()); | ||
} | ||
function formatError (err) { | ||
return format('\n {red}{bold}Error: ' + err.message + '{reset}\n'); | ||
} |
{ | ||
"name": "cli-qa", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Command-line Questions & Answers", | ||
@@ -30,4 +30,5 @@ "main": "index.js", | ||
"style-format": "0.0.0", | ||
"validate-value": "0.0.0", | ||
"variable-name": "0.0.2" | ||
} | ||
} |
@@ -19,7 +19,9 @@ ## cli-qa | ||
var questions = [ | ||
{ key: "name", title: "Hey! What's your name?" }, | ||
{ key: "foods", title: "What are your 3 most favorite foods?", list: 3 }, | ||
{ title: "Favorite books?", description: "Type as much as you want!", list: true }, // unlimited list input | ||
"Thoughts?", | ||
{ title: "That's all?", description: "Yes/No", bool: true } | ||
"{bold}Name:{reset}", | ||
{ title: "Username:", default: process.env.USER }, | ||
{ key: "email", title: "E-Mail:", validate: { email: true } }, | ||
{ title: "{bold}Favorite foods:{reset}", list: 3 }, | ||
{ key: "books", title: "{bold}Favorite books {grey}(Type as much as you want!){reset}{bold}:{reset}", list: true }, | ||
{ title: "{yellow}Favorite {green}Fruits{reset}:", commaList: true }, | ||
{ key: 'thatsAll', title: "{yellow}{bold}That's all {grey}(yes/no) {yellow}?{reset}", bool: true }, | ||
]; | ||
@@ -31,2 +33,4 @@ | ||
// "name": "Azer", | ||
// "username": "ak", | ||
// "email": "azer@roadbeats.com", | ||
// "foods": ["falafel", "babi guling", "kebab"], | ||
@@ -50,1 +54,13 @@ // "favoriteBooks": ["snow", "white castle"], | ||
``` | ||
### Reference | ||
The list of available options for each question: | ||
* key: *The key that will be used in the answers object. If not specified, [it'll be auto-generated](http://github.com/azer/variable-name).* | ||
* title: *Title of the question. [styling](http://github.com/azer/style-format) accepted.* | ||
* list: *Specify "true" if a numerical list is expected as an answer.* | ||
* commaList: *Specify "true" if a comma-separated list is expected as an answer.* | ||
* bool: *Yes/no question? true/false* | ||
* default: *Default value if answer is empty.* | ||
* validate: *Specify [requirements](https://github.com/azer/validate-value#reference) for [validating](https://github.com/azer/validate-value) the user input.* |
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
6134
123
64
6
+ Addedvalidate-value@0.0.0
+ Addednew-error@0.0.0(transitive)
+ Addednew-format@2.0.0(transitive)
+ Addedvalidate-value@0.0.0(transitive)