Comparing version 2.1.2 to 2.2.0
@@ -38,3 +38,4 @@ var struct = require("new-struct"); | ||
default: options.default, | ||
expect: options.expect | ||
expect: options.expect, | ||
validateFn: options.validate | ||
}); | ||
@@ -58,8 +59,7 @@ } | ||
var err; | ||
if ((err = question.validate(answer))) { | ||
return callback(err); | ||
} | ||
question.validate(answer, function (error) { | ||
if (error) return callback(error); | ||
callback(undefined, answer); | ||
callback(undefined, answer); | ||
}); | ||
}); | ||
@@ -92,4 +92,11 @@ } | ||
function validate (question, answer) { | ||
return question.expect && validateValue(answer, question.expect); | ||
function validate (question, answer, callback) { | ||
var err; | ||
if (err = question.expect && validateValue(answer, question.expect)) { | ||
return callback(err); | ||
} | ||
if (question.validateFn) { | ||
question.validateFn(callback); | ||
} | ||
} | ||
@@ -96,0 +103,0 @@ |
{ | ||
"name": "cli-qa", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "Command-line Questions & Answers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,8 +45,24 @@ ## cli-qa | ||
* 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: *If a numeric value is passed, user will be prompted to enter a list with expected number of lines. If true passed, the list input won't be limited.* | ||
* commaList: *Specify "true" if a comma-separated list is expected as an answer.* | ||
* yesno: *Yes/no question? true/false* | ||
* default: *Default value if answer is empty.* | ||
* expect: *Specify [requirements](https://github.com/azer/validate-value#reference) for [validating](https://github.com/azer/validate-value) the user input.* | ||
##### 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 | ||
If a numeric value is passed, user will be prompted to enter a list with expected number of lines. If true passed, the list input won't be limited. | ||
##### commaList | ||
Specify "true" if a comma-separated list is expected as an answer | ||
##### yesno | ||
Yes/no question? true/false | ||
##### default | ||
Default value if answer is empty. | ||
##### expect | ||
Specify [requirements](https://github.com/azer/validate-value#reference) for [validating](https://github.com/azer/validate-value) the user input. | ||
##### validate | ||
Async validation function. See tests for example. |
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
8091
189
68