Comparing version 0.2.2 to 0.2.3
@@ -144,4 +144,4 @@ /* | ||
// | ||
// ### function get (msg, callback) | ||
// #### @msg {Array|Object|string} Set of variables to get input for. | ||
// ### function get (schema, callback) | ||
// #### @schema {Array|Object|string} Set of variables to get input for. | ||
// #### @callback {function} Continuation to pass control to when complete. | ||
@@ -193,3 +193,3 @@ // Gets input from the user via stdin for the specified message(s) `msg`. | ||
// 'prop-name' | ||
// | ||
// | ||
// ['string-name', { path: ['or-well-formed-subschema'], properties: ... }] | ||
@@ -203,3 +203,3 @@ // | ||
// | ||
// { path: ['path', 'to', 'property'], properties: { path: { to: ...} } } | ||
// { path: ['path', 'to', 'property'], properties: { path: { to: ...} } } | ||
// | ||
@@ -378,12 +378,4 @@ function iterate(schema, get, done) { | ||
// | ||
// Handle overrides here. | ||
// TODO: Make overrides nestable | ||
// | ||
if (prompt.override && prompt.override[propName]) { | ||
return callback(null, prompt.override[propName]); | ||
} | ||
// | ||
// If there is a stored schema for `propName` in `propmpt.properties` | ||
// then use it. | ||
// then use it. | ||
// | ||
@@ -402,3 +394,3 @@ if (schema instanceof Object && !Object.keys(schema).length && | ||
} | ||
schema = convert(schema); | ||
@@ -417,3 +409,3 @@ defaultLine = schema.default; | ||
// | ||
// If the schema has no `properties` value then set | ||
// If the schema has no `properties` value then set | ||
// it to an object containing the current schema | ||
@@ -429,4 +421,19 @@ // for `propName`. | ||
} | ||
// | ||
// Handle overrides here. | ||
// TODO: Make overrides nestable | ||
// | ||
if (prompt.override && prompt.override[propName]) { | ||
var isValid = prompt._performValidation(name, prop, prompt.override, schema, -1, callback); | ||
if(isValid){ | ||
return callback(null, prompt.override[propName]); | ||
}else{ | ||
delete prompt.override[propName]; | ||
} | ||
} | ||
// | ||
// Calculate the raw length and colorize the prompt | ||
@@ -464,3 +471,3 @@ // | ||
var against = {}, | ||
valid; | ||
isValid; | ||
@@ -475,19 +482,6 @@ if (typeof line !== 'string') { | ||
// Validate. | ||
try { valid = validate(against, schema) } | ||
catch (err) { return callback(err) } | ||
// Validate | ||
isValid = prompt._performValidation(name, prop, against, schema, line, callback); | ||
if (!valid.valid) { | ||
if (prompt.colors) { | ||
logger.error('Invalid input for ' + name.grey); | ||
} | ||
else { | ||
logger.error('Invalid input for ' + name); | ||
} | ||
if (prop.schema.message) { | ||
logger.error(prop.schema.message); | ||
} | ||
prompt.emit('invalid', prop, line); | ||
if(!isValid){ | ||
return prompt.getInput(prop, callback); | ||
@@ -508,2 +502,44 @@ } | ||
// | ||
// ### function performValidation (name, prop, against, schema, line, callback) | ||
// #### @name {Object} Variable name | ||
// #### @prop {Object|string} Variable to get input for. | ||
// #### @against {Object} Input | ||
// #### @schema {Object} Validation schema | ||
// #### @line {String|Boolean} Input line | ||
// #### @callback {function} Continuation to pass control to when complete. | ||
// Perfoms user input validation, print errors if needed and returns value according to validation | ||
// | ||
prompt._performValidation = function(name, prop, against, schema, line, callback){ | ||
var valid, msg; | ||
try { | ||
valid = validate(against, schema); | ||
} | ||
catch (err) { | ||
return (line !== -1) ? callback(err) : false; | ||
} | ||
if (!valid.valid) { | ||
msg = line !== -1 ? 'Invalid input for ' : 'Invalid command-line input for '; | ||
if (prompt.colors) { | ||
logger.error(msg + name.grey); | ||
} | ||
else { | ||
logger.error(msg + name); | ||
} | ||
if (prop.schema.message) { | ||
logger.error(prop.schema.message); | ||
} | ||
prompt.emit('invalid', prop, line); | ||
} | ||
return valid.valid; | ||
}; | ||
// | ||
// ### function addProperties (obj, properties, callback) | ||
@@ -603,4 +639,9 @@ // #### @obj {Object} Object to add properties to | ||
schema.message = schema.warning; | ||
schema.pattern = schema.validator; | ||
if (typeof schema.validator === 'function') { | ||
schema.conform = schema.validator; | ||
} else { | ||
schema.pattern = schema.validator; | ||
} | ||
if (typeof schema.empty !== 'undefined') { | ||
@@ -607,0 +648,0 @@ schema.required = !(schema.empty); |
{ | ||
"name": "prompt", | ||
"description": "A beautiful command-line prompt for node.js", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"author": "Nodejitsu Inc. <info@nodejitsu.com>", | ||
@@ -16,3 +16,3 @@ "maintainers": [ | ||
"pkginfo": "0.x.x", | ||
"read": "https://github.com/indexzero/read/tarball/refactor-optional-streams", | ||
"read": "0.1.x", | ||
"revalidator": "0.1.x", | ||
@@ -19,0 +19,0 @@ "utile": "0.1.x", |
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
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
111806
23
1909
0
+ Addedread@0.1.1(transitive)
Updatedread@0.1.x