npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prompt-improved

v0.1.10

Published

Prompts for beautiful and configurable CLI interfaces

Downloads

7

Readme

Prompts Improved

Node.js promots like you always wanted. Style them to your heart's content using Chalk, an amazing CLI package for colors and text styling. Features include:

  • Default options
  • Input validation (using regexe's or functions)
  • Input filters (both before validation and after)
  • Required fields
  • Input attempt limits (think limiting password tries)
  • Ask single or multiple questions
  • When asking multiple questions, subsequent questions can be dependant on previous input. This allows for simple prompt path logic.
  • Configurable prefixs and suffixes
  • Custom error messaging
  • Input timeouts
  • Per-prompt configuration
  • Convient error handeling
  • 100% test coverage
  • (Coming Soon) Multiple choice questions

Examples

Just ask your user a question:

var Prompt = require('prompt-imporved');

var prompt = new Prompt({
	// Some options for all prompts
	prefix: '[?] ',
	prefixTheme: Prompt.chalk.green
});

prompt.ask('Where in the world is Carmen Sandiego?', function(err, res) {
	if (err) return console.error(err); // err is null if no errors
	console.log('Response: ' + res);
});

// Outputs: [?] Where in the world is Carmen Sandiego?: 

Options can be provided for all prompts or overridden on a per-prompt basis:

var Prompt = require('prompt-imporved');

var prompt = new Prompt({
	suffix: '? '
});

prompt.ask('How is your day going beautiful', function(err, res) {
	if (err) return console.error(err);
	console.log('Response: ' + res);
});

// Outputs: How is your day going beautiful?  

Asking multiple questions:

var Prompt = require('prompt-imporved');
var prompt = new Prompt();
prompt.ask([{
	question: 'Who\'s your daddy?',
	key: 'father',
}, {
	question: 'What is your Mothers name?',
}], function(err, res) {
	if (err) return console.error(err);
	console.log('Father\'s name: ' res.father);
	console.log('Mother\'s name: ' res['What is your Mothers name?']);
});

Full example will all options:

var Prompt = require('prompt-imporved');

// These are all the defaults
var prompt = new Prompt({
	prefix        : '',
	suffix        : ': ',
	defaultPrefix : ' (',
	defaultSuffix : ')',
	textTheme     : Prompt.chalk.bold,
	prefixTheme   : Prompt.chalk.white,
	suffixTheme   : Prompt.chalk.white,
	defaultTheme  : Prompt.chalk.white,
	inputError    : 'Error encountered, try again.',
	requiredError : 'Required! Try again.',
	invalidError  : 'Invalid input: ',
	attemptsError : 'Maximum attempts reached!',
	stdin         : process.stdin,
	stdout        : process.stdout,
	stderr        : process.stderr,
	timeout       : null
});

// Each question can have it's own options
prompt.ask([{
	question: 'A yes or no question',
	key: 'answer-key',
	attempts: 3,
	required: true,
	default: 'Y',
	validate: /^(?:y(?:es)?|n(?:o)?)$/i,
	after: function(value) {
		value = value.toLowerCase();
		if (value === 'y' || value === 'yes') return true;
		return false;
	}
}{
	question: 'Something where the first letter should be uppercase',
	key: 'answer-key1',
	before: function(val) {
		return val.charAt(0).toUpperCase() + val.slice(1);
	},
	depends: function(answers) {
		return !!answers['answer-key'];
	}
}], function(err, res) {
	if (err) return console.error(err);
	console.log('Response: ' + res);
});

Tests

Unit tests and test coverage are available:

// runs the tests and watches for file changes
$ grunt 

// Runs the coverage generator and opens your borwser to the results
$ grunt coverage

Contributions

Please contribute. Please make pull requests against the develop branch.