Socket
Socket
Sign inDemoInstall

prompt

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prompt - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

examples/override-validation.js

109

lib/prompt.js

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

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