Comparing version 0.2.8 to 0.2.9
@@ -298,3 +298,3 @@ /* | ||
var keys; | ||
if (typeof attr !== 'object') { | ||
if (typeof attr !== 'object' || attr instanceof Array) { | ||
return attr; | ||
@@ -377,2 +377,7 @@ } | ||
// Variables needed outside of getInput for multiline arrays. | ||
var tmp = []; | ||
// ### function getInput (prop, callback) | ||
@@ -451,2 +456,18 @@ // #### @prop {Object|string} Variable to get input for. | ||
var type = (schema.properties && schema.properties[name] && | ||
schema.properties[name].type || '').toLowerCase().trim(), | ||
wait = type === 'array'; | ||
if (type === 'array') { | ||
length = prop.schema.maxItems; | ||
if (length) { | ||
msg = (tmp.length + 1).toString() + '/' + length.toString(); | ||
} | ||
else { | ||
msg = (tmp.length + 1).toString(); | ||
} | ||
msg += delim; | ||
raw.push(prompt.colors ? msg.grey : msg); | ||
} | ||
// | ||
@@ -492,3 +513,3 @@ // Calculate the raw length and colorize the prompt | ||
}, function (err, line) { | ||
if (err) { | ||
if (err && wait === false) { | ||
return callback(err); | ||
@@ -503,21 +524,56 @@ } | ||
// | ||
// Attempt to parse input as a float if the schema expects a number. | ||
// | ||
if (schema.properties[name] && schema.properties[name].type == 'number') { | ||
numericInput = parseFloat(line, 10); | ||
if (!isNaN(numericInput)) { | ||
line = numericInput; | ||
if (schema.properties[name]) { | ||
var type = (schema.properties[name].type || '').toLowerCase().trim() || undefined; | ||
// | ||
// Attempt to parse input as a float if the schema expects a number. | ||
// | ||
if (type == 'number') { | ||
numericInput = parseFloat(line, 10); | ||
if (!isNaN(numericInput)) { | ||
line = numericInput; | ||
} | ||
} | ||
} | ||
// | ||
// Attempt to parse input as a boolean if the schema expects a boolean | ||
// | ||
if (schema.properties[name] && schema.properties[name].type == 'boolean') { | ||
if(line === "true") { | ||
line = true; | ||
// | ||
// Attempt to parse input as a boolean if the schema expects a boolean | ||
// | ||
if (type == 'boolean') { | ||
if(line === "true") { | ||
line = true; | ||
} | ||
if(line === "false") { | ||
line = false; | ||
} | ||
} | ||
if(line === "false") { | ||
line = false; | ||
// | ||
// If the type is an array, wait for the end. Fixes #54 | ||
// | ||
if (type == 'array') { | ||
var length = prop.schema.maxItems; | ||
if (err) { | ||
if (err.message == 'canceled') { | ||
wait = false; | ||
stdout.write('\n'); | ||
} | ||
} | ||
else { | ||
if (length) { | ||
if (tmp.length + 1 < length) { | ||
isValid = false; | ||
wait = true; | ||
} | ||
else { | ||
isValid = true; | ||
wait = false; | ||
} | ||
} | ||
else { | ||
isValid = false; | ||
wait = true; | ||
} | ||
tmp.push(line); | ||
} | ||
line = tmp; | ||
} | ||
@@ -528,9 +584,9 @@ } | ||
} | ||
if(schema.properties[name] && schema.properties[name].before) { | ||
line = schema.properties[name].before(line); | ||
if (prop && prop.schema.before) { | ||
line = prop.schema.before(line); | ||
} | ||
// Validate | ||
isValid = prompt._performValidation(name, prop, against, schema, line, callback); | ||
if (isValid === undefined) isValid = prompt._performValidation(name, prop, against, schema, line, callback); | ||
@@ -549,2 +605,5 @@ if (!isValid) { | ||
callback(null, line); | ||
// Make sure `tmp` is emptied | ||
tmp = []; | ||
}); | ||
@@ -551,0 +610,0 @@ }; |
{ | ||
"name": "prompt", | ||
"description": "A beautiful command-line prompt for node.js", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"author": "Nodejitsu Inc. <info@nodejitsu.com>", | ||
@@ -22,3 +22,3 @@ "maintainers": [ | ||
"devDependencies": { | ||
"vows": "0.6.x" | ||
"vows": "0.7.0" | ||
}, | ||
@@ -25,0 +25,0 @@ "main": "./lib/prompt", |
@@ -106,2 +106,3 @@ # prompt [![Build Status](https://secure.travis-ci.org/flatiron/prompt.png)](http://travis-ci.org/flatiron/prompt) | ||
description: 'Enter your password', // Prompt displayed to the user. If not supplied name will be used. | ||
type: 'string', // Specify the type of input to expect. | ||
pattern: /^\w+$/, // Regular expression that input must be valid against. | ||
@@ -118,2 +119,11 @@ message: 'Password must be letters', // Warning message to display if validation fails. | ||
Using `type: 'array'` has some special cases. | ||
- `description` will not work in the schema if `type: 'array'` is defined. | ||
- `maxItems` takes precedence over `minItems`. | ||
- Arrays that do not have `maxItems` defined will require users to `SIGINT` (`^C`) before the array is ended. | ||
- If `SIGINT` (`^C`) is triggered before `minItems` is met, a validation error will appear. This will require users to `SIGEOF` (`^D`) to end the input. | ||
For more information on things such as `maxItems` and `minItems`, refer to the [revalidator](https://github.com/flatiron/revalidator) repository. | ||
### Alternate Validation API: | ||
@@ -120,0 +130,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
117316
2103
294
25
1