Giter VIP home page Giter VIP logo

minimal-prompt's Introduction

Minimal Prompt

Build Status

A library for creating command-line interfaces and harvesting information from them.

Installation

npm install minimal-prompt --save

Usage

prompt.question(questions, options)

Used to prompt the user with a specific set of questions and get their answers to each one.

Arguments

  1. questions (array): The set of questions to prompt the user with.
  2. options (object): An object describing the behavior of the prompt.

Options

  1. prompt (string): A string to begin each input line with.
  2. delimiter (string): A string to separate the prompt from the user input.
  3. onComplete (function): The function invoked when all questions are complete.
  4. formatPrompt (function): A function to format the prompt.
    • formatPrompt(prompt, delimiter, name)
      1. prompt (string): The specified prompt string.
      2. delimiter (string): The specified delimter string.
      3. name (string): If using a question prompt, the question being asked. (Only available for a question prompt)

Example

var prompt = require('minimal-prompt');

prompt.question(['First Name', 'Last Name'], {
    prompt: '>',
    delimiter: ':',
    formatPrompt: function(prompt, delim, name) {
        // Note: this is the default prompt for the question option.
        return prompt + delim + ' ' + name + delim + ' ';
    },
    onComplete: function(results) {
        console.log('First name:', results.firstName);
        console.log('Last name:', results.lastName);
    }
});

// prompt.start() will begin the prompting process.
prompt.start();

prompt.repeat(options)

Used to repeatedly prompt the user for information using the same prompt.

Arguments

  1. options (object): An object describing the behavior of the prompt.

Options

  1. prompt (string): A string to begin each input line with.
  2. delimiter (string): A string to separate the prompt from the user input.
  3. onLine (function): The function invoked when a new line of input is ready.
  4. formatPrompt (function): A function to format the prompt.
    • formatPrompt(prompt, delimiter)
      1. prompt (string): The specified prompt string.
      2. delimiter (string): The specified delimter string.

Example

var prompt = require('minimal-prompt');

prompt.repeat({
    prompt: '>',
    delimiter: ':',
    formatPrompt: function(prompt, delim, name) {
        // Note: this is the default prompt for the repeat option.
        return prompt + delim + ' ';
    },
    onLine: function(results) {
        console.log('Response:', res);
    }
});

// prompt.start() will begin the prompting process.
prompt.start();

minimal-prompt's People

Contributors

vicjohnson1213 avatar

Stargazers

Jrson avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.