Socket
Socket
Sign inDemoInstall

prompt

Package Overview
Dependencies
Maintainers
5
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.6 to 0.2.7

examples/schema.js

44

lib/prompt.js

@@ -463,2 +463,14 @@ /*

//
// If there is no default line, set it to an empty string
//
if(typeof defaultLine === 'undefined') {
defaultLine = '';
}
//
// set to string for readline ( will not accept Numbers )
//
defaultLine = defaultLine.toString();
//
// Make the actual read

@@ -469,3 +481,3 @@ //

silent: prop.schema && prop.schema.hidden,
default: defaultLine || '',
default: defaultLine,
input: stdin,

@@ -479,9 +491,29 @@ output: stdout

var against = {},
numericInput,
isValid;
if (typeof line !== 'string') {
line = '';
}
if (line !== '') {
if (line && line !== '') {
//
// 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;
}
}
//
// 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;
}
if(line === "false") {
line = false;
}
}
against[propName] = line;

@@ -519,3 +551,3 @@ }

prompt._performValidation = function (name, prop, against, schema, line, callback) {
var valid, msg;
var numericInput, valid, msg;

@@ -522,0 +554,0 @@ try {

2

package.json
{
"name": "prompt",
"description": "A beautiful command-line prompt for node.js",
"version": "0.2.6",
"version": "0.2.7",
"author": "Nodejitsu Inc. <info@nodejitsu.com>",

@@ -6,0 +6,0 @@ "maintainers": [

@@ -35,3 +35,3 @@ /*

['resume', 'pause', 'setEncoding', 'flush'].forEach(function (method) {
['resume', 'pause', 'setEncoding', 'flush', 'end'].forEach(function (method) {
MockReadWriteStream.prototype[method] = function () { /* Mock */ };

@@ -104,2 +104,7 @@ });

},
number: {
type: 'number',
message: 'pick a number, any number',
default: 10
},
username: {

@@ -106,0 +111,0 @@ pattern: /^[\w|\-]+$/,

@@ -35,2 +35,12 @@ /*

assert.equal(result, '123');
},
"and then when passed a complex property expecting a number": {
topic: function () {
winston.info('When prompted, enter: 123 [enter]');
prompt.getInput({ path: ['number'], schema: helpers.schema.properties.number }, this.callback);
},
"should respond with `123` (as a number)": function (err, result) {
assert.isNull(err);
assert.equal(result, 123);
}
}

@@ -37,0 +47,0 @@ }

@@ -281,2 +281,31 @@ /*

"that is a property name in prompt.properties": {
"that expects a numeric value": {
"and gets valid input": {
topic: function () {
var that = this;
helpers.stdout.once('data', function (msg) {
that.msg = msg;
});
prompt.properties.number = schema.properties.number;
prompt.get('number', this.callback);
helpers.stdin.writeNextTick('15\n');
},
"should prompt to stdout and respond with a numeric value": function (err, result) {
assert.isNull(err);
assert.include(result, 'number');
assert.equal(result['number'], 15);
}
}
}
}
}
}
}
}).addBatch({
"When using prompt": {
"the get() method": {
"with a simple string prompt": {
"that is a property name in prompt.properties": {
"with a sync function validator (.validator)": {

@@ -297,3 +326,3 @@ topic: function () {

}
},
}
}

@@ -300,0 +329,0 @@ }

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