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

souffleur

v2.0.1

Published

Simple command line prompt with retry for empty answers

Downloads

880

Readme

Souffleur

Simple promise-based command line prompt with retry for empty answers and without external dependencies.

Build Status npm version

Installation

npm install souffleur

Usage

Souffleur is simple promise based prompt.

If you have just one question pass the question as a string or object to souffleur or if you have more questions pass an array.

It'll return an object with each question as a key and each answer as a value.

const prompt = require('souffleur')

// For single question
prompt('Any question')
  .then(results => console.log(results))
// Returns {"Any question": "some answer"}
  
// For optional questions
prompt({
  question: 'Optional question',
  optional: true
})
  .then(results => console.log(results))
// Returns {"Optional question": null} if answer is empty

// For default values
prompt({
  question: 'Question',
  default: 42
})
  .then(results => console.log(results))
// Returns {"Question": 42} if answer is empty

// For multiple questions
prompt([
  'Question1',
  {
    question: 'Question 2',
    color: 'green',
    optional: true
  }])
  .then(results => console.log(results))
// Returns {"Question1": "Answer1", "Question 1": "Answer 2"}

If you pass an empty answer it'll prompt again with the same question unless you mark that question as an optional.

Simple demo:

API

suffleur(questions, [PromiseImplementation])

- questions

Questions can be string, object or an array.

In case of a string, that string will be used as a question and an answer will be required.

If you pass an object following options are allowed:

{
  question: '',   // String, required
  color: 'cyan',  // String, optional, one of the provided colors, default is cyan
  default: '',    // String or a number, optional, the default answer to the question
  optional: false // Boolean, optional, is an answer required, default is true
}

Available colors:

  • cyan
  • blue
  • green
  • magenta
  • red
  • yellow

String questions are the same as following object:

{
  question: 'Some question',
  color: 'cyan',
  optional: false
}

To pass multiple questions just pass an array of strings and objects.

- PromiseImplementation (optional)

Pass your promise implementation if you don't want to use the default one, you can use Bluebird and any other A+ Promise library.

- return

Souffleur always returns an object with questions as keys and answers as values.

If answer was empty, value will be null.

Running tests

Run all the tests:

npm run test

Run only some tests:

npm run test -- filter=prefix

Get detailed hierarchical test name reporting:

npm run test -- full

Other

Feather icon by Mister Pixel from the Noun Project.

Licence

MIT - see LICENCE