Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cli-qa

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-qa - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

1

example.js

@@ -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 },

@@ -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');
}

3

package.json
{
"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.*
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc