
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
simple-prompt
Advanced tools
Simple commandline prompt for Node.js
While working on a Node.js automation tool I needed to generate some files and code after gathering a few details from the user. Most of the modules that I found were a bit of an over-kill, all I wanted was a good old prompt (like the browser type) so I wrote this module.
Version 0.2.0 breaks the 0.1.x API. If you want to use the old API please install v0.1.6.
The new version allows you create multiple simple-prompt
instances run independently.
npm install simple-prompt
Simple prompt accepts an array of question objects
var Prompt = require('simple-prompt');
var questions = [
{
question: 'Name',
required: true, // required
default: 'John' // default value
},
{
question: 'Last Name' //optional
},
{
question: 'Age',
required: true, // required
validate: function (answer) {
return parseInt(answer, 10) >= 18; // only 18 or higher
},
filter: function (answer) {
return parseInt(answer, 10); // bring back my answer as a number
},
default: 18 // default value
}
];
var profile = new Prompt(questions);
profile.create().then(function (error, answers) {
if (error) {
return;
}
var name = answers.Name;
var lastName = answers.LastName;
var age = answers.Age;
// Do something with values
});
var moreQuestions = [
{
question: 'Favourite Text Editor',
},
{
question: 'Favourite OS',
},
{
question: 'Favourite Beverage',
}
];
var favourites = new Prompt(moreQuestions);
favourites.create().then(function (error, answers) {
if (error) {
return;
}
var editor = answers.FavouriteTextEditor;
var os = answers.FavouriteOS;
var beverage = answers.FavouriteBeverage;
// Do something with values
});
The question object
has 4 properties that you can specify:
Simple-prompt only has 2 methods:
npm test
(MIT License)
Copyright (c) 2013 Qawelesizwe Mlilo qawemlilo@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Simple CLI prompt for Node
The npm package simple-prompt receives a total of 41 weekly downloads. As such, simple-prompt popularity was classified as not popular.
We found that simple-prompt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.