rapid-inquirer
Advanced tools
Comparing version 0.0.1 to 0.0.2
function promptsToBuildObject(obj, options) { | ||
var answers; | ||
if(!options) { | ||
@@ -8,6 +9,8 @@ options = {}; | ||
var keys = Object.keys(obj); | ||
var subObjects = []; | ||
keys.forEach(key => { | ||
var buildFieldPrompt = function(target, key, layerOptions) { | ||
var type, promptType; | ||
var val = obj[key]; | ||
var skipKey = false; | ||
var val = target[key]; | ||
if(val === undefined || val === null) { | ||
@@ -29,2 +32,5 @@ type = "string"; // No value defaults to string | ||
} else if(typeof val === "object" || val instanceof Object) { | ||
skipKey = true; | ||
subObjects.push({ key: key, obj: val }); | ||
} else { | ||
@@ -36,7 +42,7 @@ type = "string"; | ||
if(!options.onlyEmptyFields || type === "boolean" || val === undefined || val === null || val === '') { | ||
if(!skipKey && (!layerOptions.onlyEmptyFields || type === "boolean" || val === undefined || val === null || val === '')) { | ||
var p = { | ||
type: promptType, | ||
name: key, | ||
message: options.fieldPrefix ? `${options.fieldPrefix}.${key}: ` : `${key}: ` | ||
message: layerOptions.fieldPrefix ? `${layerOptions.fieldPrefix}.${key}: ` : `${key}: ` | ||
}; | ||
@@ -48,6 +54,17 @@ if(val !== undefined && val !== null && val !== "") { | ||
} | ||
}; | ||
keys.forEach(key => { | ||
buildFieldPrompt(obj, key, options); | ||
}); | ||
return this.prompt(prompts) | ||
.then(answers => { | ||
.then(results => { | ||
answers = results; | ||
return Promise.all(subObjects.map(sub => { | ||
return buildNestedObject.call(this, answers, sub.key, sub.obj, options); | ||
})); | ||
}) | ||
.then(() => { | ||
return answers; | ||
@@ -57,2 +74,12 @@ }); | ||
function buildNestedObject(answers, key, nestedObj, options) { | ||
var fieldPrefix = options.fieldPrefix ? `${options.fieldPrefix} ${key}` : `${key} `; | ||
var nestedOptions = Object.assign({}, options, { fieldPrefix: fieldPrefix }); | ||
return this.promptsToBuildObject(nestedObj, nestedOptions) | ||
.then(results => { | ||
answers[key] = results; | ||
return answers; | ||
}); | ||
} | ||
module.exports = promptsToBuildObject; |
{ | ||
"name": "rapid-inquirer", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Streamline extension for inquirer to have less overhead", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
18423
416