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 2.0.1 to 2.1.0

2

index.js
module.exports = require("./lib/qa");
module.exports.Question = require('./lib/question').Question;
module.exports.NewQuestion = require('./lib/question');

@@ -18,2 +18,3 @@ var struct = require("new-struct");

module.exports = NewQA;
module.exports.QA = QA;

@@ -20,0 +21,0 @@ function NewQA (options) {

11

lib/question.js

@@ -15,2 +15,3 @@ var struct = require("new-struct");

lines: lines,
render: render,
validate: validate

@@ -30,3 +31,3 @@ });

return Question({
return (this.struct || Question)({
QA: QA,

@@ -45,3 +46,3 @@ key: options.key || generateKey(options),

return ' '
+ style(formatText(question.title, question.QA.context()))
+ style(question.render(question.title))
+ (question.list ? '\n' : ' ');

@@ -60,3 +61,3 @@ }

answer = isEmpty(answer) && question.default || answer;
answer = isEmpty(answer) && question.render(question.default) || answer;

@@ -83,2 +84,6 @@ callback(undefined, answer);

function render (question, text) {
return formatText(text, question.QA.context());
}
function validate (question, answer) {

@@ -85,0 +90,0 @@ return question.expect && validateValue(answer, question.expect);

{
"name": "cli-qa",
"version": "2.0.1",
"version": "2.1.0",
"description": "Command-line Questions & Answers",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,15 +16,14 @@ ## cli-qa

```js
var QA = require('cli-qa')
var NewQA = require('cli-qa')
var questions = [
"{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 },
];
var QA = NewQA()
QA.ask("{white}Name:{reset}")
QA.ask({ title: "Username:", default: process.env.USER })
QA.ask({ key: "email", title: "E-Mail:", expect: { email: true } })
QA.ask({ title: "{red}Favorite foods:{reset}", list: 3 })
QA.ask({ key: "books", title: "{white}Favorite books:{reset}", list: true })
QA.ask({ title: "{yellow}Favorite {green}Fruits{reset}:", commaList: true })
QA.ask({ key: 'thatsAll', title: "{yellow}That's all, {name}? (yes/no){reset}", yesno: true })
QA(questions, function (answers) {
QA.start(function (answers) {
console.log(answers)

@@ -60,6 +59,6 @@ // => {

* 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.*
* 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.*
* bool: *Yes/no question? true/false*
* yesno: *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.*
* expect: *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