Comparing version 0.2.7 to 0.2.8
@@ -347,10 +347,14 @@ /* | ||
// | ||
prompt.confirm = function (msg, callback) { | ||
var vars = !Array.isArray(msg) ? [msg] : msg, | ||
RX_Y = /^[yt]{1}/i, | ||
RX_YN = /^[yntf]{1}/i; | ||
prompt.confirm = function (/* msg, options, callback */) { | ||
var args = Array.prototype.slice.call(arguments), | ||
msg = args.shift(), | ||
callback = args.pop(), | ||
opts = args.shift(), | ||
vars = !Array.isArray(msg) ? [msg] : msg, | ||
RX_Y = /^[yt]{1}/i, | ||
RX_YN = /^[yntf]{1}/i; | ||
function confirm(target, next) { | ||
var yes = target.yes || RX_Y, | ||
options = { | ||
options = utile.mixin({ | ||
description: typeof target === 'string' ? target : target.description||'yes/no', | ||
@@ -360,4 +364,5 @@ pattern: target.pattern || RX_YN, | ||
message: target.message || 'yes/no' | ||
}; | ||
}, opts || {}); | ||
prompt.get([options], function (err, result) { | ||
@@ -520,2 +525,6 @@ next(err ? false : yes.test(result[options.name])); | ||
} | ||
if(schema.properties[name] && schema.properties[name].before) { | ||
line = schema.properties[name].before(line); | ||
} | ||
@@ -522,0 +531,0 @@ // Validate |
{ | ||
"name": "prompt", | ||
"description": "A beautiful command-line prompt for node.js", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"author": "Nodejitsu Inc. <info@nodejitsu.com>", | ||
@@ -6,0 +6,0 @@ "maintainers": [ |
@@ -111,2 +111,3 @@ # prompt [![Build Status](https://secure.travis-ci.org/flatiron/prompt.png)](http://travis-ci.org/flatiron/prompt) | ||
required: true // If true, value entered must be non-empty. | ||
before: function(value) { return 'v' + value; } // Runs before node-prompt callbacks. It modifies user's input | ||
} | ||
@@ -113,0 +114,0 @@ ``` |
@@ -12,3 +12,3 @@ /* | ||
exports.shouldConfirm = function (options) { | ||
exports.shouldConfirm = function (options, mixin) { | ||
var message = options.response.toString().replace(/\n/g, ''), | ||
@@ -29,3 +29,6 @@ messages = ["When using prompt", "the confirm() method"], | ||
topic: function () { | ||
prompt.confirm(options.prop, this.callback); | ||
if(!mixin) | ||
prompt.confirm(options.prop, this.callback); | ||
else | ||
prompt.confirm(options.prop, mixin, this.callback); | ||
@@ -80,2 +83,3 @@ if (!Array.isArray(options.response)) { | ||
return context; | ||
}; | ||
}; | ||
@@ -377,2 +377,34 @@ /* | ||
"the get() method": { | ||
"with a simple string prompt": { | ||
"that is a property name in prompt.properties": { | ||
"with a sync function before (.before)": { | ||
topic: function() { | ||
var that = this; | ||
helpers.stdout.once('data', function(msg) { | ||
that.msg = msg; | ||
}); | ||
prompt.get({ | ||
properties: { | ||
fnbefore: { | ||
before: function(v) { | ||
return 'v' + v; | ||
} | ||
} | ||
} | ||
}, this.callback); | ||
helpers.stdin.writeNextTick('fn456\n'); | ||
}, | ||
"should modify user's input": function(e, result) { | ||
assert.equal(result.fnbefore, 'vfn456'); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the get() method": { | ||
"skip prompt with prompt.overide": { | ||
@@ -511,2 +543,10 @@ topic: function () { | ||
).addBatch( | ||
macros.shouldConfirm({ | ||
messages: ['with an empty string and default yes'], | ||
prop: 'test', | ||
response: '' | ||
}, { | ||
default: 'yes' | ||
}) | ||
).addBatch( | ||
macros.shouldNotConfirm({ | ||
@@ -513,0 +553,0 @@ messages: ['with a string message'], |
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
115629
26
2072
284
0