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-wizard

v1.2.1

Published

CLI tool for multi-step user prompts

Downloads

7

Readme

prompt-wizard

A user-friendly library for creating multi-step CLI interfaces to collect user input.

Examples:

Examples

In its simplest form, a wizard will ask a series of questions before resolving a promise with the consolidated answers:

const wizard = Wizard.create([
    { prompt: 'What is your name?' },
    { prompt: 'What is your favourite colour?' }
]);

wizard.execute().then(console.log);

Custom Keys:

The keys that values are stored on in the final resolve object can be configured by setting a key property on the steps.

const wizard = Wizard.create([
    {
        prompt: 'What is your name?',
        key: 'name'
    },
    {
        prompt: 'What is your favourite colour?',
        key: 'colour'
    }
]);

wizard.execute().then(console.log);
/*
{ name: 'Lancelot', colour: 'blue' }
*/

Validation:

Fields can be marked as required to force the user to provide an answer. Unanswered fields will result in a warning message being shown and the prompt repeated:

const wizard = Wizard.create([
    {
        prompt: 'What is your name?',
        required: true
    },
    {
        prompt: 'What is your favourite colour?',
        required: true
    }
]);

wizard.execute().then(console.log);

Custom Validation:

Custom validation methods can be added to fields. These should return a falsy value for valid inputs, or a message to be displayed for invalid inputs.

const wizard = Wizard.create([
    {
        prompt: 'Username:',
        required: true,
        validate: (input) => input.match/^[a-z0-9]*$/i) ? null : 'username should contain only letters and numbers'
    }
]);

wizard.execute().then(console.log);

Password Input:

Password input can be hidden from view by passing a password: true option for the field. This will also prompt the user to re-enter their password. If the second input does not match the first then the user will be prompted again.

const wizard = Wizard.create([
    {
        prompt: 'Username:',
        required: true
    },
    {
        prompt: 'Password:',
        required: true,
        password: true
    }
]);

wizard.execute().then(console.log);

By default, this will replace input characters with '*'. This can be configured, or disabled, by setting a replace option.

The confirmation prompt can be set by passing the desired message as a confirm option.

Default Values:

The default value for an input can be passed with the default parameter. If this is se to a function then it is called with the previous fields' input values.

const wizard = Wizard.create([
    {
        prompt: 'Name:',
        key: 'name',
        required: true
    },
    {
        prompt: 'Username:',
        key: 'username',
        required: true,
        default: (i) => i.name.toLowerCase().replace(' ', '.')
    }
]);

wizard.execute().then(console.log);

Other Options

This module uses read under the hood, so any options that can be passed to read can also be configured on wizard steps.