Comparing version 0.1.0 to 0.2.0
23
index.js
@@ -11,4 +11,4 @@ 'use strict'; | ||
opts = {}; | ||
} else { | ||
opts = opts || {}; | ||
} else if (!opts) { | ||
opts = {}; | ||
} | ||
@@ -114,4 +114,4 @@ | ||
opts = {}; | ||
} else { | ||
opts = opts || {}; | ||
} else if (!opts) { | ||
opts = {}; | ||
} | ||
@@ -156,4 +156,4 @@ | ||
opts = {}; | ||
} else { | ||
opts = opts || {}; | ||
} else if (!opts) { | ||
opts = {}; | ||
} | ||
@@ -167,8 +167,13 @@ | ||
// Push the choice validator | ||
var nrChoices = choices.length; | ||
var validator = function (value) { | ||
if (choices.indexOf(value) === -1) { | ||
throw new Error('Invalid choice: ' + value); | ||
var x; | ||
for (x = 0; x < nrChoices; x++) { | ||
if (choices[x] == value) { | ||
return choices[x]; | ||
} | ||
} | ||
return value; | ||
throw new Error('Invalid choice: ' + value); | ||
}; | ||
@@ -175,0 +180,0 @@ opts.validator.push(validator); |
{ | ||
"name": "promptly", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Simple command line prompting utility", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,3 +0,2 @@ | ||
# promptly # | ||
--- | ||
# promptly | ||
@@ -8,3 +7,3 @@ [![Build Status](https://secure.travis-ci.org/IndigoUnited/node-promptly.png)](http://travis-ci.org/IndigoUnited/node-promptly.png) | ||
## Installation ## | ||
## Installation | ||
@@ -14,3 +13,3 @@ `$ npm install promptly` | ||
## API ## | ||
## API | ||
@@ -21,3 +20,3 @@ | ||
### .prompt(message, opts, fn) ### | ||
### .prompt(message, opts, fn) | ||
@@ -111,3 +110,3 @@ Prompts for a value, printing the `message` and waiting for the input. | ||
### .confirm(message, opts, fn) ### | ||
### .confirm(message, opts, fn) | ||
@@ -130,3 +129,3 @@ Ask the user to confirm something. | ||
### .choose(message, choices, opts, fn) ### | ||
### .choose(message, choices, opts, fn) | ||
@@ -145,3 +144,3 @@ Ask the user to choose between multiple `choices` (array of choices). | ||
### .password(message, opts, fn) ### | ||
### .password(message, opts, fn) | ||
@@ -162,4 +161,4 @@ Prompts for a password, printing the `message` and waiting for the input. | ||
## License ## | ||
## License | ||
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php). |
@@ -217,2 +217,16 @@ 'use strict'; | ||
}); | ||
it('should not use strict comparison when matching against valid choices', function (next) { | ||
stdout = ''; | ||
promptly.choose('choices: ', [1, 2, 3], function (err, value) { | ||
expect(err).to.be(null); | ||
expect(typeof value).to.equal('number'); | ||
expect(value).to.be(1); | ||
expect(stdout).to.contain('choices: '); | ||
next(); | ||
}); | ||
process.stdin.emit('data', '1\n'); | ||
}); | ||
}); | ||
@@ -219,0 +233,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
21796
405
158
1